// pages/order/address/mineAddAddress.js var app = getApp(); const card = require('../../../utils/card.js'); Page({ /** * 页面的初始数据 */ data: { type: 0, id: "", name: "", man: true, sex: 1, iphone: app.iphone, address: "", detailAddress: "", isDefault: 0, }, /** * 生命周期函数--监听页面加载 */ onLoad: function(options) { this.data.type = options.type; if (options.map) { var map = JSON.parse(options.map); var list = map.receiveAddress.split("-"); this.setData({ id: map.id, name: map.name, iphone: map.receiveMobile, address: list[0], detailAddress: list[1], isSwitch: map.isDefault == 1 }); } }, /** * */ cy_getInputContent: function(e) { var index = e.currentTarget.dataset.index; var value = e.detail.value; if (index == 1) { // 姓名 this.data.name = value; } else if (index == 2) { //手机 this.data.iphone = value; } else if (index == 3) { // 门牌号 this.data.detailAddress = value; } }, /** * */ cy_getPhoneNumber: function(e) { // 获取手机号 var that = this; if (e.detail.errMsg == 'getPhoneNumber:ok') { var iv = e.detail.iv; var encryptedData = e.detail.encryptedData; card.wx_getPhoneNumber(iv, encryptedData, function(json) { var result = json.data; console.log(json); if (result.status == '1') { var data = result.data.data; app.iphone = data.purePhoneNumber; that.setData({ iphone: data.purePhoneNumber, }); } else { wx.showToast({ title: '手机号获取失败,请手动输入', icon: "none" }) } }, function(err) { wx.showToast({ title: '手机号获取失败,请手动输入', icon: "none" }) }); } else { wx.showToast({ title: '手机号获取失败,请手动输入', icon: "none" }) } }, /** * */ cy_selectLocation() { var that = this; wx.chooseLocation({ success: function(res) { if (res.errMsg == "chooseLocation:ok") { console.log(res); var address = res.address + res.name; that.setData({ address: address }) } }, fail: function(res) { } }) }, /** * */ radioChange: function(e) { this.setData({ sex: e.detail.value }) }, /** * */ cy_switchChange: function(e) { if (e.detail.value) { this.data.isDefault = 1; } else { this.data.isDefault = 0; } }, /** * 保存收货地址 */ cy_save: function() { var that = this; if (this.data.iphone.length == 0) { app.utils.alertErrorMsg("提示", "请输入手机"); return; } if (this.data.iphone.length != 11) { app.utils.alertErrorMsg("提示", "手机输入错误"); return; } if (this.data.address.length == 0) { app.utils.alertErrorMsg("提示", "请输入地址"); return; } var method = this.cy_getAddressMethod(); var address = this.data.address + "-" + this.data.detailAddress; var params = { "method": method, "wid": app.wid, "openId": app.openId, "name": this.data.name, "mobile": this.data.iphone, "receiveMobile": this.data.iphone, "receiveAddress": address, "isDefault": this.data.isDefault, "sex": this.data.sex, } var ignores = []; if (this.data.id != "") { params.id = that.data.id; ignores.push("id"); } ignores.push("mobile"); ignores.push("receiveMobile"); ignores.push("receiveAddress"); ignores.push("sex"); ignores.push("isDefault"); ignores.push("name"); // 忽略签名参数 app.jsapi.api(app.globalData.appKey, app.globalData.appSecret, app.globalData.serverUrl).ajax(params, ignores, function(json) { console.log(json); var result = json.data; if (result.status == 1) { var pages = getCurrentPages(); var prevPage = pages[pages.length - 2] //上一个页面 prevPage.cy_getLoadAddress(); wx.navigateBack({}); } else { app.msg.showMsg("提示", result.message); } }, function(error) { app.msg.showMsg("提示", "网络中断,获取门店失败"); } ); }, /** * */ cy_getAddressMethod: function() { var method = "wxdc.save.distribution.address"; if (this.data.type == 0) { method = "wxdc.save.distribution.address"; } else { method = "wxdc.update.distribution.address"; } return method; } })