var e = getApp(), t = require("../../utils/login.js"); Page({ data: { showLoding: !0, urlList: [], wangdianList: [], servicetel: "", notice: "", noticeurl: null, banner: [], isScan: !1, user: {}, tmplIds: [], joinUs: "", tabStatus: { coupon: !1, shop: !1 }, showOneTimeOptions: !1, oneTimeOptions: [], oneTimeLoading: !1 }, bindViewTap: function () { wx.navigateTo({ url: "../logs/logs" }); }, onLoad: function () { wx.showLoading({ title: "" }); var a = this; // 获取地理位置 wx.getLocation({ type: 'gcj02', success: function (res) { // 存储经纬度 wx.setStorageSync('latitude', res.latitude); wx.setStorageSync('longitude', res.longitude); e.globalData.latitude = res.latitude; e.globalData.longitude = res.longitude; // 获取网点列表 t.request('/v2/miniprogram/branch/lists', { latitude: res.latitude || '', longitude: res.longitude || '' }, !0).then(function (res) { a.setData({ wangdianList: res.data || [] }); }); }, fail: function () { // 即使获取位置失败也加载网点列表,只是不传入经纬度参数 t.request('/v2/miniprogram/branch/lists', {}, !0).then(function (res) { a.setData({ wangdianList: res.data || [] }); }); }, complete: function () { t.pageStart(e).then(function (t) { a.getData(); a.setData({ servicetel: e.globalData.servicetel, isScan: !!e.globalData.devicecode }); }); } }); // 获取首页数据 t.request('/v2/miniprogram/index/home', { method: 'GET' }, !0).then(function (e) { a.setData({ banner: e.data.banner, tmplIds: e.data.tmplIds, joinUs: e.data.joinUs, notice: e.data.notice, noticeurl: e.data.noticeurl, tabStatus: e.data.tabStatus, urlList: e.data.urlList }, function () { wx.hideLoading(), 0 == e.data.banner.length ? a.setData({ showLoding: !1 }) : setTimeout(function () { a.setData({ showLoding: !1 }); }, 50); }); }); }, getData: function () { var a = this; // 获取首页数据 t.request('/v2/miniprogram/index/balance', e.globalData.deviceData, !0).then(function (e) { a.setData({ user: e.data || [], }); // 存储进度订单 wx.setStorageSync('progressorder', e.data.progressorder || []); }); }, load: function (e) { console.log(e); }, openLocation: function (e) { var latitude = Number(e.currentTarget.dataset.latitude); var longitude = Number(e.currentTarget.dataset.longitude); var name = e.currentTarget.dataset.name; var address = e.currentTarget.dataset.address; wx.openLocation({ latitude: latitude, longitude: longitude, name: name, address: address, scale: 18 }); var t = e.currentTarget.dataset.index, a = this.data.swiperWidth * e.detail.height / e.detail.width; this.data.banner[t].height = a, this.setData({ swiperHeight: a }); }, onShow: function () { this.setData({ isScan: !!e.globalData.devicecode || this.data.isScan }), (this.getData(), this.isneedUpload = !1); }, toPage: function (t) { if (t.currentTarget.dataset.phone) { // 打开客服聊天窗口 return wx.openCustomerServiceChat(); // 增加打电话 wx.makePhoneCall({ phoneNumber: "" + t.currentTarget.dataset.phone }); return; } var a = t.currentTarget.dataset, i = a.url, o = a.needlogin, n = a.showimg; if (console.log("showImg", n), i) { this.isneedUpload = !0; if (o && !e.globalData.user.session) return this.isneedUpload = !0, wx.navigateTo({ url: "/pages/login/login" }), e.globalData.needJumpUrl = "/pages/".concat(i), !1; wx.navigateTo({ url: "/pages/".concat(i) }), this.isneedUpload = !0; } else { if (!n) return !1; wx.previewImage({ urls: [this.data.joinUs] }); } }, toScan: function () { e.globalData.needJumpUrl = !1; var a = this; wx.scanCode({ success: function (i) { console.log(i), wx.showLoading({ title: "" }), e.globalData.qrcode = i.result, t.request("/v2/miniprogram/identify/index", i, !0).then(function (t) { console.log("data", t), wx.hideLoading(), e.globalData.deviceData = t.data || e.globalData.deviceData || {}; e.globalData.devicecode = t.data.devicecode || e.globalData.devicecode; a.setData({ isScan: !!t.data.devicecode }); }).catch(function (e) { wx.hideLoading(); }); } }); }, isSubmit: !1, isneedUpload: !1, isshowModal: !1, needUpload: function () { this.isneedUpload = !0; }, toStart: function () { e.globalData.needJumpUrl = !1, this.isneedUpload = !0; var t = this; if (console.log("this.isSubmit", this.isSubmit), this.isSubmit) return !1; wx.showActionSheet({ itemList: ["单次消费", "立即启动"], success: function (res) { if (res.tapIndex === 0) { t.openOneTimeOptions(); } else { if (t.data.user.money == 0) { wx.showModal({ title: "提示", content: "您的洗车金额为0元,是否需要购买洗车金额?", confirmText: "去购买", cancelText: "取消", success: function (m) { if (m.confirm) { wx.navigateTo({ url: "/pages/voucher/voucher" }), t.isneedUpload = !0; } } }); return; } else if (t.data.user.money < 10) { wx.showModal({ title: "提示", content: "洗车金额不足10元,是否需要购买洗车金额还是直接开机?", confirmText: "去购买", cancelText: "直接开机", success: function (m) { if (m.confirm) { wx.navigateTo({ url: "/pages/voucher/voucher" }), t.isneedUpload = !0; } else { t.startup(); } } }); return; } t.startup(); } } }); }, openOneTimeOptions: function () { var a = this; if (a.data.oneTimeLoading) return !1; a.setData({ oneTimeLoading: !0 }); t.request('/v2/miniprogram/recharge/once', e.globalData.deviceData || {}, !0).then(function (res) { a.setData({ oneTimeOptions: res.data && res.data.list ? res.data.list : (res.data || []), showOneTimeOptions: !0, oneTimeLoading: !1 }); }).catch(function () { a.setData({ oneTimeLoading: !1 }); }); }, closeOneTimeOptions: function () { this.setData({ showOneTimeOptions: !1 }); }, payOneTime: function (evt) { var a = this, i = evt.currentTarget.dataset.id; if (!i) return !1; wx.showLoading({ title: "" }); t.request('/v2/miniprogram/recharge/once/create', { id: i, devicecode: e.globalData.devicecode }, !0).then(function (res) { if (wx.hideLoading(), 200 != res.code) return wx.showModal({ title: "提示", content: res.message || "" }), !1; var r = res.data.result; wx.requestPayment({ timeStamp: r.timeStamp, nonceStr: r.nonceStr, package: r.package, signType: r.signType, paySign: r.paySign, success: function () { a.setData({ showOneTimeOptions: !1 }); wx.showModal({ title: "提示", content: "限单次洗车" }); a.getData(); a.startup(); } }); }).catch(function () { wx.hideLoading(); }); }, startup: function () { var a = this; wx.showModal({ title: "提示", content: "你当前将要使用的机器编号是:".concat(e.globalData.deviceData.title || e.globalData.deviceData.devicecode, ",确认开机吗?"), success: function (i) { i.confirm && (a.isSubmit = !0, wx.showLoading({ title: "正在启动" }), t.request('/v2/miniprogram/' + e.globalData.deviceData.type + '/startup', e.globalData.deviceData || {}, !0).then(function (e) { a.isSubmit = !1, wx.hideLoading(), 200 == e.code && (wx.showModal({ title: "", content: e.message }), a.data.tmplIds.length > 0 && a.requestSubscribeMessage(), wx.redirectTo({ // url: "/pages/washing/washing" url: "/pages/index/index" }), a.isneedUpload = !0), 888 == e.code && (wx.navigateTo({ url: "/pages/voucher/voucher" }), a.isneedUpload = !0); }).catch(function (e) { a.isSubmit = !1, wx.hideLoading(); })); }, fail: function (e) { console.log("fail:", e); } }); }, requestSubscribeMessage: function () { wx.requestSubscribeMessage({ tmplIds: this.data.tmplIds, success: function (e) { console.log("requestSubscribeMessage", e), t.request("/miniprogram/index/newtmpl", e, !0).then(function (e) { }).catch(function (e) { }); }, fail: function (e) { console.log("requestSubscribeMessagefail", e); } }); }, onShareAppMessage: function () { } });