123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- // customized/pages/address/add/add.js
- let app = getApp();
- let host = app.globalData.servsers; // 请求的url
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- name:'',
- phone:'',
- region: ['上海市', '上海市', '黄浦区'],
- detailAddress:'',
- id:null,
- switchChecked:false, //是否默认
- type:'add',
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- console.log(options,"options")
- if (options.type ==='edit'){ // 表示编辑
- this.setData({
- type:'edit'
- })
- this.getEditAddress(this)
- }
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
-
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- },
- bindRegionChange(e) {
- console.log('picker发送选择改变,携带值为', e.detail.value)
- this.setData({
- region: e.detail.value
- })
- },
- switchChange(e){
- this.setData({
- switchChecked: e.detail.value
- })
- },
- nameChange(e){
- this.setData({
- name: e.detail.value
- })
- },
- phoneChange(e) {
- this.setData({
- phone: e.detail.value
- })
- },
- addressInput(e){ // 详细地址
- console.log(e)
- this.setData({
- detailAddress: e.detail.value
- })
- },
- addAddress(){ // 保存地址
- let that =this;
- if(!that.data.name){
- wx.showToast({
- title: '收货人没有输入',
- icon:"none"
- });
- return
- }
- if(!that.data.phone){
- wx.showToast({
- title: '手机号码没有输入',
- icon: "none"
- });
- return
- }
- if (!that.data.detailAddress) {
- wx.showToast({
- title: '详细地址没有输入',
- icon: "none"
- });
- return
- }
- let data ={
- consignee: that.data.name, //收货人
- province: that.data.region[0],
- city: that.data.region[1],
- area: that.data.region[2],
- adress: that.data.detailAddress,
- phone: that.data.phone,
- adress_flag: that.data.switchChecked ? 0 : 1 // 是否默认 0是 1 否
- },
- url = host + '/adressapi/insertadd',
- title = "地址添加成功";
- if(that.data.type == 'edit'){
- data['action_account'] = null;
- data['id'] = that.data.id;
- url = host + '/adressapi/update';
- title = "地址编辑成功";
- } else {
- data['user_id'] =app.globalData.user_id;
- url = host + '/adressapi/insertadd';
- title = "地址添加成功";
- }
- wx.request({
- url: url,
- header: {
- 'content-type': 'application/x-www-form-urlencoded'
- },
- data: data,
- success(res){
- console.log(res,"地址保存")
- wx.showToast({
- title: title,
- icon:'none',
- success(){
- setTimeout(()=>{
- wx.navigateBack({
- delta: 1
- })
- },1000)
-
- }
- })
-
- }
- })
- },
- getEditAddress(that){ // 获取编辑的地址
-
- let address = wx.getStorageSync('address'),
- name = address.consignee,
- phone =address.phone,
- region = [address.province,address.city,address.area],
- detailAddress =address.adress,
- switchChecked = address.adress_flag == '0'? true : false ,
- id = address.id;
- console.log(address)
- that.setData({
- name:name,
- phone:phone,
- region: region,
- detailAddress: detailAddress,
- switchChecked: switchChecked,
- id: id
- })
- }
- })
|