shopCar.js
6.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
"use strict";
var common_vendor = require("../../common/vendor.js");
var api_index = require("../../api/index.js");
require("../../utils/request.js");
if (!Array) {
const _easycom_u_navbar2 = common_vendor.resolveComponent("u-navbar");
_easycom_u_navbar2();
}
const _easycom_u_navbar = () => "../../uni_modules/uview-plus/components/u-navbar/u-navbar.js";
if (!Math) {
_easycom_u_navbar();
}
const _sfc_main = {
setup(__props) {
common_vendor.onShow(() => {
getCarLists();
common_vendor.index.getStorageSync("defaultAdres") ? data.adress = common_vendor.index.getStorageSync("defaultAdres").diqu + common_vendor.index.getStorageSync("defaultAdres").address : "";
console.log("\u9ED8\u8BA4", data.adress);
});
let data = common_vendor.reactive({
shopList: [],
btnStatus: true,
adress: "\u8BF7\u65B0\u5EFA\u9ED8\u8BA4\u5730\u5740"
});
const changingOver = () => {
console.log(data.btnStatus);
data.btnStatus = !data.btnStatus;
};
const toMyAddress = () => {
common_vendor.index.navigateTo({
url: "/pages/mine/myAddress"
});
};
const checkShop = (index) => {
data.shopList[index].checkType = !data.shopList[index].checkType;
};
const settleBtn = () => {
if (data.btnStatus) {
let arrId = data.shopList.filter((item) => item.checkType).map((it) => it.cart_id);
common_vendor.index.navigateTo({
url: `/pages/shopCar/confirmOrder?ids=${arrId.join(",")}`
});
} else {
let arr = data.shopList.filter((item) => item.checkType).map((it) => it.cart_id);
getDelCars(arr.join(","));
}
};
const getDelCars = async (ids) => {
try {
const res = await api_index.getDelCar(ids);
getCarLists();
common_vendor.index.showToast({ title: "\u6210\u529F\u79FB\u51FA\u8D2D\u7269\u8F66~", icon: "none" });
console.log("getDelCar", res);
} catch (err) {
common_vendor.index.showToast({ title: err, icon: "none" });
console.log("getDelCar", err);
}
};
const numBtn = (type, item) => {
if (type == 0) {
if (item.total_num == 1)
return common_vendor.index.showToast({ title: "\u81F3\u5C11\u4E00\u4EF6\u54E6~", icon: "none" });
getCarReduces(item.cart_id, item.total_num - 1);
item.total_num = item.total_num - 1;
} else {
getCarAdds(item.cart_id, item.total_num + 1);
item.total_num = item.total_num + 1;
}
};
const getCarAdds = async (id, num) => {
try {
const res = await api_index.getCarAdd(id, num);
console.log("getCarAdd", res);
} catch (err) {
common_vendor.index.showToast({ title: err, icon: "none" });
console.log("getCarAdd", err);
}
};
const getCarReduces = async (id, num) => {
try {
const res = await api_index.getCarReduce(id, num);
console.log("getCarReduce", res);
} catch (err) {
common_vendor.index.showToast({ title: err, icon: "none" });
console.log("getCarReduce", err);
}
};
const checkAll = () => {
if (allCheck.value) {
data.shopList.forEach((item) => {
item.checkType = false;
});
} else {
data.shopList.forEach((item) => {
item.checkType = true;
});
}
};
const getCarLists = async () => {
try {
const res = await api_index.getCarList();
res.goods_list.forEach((item) => item.checkType = false);
data.shopList = res.goods_list;
console.log("\u662F\u4EC0\u4E48", data.shopList);
console.log("getCarList", res);
} catch (err) {
console.log("getCarList", err);
}
};
const allCheck = common_vendor.computed$1(() => {
return data.shopList.every((item) => item.checkType === true);
});
const allMoney = common_vendor.computed$1(() => {
return data.shopList.filter((it) => it.checkType).reduce((acc, item) => {
return acc + item.total_price * 1;
}, 0);
});
return (_ctx, _cache) => {
return common_vendor.e({
a: common_vendor.p({
bgColor: "#F6F8FA",
placeholder: true,
title: "\u8D2D\u7269\u8F66",
autoBack: true
}),
b: common_vendor.unref(data).shopList.length > 0
}, common_vendor.unref(data).shopList.length > 0 ? {
c: common_vendor.t(common_vendor.unref(data).adress),
d: common_vendor.o(toMyAddress),
e: common_vendor.t(common_vendor.unref(data).btnStatus ? "\u7BA1\u7406" : "\u5B8C\u6210"),
f: common_vendor.o(changingOver),
g: common_vendor.f(common_vendor.unref(data).shopList, (item, index, i0) => {
return common_vendor.e({
a: !item.checkType
}, !item.checkType ? {} : {}, {
b: common_vendor.o(($event) => checkShop(index)),
c: item.image,
d: item.status == 0
}, item.status == 0 ? {} : {}, {
e: common_vendor.t(item.name),
f: common_vendor.t(item.goods_price),
g: common_vendor.o(($event) => numBtn(0, item)),
h: common_vendor.t(item.total_num),
i: common_vendor.o(($event) => numBtn(1, item)),
j: item.id
});
})
} : {}, {
h: common_vendor.unref(data).shopList.length > 0
}, common_vendor.unref(data).shopList.length > 0 ? common_vendor.e({
i: !common_vendor.unref(allCheck)
}, !common_vendor.unref(allCheck) ? {} : {}, {
j: common_vendor.o(checkAll),
k: common_vendor.unref(data).btnStatus
}, common_vendor.unref(data).btnStatus ? {
l: common_vendor.t(+common_vendor.unref(allMoney).toFixed(2))
} : {}, {
m: common_vendor.t(common_vendor.unref(data).btnStatus ? "\u7ED3\u7B97" : "\u5220\u9664"),
n: common_vendor.o(settleBtn)
}) : {});
};
}
};
var MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/vue/\u5927\u5065\u5EB7\u5546\u57CE/healthMall/pages/shopCar/shopCar.vue"]]);
wx.createPage(MiniProgramPage);