// pages/my/addressAdd.js import request from '../../utils/request' // import { on } from 'cluster' Page({ /** * 页面的初始数据 */ data: { region: ['请选择省市区', '', ''], nameValue:'', telValue: '', delValue: '', delId: '' }, valueInput(e){ console.log(e.detail.value) this.setData({ nameValue: e.detail.value }) }, valueInput1(e){ this.setData({ telValue: e.detail.value }) }, valueInput2(e){ this.setData({ delValue: e.detail.value }) }, bindRegionChange: function (e) { this.setData({ region: e.detail.value }) }, saveEvent(){ if(!this.data.nameValue){ wx.showToast({ title: '请输入姓名', icon: 'none', duration:3000 }) return } if(!this.data.telValue){ wx.showToast({ title: '请输入联系电话', icon: 'none', duration:3000 }) return } if(!this.isTel(this.data.telValue)){ wx.showToast({ title: '手机号码格式错误', icon: 'none', duration:3000 }) return } if(!this.data.region[1]){ wx.showToast({ title: '请选择地址', icon: 'none', duration:3000 }) return } if(!this.data.delValue){ wx.showToast({ title: '请输入详细地址', icon: 'none', duration:3000 }) return } const param = { "name": this.data.nameValue, // 收货⼈,必填项 "phone": this.data.telValue, // 收货⼈联系电话,必填项 // "provinceCode": "45000", // 省编号,必填项 "province": this.data.region[0], // 省,必填项 // "cityCode": "52100", // 市编号,必填项 "city": this.data.region[1], // 市,必填项 // "townCode": "00021", // 区域编号,必填项 "town": this.data.region[2], // 区域,必填项 "address": this.data.delValue, // 具体地址,必填项 "isDefault": 1 // 是否默认地址,1是 2否,必填项 } if(this.data.delId){ // 编辑 param.id = this.data.delId request._post('/firefly/account-address/my-address/update',param, res=>{ if(res.retCode == 0){ const text = this.data.delId? '更新成功': '添加成功' wx.showToast({ title: text, icon: 'none', duration:3000 }) setTimeout(() => { wx.navigateBack({ delta: 1 }) // wx.redirectTo({ // url: '/pages/my/addressList' // }) },1500) } }) }else{ // 新增 request._post('/firefly/account-address/my-address/add/new',param, res=>{ if(res.retCode == 0){ wx.showToast({ title: '添加地址成功', icon: 'none', duration:3000 }) setTimeout(() => { wx.redirectTo({ url: '/pages/my/addressList' }) },1500) } }) } }, getDetail(id){ const param = { id: id } request._post('/firefly/account-address/my-address/detail',param, res=>{ this.data.region[0] = res.body.province this.data.region[1] = res.body.city this.data.region[2] = res.body.town this.setData({ nameValue: res.body.name, telValue: res.body.phone, delValue: res.body.address, region: this.data.region }) }) }, // 判断手机号   isTel(value) {     return /^1[3,4,5,6,7,8,9][0-9]{9}$/.test(value.toString());   }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { if(options.id){ this.getDetail(options.id) this.setData({ delId: options.id }) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })