123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- "use strict";
- var common_vendor = require("../common/vendor.js");
- const likeProduct = () => "./components/likeProduct.js";
- const _sfc_main = {
- components: {
- likeProduct
- },
- data() {
- return {
- totalMoney: 0,
- carts: [],
- checkAll: false
- };
- },
- onLoad() {
- },
- onShow() {
- this.getCarts();
- },
- onReachBottom() {
- },
- methods: {
- delCart() {
- var selectCarts = this.carts.flatMap((item) => item.list.filter((listItem) => listItem.checked === true)).map((el) => el.id);
- if (selectCarts.length == 0) {
- common_vendor.index.showToast({
- icon: "none",
- title: "\u8BF7\u9009\u62E9\u5546\u54C1\u5220\u9664"
- });
- return;
- }
- let data = { ids: selectCarts };
- delCart(data).then((res) => {
- if (res.code == 200) {
- common_vendor.index.showToast({
- icon: "success",
- title: "\u64CD\u4F5C\u6210\u529F"
- });
- this.getCarts();
- } else {
- common_vendor.index.showToast({
- icon: "none",
- title: res.msg
- });
- }
- }, (rej) => {
- });
- console.log(selectCarts);
- },
- computedMoney() {
- var money = 0;
- this.carts.forEach((item, index, arr) => {
- item.list.forEach((it) => {
- if (it.checked) {
- money += it.price * it.cartNum;
- }
- });
- });
- console.log(money);
- this.totalMoney = money;
- },
- handleCheckAll() {
- this.checkAll = !this.checkAll;
- var that = this;
- this.carts.forEach((item, index, arr) => {
- item.checked = that.checkAll;
- item.list.forEach((it) => {
- it.checked = that.checkAll;
- });
- });
- this.computedMoney();
- },
- checkShopChange(item) {
- item.checked = !item.checked;
- item.list.forEach((it) => {
- it.checked = item.checked;
- });
- this.computedMoney();
- },
- checkChange(item, shop) {
- item.checked = !item.checked;
- shop.checked = shop.list.every((it) => it.checked == true);
- this.computedMoney();
- },
- changeNum(e, item) {
- item.cartNum = e.detail.value.replace(/\D/g, "");
- if (item.cartNum <= 1) {
- common_vendor.index.showToast({
- title: "\u5DF2\u7ECF\u662F\u5E95\u7EBF\u5566!",
- icon: "none",
- duration: 2e3
- });
- return;
- }
- if (item.cartNum < 1) {
- item.cartNum = 1;
- }
- if (item.cartNum >= item.stock) {
- item.cartNum = item.stock;
- }
- this.changeCartNum(item);
- },
- changeCartNum(item) {
- let data = { number: item.cartNum, id: item.id };
- cartNum(data).then((res) => {
- if (res.code == 200) {
- common_vendor.index.showToast({
- icon: "none",
- title: "\u64CD\u4F5C\u6210\u529F"
- });
- this.computedMoney();
- } else {
- common_vendor.index.showToast({
- icon: "none",
- title: res.msg
- });
- }
- }, (rej) => {
- });
- },
- getCarts() {
- getCarts().then((res) => {
- if (res.code == 200) {
- this.carts = res.carts;
- this.carts.forEach((item) => {
- item.checked = false;
- item.list.forEach((it) => {
- it.checked = false;
- });
- });
- this.computedMoney();
- } else {
- common_vendor.index.showToast({
- icon: "none",
- title: "\u8BF7\u6C42\u5931\u8D25"
- });
- }
- }, (rej) => {
- });
- },
- delNum(item) {
- if (item.cartNum <= 1) {
- common_vendor.index.showToast({
- title: "\u5DF2\u7ECF\u662F\u5E95\u7EBF\u5566!",
- icon: "none",
- duration: 2e3
- });
- return;
- }
- item.cartNum--;
- if (item.cartNum < 1) {
- item.cartNum = 1;
- }
- this.changeCartNum(item);
- },
- addNum(item) {
- console.log(item);
- item.cartNum++;
- if (item.cartNum >= item.stock) {
- item.cartNum = item.stock;
- }
- this.changeCartNum(item);
- },
- submit() {
- let selectCarts = this.carts.filter((item) => item.list.some((listItem) => listItem.checked === true)).map((item) => ({
- storeId: item.list[0].storeId || "",
- data: {
- type: "cart",
- cartIds: item.list.filter((it) => it.checked == true).map((it) => it.id).join(",")
- }
- }));
- if (selectCarts.length == 0) {
- common_vendor.index.showToast({
- icon: "none",
- title: "\u8BF7\u9009\u62E9\u5546\u54C1"
- });
- return;
- }
- common_vendor.index.navigateTo({
- url: "./confirmOrder?type=cart&confirmParam=" + encodeURIComponent(JSON.stringify(selectCarts))
- });
- },
- showProduct(item) {
- common_vendor.index.navigateTo({
- url: "../shopping/productDetails?productId=" + item.productId
- });
- }
- }
- };
- if (!Array) {
- const _component_likeProduct = common_vendor.resolveComponent("likeProduct");
- _component_likeProduct();
- }
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
- return common_vendor.e({
- a: common_vendor.f($data.carts, (shop, idx, i0) => {
- return common_vendor.e({
- a: shop.storeName && shop.storeName != "null"
- }, shop.storeName && shop.storeName != "null" ? {
- b: shop.checked,
- c: shop.checked,
- d: common_vendor.o(($event) => $options.checkShopChange(shop)),
- e: common_vendor.t(shop.storeName)
- } : {}, {
- f: common_vendor.f(shop.list, (item, index, i1) => {
- return common_vendor.e({
- a: item.checked,
- b: item.checked,
- c: common_vendor.o(($event) => $options.checkChange(item, shop)),
- d: item.productAttrImage == null || item.productAttrImage == "" ? item.productImage : item.productAttrImage,
- e: common_vendor.t(_ctx.utils.getDictLabelName("storeProductType", item.productType)),
- f: common_vendor.t(item.productName),
- g: common_vendor.t(item.productAttrName),
- h: common_vendor.t(item.price),
- i: item.cartNum <= 1
- }, item.cartNum <= 1 ? {} : {}, {
- j: common_vendor.o(($event) => $options.delNum(item)),
- k: common_vendor.o(($event) => $options.changeNum($event, item)),
- l: item.cartNum,
- m: common_vendor.o(($event) => $options.addNum(item)),
- n: index
- });
- }),
- g: idx
- });
- }),
- b: $data.carts.length == 0
- }, $data.carts.length == 0 ? {} : {}, {
- c: common_vendor.sr("product", "50e5f29e-0"),
- d: $data.checkAll,
- e: common_vendor.o(($event) => $options.handleCheckAll()),
- f: common_vendor.o(($event) => $options.delCart()),
- g: common_vendor.t($data.totalMoney.toFixed(2)),
- h: common_vendor.o((...args) => $options.submit && $options.submit(...args))
- });
- }
- var MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "C:/Users/Administrator/Desktop/\u9879\u76EE/\u76F4\u64AD/liveH5-v3/pages_shop/cart.vue"]]);
- wx.createPage(MiniProgramPage);
|