SecondStep.js 10.3 KB
// packageEquity/pages/carEquity/components/SecondStep/SecondStep.js
import data from '../constant/stepData'
import fn from '../constant/ruleFn'
import { priceCounter } from '~/packageEquity/api'
const defaultLabelWidth = 'var(--fontSize140)'
Component({
  options: {
    styleIsolation: 'apply-shared'
  },
  // behaviors: ['wx://component-export'],
  attached() {
    console.log('component attached')
    this.makeYear()
  },

  /**
   * 组件的属性列表
   */
  pageLifetimes: {
    show: function () {},
    attached: function () {
      // 在组件实例进入页面节点树时执行
    },
    hide: function () {}
  },
  properties: {
    serviceInfo: {
      type: Object,
      value: () => {}
    },
    orderInfo: {
      type: Object,
      observer: function (n) {
        if (n.quotedPriceUpdate) {
          this.setData({
            testQuotedPriceUpdate: n.quotedPriceUpdate
          })
        }
        if (n?.modifyEquityQuotation) {
          this.setData({
            activeNames: ['3'],
            disable: true
          })
        } else {
          this.setData({
            activeNames: ['1', '2', '3', '4'],
            disable: false
          })
        }
      }
    },
    quotationGoodsList: {
      type: Array,
      value: () => {}
    }
  },
  observers: {
    'orderInfo.outTradeNo': function (value) {
      console.log(value, 'outTradeNo')
      this.setData({
        textNameObj: {
          confirmName: '下一步(2/4)'
        }
      })
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    defaultLabelWidth,
    showYear: false,
    // 选择时间的年份
    columns: [],
    disable: false,
    currentDate: new Date().getTime(),

    // 默认当前年份
    currentIndex: new Date().getFullYear() - (new Date().getFullYear() - 25),

    currentName: new Date().getFullYear() + '年',
    popupShow: false,
    popupInputShow: false,
    // customInput: true,
    // secondObj: data.secondObj,
    formRule: data.formRule,
    textNameObj: {
      confirmName: '下一步·生成告知书(2/4)',
      // editName: '修改',
      cancelName: '存草稿'
    },
    // '1', '2', '3',
    activeNames: ['1', '2', '3', '4'],
    showPicker: false,
    // optionsSelect: Object.freeze(optionsSelect),
    popObj: {
      popValue: ''
    },
    popinputobj: {
      type: 'add'
    },
    showError: false,
    insuranceCheck: false,
    testQuotedPriceUpdate: 0
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // test() {
    //   let { activeNames } = this.data
    //   console.log('activeNames', activeNames)
    // },
    onChangeInsurance(e) {
      console.log(e)
      // vdQuotationGoodsList
      let { detail } = e
      let { id } = e.currentTarget.dataset
      console.log(detail, 'detail')
      if (!detail) {
        return this.setData({
          insuranceCheck: false
        })
      }
      let thisPage = wx.$router.getPageInstance()
      let { quotationGoodsList } = this.data
      let goodsItem = quotationGoodsList.find(item => item.id == id)
      let { id: appreciation, goodsInfo, upgradeGoodsName: goodsName, upgradeGoodsServiceItemsList } = goodsItem
      thisPage.setData({})

      let params = thisPage.getInsurance()
      let owner = thisPage.getOwnerInfo()
      owner.salesType = owner.salesType=='售后'?1:0
      //  const owner = wx.$util.deepClone(thisPage.data.owner)
      params.owner = owner
      params.goodsId = goodsItem.id
      params.goodsName = goodsItem.goodsName
      params.insureList = params.insureList.map(item => {
        if (item.type == 3) {
          item = {
            appreciation,
            goodsName,
            type: 3
          }
        }
        return item
      })

      //  params.owner = owner
      //  params.owner.price = this.multipliedByHundred(orderInfo.owner?.price) || ''
      // console.log(thisPage)
      if (params.owner?.buyCarTime) {
        delete params.owner.buyCarTime
      }
      // quotedPriceUpdate
      delete params?.quotedPriceUpdate
      // if (params?.quotedPriceUpdate) {

      // }
      // params.insureList = []
      console.log(params, 'params')
      wx.$util.showLoading()
      priceCounter(params)
        .then(result => {
          wx.hideLoading()
          console.log('result', result)
          let { data, code, message } = result

          if (code == 0) {
            let thisPage = wx.$router.getPageInstance()

            thisPage.setData({
              ['orderInfo.quotedPriceUpdate']: data.quotedPriceUpdate,
              ['orderInfo.goodsId']: goodsItem.id,
              ['orderInfo.goodsName']: goodsItem.goodsName,
              ['orderInfo.valueAddedVehicleLoss']: {
                appreciation,
                goodsName,
                type: 3
              },
              ['orderInfo.quotationGoodsInfo']: {
                titlePictureUrl: goodsInfo.thumbUrl,
                goodsName,
                quotationGoodsServiceItemsRelationDTOList: upgradeGoodsServiceItemsList
              }
            })
            this.setData({
              insuranceCheck: true,
              testQuotedPriceUpdate: data.quotedPriceUpdate / 100
            })
          } else {
            wx.$util.showToast({
              title: message || '获取报价失败',
              icon: 'error'
            })
          }
        })
        .catch(err => {})
    },
    //--------自定义方法----------
    // 选择年份的区域,弹出弹窗框
    chooseYear() {
      console.log('选择年份')
      this.setData({
        showYear: true
      })
    },

    // 弹出框确认事件
    onConfirm(e) {
      // console.log(e, 1111)
      let { value } = e.detail
      let thisPage = wx.$router.getPageInstance()
      console.log(value, 'value')
      thisPage.setData({
        // ['orderInfo' + '.' + attrtype + '.' + attrname]: value
        ['orderInfo.vehiclesAndVessels.compensation']: value + '年'
      })
      this.setData({
        showYear: false
      })
      this.cancelInsuranceCheck()
    },
    cancelInsuranceCheck() {
      // this.setData({
      //   // insuranceCheck: false

      // })
      let thisPage = wx.$router.getPageInstance()

      thisPage.setData({
        ['orderInfo.quotedPriceUpdate']: '',
        ['orderInfo.goodsId']: '',
        ['orderInfo.goodsName']: '',
        ['orderInfo.valueAddedVehicleLoss']: {
          appreciation: '',
          goodsName: '',
          type: 3
        }
      })
    },
    // 取消选择年份的弹框
    onCancel() {
      let that = this
      that.setData({
        showYear: false
      })
    },
    // 对选择时间进行单独的处理
    makeYear() {
      // console.log('makeYear')
      let year = []
      let currentDate = new Date()
      console.log(currentDate.getFullYear())
      for (let j = currentDate.getFullYear() - 25; j < currentDate.getFullYear(); j++) {
        year.push(j)
      }
      for (let i = currentDate.getFullYear(); i <= currentDate.getFullYear() + 25; i++) {
        year.push(i)
      }
      // console.log(year, 'year')
      this.setData({
        columns: year
      })
    },
    handlePopupShow(e) {
      // console.log(e)
      let { disable } = this.data
      if (disable) return false //修改权益价时,不可修改
      // let { attrtype, attrname, typename } = e.target.dataset
      let { attrtype, attrname, typename } = e.currentTarget.dataset
      console.log(attrtype, attrname, typename, 'attrType, attrName')
      let thisPage = wx.$router.getPageInstance()
      let popValue = thisPage.data.orderInfo?.[attrtype]?.[attrname] || ''
      this.setData({
        popupShow: true,
        // popValue
        popObj: {
          attrtype,
          attrname,
          popValue,
          typename
        }
      })
    },
    handlePopInputShow(e) {
      // console.log(e)
      let { disable } = this.data
      if (disable) return false //修改权益价时,不可修改

      let { handletype, index } = e.currentTarget.dataset
      // console.log(handletype, index, 'type, index')
      let thisPage = wx.$router.getPageInstance()
      let popValue = ''
      if (handletype == 'edit') {
        popValue = thisPage.data.orderInfo?.['otherInsuranceList']?.[index] || ''
      }
      // console.log(popValue, 'popValue')
      this.setData({
        popupInputShow: true,
        popinputobj: {
          handletype,
          index,
          ...popValue
        }
      })
    },
    btnTap(e) {
      // console.log(e)
      let { name } = e.detail
      // let { attrtype, attrname, typename } = this.data.tableObj
      let { showError, insuranceCheck, orderInfo } = this.data
      if (showError) return wx.$util.showToast('权益价不能小于最低权益价')

      if (name == 'confirm') {
        // 不是修改报价时,需要勾选保险
        // if (!insuranceCheck && !orderInfo.modifyEquityQuotation) return wx.$util.showToast('请先勾选保险')
        if (!orderInfo.quotedPriceUpdate && !orderInfo.modifyEquityQuotation) return wx.$util.showToast('请先勾选增值车损险')
        this.triggerEvent('confirm')
      } else {
        this.triggerEvent('editSave')
      }
    },
    onChange(event) {
      console.log(event, 'event')
      this.setData({
        activeNames: event.detail
      })
    },

    handleInput(e) {
      let value = e.detail
      console.log(e)
      let { attrname, attrtype, type } = e.currentTarget.dataset

      value = type == 'number' ? wx.$util.numberFixedDigit(value) : value
      if (type == 'number') {
        value = parseFloat(value) > 2000000 ? 2000000 : value
      }
      let thisPage = wx.$router.getPageInstance()
      console.log(attrtype)

      if (attrtype == 'modifyEquityQuotation') {
        let { orderInfo } = this.data
        let showError = orderInfo.modifyEquityQuotation.minEquityPrice <= value ? false : true
        this.setData({
          showError
        })
      }
      // ['orderInfo' + '.' + attrType]
      // console.log(['orderInfo' + '.' + attrType], '2')
      thisPage.setData({
        ['orderInfo' + '.' + attrtype + '.' + attrname]: value
      })
      this.cancelInsuranceCheck()
      // console.log(thisPage.data)
    }
    // numberFixedDigit (e) { // 固定两位小数
    //   e.target.value = (e.target.value.match(/^\d*(\.?\d{0,2})/g)[0]) || ''
    //   this.$nextTick(() => {
    //     this.number= e.target.value
    //   })
    // },
  }
})