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

Component({
    properties: {
        config: {
            type: [ String, Number ],
            value: ""
        },
        displayConfig: {
            type: String,
            value: ""
        }
    },
    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"
        },
        maxNumber: 9999,
        configList: [],
        form: {},
        list: []
    },
    methods: {
        onChange: function(t) {
            var a = t.currentTarget.id, e = this.data.form;
            e[a] = t.detail, console.log(e), this.setData({
                form: e
            });
        },
        inputEvent: function(t) {
            var a = {};
            a[t.currentTarget.id] = t.detail.value, this.setData(a);
        },
        getParams: function() {
            var t = e.globalData.userInfo, a = {};
            return a.merchantCode = t.merchant.merchantId, a;
        },
        getList: function() {
            var a = this, e = a.getParams();
            e.productConfigCode = a.data.config, (0, t.GETGHPRODUCTCONFIGOTHER)(e, function(t) {
                if (console.log(t), 0 == t.returnCode) {
                    var e = (t.data || {}).listConfigOther || [], o = [], i = [];
                    e.map(function(t) {
                        var a = o.findIndex(function(a) {
                            return t.attribTypeId == a;
                        });
                        if (a >= 0) i[a].list.push(t); else {
                            var e = {};
                            e.name = t.attribTypeName, e.id = t.attribTypeId, e.list = [ t ], i.push(e), o.push(t.attribTypeId);
                        }
                    }), console.log(i), a.setData({
                        configList: i,
                        list: e
                    });
                }
            });
        },
        addEvent: function() {
            var e = this, o = e.getParams(), i = e.data.form, n = [], r = e.data.list;
            for (var s in i) !function(t) {
                console.log(t);
                var a = i[t], e = r.find(function(t) {
                    return t.attribInfoId == a;
                });
                e && n.push(e);
            }(s);
            return "N" != e.data.displayConfig && (!n || n.length <= 0) ? ((0, a.showToast)("请选择配置"), 
            !1) : e.data.total ? (o.productConfigCode = e.data.config, o.total = e.data.total, 
            o.remark = e.data.remark, o.listCartConfig = n, console.log(o), void (0, t.ADDGHPRODUCTCONFIGCART)(o, function(t) {
                console.log(t), 0 == t.returnCode && ((0, a.showToast)("加入购物车成功"), e.triggerEvent("change", {
                    close: !1
                }));
            })) : ((0, a.showToast)("请设置发货数量"), !1);
        },
        updateNumber: function(t) {
            var a = t.currentTarget.id;
            console.log(t);
            var e = {};
            e[a] = t.detail, this.setData(e);
        }
    },
    ready: function() {
        console.log(this.data.config), this.getList();
    }
});