FirstStep.js 4.83 KB
// packageEquity/pages/carEquity/components/FirstStep/FirstStep.js
import data from '../constant/stepData'
import fn from '../constant/ruleFn'
import carLifeApi from '~/packageEquity/carEquityApi'

const defaultLabelWidth = '140rpx'
// import api from '~/api/api'
Component({
  options: {
    styleIsolation: 'apply-shared'
  },
  /**
   * 组件的属性列表
   */
  properties: {
    serviceInfo: {
      type: Object,
      observer: function (n) {
        this.setData({
          formData: n
        })
      }
    },
    orderInfo: {
      type: Object,
      observer: function (n) {
        if (n?.modifyEquityQuotation) {
          this.setData({
            // activeNames: ['3'],
            disable: true
          })
        } else {
          this.setData({
            disable: false
          })
        }
      }
    },
    // 页面存放表单对象的对象名
    dataAttrName: {
      type: String,
      value: null
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    defaultLabelWidth,
    formData: {},
    employeeList: [],
    first: data.firstObj,
    disable: true,
    // salesList: [
    //   {
    //     id: '1',
    //     name: 'CCC'
    //   },
    //   {
    //     id: '2',
    //     name: 'AAA'
    //   }
    // ],
    formRule: data.formRule,
    // 品牌车型
    // brandBox: false,
    textNameObj: {
      confirmName: '下一步(1/4)',
      cancelName: '存草稿'
    }
  },

  lifetimes: {
    attached() {
      this.getEmployee()
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // 推荐人
    // handleSalesChange(e) {
    //   let idx = e.detail.value || 0
    //   this.setData({
    //     'formData.referrerId': this.data.employeeList[idx].uuid,
    //     'formData.referrer': this.data.employeeList[idx].staffName
    //   })
    // },
    handleSalesChange(e) {
      // let value = e.detail
      console.log(e)
      // let { attrname, attrtype } = e.target.dataset
      // let {  } = this.data
      // let thisPage = wx.$router.getPageInstance()
      // ['orderInfo' + '.' + attrType]
      // console.log(['orderInfo' + '.' + attrType], '2')
      // thisPage.setData({
      //   ['orderInfo' + '.' + attrtype + '.' + attrname]: value
      // })
      let idx = e.detail.value || 0
      let { employeeList, disable } = this.data
      if (disable) return false
      let thisPage = wx.$router.getPageInstance()

      thisPage.setData({
        ['orderInfo.referrerId']: employeeList[idx].uuid,
        ['orderInfo.referrer']: employeeList[idx].staffName
      })
      // ['orderInfo' + '.' + attrType]
      // console.log(['orderInfo' + '.' + attrType], '2')
      // this.setData({
      //   'formData.actualSalesPersonId': this.data.employeeList[idx].uuid,
      //   'formData.actualSalesPerson': this.data.employeeList[idx].staffName
      // })
      // console.log(thisPage.data)
    },
    // 获取推荐人列表
    getEmployee() {
      let userInfo = wx.$util.getStorageSync('dj_boutique_user_info')
      let params = {
        merchantId: userInfo.default4SStoreInfo.merchantId
      }
      carLifeApi.getEmployeeList(params).then(res => {
        if (res.code == 0) {
          this.setData({
            employeeList: res.data
          })
        } else {
          wx.$util.showToast(res.message || '接口异常')
        }
      })
    },
    // // 推荐人
    // handleSalesChange(e) {
    //   let idx = e.detail.value || 0
    //   this.setData({
    //     'formData.actualSalesPersonId': this.data.salesList[idx].id,
    //     'formData.actualSalesPerson': this.data.salesList[idx].name
    //   })
    // },
    navOcr(e) {
      // idCard:1,
      // vehicleCertificate:5
      let { type } = e.currentTarget.dataset
      console.log(type)
      // wx.$router.go('ocrEquityModules', { type })
      wx.$router.go(`ocrEquityModules?type=${type}`)
    },
    // handleInput(e) {
    //   let { value } = e.detail
    //   let { attr } = e.currentTarget.dataset
    //   this.setData({
    //     ['formData.' + attr]: value
    //   })
    // },

    btnTap(e) {
      console.log(e)
      let { name } = e.detail
      if (name == 'confirm') {
        // this.triggerEvent('confirm')
        // 需要校验
        this.handleConfirm()
      } else {
        this.triggerEvent('editSave')
      }
    },
    handleConfirm() {
      var { dataAttrName, formRule } = this.data
      // let thisPage = this.$router.getCurrentPage()
      let thisPage = wx.$router.getPageInstance()
      // console.log(thisPage.data['orderInfo']['actualSalesPersonId'])
      if (!thisPage.data['orderInfo']['referrerId']) {
        wx.$util.showToast('请选择推荐人')
        return
      }
      let validObj = fn.checkRequired(thisPage.data[dataAttrName], formRule)
      if (validObj) {
        wx.$util.showToast(validObj.message)
        return
      }

      this.triggerEvent('confirm')
    }
  }
})