add.js 3.15 KB

Component({
  /**
   * 组件的属性列表
   */
  options: {
    styleIsolation: 'apply-shared' // apply-shared 或 shared
  },
  properties: {
    codeId: {
      type: String,
      value: ''
    },
    userPhone: {
      type: Number,
      value: ''
    }
  },
  observers: {
    'codeId': function (data) { }
  },
  /**
   * 组件的初始数据
   */
  data: {
    list_fill: [{
      label: '手机号',
      value: 'ownerPhone',
      type: 'input'
    },
    {
      label: '车牌号',
      value: 'carNumber'
    },
    {
      label: '留言',
      value: 'ownerRemark',
      type: 'textarea'
    }
    ],
    form: {
      ownerPhone: '',
      carNumber: '',
      ownerRemark: '临时停靠,马上回来',
      userPhone: ''
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    inputHandle(e) {
      let {
        detail: {
          value
        },
        currentTarget: {
          dataset: {
            index
          }
        }
      } = e
      const list = ['form.ownerPhone', '', 'form.ownerRemark']
      this.setData({
        [list[index]]: value
      })
    },
    clickRow(e) {
      let {
        index
      } = e.currentTarget.dataset

      if (index == 1) {
        wx.chooseLicensePlate().then(res => {
          console
          this.setData({
            'form.carNumber': res.plateNumber
          })
        })
      }
    },
    //绑定
    bindHandle() {
      const phoneRex = /^[1]([3-9])[0-9]{9}$/
      let index;
      let {
        form: {
          ownerPhone,
          carNumber,
          ownerRemark,
          id
        },
        codeId,
        userPhone
      } = this.data
      try {
        if (!ownerPhone) throw '请输入手机号'
        if (!phoneRex.test(ownerPhone)) throw '请输入正确的手机号'
      } catch (error) {
        wx.p.wxApi.showToast(error)
        return
      }
      index = codeId ? 1 : 0
      let userInfo = wx.p.cache.userInfo.getUserInfo()
      const Api = ['getUpdateRescueinfo', 'bindMovecode']
      let params = {
        ownerPhone,
        carNumber,
        ownerRemark,
        unionId:userInfo.unionId
      }
      if (codeId) {
        params.userPhone = userInfo.phone
        params.codeId = codeId
      } else {
        params.id = id
      }

      wx.p.api.rescueApi[Api[index]](params).then(res => {
        if (res) {
          wx.p.wxApi.showToast('绑定成功')
          //数据上报
          // this.trackHttp()
          wx.p.router.redirectTo('/packageMine/pages/move/success/success')
        } else {
          wx.p.wxApi.showToast(res.message)
        }

      })
    },
    trackHttp() {
      const {
        merchantId
      } = wx.p.storage.get('merchant_info')
      let {
        form: {
          ownerPhone,
          carNumber,
        }
      } = this.data,
        userInfo = wx.p.cache.userInfo.getUserInfo() || {},
        data = {
          unionId: userInfo.unionId || null,
          car_number: carNumber,
          customer_phone: ownerPhone || null,
          add_way: 110,
          merchant_id: merchantId
        }
      const jsonList = [JSON.stringify(data)]
      wx.p.api.shopmallApi.trackHttp({
        jsonList
      })
    }
  }
})