var e = require("../../@babel/runtime/helpers/interopRequireDefault"), t = require("../../@babel/runtime/helpers/toConsumableArray"), a = e(require("../../@babel/runtime/regenerator")), n = require("../../@babel/runtime/helpers/slicedToArray"), o = require("../../@babel/runtime/helpers/asyncToGenerator"), r = (getApp(), require("../../utils/login.js")); Page({ data: { showLoding: !0, hotsale: !1, banner: [], customerService: [], recommendedList: [], lists: [], share: {}, user: {}, tab: "new", tabList: [ { type: "new", name: "最新开抢" }, { type: "hot", name: "热门" }, { type: "shortrange", name: "离我最近" } ], point: {}, loading: !1, count: 0, limit: 0, page: 1 }, onLoad: function(e) { this.pageStart(); }, onShow: function() {}, onPullDownRefresh: function() { this.setData({ lists: [], page: 1, loading: !1 }), this.pageStart(), wx.stopPullDownRefresh(); }, onReachBottom: function() { if (this.data.loading) return !1; this.getgoodsList(); }, onShareAppMessage: function() {}, pageStart: function() { this.getData(), this.getgoodsList(); }, getData: function() { var e = this; return o(a.default.mark(function t() { var o, s; return a.default.wrap(function(t) { for (;;) switch (t.prev = t.next) { case 0: return e, t.prev = 1, t.next = 4, r.request(r.baseUrl + "shop/home", {}, !0); case 4: o = t.sent, (s = o.data).recommendedList.forEach(function(e) { var t = e.price.split("."), a = n(t, 2); e.price_buck = a[0], e.price_cent = a[1]; }), e.setData({ showLoding: !1, banner: s.banner, customerService: s.customerService, recommendedList: s.recommendedList, share: s.share, user: s.user, tabList: s.tab }), t.next = 14; break; case 10: t.prev = 10, t.t0 = t.catch(1), console.log(t.t0), e.setData({ showLoding: !1 }); case 14: case "end": return t.stop(); } }, t, null, [ [ 1, 10 ] ]); }))(); }, getgoodsList: function(e) { var s = this; return o(a.default.mark(function e() { var o, i, c, u; return a.default.wrap(function(e) { for (;;) switch (e.prev = e.next) { case 0: if (o = s, !s.data.loading && 0 != s.data.page) { e.next = 3; break; } return e.abrupt("return", !1); case 3: return s.setData({ loading: !0 }), e.prev = 4, e.next = 7, r.request(r.baseUrl + "shop/home/shopList", { type: s.data.tab, point: { lng: s.longitude, lat: s.latitude }, page: s.data.page }, !0); case 7: i = e.sent, (c = i.data).data.forEach(function(e) { var t = e.price.split("."), a = n(t, 2); e.price_buck = a[0], e.price_cent = a[1]; }), u = c.data.length < c.limit ? 0 : s.data.page + 1, s.setData({ loading: !1, lists: [].concat(t(s.data.lists), t(c.data)), count: c.count, page: u, limit: c.limit }), e.next = 18; break; case 14: e.prev = 14, e.t0 = e.catch(4), console.log(e.t0), o.setData({ loading: !1 }); case 18: case "end": return e.stop(); } }, e, null, [ [ 4, 14 ] ]); }))(); }, latitude: null, longitude: null, changeTab: function(e) { var t = this; return o(a.default.mark(function n() { var o, r; return a.default.wrap(function(a) { for (;;) switch (a.prev = a.next) { case 0: if (o = e.currentTarget.dataset.tab, t, "shortrange" != o) { a.next = 20; break; } return a.prev = 3, a.next = 6, t.getlocation(); case 6: if (r = a.sent, console.log("result:", r), !r) { a.next = 14; break; } t.latitude = r.latitude, t.longitude = r.longitude, t.setData({ tab: o }), a.next = 15; break; case 14: return a.abrupt("return", !1); case 15: a.next = 20; break; case 17: a.prev = 17, a.t0 = a.catch(3), console.log(a.t0); case 20: t.setData({ tab: o, lists: [], page: 1, loading: !1 }), t.getgoodsList(); case 22: case "end": return a.stop(); } }, n, null, [ [ 3, 17 ] ]); }))(); }, getlocation: function() { var e = this; return new Promise(function(t, a) { wx.getLocation({ type: "wgs84", success: function(e) { e.latitude, e.longitude; t(e); }, fail: function(a) { wx.showModal({ title: "用户未授权", content: "请开启相关权限,以便更好使用小程序哦!", showCancel: !0, success: function(a) { a.confirm ? wx.openSetting({ success: function(a) { console.log("authSetting", a), a.authSetting ? wx.chooseLocation({ success: function(a) { e.setData({ receiver_address: a.name }), "" == a.name ? wx.showToast({ title: "未选择位置", icon: "none", duration: 2e3 }) : (console.log("res ok ", a), t(a)); }, fail: function(a) { e.showLocationFail(), t(!1); } }) : (e.showLocationFail(), t(!1)); } }) : a.cancel; }, fail: function(a) { e.showLocationFail(), t(!1); } }); } }); }); }, showLocationFail: function() { wx.showToast({ title: "位置失败", icon: "none", duration: 1e3 }); } });