search.js 5.13 KB
function t(t, e, r) {
    return e in t ? Object.defineProperty(t, e, {
        value: r,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : t[e] = r, t;
}

var e, r = require("../../../utils/util"), a = require("../../restapi"), o = getApp();

Page({
    data: (e = {
        orderHistory: [],
        orderList: [],
        spaProductCode: "",
        maxNumber: 9999,
        showNodata: !1,
        isLast: !1,
        pageSize: 9999,
        current: 0
    }, t(e, "showNodata", !1), t(e, "showPopup", !1), t(e, "showOverlay", !1), t(e, "logistics", []), 
    t(e, "userInfo", {}), e),
    onLoad: function(t) {
        wx.setNavigationBarTitle({
            title: "搜索"
        });
    },
    onReady: function() {},
    onShow: function() {
        var t = wx.getStorageSync("orderHistory") || [];
        this.setData({
            orderHistory: t
        });
    },
    clearHistory: function() {
        this.setData({
            orderHistory: []
        }), wx.removeStorageSync("orderHistory");
    },
    onChange: function(t) {
        this.setData({
            spaProductCode: t.detail
        });
    },
    onSearch: function() {
        var t = this, e = wx.getStorageSync("orderHistory") || [], r = t.data.spaProductCode;
        if (!r) return !1;
        e.push(r), wx.setStorageSync("orderHistory", e), this.getList();
    },
    clickEvent: function(t) {
        var e = t.currentTarget.dataset.name, r = this.data.queryCondition || {};
        this.setData({
            spaProductCode: e,
            queryCondition: r
        }), this.getList();
    },
    getList: function() {
        var t = this, e = {}, r = t.data.isLast;
        e.pageNum = 1, e.pageSize = t.data.pageSize, e.spaProductCode = t.data.spaProductCode, 
        e.spaProductName = t.data.spaProductCode, e.spaPurchaseCode = t.data.spaProductCode, 
        (0, a.GETWXLISTMERCHANTORDERS)(e, function(e) {
            var a = (e.data || {}).list || [], o = t.data.orderList || [];
            if (a.map(function(t) {
                var e = (t.listMerchantOrderConfig || []).filter(function(t) {
                    return "F" != t.option;
                });
                return t.listMerchantOrderConfig = e, t;
            }), 0 != e.returnCode) return t.setData({
                isLast: !0
            }), !1;
            a.length < 10 && (r = !0);
            var n = o.concat(a), s = !1;
            n.length <= 0 && (s = !0);
            var i = {};
            console.log(n), i.orderList = a, i.isLast = r, i.current = 1, i.showNodata = s, 
            t.setData(i);
        });
    },
    remind: function(t) {
        var e = t.currentTarget.dataset, r = o.globalData.userInfo, n = {};
        n.spaPurchaseCode = e.code, n.merchantName = r.merchant.merchantName, n.ghMerchantOrderCode = e.id, 
        (0, a.WXREMINDERORDER)(n, function(t) {
            if (0 == t.returnCode) {
                var e = "您的催单请求已发送客服进行跟进,请耐心等待";
                t.data >= 5 && (e = "您的催单请求已达上限,客服会尽快与您联系"), wx.showModal({
                    content: e,
                    showCancel: !1
                });
            }
        });
    },
    buyAgain: function(t) {
        console.log(t);
        var e = this, o = this.data.orderList || [], n = t.currentTarget.dataset.id, s = o.find(function(t) {
            return t.id == n;
        }), i = {};
        i.ghMerchantOrderCode = s.ghMerchantOrderCode, i.merchantCode = s.merchantCode, 
        i.productConfigCode = s.productConfigCode, i.remark = s.remark, i.total = s.total, 
        i.listCartConfig = s.listMerchantOrderConfig, (0, a.ADDGHPRODUCTCONFIGCART)(i, function(t) {
            0 == t.returnCode && ((0, r.showToast)("已加入购物车"), e.triggerEvent("change", !0));
        });
    },
    getLogistics: function(t, e) {
        var o = this, n = {};
        n.ghMerchantOrderCode = t, (0, a.GETLOGISTICSBYSPAPURCHASECODE)(n, function(t) {
            if (0 != t.returnCode) return (0, r.showToast)(t.message || t.msg), !1;
            var a = t.data || [], n = a[0] ? a[0].bsAddress : {};
            o.setData({
                showPopup: !0,
                menuShow: e,
                logistics: a,
                userInfo: n
            });
        });
    },
    cancelEvent: function(t) {
        var e = this, o = {};
        o.ghMerchantOrderCode = t.currentTarget.dataset.code, wx.showModal({
            content: "请确认是否取消订单?",
            showCancel: !0,
            success: function(t) {
                t.confirm && (0, a.WXCANCELORDER)(o, function(t) {
                    0 == t.returnCode && ((0, r.showToast)(t.message || "取消成功"), e.getList());
                });
            }
        });
    },
    openDialog: function(t) {
        var e = this.data.menuShow, r = t.currentTarget.dataset.index, a = t.currentTarget.dataset.code;
        r >= 0 && (e[r] = !1), this.getLogistics(a, e);
    },
    closeDialog: function() {
        this.setData({
            showPopup: !1
        });
    },
    clear: function() {
        this.setData({
            spaProductCode: "",
            orderList: []
        });
    }
});