distributionChanged.js 6.9 KB
import {
  request
} from "../../request/index.js"

// pages/distributionChanged/distributionChanged.js
const a = getApp()
Page({
  data: {
    imagesUrl: a.globalData.baseUrl,
    id: '',
    names: '',
    phone: '',
    msg: '',
    imgtap: false,
    type: 0,
    detaillist: {},
    shifu: {},
    shi: '',
    fen_di: '',
    itemid: '',
    wait: 0,
    showModalStatus: false,
    jump_img: '',
    jump_url: '',

  },
  onLoad: function (options) {
    let that = this
    console.log(options);
    that.setData({
      id: options.id,
    })
    that.getdetails()
  },
  onReady: function () {

  },
  onShow: function () {},
  toggleDialog() {

  },
  async getdetails() {
    let that = this
    try {
      const {
        data: {
          data
        }
      } = await request({
        url: 'api/active/order',
        data: {
          id: that.data.id
        }
      })
      that.setData({
        detaillist: data,
        shi: data.active.price,
        itemid: data.id,
        jump_img: data.active.jump_img2,
        jump_url: data.active.jump_url,

      })
      console.log(data);
    } catch (err) {
      console.log(err);
      that.setData({
        msg: err.msg
      })
      that.popMaskTest()
    }
  },
  changeChe(e) { //车唛积分
    let that = this
    that.setData({
      itemid: e.currentTarget.dataset.id
    })
    if (that.data.imgtap) {
      that.setData({
        imgtap: false,
        type: 0
      })
      that.actualPacket()
    } else {
      that.setData({
        imgtap: true,
        type: 1
      })
      that.actualPacket()
    }
  },
  async actualPacket() {
    let that = this
    const {
      data: {
        data
      }
    } = await request({
      url: 'api/active/shiPay',
      data: {
        id: that.data.itemid,
        type: that.data.type
      }
    })
    console.log(data);
    that.setData({
      shifu: data,
      shi: data.shi,
      fen_di: data.di
    })

  },
  formSubmit(e) {
    let that = this
    // console.log('form发生了submit事件,携带数据为:', e.detail.value)
    if (e.detail.value.phone != '' && e.detail.value.names != '') {
      let phone = e.detail.value.phone
      if (phone.length == 11) {
        if (!(/^1[34578]\d{9}$/.test(phone))) {
          wx.showToast({
            title: '手机号有误',
            icon: 'none',
            duration: 1000
          })
        } else {
          that.setData({
            obj: e.detail.value
          })
          that.getsubmit()
        }
      } else {
        that.setData({
          msg: '手机号有误'
        })
        that.popMaskTest()
      }
    } else if (e.detail.value.names == '') {
      that.setData({
        msg: '姓名不能为空'
      })
      that.popMaskTest()
    } else if (e.detail.value.phone == '') {
      that.setData({
        msg: '手机号不能为空'
      })
      that.popMaskTest()
    } else {
      that.setData({
        msg: '姓名或手机号不能为空'
      })
      that.popMaskTest()
    }
  },
  async getsubmit() {
    let that = this
    let obj = that.data.obj
    try {
      const {
        data
      } = await request({
        url: 'api/active/pay',
        data: {
          name: obj.names,
          phone: obj.phone,
          id: that.data.itemid,
          type: that.data.type,
        }
      })
      console.log(data);
      if (data.code == 1) {
        if (data.data != null) {
          if (data.data.type == 0) {
            wx.requestPayment({
              timeStamp: data.data.timeStamp,
              nonceStr: data.data.nonceStr,
              package: data.data.package,
              signType: 'MD5',
              paySign: data.data.paySign,
              success(res) {
                console.log(res);
                that.setData({
                  wait: 1
                })
                console.log(that.data.jump_img);
                if (that.data.jump_img != '') {
                  that.showModal()
                } else {
                  wx.redirectTo({
                    url: '/pages/binding4S/binding4S',
                  })
                }
              },
              fail(res) {
                console.log(res)
              }
            })
          } else if (data.data.type == 1) {
            console.log(that.data.jump_img);
            if (that.data.jump_img != '') {
              that.showModal()
            } else {
              that.setData({
                wait: 1
              })
              a.popSuccessTest(data.msg)
              setTimeout(() => {
                wx.redirectTo({
                  url: '/pages/binding4S/binding4S',
                })
              }, 1500);
            }

          } else {
            console.log(that.data.jump_img);
            if (that.data.jump_img != '') {
              that.showModal()
            } else {
              that.setData({
                wait: 1
              })
              a.popSuccessTest(data.msg)
              setTimeout(() => {
                wx.redirectTo({
                  url: '/pages/binding4S/binding4S',
                })
              }, 1500);
            }
          }
        } else {
          that.setData({
            msg: data.msg
          })
          that.popMaskTest()
        }
      }
    } catch (err) {
      console.log(err);
      that.setData({
        msg: err.msg
      })
      that.popMaskTest()
    }
  },
  jumpImgUrl() {
    let that = this
    wx.navigateTo({
      url: '/pages/webview/webview?url=' + that.data.jump_url
    })
    that.hideModal()
  },
  offclose() {
    this.hideModal()
  },

  popMaskTest() {
    wx.showToast({
      title: this.data.msg,
      icon: 'none',
      duration: 2000,
      mask: true //是否有透明蒙层,默认为false 
      //如果有透明蒙层,弹窗的期间不能点击文档内容 
    })
  },
  popSuccessTest() {
    wx.showToast({
      title: this.data.msg,
      icon: '', //默认值是success,就算没有icon这个值,就算有其他值最终也显示success
      duration: 2000, //停留时间
    })
  },
  showModal() { //显示对话框
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
      showModalStatus: true
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export()
      })
    }.bind(this), 100)
  },
  hideModal() { //隐藏对话框
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export(),
        showModalStatus: false
      })
    }.bind(this), 100)
  },


})