shopCar.js 5.9 KB
"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);
        getCarLists();
      } catch (err) {
        common_vendor.index.showToast({ title: err, icon: "none" });
      }
    };
    const getCarReduces = async (id, num) => {
      try {
        const res = await api_index.getCarReduce(id, num);
        getCarLists();
      } catch (err) {
        common_vendor.index.showToast({ title: err, icon: "none" });
      }
    };
    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);