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

349 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;
};
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 = "";
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("触底了");
};
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(($event) => keyword.value = $event),
d: common_vendor.p({
placeholder: "请输入商品",
showAction: false,
modelValue: keyword.value
}),
e: common_assets._imports_0$1,
f: common_vendor.o(($event) => navTo("/pages/cart/cart")),
g: common_assets._imports_1$1,
h: common_vendor.o(($event) => navTo("/pages/my/my")),
i: 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)
};
}),
j: common_vendor.p({
name: "list"
}),
k: common_vendor.o(($event) => show.value = 1),
l: show.value === 1
}, show.value === 1 ? {
m: 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)
};
}),
n: common_vendor.o(($event) => show.value = 0),
o: common_vendor.p({
nav: true
})
} : {}, {
p: 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)
};
}),
q: 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)
};
}),
r: common_vendor.p({
name: "arrow-down"
}),
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
}, show.value === 2 ? {
B: 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)
};
}),
C: common_vendor.o(($event) => show.value = 0)
} : {}, {
D: 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)
};
}),
E: common_vendor.p({
name: "plus-circle-fill",
size: "20",
color: "#20b128"
}),
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"
}),
N: common_vendor.o(($event) => showGoodPopup.value = false),
O: common_vendor.o(changeGood),
P: 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);