// pages/jz/jz.js //获取应用实例 const app = getApp() Page({ data: { imgUrls: [ '/images/banner1.png' ], indicatorDots: true, autoplay: true, interval: 5000, duration: 1000, price: '399', img1: '/images/title-icon.png', img2: '/images/banner2.png', nowDate: new Date().getTime(), cityId: 440100000, _num: 1, typeNum: 10, addrArray: { id: [440100000, 430426000], name: ['广州', '深圳', '上海', '长沙', '武汉', '杭州', '北京'] }, addrIndex: 0, items1: [], }, getActive: function (e) { this.setData({ _num: e.target.dataset.num }) }, bindAddrChange: function (e) { if (e != undefined && e.detail != undefined) { this.setData({ _num: e.detail == undefined ? 1 : e.detail.value + 1, addrIndex: e.detail == undefined ? 0 : e.detail.value, }) } var that = this; wx.request({ url: getApp().gw.hostUrl + '/mall/web/goods/list', data: { selectedCityId: that.data.addrIndex }, header: { "Content-Type": "application/json" }, method: 'GET', dataType: 'json', responseType: 'text', success: function (res) { if (res.data.code == 0 && res.data.response.goodsList.length > 0) { that.setData({ items1: res.data.response.goodsList, }); } }, fail: function (res) { }, complete: function (res) { }, }) }, loading: function (e) { wx.navigateTo({ url: '../detail/detail?goodsNo=' + e.currentTarget.dataset.item.goodsNo }) }, loadingClick: function () { var price = event.currentTarget.dataset.price; console.log(price); var pages = getCurrentPages(); var currPage = pages[pages.length - 1]; //当前页面 var prevPage = pages[pages.length]; //下一个页面 //直接调用上一个页面的setData()方法,把数据存到下一个页面中去 prevPage.setData({ price: price }); }, onLoad: function () { if (app.globalData.userInfo) { this.setData({ userInfo: app.globalData.userInfo, hasUserInfo: true }) this.bindAddrChange(); } else if (this.data.canIUse) { // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回 // 所以此处加入 callback 以防止这种情况 app.userInfoReadyCallback = res => { this.setData({ userInfo: res.userInfo, hasUserInfo: true }) this.bindAddrChange(); } } else { // 在没有 open-type=getUserInfo 版本的兼容处理 wx.getUserInfo({ success: res => { app.globalData.userInfo = res.userInfo this.setData({ userInfo: res.userInfo, hasUserInfo: true }) this.bindAddrChange(); } }) } }, getUserInfo: function (e) { app.globalData.userInfo = e.detail.userInfo this.setData({ userInfo: e.detail.userInfo, hasUserInfo: true }) } })