CarQuotationDetail.js 4.54 KB
// packageEquity/pages/carQuotation/CarQuotationDetail/CarQuotationDetail.js
import { getOrderDetail,getQuotationInfoById } from '../../../api'
let timer = null
Page({
  /**
   * 页面的初始数据
   */
  data: {
    textNameObj: {
      confirmName: '下一步·去签名(4/4)(10s)',
      // editName: '修改',
      // cancelName: '稍后处理',
      timer: null
    }
  },

  // 倒计时10s功能
  countDownTimer() {
    let sec = 10
    let { id, orderId, timer } = this.data
    let that = this
    timer = setInterval(() => {
      let objNameStr = 'textNameObj.confirmName'
      // const str = '前往提单(10s)'
      that.setData({
        [objNameStr]: `下一步·去签名(4/4)(${sec}s)`
      })
      sec--
      if (sec == -1) {
        clearInterval(timer) // 清除定时器
        // 跳转提单页面
        // this.navigator()
        // 跳转签名页面
        wx.$router.redirectTo('signature', { id, orderId })
      }
    }, 1000)
    this.setData({timer})
  },
  btnTap(e) {
    console.log(e)
    let { name } = e.detail
    let { id, orderId, timer } = this.data
    if (name == 'confirm') {
      clearInterval(timer)
      wx.$router.redirectTo('signature', { id, orderId })
    } else {
      // this.triggerEvent('editSave')
      this.navigator()
      // wx.$router.reLaunch('packageEquity.equityPage')
      // wx.$router.reLaunch('packageEquity.index')
    }
  },
  navigator() {
    let { orderId } = this.data
    wx.$router.go('serviceInfo', {
      orderId: orderId,
      apiName: 'handler'
    })
  },
  getQuotationInfoById() {
    let { id } = this.data
    getQuotationInfoById({ id }).then(res => {
      let { code, data } = res
      console.log(res)
      let { orderId, payId, merchantAddress, merchantName4s, quotationGoodsInfoList } = data
      quotationGoodsInfoList
      if (quotationGoodsInfoList&&quotationGoodsInfoList.length) {
        quotationGoodsInfoList.forEach(item=>{
          if (item.position) {
            const fieldMap = {
              "4大件": "燃油车4大件服务",
              "3电": "新能源3电服务",
              "6大件": "新能源6大件服务",
              // 在这里可以添加更多的替换规则
            };
            // 如果输入字段在字段映射中有匹配项,则进行替换,否则保持不变
            fieldMap[item.position]&&( item.position = fieldMap[item.position])
          }
          if (item.quotationGoodsServiceItemsRelationDTOList&&item.quotationGoodsServiceItemsRelationDTOList.length) {
            item.serviceItems = item.quotationGoodsServiceItemsRelationDTOList.reduce((prev,subItm,index)=>{
              let unit = index == 0 ? '':'/'
              prev += unit+subItm.serviceName
              return prev
            },'')
          }
        }) 
      }
      this.setData({
        orderCode: payId,
        merchantAddress,
        merchantName4s,
        orderId,
        ['orderDetail.quotationGoodsInfoList']:quotationGoodsInfoList
        // quotationGoodsInfoList
        // id
      })
      this.createWxQrcode()
    })
  },
  getOrderDetail() {
    let { orderCode, orderDetail } = this.data
    getOrderDetail({ orderCode }).then(res => {
      let { code, data } = res

      data.orderTime = data.orderTime ? wx.$util.tsFormatTime(data.orderTime, 'Y年M月D日 h:m:s') : ''
      let paySuccessDate = data?.paySuccessDate || new Date()
      data.paySuccessDate = wx.$util.tsFormatTime(paySuccessDate, 'Y年M月D日 h:m:s')
      if (code == 0) {
        this.setData({
          orderDetail: {
            ...orderDetail,
            ...data.customer,
            ...data
          }
        })
      }
    })
  },
  onRoute(options) {
    let { orderDetail, orderCode, orderId, id } = options
    this.setData({
      orderCode: orderCode,
      orderDetail,
      orderId,
      id
    })
    this.getOrderDetail()
    this.getQuotationInfoById()
    // this.countDownTimer()
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    this.countDownTimer()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

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

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

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

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