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

Component({
    properties: {},
    options: {
        styleIsolation: "shared"
    },
    data: {
        active: 0,
        searchText: "",
        orderList: [],
        menuShow: {},
        showPopup: !1,
        showOverlay: !1,
        menuList: [],
        TYPELIST: {
            0: "U",
            1: "F",
            2: "O",
            3: "C"
        },
        isLast: !1,
        pageSize: 10,
        current: 0,
        showNodata: !1,
        typeId: "",
        logistics: [],
        userInfo: {}
    },
    methods: {
        showMenu: function(t) {
            var e = this.data.menuShow, a = t.currentTarget.dataset.index;
            e[a] = !e[a], this.setData({
                menuShow: e
            });
        },
        hideMenu: function(t) {
            var e = this.data.menuShow;
            e[t.currentTarget.dataset.index] = !1, this.setData({
                menuShow: e
            });
        },
        onChange: function(t) {
            this.setData({
                active: t.detail.index,
                isLast: !1,
                current: 0,
                orderList: []
            }), this.getList();
        },
        openDialog: function(t) {
            var e = this.data.menuShow, a = t.currentTarget.dataset.index, r = t.currentTarget.dataset.code;
            a >= 0 && (e[a] = !1), this.getLogistics(r, e);
        },
        closeDialog: function() {
            this.setData({
                showPopup: !1
            });
        },
        remind: function(e) {
            var r = e.currentTarget.dataset, n = a.globalData.userInfo, s = {};
            s.spaPurchaseCode = r.code, s.merchantName = n.merchant.merchantName, s.ghMerchantOrderCode = r.id, 
            (0, t.WXREMINDERORDER)(s, function(t) {
                if (0 == t.returnCode) {
                    var e = "您的催单请求已发送客服进行跟进,请耐心等待";
                    t.data >= 5 && (e = "您的催单请求已达上限,客服会尽快与您联系"), wx.showModal({
                        content: e,
                        showCancel: !1
                    });
                }
            });
        },
        buyAgain: function(a) {
            console.log(a);
            var r = this, n = this.data.orderList || [], s = a.currentTarget.dataset.id, o = n.find(function(t) {
                return t.id == s;
            }), i = {};
            i.ghMerchantOrderCode = o.ghMerchantOrderCode, i.merchantCode = o.merchantCode, 
            i.productConfigCode = o.productConfigCode, i.remark = o.remark, i.total = o.total, 
            i.listCartConfig = o.listMerchantOrderConfig, (0, t.ADDGHPRODUCTCONFIGCART)(i, function(t) {
                0 == t.returnCode && ((0, e.showToast)("已加入购物车"), r.triggerEvent("change", !0));
            });
        },
        getMenu: function() {
            var e = this, a = e.getParams();
            a.type = 27, (0, t.GETTYPELIST)(a, function(t) {
                if (0 == t.returnCode) {
                    var a = t.data || [];
                    e.setData({
                        menuList: a
                    });
                }
            });
        },
        getParams: function() {
            var t = a.globalData.userInfo, e = {};
            return e.merchantCode = t.merchant.merchantId, e;
        },
        openFilter: function() {
            this.setData({
                showOverlay: !0
            });
        },
        closeFilter: function() {
            this.setData({
                showOverlay: !1
            });
        },
        getList: function() {
            var a = this, r = a.data.TYPELIST, n = a.getParams(), s = a.data.current + 1, o = a.data.isLast;
            if (n.dtoStatus = r[a.data.active], n.categoryId = a.data.typeId, n.pageNum = s, 
            n.pageSize = a.data.pageSize, o) return !1;
            (0, e.showLoading)("加载中..."), (0, t.GETWXLISTMERCHANTORDERS)(n, function(t) {
                (0, e.hideLoading)();
                var r = (t.data || {}).list || [], n = a.data.orderList || [];
                if (r.map(function(t) {
                    var e = (t.listMerchantOrderConfig || []).filter(function(t) {
                        return "F" != t.option;
                    });
                    return t.listMerchantOrderConfig = e, t;
                }), 0 != t.returnCode) return a.setData({
                    isLast: !0
                }), !1;
                r.length < 10 && (o = !0);
                var i = n.concat(r), c = !1;
                i.length <= 0 && (c = !0);
                var u = {};
                console.log(i), u.orderList = i, u.isLast = o, u.current = s, u.showNodata = c, 
                a.setData(u);
            });
        },
        treatData: function(t) {
            var e = [];
            return t.map(function(t) {
                var a = e.findIndex(function(e) {
                    return e.spaPurchaseCode == t.spaPurchaseCode;
                });
                if (a < 0) {
                    var r = JSON.parse(JSON.stringify(t));
                    r.list = [ t ], e.push(r);
                } else e[a].list.push(t);
            }), e;
        },
        getLogistics: function(a, r) {
            var n = this, s = {};
            s.ghMerchantOrderCode = a, (0, t.GETLOGISTICSBYSPAPURCHASECODE)(s, function(t) {
                if (0 != t.returnCode) return (0, e.showToast)(t.message || t.msg), !1;
                var a = t.data || [], s = a[0] ? a[0].bsAddress : {};
                n.setData({
                    showPopup: !0,
                    menuShow: r,
                    logistics: a,
                    userInfo: s
                });
            });
        },
        cancelEvent: function(a) {
            var r = this, n = {};
            n.ghMerchantOrderCode = a.currentTarget.dataset.code, wx.showModal({
                content: "请确认是否取消订单?",
                showCancel: !0,
                success: function(a) {
                    a.confirm && (0, t.WXCANCELORDER)(n, function(t) {
                        0 == t.returnCode && ((0, e.showToast)(t.message || "取消成功"), r.setData({
                            isLast: !1,
                            orderList: [],
                            current: 0
                        }), r.getList());
                    });
                }
            });
        },
        menuEvent: function(t) {
            var e = t.currentTarget.dataset.id;
            this.setData({
                typeId: e,
                showOverlay: !1,
                isLast: !1,
                current: 0,
                orderList: []
            }), this.getList();
        },
        goSearch: function() {
            wx.navigateTo({
                url: "/packageIndex/pages/search/search"
            });
        }
    },
    ready: function() {
        this.getMenu(), this.getList();
    }
});