2024-04-25 18:02:30 +08:00
|
|
|
"use strict";
|
|
|
|
const common_vendor = require("../../common/vendor.js");
|
|
|
|
const common_assets = require("../../common/assets.js");
|
2024-04-28 18:08:57 +08:00
|
|
|
const api_cart = require("../../api/cart.js");
|
2024-04-30 16:24:55 +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");
|
|
|
|
const _easycom_u__icon2 = common_vendor.resolveComponent("u--icon");
|
2024-04-26 18:04:56 +08:00
|
|
|
const _easycom_up_empty2 = common_vendor.resolveComponent("up-empty");
|
|
|
|
const _easycom_up_button2 = common_vendor.resolveComponent("up-button");
|
|
|
|
const _easycom_up_transition2 = common_vendor.resolveComponent("up-transition");
|
|
|
|
(_easycom_up_navbar2 + _easycom_u__icon2 + _easycom_up_empty2 + _easycom_up_button2 + _easycom_up_transition2)();
|
2024-04-25 18:02:30 +08:00
|
|
|
}
|
|
|
|
const _easycom_up_navbar = () => "../../uni_modules/uview-plus/components/u-navbar/u-navbar.js";
|
|
|
|
const _easycom_u__icon = () => "../../uni_modules/uview-plus/components/u-icon/u-icon.js";
|
2024-04-26 18:04:56 +08:00
|
|
|
const _easycom_up_empty = () => "../../uni_modules/uview-plus/components/u-empty/u-empty.js";
|
|
|
|
const _easycom_up_button = () => "../../uni_modules/uview-plus/components/u-button/u-button.js";
|
|
|
|
const _easycom_up_transition = () => "../../uni_modules/uview-plus/components/u-transition/u-transition.js";
|
2024-04-25 18:02:30 +08:00
|
|
|
if (!Math) {
|
2024-04-29 18:14:58 +08:00
|
|
|
(_easycom_up_navbar + _easycom_u__icon + _easycom_up_empty + _easycom_up_button + _easycom_up_transition + goodPopup)();
|
2024-04-25 18:02:30 +08:00
|
|
|
}
|
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: "cart",
|
|
|
|
setup(__props) {
|
2024-04-30 16:24:55 +08:00
|
|
|
const cartStore = store_cart.useCartStore();
|
2024-04-26 18:04:56 +08:00
|
|
|
const list = common_vendor.ref(["购物车", "常买"]);
|
2024-04-25 18:02:30 +08:00
|
|
|
const tabsActive = common_vendor.ref(0);
|
|
|
|
const changeTab = (e) => {
|
|
|
|
tabsActive.value = e;
|
2024-04-26 18:04:56 +08:00
|
|
|
swiperCurrent.value = e;
|
2024-04-25 18:02:30 +08:00
|
|
|
};
|
|
|
|
const swiperCurrent = common_vendor.ref(0);
|
|
|
|
const animationfinish = ({ detail: { current } }) => {
|
|
|
|
swiperCurrent.value = current;
|
|
|
|
tabsActive.value = current;
|
|
|
|
};
|
2024-04-27 18:02:43 +08:00
|
|
|
const settleAccounts = () => {
|
2024-04-30 16:24:55 +08:00
|
|
|
let list2 = [];
|
|
|
|
cartList.value.forEach((item) => {
|
|
|
|
if (item.check)
|
|
|
|
list2.push(item.cart_id);
|
|
|
|
});
|
|
|
|
cartStore.setCartList(list2);
|
2024-04-28 18:08:57 +08:00
|
|
|
common_vendor.index.navigateTo({
|
|
|
|
url: "/pagesOrder/settle/settle"
|
|
|
|
});
|
2024-04-27 18:02:43 +08:00
|
|
|
};
|
2024-04-30 16:24:55 +08:00
|
|
|
const deleteCartList = () => {
|
|
|
|
let list2 = [];
|
|
|
|
cartList.value.forEach((item) => {
|
|
|
|
if (item.check)
|
|
|
|
list2.push(item.cart_id);
|
|
|
|
});
|
|
|
|
api_cart.cartDeleteApi({
|
|
|
|
cart_id: list2
|
|
|
|
}).then(() => {
|
|
|
|
getcartList(false);
|
|
|
|
});
|
|
|
|
};
|
2024-04-29 18:14:58 +08:00
|
|
|
const addCart = (id, cart_num) => {
|
2024-04-30 16:24:55 +08:00
|
|
|
api_cart.cartCreateApi({
|
|
|
|
cart_num: +cart_num,
|
|
|
|
goods_id: id
|
2024-04-29 18:14:58 +08:00
|
|
|
}).then((res) => {
|
|
|
|
getcartList();
|
|
|
|
});
|
|
|
|
};
|
2024-04-30 16:24:55 +08:00
|
|
|
const isAdmin = common_vendor.ref(false);
|
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) => {
|
2024-04-30 16:24:55 +08:00
|
|
|
goodData.value = JSON.parse(JSON.stringify(item));
|
|
|
|
goodRef.value.setData(goodData.value);
|
2024-04-29 18:14:58 +08:00
|
|
|
showGoodPopup.value = true;
|
|
|
|
};
|
|
|
|
const changeGood = (data) => {
|
|
|
|
showGoodPopup.value = false;
|
2024-04-30 16:24:55 +08:00
|
|
|
addCart(data.goods_id || data.id, data.cart_num);
|
2024-04-29 18:14:58 +08:00
|
|
|
};
|
|
|
|
const cartList = common_vendor.ref([]);
|
|
|
|
const cartInfo = common_vendor.ref({});
|
2024-04-30 16:24:55 +08:00
|
|
|
const getcartList = (check = true) => {
|
2024-04-28 18:08:57 +08:00
|
|
|
api_cart.cartListApi().then((res) => {
|
2024-04-30 16:24:55 +08:00
|
|
|
var _a, _b, _c;
|
|
|
|
if (check) {
|
|
|
|
res.data.lists = res.data.lists.map((item) => {
|
|
|
|
item.check = true;
|
|
|
|
return item;
|
|
|
|
});
|
|
|
|
checkAll.value = ((_a = res.data) == null ? void 0 : _a.count) || 0;
|
|
|
|
} else {
|
|
|
|
checkAll.value = 0;
|
|
|
|
}
|
2024-04-29 18:14:58 +08:00
|
|
|
cartList.value = res.data.lists;
|
2024-04-30 16:24:55 +08:00
|
|
|
cartInfo.value = {
|
|
|
|
total_price: ((_b = res.data) == null ? void 0 : _b.extend.total_price) || "0.00",
|
|
|
|
count: ((_c = res.data) == null ? void 0 : _c.count) || 0
|
|
|
|
};
|
2024-04-28 18:08:57 +08:00
|
|
|
});
|
|
|
|
};
|
2024-04-30 16:24:55 +08:00
|
|
|
const c_price0 = common_vendor.computed(() => {
|
|
|
|
let price = cartInfo.value.total_price + "";
|
|
|
|
return price.split(".")[0] || "0";
|
|
|
|
});
|
|
|
|
const c_price1 = common_vendor.computed(() => {
|
|
|
|
let price = cartInfo.value.total_price + "";
|
|
|
|
return price.split(".")[1] || "00";
|
|
|
|
});
|
|
|
|
let checkAll = common_vendor.ref(0);
|
|
|
|
const checkItem = (item, type) => {
|
|
|
|
item.check = type;
|
|
|
|
let price = Number(cartInfo.value.total_price);
|
|
|
|
if (type) {
|
|
|
|
price += item.sell * item.cart_num;
|
|
|
|
checkAll.value++;
|
|
|
|
} else {
|
|
|
|
price -= item.sell * item.cart_num;
|
|
|
|
checkAll.value--;
|
|
|
|
}
|
|
|
|
cartInfo.value.total_price = price.toFixed(2);
|
|
|
|
};
|
|
|
|
const changeAll = (flag = false) => {
|
|
|
|
cartList.value.forEach((item) => {
|
|
|
|
item.check = !flag;
|
|
|
|
});
|
|
|
|
if (!flag)
|
|
|
|
checkAll.value = cartInfo.value.count;
|
|
|
|
else
|
|
|
|
checkAll.value = 0;
|
|
|
|
};
|
|
|
|
const frequentlyList = common_vendor.ref([]);
|
|
|
|
const where = common_vendor.ref({
|
|
|
|
page_no: 1,
|
|
|
|
page_size: 25
|
|
|
|
});
|
|
|
|
const getFrequentlyPurchase = () => {
|
|
|
|
api_cart.frequentlyPurchaseApi({
|
|
|
|
...where.value
|
|
|
|
}).then((res) => {
|
|
|
|
frequentlyList.value = res.data;
|
|
|
|
});
|
2024-04-29 18:14:58 +08:00
|
|
|
};
|
2024-04-30 16:24:55 +08:00
|
|
|
getFrequentlyPurchase();
|
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({
|
|
|
|
a: common_vendor.f(list.value, (item, index, i0) => {
|
|
|
|
return {
|
|
|
|
a: common_vendor.t(item),
|
|
|
|
b: tabsActive.value == index ? 1 : "",
|
2024-04-26 18:04:56 +08:00
|
|
|
c: index,
|
|
|
|
d: common_vendor.o(($event) => changeTab(index), index)
|
2024-04-25 18:02:30 +08:00
|
|
|
};
|
|
|
|
}),
|
|
|
|
b: common_vendor.p({
|
2024-04-29 18:14:58 +08:00
|
|
|
placeholder: true,
|
|
|
|
autoBack: true
|
|
|
|
}),
|
2024-04-30 16:24:55 +08:00
|
|
|
c: common_vendor.t(cartList.value.length),
|
|
|
|
d: !isAdmin.value
|
|
|
|
}, !isAdmin.value ? {
|
|
|
|
e: common_vendor.o(($event) => {
|
|
|
|
isAdmin.value = true;
|
|
|
|
})
|
|
|
|
} : {
|
|
|
|
f: common_vendor.o(($event) => {
|
|
|
|
isAdmin.value = false;
|
|
|
|
})
|
|
|
|
}, {
|
|
|
|
g: cartList.value.length > 0
|
|
|
|
}, cartList.value.length > 0 ? {
|
|
|
|
h: common_vendor.f(cartList.value, (item, index, i0) => {
|
2024-04-25 18:02:30 +08:00
|
|
|
return common_vendor.e({
|
2024-04-29 18:14:58 +08:00
|
|
|
a: !item.check
|
|
|
|
}, !item.check ? {
|
2024-04-30 18:08:36 +08:00
|
|
|
b: common_assets._imports_1
|
2024-04-25 18:02:30 +08:00
|
|
|
} : {
|
2024-04-30 18:08:36 +08:00
|
|
|
c: common_assets._imports_0
|
2024-04-25 18:02:30 +08:00
|
|
|
}, {
|
2024-04-30 16:24:55 +08:00
|
|
|
d: common_vendor.o(($event) => checkItem(item, !item.check), index),
|
|
|
|
e: item.imgs,
|
|
|
|
f: common_vendor.t(item.goods_name),
|
|
|
|
g: common_vendor.t(item.unit_name),
|
|
|
|
h: common_vendor.t(item.sell),
|
|
|
|
i: common_vendor.t(item.cart_num),
|
|
|
|
j: "da603134-1-" + i0,
|
|
|
|
k: index,
|
|
|
|
l: common_vendor.o(($event) => openGoodPopup(item), index)
|
2024-04-25 18:02:30 +08:00
|
|
|
});
|
|
|
|
}),
|
2024-04-30 16:24:55 +08:00
|
|
|
i: common_vendor.p({
|
2024-04-25 18:02:30 +08:00
|
|
|
name: "plus-circle-fill",
|
|
|
|
size: "20",
|
|
|
|
color: "#20b128"
|
2024-04-26 18:04:56 +08:00
|
|
|
})
|
2024-04-30 16:24:55 +08:00
|
|
|
} : {
|
|
|
|
j: common_vendor.p({
|
|
|
|
text: "购物车空空如也",
|
|
|
|
icon: "https://lihai001.oss-cn-chengdu.aliyuncs.com/def/29955202404260944367594.png"
|
|
|
|
})
|
2024-04-26 18:04:56 +08:00
|
|
|
}, {
|
2024-04-30 16:24:55 +08:00
|
|
|
k: common_vendor.f(frequentlyList.value, (item, index, i0) => {
|
2024-04-26 18:04:56 +08:00
|
|
|
return {
|
2024-04-30 16:24:55 +08:00
|
|
|
a: item.imgs,
|
|
|
|
b: common_vendor.t(item.name),
|
|
|
|
c: common_vendor.t(item.unit_name),
|
|
|
|
d: common_vendor.t(item.sell),
|
|
|
|
e: "da603134-3-" + i0,
|
|
|
|
f: index,
|
|
|
|
g: common_vendor.o(($event) => openGoodPopup(item), index)
|
2024-04-26 18:04:56 +08:00
|
|
|
};
|
2024-04-25 18:02:30 +08:00
|
|
|
}),
|
2024-04-30 16:24:55 +08:00
|
|
|
l: common_vendor.p({
|
2024-04-26 18:04:56 +08:00
|
|
|
size: "small",
|
|
|
|
plain: true,
|
|
|
|
color: "#20b128",
|
|
|
|
shape: "circle"
|
|
|
|
})
|
|
|
|
}, {
|
2024-04-30 16:24:55 +08:00
|
|
|
n: swiperCurrent.value,
|
|
|
|
o: common_vendor.o(animationfinish),
|
|
|
|
p: common_vendor.unref(checkAll) != cartInfo.value.count
|
|
|
|
}, common_vendor.unref(checkAll) != cartInfo.value.count ? {
|
2024-04-30 18:08:36 +08:00
|
|
|
q: common_assets._imports_1
|
2024-04-30 16:24:55 +08:00
|
|
|
} : {
|
2024-04-30 18:08:36 +08:00
|
|
|
r: common_assets._imports_0
|
2024-04-26 18:04:56 +08:00
|
|
|
}, {
|
2024-04-30 16:24:55 +08:00
|
|
|
s: common_vendor.unref(checkAll)
|
|
|
|
}, common_vendor.unref(checkAll) ? {
|
|
|
|
t: common_vendor.t(common_vendor.unref(checkAll))
|
|
|
|
} : {}, {
|
|
|
|
v: common_vendor.o(($event) => changeAll(common_vendor.unref(checkAll) === cartInfo.value.count)),
|
|
|
|
w: !isAdmin.value
|
|
|
|
}, !isAdmin.value ? common_vendor.e({
|
|
|
|
x: common_vendor.t(c_price0.value),
|
|
|
|
y: common_vendor.t(c_price1.value),
|
|
|
|
z: common_vendor.unref(checkAll)
|
|
|
|
}, common_vendor.unref(checkAll) ? {
|
|
|
|
A: common_vendor.t(common_vendor.unref(checkAll))
|
|
|
|
} : {}, {
|
|
|
|
B: common_vendor.o(settleAccounts),
|
|
|
|
C: common_vendor.p({
|
2024-04-27 18:02:43 +08:00
|
|
|
color: "#20b128",
|
|
|
|
shape: "circle",
|
2024-04-30 16:24:55 +08:00
|
|
|
disabled: !common_vendor.unref(checkAll)
|
|
|
|
})
|
|
|
|
}) : {
|
|
|
|
D: common_vendor.o(($event) => deleteCartList()),
|
|
|
|
E: common_vendor.p({
|
|
|
|
size: "small",
|
|
|
|
plain: true,
|
|
|
|
color: "#989898",
|
|
|
|
shape: "circle"
|
2024-04-26 18:04:56 +08:00
|
|
|
})
|
|
|
|
}, {
|
2024-04-30 16:24:55 +08:00
|
|
|
F: common_vendor.p({
|
2024-04-26 18:04:56 +08:00
|
|
|
show: tabsActive.value == 0
|
2024-04-29 18:14:58 +08:00
|
|
|
}),
|
2024-04-30 16:24:55 +08:00
|
|
|
G: common_vendor.sr(goodRef, "da603134-8", {
|
2024-04-29 18:14:58 +08:00
|
|
|
"k": "goodRef"
|
|
|
|
}),
|
2024-04-30 16:24:55 +08:00
|
|
|
H: common_vendor.o(($event) => showGoodPopup.value = false),
|
|
|
|
I: common_vendor.o(changeGood),
|
|
|
|
J: common_vendor.p({
|
2024-04-29 18:14:58 +08:00
|
|
|
show: showGoodPopup.value
|
2024-04-26 18:04:56 +08:00
|
|
|
})
|
2024-04-25 18:02:30 +08:00
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/里海数字乡村/purchase-let/pages/cart/cart.vue"]]);
|
|
|
|
wx.createPage(MiniProgramPage);
|