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

277 lines
10 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");
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_transition2 = common_vendor.resolveComponent("up-transition");
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_transition2 + _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_transition = () => "../../uni_modules/uview-plus/components/u-transition/u-transition.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_transition + _easycom_up_button)();
}
const viewPopup = () => "../../components/viewPopup.js";
const _sfc_main = {
__name: "index",
setup(__props) {
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;
};
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;
};
const rightActive = common_vendor.ref(0);
const changeThree = (item, index) => {
console.log("选择", item, index);
rightActive.value = item.id;
show.value = 0;
};
const cartList = common_vendor.reactive(/* @__PURE__ */ new Map());
const addCart = (id) => {
api_cart.cartCreateApi({
cart_num: 1,
is_new: 0,
// 是否直接购买0否1是
goods_id: id
}).then((res) => {
console.log(res);
let now = cartList.get(id) || 0;
cartList.set(id, now + 1);
});
};
const removeCart = (id) => {
let num = cartList.get(id) || 0;
if (num == 0)
return;
api_cart.cartChangeApi({
goods_id: id,
cart_num: num--
}).then((res) => {
console.log(res);
cartList.set(id, num);
});
};
const keyword = common_vendor.ref("");
const searchKeyword = () => {
console.log("搜索", keyword.value);
where.value = keyword.value;
};
const changeOrder = (order) => {
console.log("排序", order);
where.value.order = order;
};
const where = common_vendor.ref({
page: 1,
pageSize: 25,
keyword: "",
order: ""
});
const loading = common_vendor.ref(true);
const goodList = common_vendor.ref([]);
const getGoodList = () => {
loading.value = true;
api_good.goodListApi(where.value).then((res) => {
goodList.value = [...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;
goodClassList.value = ((_a = res.data) == null ? void 0 : _a.lists) || [];
goodClassTow.value = ((_b = goodClassList.value[0]) == null ? void 0 : _b.children) || [];
goodClassThree.value = ((_c = goodClassTow.value[0]) == null ? void 0 : _c.children) || [];
topActive.value = (_d = goodClassList.value[0]) == null ? void 0 : _d.id;
leftActive.value = (_e = goodClassTow.value[0]) == null ? void 0 : _e.id;
rightActive.value = (_f = goodClassThree.value[0]) == null ? void 0 : _f.id;
});
};
const navTo = (url) => {
common_vendor.index.navigateTo({
url
});
};
common_vendor.onLoad(() => {
getgoodClassList();
getGoodList();
});
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,
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) => {
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: common_vendor.o(($event) => removeCart(item.id), item.id),
i: "1ba6254c-10-" + i0 + "," + ("1ba6254c-9-" + i0),
j: "1ba6254c-9-" + i0,
k: common_vendor.p({
show: cartList.get(item.id) > 0
}),
l: common_vendor.t(cartList.get(item.id)),
m: "1ba6254c-11-" + i0,
n: common_vendor.p({
show: cartList.get(item.id) > 0
}),
o: common_vendor.o(($event) => addCart(item.id), item.id),
p: "1ba6254c-12-" + i0,
q: item.id
};
}),
E: common_vendor.p({
name: "minus-circle-fill",
size: "20",
color: "#20b128"
}),
F: common_vendor.p({
name: "plus-circle-fill",
size: "20",
color: "#20b128"
}),
G: common_vendor.o(loadMoreGood),
H: common_vendor.p({
color: "#20b128"
}),
I: common_assets._imports_2
});
};
}
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/里海数字乡村/purchase-let/pages/index/index.vue"]]);
wx.createPage(MiniProgramPage);