var e = getApp(), t = require("../../utils/login.js"); Page({ data: { banner: [], list: [], loading: !1, message: "", selectItemID: null, approve: !0, protocol: { url: "", name: "聚美汽服购买协议" }, isSubmit: !1 }, onLoad: function () { this.getAgentConfig(); }, getAgentConfig: function () { var a = this; if (a.data.loading) return !1; a.setData({ loading: !0 }); var payload = { number: e.globalData.deviceData.number || e.globalData.devicecode || "", agentid: e.globalData.deviceData.agentid || "", method: "POST" }; t.request('/miniprogram/single/getAgentConfig', payload, !0).then(function (res) { a.setData({ loading: !1 }); if (res.code != 200) { a.setData({ list: [], message: res.message || "加载失败" }); return; } var list = (res.data || []).map(function (x, idx) { x.selected = idx === 0; return x; }); a.setData({ list: list, selectItemID: list.length ? list[0].id : null, message: "" }); }).catch(function () { a.setData({ loading: !1, list: [], message: "网络异常,请稍后重试" }); }); }, selectItem: function (n) { var id = n.currentTarget.dataset.id; var list = (this.data.list || []).map(function (x) { x.selected = x.id == id; return x; }); this.setData({ selectItemID: id, list: list }); }, tobuyNow: function () { if (!this.data.approve) return wx.showToast({ title: "请勾选同意相关条款", icon: "none" }), !1; if (!this.data.selectItemID || this.data.isSubmit) return wx.showToast({ title: "请选择单次洗车金额~", icon: "none" }), !1; var i = this, sel = (this.data.list || []).find(function (x) { return x.id == i.data.selectItemID; }); if (!sel || !sel.token) return wx.showToast({ title: "请选择有效档位~", icon: "none" }), !1; this.setData({ isSubmit: !0 }), wx.showLoading({ title: "" }); t.request('/miniprogram/single/create', { token: sel.token, method: "POST" }, !0).then(function (res) { wx.hideLoading(), i.setData({ isSubmit: !1 }); if (200 != res.code) return wx.showModal({ title: "提示", content: res.message || "下单失败" }), !1; var p = res.data.result || {}; var orderid = res.data.orderid || p.orderid || ""; wx.requestPayment({ timeStamp: p.timeStamp, nonceStr: p.nonceStr, package: p.package, signType: p.signType, paySign: p.paySign, success: function () { if (orderid) { t.request('/miniprogram/single/notify', { orderid: orderid, method: "POST" }, !0).then(function () { wx.redirectTo({ url: "/pages/washing/washing" }); }).catch(function () { wx.redirectTo({ url: "/pages/washing/washing" }); }); } else { wx.redirectTo({ url: "/pages/washing/washing" }); } } }); }).catch(function () { wx.hideLoading(), i.setData({ isSubmit: !1 }); }); }, change: function (t) { var i = t.detail.value.length; this.setData({ approve: 1 == i }); } });