// pages/order/index.js const { api } = require("../../utils/api") Page({ /** * 页面的初始数据 */ data: { id: '', info: null, addr: null, checked:false }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { const id = options.id this.data.id = id }, fetchAddr() { api('/personal/address/list', 'GET').then(res => { if (res.code === 200) { const tmps = res.data if(tmps.length > 0){ this.setData({addr:tmps[0]}) } } }) }, chooseAddr() { const _this = this wx.chooseAddress({ success(res) { const data = {isDefault:1,phone:res.telNumber, name :res.userName,detail: res.provinceName + res.cityName + res.countyName + res.detailInfo} _this.saveAddr(data) } }) }, saveAddr(data){ api('/personal/address/add','POST',data,'json').then(res => { if (res.code=== 200) { this.fetchAddr() } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { this.fetchInfo() this.fetchAddr() }, change(){ const checked = !this.data.checked this.setData({checked:checked}) }, pay(){ if (this.data.checked === false){ wx.showModal({ content: '请先勾选,我承诺会好好照顾它,不随意丢弃。', complete: (res) => { if (res.confirm) { } } }) } }, fetchInfo() { api('/claim/detail', "GET", { id: this.data.id }).then(res => { if (res.code === 200) { const tmps = res.data tmps.content = tmps.content.trim() this.setData({ info: tmps }) } }) }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })