purchase-let/unpackage/dist/dev/mp-weixin/pages/index/index.js

349 lines
13 KiB
JavaScript
Raw Normal View History

2024-04-25 18:02:30 +08:00
"use strict";
const common_vendor = require("../../common/vendor.js");
2024-04-29 10:44:50 +08:00
const common_assets = require("../../common/assets.js");
2024-04-28 18:08:57 +08:00
const api_good = require("../../api/good.js");
const api_cart = require("../../api/cart.js");
2024-04-29 18:14:58 +08:00
const store_cart = require("../../store/cart.js");
2024-04-28 18:08:57 +08:00
require("../../utils/request.js");
require("../../config/app.js");
require("../../store/user.js");
2024-04-25 18:02:30 +08:00
if (!Array) {
const _easycom_up_navbar2 = common_vendor.resolveComponent("up-navbar");
2024-04-29 10:44:50 +08:00
const _easycom_up_search2 = common_vendor.resolveComponent("up-search");
2024-04-28 18:08:57 +08:00
const _easycom_up_image2 = common_vendor.resolveComponent("up-image");
2024-04-25 18:02:30 +08:00
const _easycom_up_icon2 = common_vendor.resolveComponent("up-icon");
const _easycom_u__icon2 = common_vendor.resolveComponent("u--icon");
2024-04-29 10:44:50 +08:00
const _easycom_up_button2 = common_vendor.resolveComponent("up-button");
2024-04-29 18:14:58 +08:00
(_easycom_up_navbar2 + _easycom_up_search2 + _easycom_up_image2 + _easycom_up_icon2 + _easycom_u__icon2 + _easycom_up_button2)();
2024-04-25 18:02:30 +08:00
}
const _easycom_up_navbar = () => "../../uni_modules/uview-plus/components/u-navbar/u-navbar.js";
2024-04-29 10:44:50 +08:00
const _easycom_up_search = () => "../../uni_modules/uview-plus/components/u-search/u-search.js";
2024-04-28 18:08:57 +08:00
const _easycom_up_image = () => "../../uni_modules/uview-plus/components/u-image/u-image.js";
2024-04-25 18:02:30 +08:00
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";
2024-04-29 10:44:50 +08:00
const _easycom_up_button = () => "../../uni_modules/uview-plus/components/u-button/u-button.js";
2024-04-25 18:02:30 +08:00
if (!Math) {
2024-04-29 18:14:58 +08:00
(_easycom_up_navbar + _easycom_up_search + _easycom_up_image + _easycom_up_icon + viewPopup + _easycom_u__icon + _easycom_up_button + goodPopup)();
2024-04-25 18:02:30 +08:00
}
2024-04-27 18:02:43 +08:00
const viewPopup = () => "../../components/viewPopup.js";
2024-04-29 18:14:58 +08:00
const goodPopup = () => "../../components/goodPopup.js";
2024-04-25 18:02:30 +08:00
const _sfc_main = {
__name: "index",
setup(__props) {
2024-04-29 18:14:58 +08:00
const cartStore = store_cart.useCartStore();
2024-04-27 18:02:43 +08:00
const show = common_vendor.ref(0);
2024-04-25 18:02:30 +08:00
const topActive = common_vendor.ref(0);
2024-04-27 18:02:43 +08:00
const changeOne = (item, index) => {
2024-04-28 18:08:57 +08:00
var _a, _b, _c;
2024-04-27 18:02:43 +08:00
console.log("选择", item, index);
2024-04-28 18:08:57 +08:00
topActive.value = item.id;
2024-04-27 18:02:43 +08:00
show.value = 0;
2024-04-28 18:08:57 +08:00
goodClassTow.value = (item == null ? void 0 : item.children) || [];
goodClassThree.value = ((_a = goodClassTow.value[0]) == null ? void 0 : _a.children) || [];
2024-04-29 18:14:58 +08:00
leftActive.value = ((_b = goodClassTow.value[0]) == null ? void 0 : _b.id) || "";
rightActive.value = ((_c = goodClassThree.value[0]) == null ? void 0 : _c.id) || "";
getGoodList();
2024-04-27 18:02:43 +08:00
};
2024-04-28 18:08:57 +08:00
const leftActive = common_vendor.ref(0);
2024-04-27 18:02:43 +08:00
const changeTwo = (item, index) => {
2024-04-28 18:08:57 +08:00
var _a;
2024-04-27 18:02:43 +08:00
console.log("选择", item, index);
2024-04-28 18:08:57 +08:00
leftActive.value = item.id;
2024-04-27 18:02:43 +08:00
show.value = 0;
2024-04-28 18:08:57 +08:00
goodClassThree.value = (item == null ? void 0 : item.children) || [];
2024-04-29 18:14:58 +08:00
rightActive.value = ((_a = goodClassThree.value[0]) == null ? void 0 : _a.id) || "";
getGoodList();
2024-04-27 18:02:43 +08:00
};
2024-04-28 18:08:57 +08:00
const rightActive = common_vendor.ref(0);
2024-04-27 18:02:43 +08:00
const changeThree = (item, index) => {
console.log("选择", item, index);
2024-04-28 18:08:57 +08:00
rightActive.value = item.id;
2024-04-27 18:02:43 +08:00
show.value = 0;
2024-04-29 18:14:58 +08:00
getGoodList();
2024-04-27 18:02:43 +08:00
};
2024-04-28 18:08:57 +08:00
const cartList = common_vendor.reactive(/* @__PURE__ */ new Map());
2024-04-29 18:14:58 +08:00
const addCart = (id, cart_num) => {
2024-04-28 18:08:57 +08:00
api_cart.cartCreateApi({
2024-04-29 18:14:58 +08:00
cart_num,
2024-04-28 18:08:57 +08:00
is_new: 0,
// 是否直接购买0否1是
goods_id: id
}).then((res) => {
console.log(res);
let now = cartList.get(id) || 0;
cartList.set(id, now + 1);
2024-04-29 18:14:58 +08:00
getCartList();
2024-04-28 18:08:57 +08:00
});
};
2024-04-25 18:02:30 +08:00
const keyword = common_vendor.ref("");
2024-04-27 18:02:43 +08:00
const searchKeyword = () => {
2024-04-29 18:14:58 +08:00
where.value.name = keyword.value;
getGoodList();
2024-04-27 18:02:43 +08:00
};
const changeOrder = (order) => {
console.log("排序", order);
where.value.order = order;
};
const where = common_vendor.ref({
2024-04-29 18:14:58 +08:00
page_no: 1,
page_size: 25,
name: "",
2024-04-27 18:02:43 +08:00
order: ""
});
const loading = common_vendor.ref(true);
2024-04-28 18:08:57 +08:00
const goodList = common_vendor.ref([]);
2024-04-29 18:14:58 +08:00
const getGoodList = (loadmore = false) => {
2024-04-27 18:02:43 +08:00
loading.value = true;
2024-04-29 18:14:58 +08:00
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 = "";
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;
2024-04-28 18:08:57 +08:00
});
};
const loadMoreGood = () => {
console.log("触底了");
};
const goodClassList = common_vendor.ref([]);
const goodClassTow = common_vendor.ref([]);
const goodClassThree = common_vendor.ref([]);
const getgoodClassList = () => {
api_good.goodClassListApi().then((res) => {
2024-04-29 18:14:58 +08:00
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;
2024-04-28 18:08:57 +08:00
});
2024-04-27 18:02:43 +08:00
};
2024-04-29 10:44:50 +08:00
const navTo = (url) => {
common_vendor.index.navigateTo({
url
});
};
2024-04-29 18:14:58 +08:00
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));
});
};
2024-04-27 18:02:43 +08:00
common_vendor.onLoad(() => {
2024-04-28 18:08:57 +08:00
getgoodClassList();
2024-04-27 18:02:43 +08:00
getGoodList();
});
2024-04-29 18:14:58 +08:00
common_vendor.onShow(() => {
getCartList();
});
2024-04-25 18:02:30 +08:00
return (_ctx, _cache) => {
return common_vendor.e({
2024-04-29 10:44:50 +08:00
a: common_vendor.p({
placeholder: true
}),
b: common_vendor.o(searchKeyword),
c: common_vendor.o(($event) => keyword.value = $event),
d: common_vendor.p({
2024-04-25 18:02:30 +08:00
placeholder: "请输入商品",
showAction: false,
modelValue: keyword.value
}),
2024-04-29 10:44:50 +08:00
e: common_assets._imports_0,
f: common_vendor.o(($event) => navTo("/pages/cart/cart")),
g: common_assets._imports_1,
h: common_vendor.o(($event) => navTo("/pages/my/my")),
i: common_vendor.f(goodClassList.value, (item, index, i0) => {
2024-04-25 18:02:30 +08:00
return {
2024-04-28 18:08:57 +08:00
a: "1ba6254c-2-" + i0,
b: common_vendor.p({
height: "100rpx",
width: "100rpx",
src: item.pic
}),
c: common_vendor.t(item.name),
2024-04-29 18:14:58 +08:00
d: topActive.value === item.id ? 1 : "",
2024-04-28 18:08:57 +08:00
e: index,
f: common_vendor.o(($event) => changeOne(item, index), index)
2024-04-25 18:02:30 +08:00
};
}),
2024-04-29 10:44:50 +08:00
j: common_vendor.p({
2024-04-25 18:02:30 +08:00
name: "list"
}),
2024-04-29 10:44:50 +08:00
k: common_vendor.o(($event) => show.value = 1),
l: show.value === 1
2024-04-25 18:02:30 +08:00
}, show.value === 1 ? {
2024-04-29 10:44:50 +08:00
m: common_vendor.f(goodClassList.value, (item, index, i0) => {
2024-04-25 18:02:30 +08:00
return {
2024-04-28 18:08:57 +08:00
a: "1ba6254c-5-" + i0 + ",1ba6254c-4",
b: common_vendor.p({
height: "100rpx",
width: "100rpx",
src: item.pic
}),
c: common_vendor.t(item.name),
2024-04-29 18:14:58 +08:00
d: topActive.value === item.id ? 1 : "",
2024-04-28 18:08:57 +08:00
e: index,
f: common_vendor.o(($event) => changeOne(item, index), index)
2024-04-25 18:02:30 +08:00
};
}),
2024-04-29 10:44:50 +08:00
n: common_vendor.o(($event) => show.value = 0),
o: common_vendor.p({
2024-04-25 18:02:30 +08:00
nav: true
})
} : {}, {
2024-04-29 10:44:50 +08:00
p: common_vendor.f(goodClassTow.value, (item, index, i0) => {
2024-04-25 18:02:30 +08:00
return {
2024-04-28 18:08:57 +08:00
a: common_vendor.t(item.name),
2024-04-29 18:14:58 +08:00
b: leftActive.value === item.id ? 1 : "",
2024-04-27 18:02:43 +08:00
c: index,
d: common_vendor.o(($event) => changeTwo(item, index), index)
2024-04-25 18:02:30 +08:00
};
}),
2024-04-29 10:44:50 +08:00
q: common_vendor.f(goodClassThree.value, (item, index, i0) => {
2024-04-25 18:02:30 +08:00
return {
2024-04-28 18:08:57 +08:00
a: common_vendor.t(item.name),
2024-04-29 18:14:58 +08:00
b: rightActive.value === item.id ? 1 : "",
2024-04-28 18:08:57 +08:00
c: index,
d: common_vendor.o(($event) => changeThree(item, index), index)
2024-04-25 18:02:30 +08:00
};
}),
2024-04-29 10:44:50 +08:00
r: common_vendor.p({
2024-04-25 18:02:30 +08:00
name: "arrow-down"
}),
2024-04-29 10:44:50 +08:00
s: common_vendor.o(($event) => show.value = 2),
t: where.value.order == "" ? 1 : "",
v: common_vendor.o(($event) => changeOrder("")),
w: where.value.order == "desc" || where.value.order == "asc" ? 1 : "",
x: common_vendor.o(($event) => changeOrder(where.value.order == "asc" ? "desc" : "asc")),
y: where.value.order == "sales" ? 1 : "",
z: common_vendor.o(($event) => changeOrder("sales")),
A: show.value === 2
2024-04-25 18:02:30 +08:00
}, show.value === 2 ? {
2024-04-29 10:44:50 +08:00
B: common_vendor.f(goodClassThree.value, (item, index, i0) => {
2024-04-25 18:02:30 +08:00
return {
2024-04-28 18:08:57 +08:00
a: common_vendor.t(item.name),
2024-04-29 18:14:58 +08:00
b: rightActive.value === item.id ? 1 : "",
2024-04-28 18:08:57 +08:00
c: index,
d: common_vendor.o(($event) => changeThree(item, index), index)
2024-04-25 18:02:30 +08:00
};
}),
2024-04-29 10:44:50 +08:00
C: common_vendor.o(($event) => show.value = 0)
2024-04-25 18:02:30 +08:00
} : {}, {
2024-04-29 10:44:50 +08:00
D: common_vendor.f(goodList.value, (item, index, i0) => {
2024-04-25 18:02:30 +08:00
return {
2024-04-28 18:08:57 +08:00
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),
2024-04-29 18:14:58 +08:00
h: "1ba6254c-9-" + i0,
i: item.id,
j: common_vendor.o(($event) => openGoodPopup(item), item.id)
2024-04-25 18:02:30 +08:00
};
}),
2024-04-29 10:44:50 +08:00
E: common_vendor.p({
2024-04-25 18:02:30 +08:00
name: "plus-circle-fill",
size: "20",
color: "#20b128"
2024-04-28 18:08:57 +08:00
}),
2024-04-29 18:14:58 +08:00
F: common_vendor.o(loadMoreGood),
G: common_vendor.t(cartInfo.value.total_price),
H: common_vendor.o(settleAccounts),
I: common_vendor.p({
color: "#20b128",
disabled: cartInfo.value.count == 0
}),
J: common_assets._imports_2,
K: common_vendor.t(cartInfo.value.count),
L: common_vendor.o(($event) => navTo("/pages/cart/cart")),
M: common_vendor.sr(goodRef, "1ba6254c-11", {
"k": "goodRef"
2024-04-29 10:44:50 +08:00
}),
2024-04-29 18:14:58 +08:00
N: common_vendor.o(($event) => showGoodPopup.value = false),
O: common_vendor.o(changeGood),
P: common_vendor.p({
show: showGoodPopup.value
})
2024-04-25 18:02:30 +08:00
});
};
}
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/里海数字乡村/purchase-let/pages/index/index.vue"]]);
wx.createPage(MiniProgramPage);