order.vue 10.5 KB
<!-- 权益订单 -->
<template>
  <div>
    <report @toSearchOrderDetail="toSearchOrderDetail" ref="reportRef" :isGH="routeInfo.isGH" :pageType="pageType" :editForm.sync="editForm"></report>
    <repair ref="repairRef" @changeObjectType="changeObjectType" :isGH="routeInfo.isGH" :pageType="pageType" :serviceItemsList.sync="serviceItemsList" :totalPrice.sync="totalPrice" :accountForm.sync="accountForm"></repair>
    <material ref="materialRef" :pageType="pageType" :materialForm.sync="materialForm"></material>
    <div class="page-btm-btn" v-if="pageType != 2">
      <el-button type="primary" @click="confirmSubmit(1)">提交</el-button>
      <el-button type="primary" plain @click="confirmSubmit(2)">草稿</el-button>
    </div>
  </div>
</template>
<script>
import report from './components/report.vue'
import repair from './components/repair.vue'
import material from './components/material.vue'
import util from '@/util/util'
export default {
  name: 'order',
  components: {
    report,
    repair,
    material
  },
  data() {
    return {
      permitDraft: false,
      routeInfo: null,
      isGH: false,
      editForm: {
        contractNo: '',
        reportDate: '',
        reimbursementDate: '',
        reimbursementAddress: '',
        reporterName: '',
        reporterPhone: '',
        writeOffCode: '',
        reimbursementAddr: '',
        reimbursementProvinceCode: '',
        reimbursementCityCode: '',
        reimbursementCountiesCode: ''
      },
      pageType: 1,
      accountForm: {
        objectType: 0,
        accountType: 0,
        branchBankCode: '',
        accountName: '',
        accountNo: '',
        bankCity: '',
        payeeIDCardType: '',
        payeeIDCardNo: '',
        payeePhone: '',
        handlerName: '',
        handlerPhone: ''
      },
      saveObj: {},
      materialForm: {
        idCard: [],
        idCardBack: [],
        billInfo: [],
        otherInfo: []
      },
      serviceItemsList: []
    }
  },
  created() {
    this.initSaveObj()
    const urlParam = this.$route.params
    const urlQuery = JSON.parse(decodeURIComponent(urlParam.id))
    this.pageType = urlQuery.editNo
    this.routeInfo = urlQuery
    this.handleFormInfo(urlQuery.contractNo, urlQuery.isGH)
    // if(!this.isGH){
    // }
    if (this.routeInfo.orderId) {
      this.getDetailById()
    }
  },
  computed: {
    totalPrice() {
      let total = this.serviceItemsList.reduce(function(prev, cur) {
        return prev + +(cur.approveAmount * 100).toFixed(0)
      }, 0)
      return total / 100
    }
  },
  mounted() {
    
    console.log('更新')
  },
  methods: {
    changeObjectType(newVal) {
      if (newVal === 1) {
        this.saveObj.objectType = newVal
        delete this.saveObj.handlerName
        delete this.saveObj.handlerPhone
        this.accountForm = { ...this.accountForm, ...this.saveObj }
      } else {
        this.saveObj = { ...this.accountForm }
        this.getAccountInfo(this.editForm.contractNo)
      }
    },
    initSaveObj() {
      this.saveObj = { ...this.accountForm }
    },
    //详情
    getDetailById() {
      this.$apis.claims.getClaimsDetail({ id: this.routeInfo.orderId }).then(res => {
        // 以下是report数据
        for (let key in this.editForm) {
          this.editForm[key] = res[key]
        }
        this.editForm.reportDate = res.reporterDate
        this.editForm.reimbursementAddress = []
        const { reimbursementCityCode, reimbursementCountiesCode, reimbursementProvinceCode, serviceItemsList } = res
        this.editForm.reimbursementAddress.push(reimbursementProvinceCode, reimbursementCityCode, reimbursementCountiesCode)
        // 以下是repair数据
        for (let key in this.accountForm) {
          this.accountForm[key] = res[key]
        }
        if (this.accountForm.objectType !== 1) {
          this.accountForm.accountType = 0
          this.accountForm.objectType = 0
        }
        if (this.accountForm.accountType !== 1) this.accountForm.accountType = 0
        this.serviceItemsList = serviceItemsList
        // 以下是文件数据
        res.files.forEach(item => {
          let obj = { url: item.fileUrl, fileType: item.fileType, name: item.fileName, progress: 100 }
          if (item.fileCode == '1') {
            if (item.fileName.indexOf('&front&_') === 0) {
              this.materialForm.idCard.push(obj)
            } else {
              this.materialForm.idCardBack.push(obj)
            }
          } else if (item.fileCode == '31') {
            this.materialForm.billInfo.push(obj)
          } else if (item.fileCode == '4') {
            this.materialForm.otherInfo.push(obj)
          }
        })
      })
    },
    // 新增的时候,输入合同号,带出信息
    toSearchOrderDetail() {
      let param = {}
      param.contractNo = this.editForm.contractNo
      let targetAPI = this.$apis.claims.checkContractNo
      if (this.routeInfo.isGH) {
        param.writeOffCode = this.editForm.writeOffCode
        targetAPI = this.$apis.claims.getDetailByWOCode
      }
      targetAPI(param).then(res => {
        this.permitDraft = true
        const { serviceItemsList, contractNo } = res
        for (let key in this.editForm) {
          this.editForm[key] = res[key] || this.editForm[key]
        }
        this.serviceItemsList = serviceItemsList
        this.getAccountInfo(contractNo)
      })
    },
    // 点击同步,获取收款人信息
    getAccountInfo(contractNo) {
      if (!contractNo) return
      this.$apis.claims.getAccountInfo({ contractNo }).then(res => {
        const { accountName, accountCityCode: bankCity, openBankCode: branchBankCode, accountNo, accountType, cardNo: payeeIDCardNo, cardTypeCode: payeeIDCardType, phone: payeePhone } = res || {}
        const result = { accountName, bankCity, branchBankCode, accountNo, accountType, payeeIDCardNo, payeeIDCardType, payeePhone }
        // for (let key in this.accountForm) {
        //   this.accountForm[key] = result[key] || this.accountForm[key]
        // }
        this.accountForm = { ...this.accountForm, ...result }
        if (this.accountForm.accountType !== 1) this.accountForm.accountType = 0
        if (this.accountForm.objectType !== 1) this.accountForm.accountType = 0
      })
    },
    // 根据页面跳转参数处理表单信息-自动填入
    // 步骤流程:拿到核销码/合同号后==》请求接口获取该合同号/核销码下对应的套餐,下发数据到维修信息模块,上传资料模块,报案信息模块
    handleFormInfo(contractNo, isGH) {
      if (isGH) {
        this.editForm.writeOffCode = contractNo
      }
      this.editForm.contractNo = contractNo
    },
    // 提交的时候校验,滴加不校验经办人信息
    validAccountInfo() {
      let valid = false
      this.$refs.repairRef.$refs.accountRef.$refs.formRef.validate(aValid => {
        this.$refs.reportRef.$refs.editFormRefReport.$refs.formRef.validate(eValid => {
          if (aValid && eValid) {
            valid = true
          }
          if (this.routeInfo.isGH) {
            this.$refs.repairRef.$refs.handlerRef.$refs.formRef.validate(hValid => {
              valid = hValid
            })
          }
        })
      })
      if (!valid) return valid
      let requirePrice = true
      this.serviceItemsList.forEach(item => {
        if (item.approveAmount > 0) {
          requirePrice = false
        }
      })
      if (requirePrice) {
        this.$message.error('至少输入一项服务的定损批准金额')
        return false
      }
      let fileTip = false
      for (let key in this.materialForm) {
        if (this.materialForm[key].length < 1 && !fileTip) {
          fileTip = true
        }
      }
      if (fileTip) {
        this.$message.error(`请补全资料`)
        return false
      }
      return valid
    },
    // 提交核赔
    confirmSubmit(type) {
      if (type == 1 && !this.validAccountInfo()) {
        return false
      }
      let isUpload = false
      for (let key in this.materialForm) {
        this.materialForm[key].forEach(item => {
          if (!item.url) isUpload = true
        })
      }
      if (isUpload) {
        this.$message.error(`文件正在上传,请稍后再${type == 1 ? '提交' : '保存草稿'}`)
        return false
      }
      if (!this.routeInfo.orderId && type == 2 && !this.permitDraft) {
        this.$message.error('请同步信息之后再保存草稿')
        return
      }
      const params = { ...this.editForm, ...this.accountForm }
      if (params.accountType !== 1) {
        params.accountType = 0
      }
      params.operation = type
      params.reimbursementDate = params.reimbursementDate ? util.dateFormat(params.reimbursementDate, 'YYYY-MM-DD HH:mm:ss') : ''
      params.reportDate = params.reportDate ? util.dateFormat(params.reportDate, 'YYYY-MM-DD HH:mm:ss') : ''
      if (params.reimbursementAddress.length == 3) {
        params.reimbursementProvinceCode = params.reimbursementAddress[0]
        params.reimbursementCityCode = params.reimbursementAddress[1]
        params.reimbursementCountiesCode = params.reimbursementAddress[2]
      }
      params.approveAmounts = ''
      let tagetObj = {}
      this.serviceItemsList.forEach(item => {
        tagetObj[item.serviceItemCode] = item.approveAmount
      })
      params.approveAmounts = JSON.stringify(tagetObj)
      delete params.reimbursementAddress
      params.fileList = []
      for (let key in this.materialForm) {
        this.materialForm[key].forEach((item, index) => {
          const obj = {}
          obj.fileType = item.fileType
          obj.fileUrl = item.url
          obj.fileCode = key == 'idCard' || key == 'idCardBack' ? 1 : key == 'billInfo' ? 31 : 4
          obj.fileName = item.name
          params.fileList.push(obj)
        })
      }
      if (this.routeInfo.orderId) {
        params.id = this.routeInfo.orderId
      }
      const loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.3)'
      })
      this.$apis.claims.commitClaimsOrder(params).then(res => {
        loading.close()
        if (res) {
          this.$message({
            message: type == 1 ? '提交成功' : '保存草稿成功',
            type: 'success'
          })
          this.handleCancel()
        }
      })
    },
    handleCancel() {
      this.$router.push({ path: '/claims/index' })
    }
  }
}
</script>
<style lang="scss" scoped>
.footer {
  width: 100%;
  position: fixed;
  bottom: 0;
  height: 64px;
  left: 0;
  text-align: center;
  line-height: 64px;
  background: #ffffff;
}
</style>