car.js 7.28 KB
var t = require("../restapi"), e = require("../../utils/util"), a = getApp();

Component({
    properties: {},
    data: {
        icon: {
            active: "https://img01.glsx.com.cn/weapp/resource/eims/radio_active.png",
            normal: "https://img01.glsx.com.cn/weapp/resource/eims/radio_normal.png"
        },
        checkList: [],
        maxNumber: 9999,
        list: [],
        oList: [],
        showCheckall: !1,
        isDelete: !1,
        noPass: !1,
        total: 0,
        allcheck: !1
    },
    methods: {
        onChange: function(t) {
            var e = t.detail, a = this.data.list, o = this.data.showCheckall;
            console.log(t), o = e.length == a.length, this.setData({
                checkList: t.detail,
                showCheckall: o
            }), this.sum();
        },
        submitOrder: function() {
            var t = this.data.checkList, a = this.data.oList, o = [];
            if (console.log(t), !t || t.length <= 0) return (0, e.showToast)("请勾选下单的物品"), !1;
            var r = !0, i = !1, n = void 0;
            try {
                for (var s, c = t[Symbol.iterator](); !(r = (s = c.next()).done); r = !0) !function() {
                    var t = s.value, e = a.find(function(e) {
                        return e.cartCode == t;
                    });
                    e && o.push(e);
                }();
            } catch (t) {
                t = VM2_INTERNAL_STATE_DO_NOT_USE_OR_PROGRAM_WILL_FAIL.handleException(t);
                i = !0, n = t;
            } finally {
                try {
                    !r && c.return && c.return();
                } finally {
                    if (i) throw n;
                }
            }
            console.log(o), wx.setStorageSync("order", o), this.triggerEvent("change", {
                close: !1
            }), wx.navigateTo({
                url: "/packageIndex/pages/order/index"
            });
        },
        updateNumber: function(a) {
            console.log(a);
            var o = this, r = o.data.maxNumber, i = Number(a.detail), n = a.currentTarget.dataset.code;
            if (!a.detail) return !1;
            if (i > r) return (0, e.showToast)("购买数量超过最大数量"), o.setData({
                noPass: !1
            }), !1;
            o.setData({
                noPass: !0
            });
            var s = o.getParams();
            s.cartCode = n, s.total = i, (0, t.UPDATEGHPRODUCTCONFIGCART)(s, function(t) {
                console.log(t), 0 == t.returnCode && o.getList();
            });
        },
        sum: function() {
            var t = this.data.oList, e = this.data.checkList, a = 0, o = !0, r = !1, i = void 0;
            try {
                for (var n, s = e[Symbol.iterator](); !(o = (n = s.next()).done); o = !0) !function() {
                    var e = n.value, o = t.find(function(t) {
                        return t.cartCode == e;
                    });
                    console.log(o), o && (a += Number(o.total));
                }();
            } catch (t) {
                t = VM2_INTERNAL_STATE_DO_NOT_USE_OR_PROGRAM_WILL_FAIL.handleException(t);
                r = !0, i = t;
            } finally {
                try {
                    !o && s.return && s.return();
                } finally {
                    if (r) throw i;
                }
            }
            this.setData({
                total: a
            });
        },
        allcheckEvent: function(t) {
            console.log(t);
            var e = this.data.oList, a = [];
            if (t.detail) {
                var o = !0, r = !1, i = void 0;
                try {
                    for (var n, s = e[Symbol.iterator](); !(o = (n = s.next()).done); o = !0) {
                        var c = n.value;
                        a.push(c.cartCode.toString());
                    }
                } catch (t) {
                    t = VM2_INTERNAL_STATE_DO_NOT_USE_OR_PROGRAM_WILL_FAIL.handleException(t);
                    r = !0, i = t;
                } finally {
                    try {
                        !o && s.return && s.return();
                    } finally {
                        if (r) throw i;
                    }
                }
            }
            this.setData({
                allcheck: t.detail,
                checkList: a
            }), this.sum();
        },
        manageMethod: function(t) {
            console.log(t);
            var e = !1;
            1 == t.currentTarget.id && (e = !0), this.setData({
                isDelete: e
            });
            var a = {};
            a.isDelete = e, this.triggerEvent("change", a);
        },
        clearEvent: function() {
            var t = [];
            (this.data.oList || []).map(function(e) {
                t.push(e.cartCode);
            }), this.setData({
                checkList: [],
                allcheck: !1
            }), this.deleteProduct(t);
        },
        getParams: function() {
            var t = a.globalData.userInfo, e = {};
            return e.merchantCode = t.merchant.merchantId, e;
        },
        getList: function() {
            var e = this, a = e.getParams();
            a.pageSize = 1e5, a.pageNo = 1, (0, t.LISTGHSHOPPINGCART)(a, function(t) {
                if (console.log(t), 0 == t.returnCode) {
                    var a = (t.data || {}).listGhShoppingCart || [], o = [], r = [];
                    a.map(function(t) {
                        var e = o.findIndex(function(e) {
                            return t.categoryId == e;
                        }), a = [];
                        if ((t.listCartConfig || []).map(function(t) {
                            "F" != t.option && a.push(t);
                        }), t.configList = a, e >= 0) r[e].list.push(t); else {
                            var i = {};
                            i.name = t.categoryName, i.id = t.categoryId, i.list = [ t ], r.push(i), o.push(t.categoryId);
                        }
                    }), console.log(r), e.setData({
                        list: r,
                        oList: a
                    }), e.sum();
                }
            });
        },
        deleteProduct: function(a) {
            var o = this, r = o.getParams();
            r.cartCodes = a, (0, t.DELGHPRODUCTCONFIGCART)(r, function(t) {
                console.log(t), 0 == t.returnCode && ((0, e.showToast)("删除成功"), o.getList());
            });
        },
        singleDelete: function(t) {
            var e = this.data.checkList || [], a = t.currentTarget.id, o = [], r = e.findIndex(function(t) {
                return t == a;
            });
            r >= 0 && e.splice(r, 1), console.log(r), o.push(a), this.setData({
                checkList: e
            }), console.log(e), this.deleteProduct(o);
        },
        batchDelete: function() {
            var t = this.data.checkList, a = this.data.oList, o = [];
            if (!t || t.length <= 0) return (0, e.showToast)("请勾选要删除的产品"), !1;
            t.map(function(t) {
                var e = a.find(function(e) {
                    return e.cartCode == t;
                });
                e && o.push(e.cartCode);
            }), this.setData({
                checkList: []
            }), this.deleteProduct(o);
        }
    },
    ready: function() {
        this.getList();
    }
});