subscribeImg.js 5.3 KB
import {
  request
} from "../../request/index.js"
const a = getApp()
Page({
  data: {
    imagesUrl: a.globalData.baseUrl,
    subscribeImg: '',
    order_no: '',
    id: '',
    day: '',
    bao_arr: [],
    order: [],
    date: '',
    date1: '',
    futureDay: [], // 未来日期
    index1: '',
    index: '',
    msg: '',
    yuyuetime: '',
    Ytime: '',
    timeStamp: '',
    nonceStr: '',
    package: '',
    signType: 'MD5',
    paySign: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //  console.log(options);
    let bao_arr = JSON.parse(options.bao_arr)
    this.setData({
      bao_arr: bao_arr
    })
    //  console.log(this.data.bao_arr, bao_arr);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },


  onShow: function () {
    this.getSubscribeImg()
    this.getfutureDay()
  },
  async getSubscribeImg() {
    let that = this
    let bao_arr = that.data.bao_arr.toString()
    const {
      data: {
        data
      }
    } = await request({
      url: 'api/index/yueBao',
      data: {
        bao_arr: bao_arr
      }
    })
    //  console.log(data);
    that.setData({
      subscribeImg: data,
      order: data.bao,
      order_no: data.order_no
    })
    // //  console.log(that.data.subscribeImg, "保3223232131养");
  },
  goToRuleBook() { //保养说明
    wx.navigateTo({
      url: '/pages/upkeepInstruction/upkeepInstruction'
    })
  },
  async consulting() { // 立即预约
    let that = this
    try {
      const {
        data: {
          data
        }
      } = await request({
        url: 'api/index/yueBaoPay',
        data: {
          order_no: that.data.order_no,
          id: that.data.id,
          day: that.data.day
        }
      })
      //  console.log(data);
      that.setData({
        timeStamp: data.timeStamp,
        nonceStr: data.nonceStr,
        package: data.package,
        signType: 'MD5',
        paySign: data.paySign,
      })
      wx.requestPayment({
        timeStamp: that.data.timeStamp,
        nonceStr: that.data.nonceStr,
        package: that.data.package,
        signType: 'MD5',
        paySign: that.data.paySign,
        success(res) {
          //  console.log(res);
          wx.redirectTo({
            url: '/pages/MaintenanceService/MaintenanceService'
          })
        },
        fail(res) {
          //  console.log(res)
          wx.redirectTo({
            url: '/pages/MaintenanceService/MaintenanceService'
          })
        }
      })
    } catch (err) {
      //  console.log(err);
      that.setData({
        msg: err.msg
      })
      that.popTest()
    }
  },
  bindPickerChange: function (e) {

    let that = this
    // //  console.log('picker发送选择改变,携带值为', e.detail.value)
    this.setData({
      index1: e.detail.value
    })
    that.data.futureDay.forEach((value, index) => {
      if (index == that.data.index1) {
        that.setData({
          day: value
        })
      }
    });
    // //  console.log(that.data.day);
    that.getyuyuetime()
  },
  bindPickerChange1: function (e) {
    let that = this
    // //  console.log('picker发送选择改变,携带值为', e.detail.value)
    let obj = that.data.day
    if (obj !== '') {
      this.setData({
        index: e.detail.value
      })
      // //  console.log(e.detail.value);
      that.data.yuyuetime.forEach((value, index) => {
        if (e.detail.value == index) {
          that.setData({
            Ytime: value.qv2,
          })
        }
      });
      // //  console.log(that.data.Ytime);

    } else {
      that.setData({
        msg: '请先选择预约日期'
      })
      that.popTest()
    }
  },
  async getyuyuetime() { //预约时间
    let that = this
    try {
      const {
        data: {
          data
        }
      } = await request({
        url: 'api/index/yueTime',
        data: {
          day: that.data.day
        }
      })

      that.setData({
        yuyuetime: data
      })
      that.data.yuyuetime.forEach((value, index) => {
        if (index == that.data.index1) {
          that.setData({
            Ytime: value.qv2,
            id: value.id
          })
        }
      });
    } catch (err) {
      this.setData({
        msg: err.msg
      })
      this.popTest()
    }
  },
  async getfutureDay() { //未来7天
    let that = this
    try {
      const {
        data: {
          data
        }
      } = await request({
        url: 'api/index/yueDay',
      })
      //  console.log(data, "未来7天");
      that.setData({
        futureDay: data
      })

    } catch (err) {
      this.setData({
        msg: err.msg
      })
      this.popTest()
    }

  },
  popTest() {
    wx.showToast({
      title: this.data.msg,
      icon: 'none', //如果要纯文本,不要icon,将值设为'none'
      duration: 1500
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})