PopupInput.js 2.9 KB
// components/CarBrands/CarBrands.js
// import api from '../../api/api.js'
const formRule = {
  // owner: [{ required: true, message: '姓名不能为空' }],
  typeName: [{ required: true, message: '商业名称不能为空' }],
  compensation: [{ required: true, message: '险种不能为空' }],
  payPrice: [{ required: true, message: '保费不能为空' }]
}
import fn from '../constant/ruleFn'
Component({
  options: {
    styleIsolation: 'shared'
  },
  /**
   * 组件的属性列表
   */
  properties: {
    show: {
      type: Boolean,
      observer: function (n) {
        console.log('n', n)
        n && this.init()
      }
    },
    testdata: {
      type: Boolean
      // observer: function (n) {
      //   console.log('n', n)
      //   n && this.init()
      // }
    },
    popinputobj: {
      type: Object,
      observer: function (n) {
        this.init()
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    typeName: '1',
    compensation: '1',
    payPrice: '1'
  },
  pageLifetimes: {
    show: function () {},
    hide: function () {}
  },
  /**
   * 组件的方法列表
   */
  methods: {
    init() {
      let { popinputobj } = this.data
      let { typeName, compensation, payPrice, handletype } = popinputobj
      // console.log(popinputobj, 'popinputobj')
      if (handletype == 'add') {
        this.setData({
          typeName: '',
          compensation: '',
          payPrice: ''
        })
      } else {
        // let { typeName, compensation, payPrice } = popinputobj
        this.setData({
          typeName,
          compensation,
          payPrice
        })
      }
    },
    handleInput(e) {
      console.log(e)
      let value = e.detail
      console.log('value', value)
      let { attrname, type } = e.target.dataset
      value = type == 'number' ? wx.$util.numberFixedDigit(value) : value
      this.setData({
        [attrname]: value
      })
    },
    confirm() {
      let { compensation, payPrice, typeName, popinputobj } = this.data
      let otherInsuranceObj = {
        compensation,
        payPrice,
        typeName,
        type: 4
      }
      let validObj = fn.checkRequired(otherInsuranceObj, formRule)
      if (validObj) {
        wx.$util.showToast(validObj.message)
        return
      }
      // 新增
      console.log(otherInsuranceObj, 'otherInsuranceObj')
      if (popinputobj.handletype == 'add') {
        let thisPage = wx.$router.getPageInstance()
        thisPage.setData({
          ['orderInfo' + '.' + 'otherInsuranceList']: [...thisPage.data.orderInfo?.otherInsuranceList, otherInsuranceObj]
        })
      } else {
        let thisPage = wx.$router.getPageInstance()
        let { index } = popinputobj
        thisPage.setData({
          ['orderInfo' + '.' + 'otherInsuranceList' + '[' + index + ']']: otherInsuranceObj
        })
      }

      this.setData({
        show: false
      })
      this.triggerEvent('confirm')
    }
  }
})