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

Component({
    properties: {
        code: {
            type: [ String, Number ],
            value: ""
        },
        queryCondition: {
            type: Object,
            value: {}
        },
        spa: {
            type: [ String, Number ],
            value: ""
        }
    },
    data: {
        menuList: [],
        menuActive: "",
        show: !1,
        maxNumber: 9999,
        yearList: [],
        yearActive: "",
        checkList: [],
        modelList: [],
        remark: "",
        totalList: {},
        form: {},
        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"
        },
        cList: {}
    },
    methods: {
        menuEvent: function(t) {
            var e = t.currentTarget.id;
            this.setData({
                menuActive: e
            }), this.getYear();
        },
        showMore: function(t) {
            var e = this.data.show;
            this.setData({
                show: !e
            });
        },
        getParams: function() {
            var t = a.globalData.userInfo, e = {};
            return e.merchantCode = t.merchant.merchantId, e;
        },
        getYear: function() {
            var o = this, i = {}, n = (o.getParams(), o.data.queryCondition), r = a.globalData.userInfo;
            console.log(r), n.spaProductCode = o.data.spa || null, n.merchantCode = r.merchant.merchantId, 
            n.audiId = o.data.menuActive, o.data.code && (i.glsxProductCode = o.data.code || ""), 
            i.queryCondition = n, (0, t.LISTYEARMODE)(i, function(t) {
                console.log(t), 0 == t.returnCode ? (o.setData({
                    yearList: t.data || []
                }), o.getModel()) : (0, e.showToast)(t.message);
            });
        },
        getCarseries: function() {
            var o = this, i = {}, n = o.data.queryCondition, r = a.globalData.userInfo;
            n.spaProductCode = o.data.spa || null, n.merchantCode = r.merchant.merchantId, o.data.code && (i.glsxProductCode = o.data.code || ""), 
            i.queryCondition = n, (0, t.LISTAUDIINFO)(i, function(t) {
                if (console.log(t), 0 == t.returnCode) {
                    var a = t.data || [];
                    o.setData({
                        menuList: a,
                        menuActive: a[0] ? a[0].id : ""
                    }), a[0] && a[0].id ? o.getYear() : o.triggerEvent("change", {
                        close: !1
                    });
                } else (0, e.showToast)(t.message);
            });
        },
        getModel: function() {
            var o = this, i = {}, n = o.data.queryCondition, r = a.globalData.userInfo;
            o.data.code && (i.glsxProductCode = o.data.code || ""), n.merchantCode = r.merchant.merchantId, 
            i.queryCondition = n, i.modelYearId = o.data.yearActive, i.audiId = o.data.menuActive, 
            i.pageSize = 1e5, i.pageNo = 1, (0, t.PAGEMOTORCYCLE)(i, function(t) {
                if (0 == t.returnCode) {
                    var a = (t.data || {}).listGhProductConfig || [];
                    a.map(function(t) {
                        var e = o.treatData(t.listConfigOther || []);
                        return t.configList = e, t.total = 0, t;
                    }), console.log(a), o.setData({
                        modelList: a
                    });
                } else (0, e.showToast)(t.message);
            });
        },
        yearEvent: function(t) {
            var e = t.currentTarget.dataset.id;
            this.setData({
                yearActive: e
            }), this.getModel();
        },
        inputEvent: function(t) {
            var e = {};
            e[t.currentTarget.id] = t.detail.value, this.setData(e);
        },
        addEvent: function() {
            var a = this, o = a.getParams(), i = (a.data.form, []), n = a.data.checkList;
            if (!n || n.length <= 0) return (0, e.showToast)("请选择车型"), !1;
            n.map(function(t) {
                var e = {};
                e.productConfigCode = t.productConfigCode, e.total = t.total, e.remark = a.data.remark;
                var o = t.listConfigOther || [], n = t.listCartConfig || [];
                o.map(function(t) {
                    "F" == t.option && n.push({
                        id: t.attribInfoId
                    });
                }), e.listCartConfig = n, i.push(e);
            }), delete o.spaProductCode, o.listShopCarts = i, console.log(o), (0, t.BATCHADDGHPRODUCTCONFIGCART)(o, function(t) {
                console.log(t), 0 == t.returnCode ? ((0, e.showToast)("加入购物车成功"), a.triggerEvent("change", {
                    close: !1
                })) : (0, e.showToast)(t.message);
            });
        },
        updateNumber: function(t) {
            console.log(t);
            var a = t.currentTarget.id, o = this.data.modelList, i = this.data.checkList || [], n = this.data.totalList || {}, r = Number(t.detail), s = this.data.maxNumber, d = this.data.cList || [], c = i.findIndex(function(t) {
                return t.productConfigCode == a;
            }), u = o.find(function(t) {
                return t.productConfigCode == a;
            }), l = o.findIndex(function(t) {
                return t.productConfigCode == a;
            });
            if (r > s) return (0, e.showToast)("购买数量超过最大数量"), this.setData({
                noPass: !1
            }), !1;
            console.log(u), u.total = r, u.listCartConfig = d[a], o[l] = u, t.detail > 0 ? (n[a] = t.detail, 
            c >= 0 ? i[c] = u : i.push(u)) : (delete n[a], c >= 0 && i.splice(c, 1)), this.setData({
                checkList: i,
                modelList: o,
                totalList: n
            });
        },
        treatData: function(t) {
            var e = [], a = [];
            return t.map(function(t) {
                var o = e.findIndex(function(e) {
                    return t.attribTypeId == e;
                });
                if (o >= 0) "O" == t.option && a[o].list.push(t); else if ("O" == t.option) {
                    var i = {};
                    i.name = t.attribTypeName, i.id = t.id, i.list = [ t ], a.push(i), e.push(t.attribTypeId);
                }
            }), a;
        },
        radioChangeEvent: function(t) {
            var e = t.currentTarget.id, a = t.currentTarget.dataset.mid, o = this.data.form, i = this.data.checkList || [], n = this.data.cList || [], r = i.findIndex(function(t) {
                return console.log(t.productConfigCode + "---" + a), t.productConfigCode == a;
            });
            if (r >= 0) {
                var s = i[r].listCartConfig || [];
                s.push({
                    id: t.detail
                }), i[r].listCartConfig = s;
            } else {
                var d = n[a] || [];
                d.push({
                    id: t.detail
                }), n[a] = d;
            }
            console.log(n), o[e] = t.detail, this.setData({
                form: o,
                checkList: i,
                cList: n
            }), console.log(i);
        }
    },
    ready: function() {
        console.log(this.data.queryCondition), this.getCarseries();
    }
});