356 lines
13 KiB
JavaScript
356 lines
13 KiB
JavaScript
"use strict";
|
|
const common_vendor = require("../../common/vendor.js");
|
|
const common_assets = require("../../common/assets.js");
|
|
const api_good = require("../../api/good.js");
|
|
const api_cart = require("../../api/cart.js");
|
|
const store_cart = require("../../store/cart.js");
|
|
require("../../utils/request.js");
|
|
require("../../config/app.js");
|
|
require("../../store/user.js");
|
|
if (!Array) {
|
|
const _easycom_up_navbar2 = common_vendor.resolveComponent("up-navbar");
|
|
const _easycom_up_search2 = common_vendor.resolveComponent("up-search");
|
|
const _easycom_up_image2 = common_vendor.resolveComponent("up-image");
|
|
const _easycom_up_icon2 = common_vendor.resolveComponent("up-icon");
|
|
const _easycom_u__icon2 = common_vendor.resolveComponent("u--icon");
|
|
const _easycom_up_button2 = common_vendor.resolveComponent("up-button");
|
|
(_easycom_up_navbar2 + _easycom_up_search2 + _easycom_up_image2 + _easycom_up_icon2 + _easycom_u__icon2 + _easycom_up_button2)();
|
|
}
|
|
const _easycom_up_navbar = () => "../../uni_modules/uview-plus/components/u-navbar/u-navbar.js";
|
|
const _easycom_up_search = () => "../../uni_modules/uview-plus/components/u-search/u-search.js";
|
|
const _easycom_up_image = () => "../../uni_modules/uview-plus/components/u-image/u-image.js";
|
|
const _easycom_up_icon = () => "../../uni_modules/uview-plus/components/u-icon/u-icon.js";
|
|
const _easycom_u__icon = () => "../../uni_modules/uview-plus/components/u-icon/u-icon.js";
|
|
const _easycom_up_button = () => "../../uni_modules/uview-plus/components/u-button/u-button.js";
|
|
if (!Math) {
|
|
(_easycom_up_navbar + _easycom_up_search + _easycom_up_image + _easycom_up_icon + viewPopup + _easycom_u__icon + _easycom_up_button + goodPopup)();
|
|
}
|
|
const viewPopup = () => "../../components/viewPopup.js";
|
|
const goodPopup = () => "../../components/goodPopup.js";
|
|
const _sfc_main = {
|
|
__name: "index",
|
|
setup(__props) {
|
|
const cartStore = store_cart.useCartStore();
|
|
const show = common_vendor.ref(0);
|
|
const topActive = common_vendor.ref(0);
|
|
const changeOne = (item, index) => {
|
|
var _a, _b, _c;
|
|
console.log("选择", item, index);
|
|
topActive.value = item.id;
|
|
show.value = 0;
|
|
goodClassTow.value = (item == null ? void 0 : item.children) || [];
|
|
goodClassThree.value = ((_a = goodClassTow.value[0]) == null ? void 0 : _a.children) || [];
|
|
leftActive.value = ((_b = goodClassTow.value[0]) == null ? void 0 : _b.id) || "";
|
|
rightActive.value = ((_c = goodClassThree.value[0]) == null ? void 0 : _c.id) || "";
|
|
getGoodList();
|
|
};
|
|
const leftActive = common_vendor.ref(0);
|
|
const changeTwo = (item, index) => {
|
|
var _a;
|
|
console.log("选择", item, index);
|
|
leftActive.value = item.id;
|
|
show.value = 0;
|
|
goodClassThree.value = (item == null ? void 0 : item.children) || [];
|
|
rightActive.value = ((_a = goodClassThree.value[0]) == null ? void 0 : _a.id) || "";
|
|
getGoodList();
|
|
};
|
|
const rightActive = common_vendor.ref(0);
|
|
const changeThree = (item, index) => {
|
|
console.log("选择", item, index);
|
|
rightActive.value = item.id;
|
|
show.value = 0;
|
|
getGoodList();
|
|
};
|
|
const cartList = common_vendor.reactive(/* @__PURE__ */ new Map());
|
|
const addCart = (id, cart_num) => {
|
|
api_cart.cartCreateApi({
|
|
cart_num,
|
|
is_new: 0,
|
|
// 是否直接购买0否1是
|
|
goods_id: id
|
|
}).then((res) => {
|
|
console.log(res);
|
|
let now = cartList.get(id) || 0;
|
|
cartList.set(id, now + 1);
|
|
getCartList();
|
|
});
|
|
};
|
|
const keyword = common_vendor.ref("");
|
|
const searchKeyword = () => {
|
|
where.value.name = keyword.value;
|
|
getGoodList();
|
|
};
|
|
const changeOrder = (order) => {
|
|
console.log("排序", order);
|
|
where.value.order = order;
|
|
getGoodList();
|
|
};
|
|
const where = common_vendor.ref({
|
|
page_no: 1,
|
|
page_size: 25,
|
|
name: "",
|
|
order: ""
|
|
});
|
|
const loading = common_vendor.ref(true);
|
|
const goodList = common_vendor.ref([]);
|
|
const getGoodList = (loadmore = false) => {
|
|
loading.value = true;
|
|
let class_id = rightActive.value || leftActive.value || topActive.value || "";
|
|
let class_all = "";
|
|
if (rightActive.value == "")
|
|
class_all = leftActive.value;
|
|
if (leftActive.value == "")
|
|
class_all = topActive.value;
|
|
if (topActive.value == "")
|
|
class_all = "";
|
|
if (class_all)
|
|
class_id = "";
|
|
if (loadmore)
|
|
where.value.page_no++;
|
|
else
|
|
where.value.page_no = 1;
|
|
api_good.goodListApi({
|
|
...where.value,
|
|
class_all,
|
|
class: class_id
|
|
}).then((res) => {
|
|
if (loadmore)
|
|
goodList.value.push(...res.data.lists);
|
|
else
|
|
goodList.value = res.data.lists;
|
|
});
|
|
};
|
|
const loadMoreGood = () => {
|
|
console.log("触底了");
|
|
getGoodList(true);
|
|
};
|
|
const goodClassList = common_vendor.ref([]);
|
|
const goodClassTow = common_vendor.ref([]);
|
|
const goodClassThree = common_vendor.ref([]);
|
|
const getgoodClassList = () => {
|
|
api_good.goodClassListApi().then((res) => {
|
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
(_b = (_a = res.data) == null ? void 0 : _a.lists) == null ? void 0 : _b.unshift({
|
|
id: "",
|
|
name: "全部",
|
|
pic: "https://lihai001.oss-cn-chengdu.aliyuncs.com/def/35adb202404271727457954.png",
|
|
children: []
|
|
});
|
|
res.data.lists = res.data.lists.map((item) => {
|
|
var _a2;
|
|
if (!item.children)
|
|
item.children = [];
|
|
(_a2 = item.children) == null ? void 0 : _a2.unshift({
|
|
id: "",
|
|
pid: item.id,
|
|
name: "全部"
|
|
});
|
|
item.children = item.children.map((t) => {
|
|
var _a3;
|
|
if (!t.children)
|
|
t.children = [];
|
|
(_a3 = t.children) == null ? void 0 : _a3.unshift({
|
|
id: "",
|
|
pid: t.id,
|
|
name: "全部"
|
|
});
|
|
return t;
|
|
});
|
|
return item;
|
|
});
|
|
goodClassList.value = ((_c = res.data) == null ? void 0 : _c.lists) || [];
|
|
goodClassTow.value = ((_d = goodClassList.value[0]) == null ? void 0 : _d.children) || [];
|
|
goodClassThree.value = ((_e = goodClassTow.value[0]) == null ? void 0 : _e.children) || [];
|
|
topActive.value = (_f = goodClassList.value[0]) == null ? void 0 : _f.id;
|
|
leftActive.value = (_g = goodClassTow.value[0]) == null ? void 0 : _g.id;
|
|
rightActive.value = (_h = goodClassThree.value[0]) == null ? void 0 : _h.id;
|
|
});
|
|
};
|
|
const navTo = (url) => {
|
|
common_vendor.index.navigateTo({
|
|
url
|
|
});
|
|
};
|
|
const showGoodPopup = common_vendor.ref(false);
|
|
const goodRef = common_vendor.ref(null);
|
|
const goodData = common_vendor.ref({});
|
|
const openGoodPopup = (item) => {
|
|
goodData.value = item;
|
|
goodRef.value.setData(item);
|
|
showGoodPopup.value = true;
|
|
};
|
|
const changeGood = (data) => {
|
|
showGoodPopup.value = false;
|
|
addCart(data.id, data.cart_num);
|
|
};
|
|
const settleAccounts = () => {
|
|
common_vendor.index.navigateTo({
|
|
url: "/pagesOrder/settle/settle"
|
|
});
|
|
};
|
|
const cartInfo = common_vendor.ref({
|
|
total_price: "0.00",
|
|
count: 0
|
|
});
|
|
const getCartList = (res) => {
|
|
api_cart.cartListApi({
|
|
page_no: 1,
|
|
page_size: 100
|
|
}).then((res2) => {
|
|
var _a, _b, _c, _d;
|
|
cartInfo.value = {
|
|
total_price: ((_b = (_a = res2.data) == null ? void 0 : _a.extend) == null ? void 0 : _b.total_price) || "0.00",
|
|
count: ((_c = res2.data) == null ? void 0 : _c.count) || 0
|
|
};
|
|
cartStore.setCartList((_d = res2.data) == null ? void 0 : _d.lists.map((item) => item.cart_id));
|
|
});
|
|
};
|
|
common_vendor.onLoad(() => {
|
|
getgoodClassList();
|
|
getGoodList();
|
|
});
|
|
common_vendor.onShow(() => {
|
|
getCartList();
|
|
});
|
|
return (_ctx, _cache) => {
|
|
return common_vendor.e({
|
|
a: common_vendor.p({
|
|
placeholder: true
|
|
}),
|
|
b: common_vendor.o(searchKeyword),
|
|
c: common_vendor.o(searchKeyword),
|
|
d: common_vendor.o(($event) => keyword.value = $event),
|
|
e: common_vendor.p({
|
|
placeholder: "请输入商品",
|
|
showAction: false,
|
|
modelValue: keyword.value
|
|
}),
|
|
f: common_assets._imports_0$1,
|
|
g: common_vendor.o(($event) => navTo("/pages/cart/cart")),
|
|
h: common_assets._imports_1$1,
|
|
i: common_vendor.o(($event) => navTo("/pages/my/my")),
|
|
j: common_vendor.f(goodClassList.value, (item, index, i0) => {
|
|
return {
|
|
a: "1ba6254c-2-" + i0,
|
|
b: common_vendor.p({
|
|
height: "100rpx",
|
|
width: "100rpx",
|
|
src: item.pic
|
|
}),
|
|
c: common_vendor.t(item.name),
|
|
d: topActive.value === item.id ? 1 : "",
|
|
e: index,
|
|
f: common_vendor.o(($event) => changeOne(item, index), index)
|
|
};
|
|
}),
|
|
k: common_vendor.p({
|
|
name: "list"
|
|
}),
|
|
l: common_vendor.o(($event) => show.value = 1),
|
|
m: show.value === 1
|
|
}, show.value === 1 ? {
|
|
n: common_vendor.f(goodClassList.value, (item, index, i0) => {
|
|
return {
|
|
a: "1ba6254c-5-" + i0 + ",1ba6254c-4",
|
|
b: common_vendor.p({
|
|
height: "100rpx",
|
|
width: "100rpx",
|
|
src: item.pic
|
|
}),
|
|
c: common_vendor.t(item.name),
|
|
d: topActive.value === item.id ? 1 : "",
|
|
e: index,
|
|
f: common_vendor.o(($event) => changeOne(item, index), index)
|
|
};
|
|
}),
|
|
o: common_vendor.o(($event) => show.value = 0),
|
|
p: common_vendor.p({
|
|
nav: true
|
|
})
|
|
} : {}, {
|
|
q: common_vendor.f(goodClassTow.value, (item, index, i0) => {
|
|
return {
|
|
a: common_vendor.t(item.name),
|
|
b: leftActive.value === item.id ? 1 : "",
|
|
c: index,
|
|
d: common_vendor.o(($event) => changeTwo(item, index), index)
|
|
};
|
|
}),
|
|
r: common_vendor.f(goodClassThree.value, (item, index, i0) => {
|
|
return {
|
|
a: common_vendor.t(item.name),
|
|
b: rightActive.value === item.id ? 1 : "",
|
|
c: index,
|
|
d: common_vendor.o(($event) => changeThree(item, index), index)
|
|
};
|
|
}),
|
|
s: common_vendor.p({
|
|
name: "arrow-down"
|
|
}),
|
|
t: common_vendor.o(($event) => show.value = 2),
|
|
v: where.value.order == "" ? 1 : "",
|
|
w: common_vendor.o(($event) => changeOrder("")),
|
|
x: where.value.order == "desc" || where.value.order == "asc" ? 1 : "",
|
|
y: common_vendor.o(($event) => changeOrder(where.value.order == "asc" ? "desc" : "asc")),
|
|
z: where.value.order == "sales" ? 1 : "",
|
|
A: common_vendor.o(($event) => changeOrder("sales")),
|
|
B: show.value === 2
|
|
}, show.value === 2 ? {
|
|
C: common_vendor.f(goodClassThree.value, (item, index, i0) => {
|
|
return {
|
|
a: common_vendor.t(item.name),
|
|
b: rightActive.value === item.id ? 1 : "",
|
|
c: index,
|
|
d: common_vendor.o(($event) => changeThree(item, index), index)
|
|
};
|
|
}),
|
|
D: common_vendor.o(($event) => show.value = 0)
|
|
} : {}, {
|
|
E: common_vendor.f(goodList.value, (item, index, i0) => {
|
|
return {
|
|
a: "1ba6254c-8-" + i0,
|
|
b: common_vendor.p({
|
|
width: "160rpx",
|
|
height: "160rpx",
|
|
src: item.imgs
|
|
}),
|
|
c: common_vendor.t(item.name),
|
|
d: common_vendor.t(item.brand_name),
|
|
e: common_vendor.t(item.class_name),
|
|
f: common_vendor.t(item.unit_name),
|
|
g: common_vendor.t(item.sell),
|
|
h: "1ba6254c-9-" + i0,
|
|
i: item.id,
|
|
j: common_vendor.o(($event) => openGoodPopup(item), item.id)
|
|
};
|
|
}),
|
|
F: common_vendor.p({
|
|
name: "plus-circle-fill",
|
|
size: "20",
|
|
color: "#20b128"
|
|
}),
|
|
G: common_vendor.o(loadMoreGood),
|
|
H: common_vendor.t(cartInfo.value.total_price),
|
|
I: common_vendor.o(settleAccounts),
|
|
J: common_vendor.p({
|
|
color: "#20b128",
|
|
disabled: cartInfo.value.count == 0
|
|
}),
|
|
K: common_assets._imports_2,
|
|
L: common_vendor.t(cartInfo.value.count),
|
|
M: common_vendor.o(($event) => navTo("/pages/cart/cart")),
|
|
N: common_vendor.sr(goodRef, "1ba6254c-11", {
|
|
"k": "goodRef"
|
|
}),
|
|
O: common_vendor.o(($event) => showGoodPopup.value = false),
|
|
P: common_vendor.o(changeGood),
|
|
Q: common_vendor.p({
|
|
show: showGoodPopup.value
|
|
})
|
|
});
|
|
};
|
|
}
|
|
};
|
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/里海数字乡村/purchase-let/pages/index/index.vue"]]);
|
|
wx.createPage(MiniProgramPage);
|