goToEditor.js 3.2 KB
import {
  request
} from "../../request/index.js"
const a = getApp()
Page({
  data: {
    imagesUrl: a.globalData.baseUrl,
    name: '',
    phone: '',
    address2: '',
    msg: '',
    address: ['广东省', '广州市', '海珠区'],
    publicList: '',
    id: '',
    ajxtrue: false,

  },
  onLoad: function (options) {
    // //  console.log(options);
    this.setData({
      id: options.id
    })
    this.getPublicList()
  },
  onReady: function () {},
  onShow: function () {},
  async getPublicList() {
    let that = this
    const {
      data: {
        data
      }
    } = await request({
      url: 'api/address/addressInfo',
      data: {
        id: that.data.id
      }
    })
    that.setData({
      publicList: data,
      address: data.address.toString(),
      name: data.name,
      phone: data.phone,
      address2: data.address2
    })
    // //  console.log(that.data.address);
  },
  async formSubmit(e) {
    // //  console.log('form发生了submit事件,携带数据为:', e.detail.value)
    let that = this
    // //  console.log(that.data.name, that.data.phone, that.data.address, that.data.address2);
    let address = that.data.address.toString()
    try {
      const {
        data
      } = await request({
        method: 'get',
        url: 'api/address/updateAddress',
        data: {
          id: that.data.id,
          name: e.detail.value.name ? e.detail.value.name : that.data.name,
          phone: e.detail.value.phone ? e.detail.value.phone : that.data.phone,
          address: address,
          address2: e.detail.value.address2 ? e.detail.value.address2 : that.data.address2
        }
      })
      if (data.code == 0) {
        this.setData({
          msg: err.msg
        })
        this.popTest()
      } else {
        this.setData({
          msg: data.msg
        })
        this.popSuccessTest()
        // setTimeout(() => {
        //   wx.navigateTo({
        //     url: '/pages/shippingAddress/shippingAddress'
        //   })
        // }, 2000);
        setTimeout(() => {
          wx.navigateBack()
        }, 1300)
      }
    } catch (err) {
      this.setData({
        msg: err.msg
      })
      this.popTest()
    }

  },
  bindRegionChange: function (e) {
    // //  console.log('picker发送选择改变,携带值为', e.detail.value)
    this.setData({
      address: e.detail.value
    })
  },
  blurPhone: function (e) {
    var phone = e.detail.value;
    let that = this
    if (!(/^1[3456789]\d{9}$/.test(phone))) {
      that.setData({
        ajxtrue: false
      })
      if (phone.length >= 11) {
        wx.showToast({
          title: '手机号有误',
          icon: 'success',
          duration: 2000
        })
      }
    } else {
      that.setData({
        ajxtrue: true
      })
      // //  console.log('验证成功', that.data.ajxtrue)
    }
  },
  popSuccessTest() {
    wx.showToast({
      title: this.data.msg,
      icon: '', //默认值是success,就算没有icon这个值,就算有其他值最终也显示success
      duration: 2000, //停留时间
    })
  },
  popTest() {
    wx.showToast({
      title: this.data.msg,
      icon: 'none', //如果要纯文本,不要icon,将值设为'none'
      duration: 2000
    })
  },

})