CarQuotationDetail.js 6.83 KB
// packageEquity/pages/carQuotation/CarQuotationDetail/CarQuotationDetail.js
import { getOrderDetail,getQuotationInfoById, updateCustomerInfo } from '../../../api'
import {
  buildEquityCustomerDailyDetail
} from '../services/customerDailyFields.helpers.js'
let timer = null
Page({
  /**
   * 页面的初始数据
   */
  data: {
    textNameObj: {
      confirmName: '下一步·去签名(4/4)(10s)',
      // editName: '修改',
      // cancelName: '稍后处理',
      timer: null
    },
    showZyPopup: false,
    zyFlag: false,
    customerDailyInfo: {},
    customerTagLabels: []
  },

  // 倒计时10s功能
  countDownTimer(zyFlag) {
    let sec = 10
    let { id, orderId, timer } = this.data
    let that = this
    timer = setInterval(() => {
      let objNameStr = 'textNameObj.confirmName'
      // const str = '前往提单(10s)'
      if (zyFlag) {
        that.setData({
          [objNameStr]: `下一步·上传协议(4/4)(${sec}s)`,
          showBtnFlag: true
        })
      }
      sec--
      if (sec == -1) {
        clearInterval(timer) // 清除定时器
        // 跳转提单页面
        // this.navigator()
        if (zyFlag) { // 需要上传合同协议
          return this.setData({ showZyPopup: true }) // 上传合同协议弹窗
        }
        // 跳转列表页面
        wx.$router.reLaunch("packageEquity.equityPage?tabIndex=1");
      }
    }, 1000)
    this.setData({timer})
  },
  btnTap(e) {
    console.log(e)
    let { name } = e.detail
    let { id, orderId, timer, zyFlag } = this.data
    if (name == 'confirm') {
      clearInterval(timer)
      if (zyFlag) return this.setData({showZyPopup: true})
      wx.$router.redirectTo('signature', { id, orderId })
    } else {
      // this.triggerEvent('editSave')
      this.navigator()
      // wx.$router.reLaunch('packageEquity.equityPage')
      // wx.$router.reLaunch('packageEquity.index')
    }
  },
  // 合同协议上传确定
  zyPayConfirm(e) {
    wx.showLoading({title: '加载中', mask: true})
    let { zyPayOrderInfo, zyConfirmFlag } = this.data
    if (zyConfirmFlag) return false
    this.setData({
      zyConfirmFlag: true
    });
    // 更新客户信息
    updateCustomerInfo({ ...zyPayOrderInfo, zyPayUrl: e.detail?.zyPayUrl?.join(',') }).then(result => {
      wx.hideLoading()
      let { code, message } = result
      this.setData({
        showZyPopup: false
      })
      if (code == 0) {
        // 返回到报价单列表
      wx.$router.reLaunch("packageEquity.equityPage?tabIndex=1");
      } else {
        wx.$util.showToast(message)
      }
      setTimeout(() => {
        this.setData({
          zyConfirmFlag: false,
        })
      })
    })
  },
  getInsurance(res) {
    let obj = wx.$util.deepClone(res), orderInfo = {};
    let { default4SStoreInfo } = wx.$util.getUserInfo();
    orderInfo.check = true
    orderInfo.id = obj.id
    orderInfo.orderId = obj.orderId
    orderInfo.merchantId4s = default4SStoreInfo?.merchantId;
    orderInfo.merchantName4s = default4SStoreInfo?.merchantName;
    orderInfo.referrer = obj.referrer
    orderInfo.referrerId = obj.referrerId
    return orderInfo;
  },
  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
            },'')
          }
        }) 
      }
      // 处理用于上传合同协议更新客户信息接口的参数
      let zyPayOrderInfo = this.getInsurance(data)
      const { customerDailyInfo, customerTagLabels } =
        buildEquityCustomerDailyDetail(data)
      this.setData({
        orderCode: payId,
        merchantAddress,
        merchantName4s,
        orderId,
        ['orderDetail.quotationGoodsInfoList']:quotationGoodsInfoList,
        zyPayOrderInfo,
        customerDailyInfo,
        customerTagLabels
        // quotationGoodsInfoList
        // id
      })
      this.setData({
        zyFlag: data?.zyPayStatus == 1 && data.orderStatus == 7
      })
      this.countDownTimer(data?.zyPayStatus == 1  && data.orderStatus == 7)
    })
  },
  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() {
    let { timer } = this.data
    clearInterval(timer) // 清除定时器
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
    let { timer } = this.data
    clearInterval(timer) // 清除定时器
  },

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

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

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