123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- "use strict";
- const common_vendor = require("../common/vendor.js");
- const common_assets = require("../common/assets.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: "请选择商品删除"
- });
- return;
- }
- let data = { ids: selectCarts };
- delCart(data).then(
- (res) => {
- if (res.code == 200) {
- common_vendor.index.showToast({
- icon: "success",
- title: "操作成功"
- });
- 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: "已经是底线啦!",
- 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: "操作成功"
- });
- 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: "请求失败"
- });
- }
- },
- (rej) => {
- }
- );
- },
- // 购物车减法
- delNum(item) {
- if (item.cartNum <= 1) {
- common_vendor.index.showToast({
- title: "已经是底线啦!",
- 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: "请选择商品"
- });
- 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), idx),
- 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), index),
- 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_assets._imports_0$8
- } : {
- k: common_assets._imports_1$5
- }, {
- l: common_vendor.o(($event) => $options.delNum(item), index),
- m: common_vendor.o(($event) => $options.changeNum($event, item), index),
- n: item.cartNum,
- o: common_vendor.o(($event) => $options.addNum(item), index),
- p: index
- });
- }),
- g: idx
- });
- }),
- b: common_assets._imports_2$4,
- c: $data.carts.length == 0
- }, $data.carts.length == 0 ? {
- d: common_assets._imports_2$3
- } : {}, {
- e: common_vendor.sr("product", "50e5f29e-0"),
- f: $data.checkAll,
- g: common_vendor.o(($event) => $options.handleCheckAll()),
- h: common_vendor.o(($event) => $options.delCart()),
- i: common_vendor.t($data.totalMoney.toFixed(2)),
- j: common_vendor.o((...args) => $options.submit && $options.submit(...args))
- });
- }
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
- wx.createPage(MiniProgramPage);
|