<template xmlns:v-slot="http://www.w3.org/1999/XSL/Transform">
  <div>
      <el-form size="middle" :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method === 'view'"
               label-width="120px" @submit.native.prevent>

        <el-divider content-position="left"><i class="el-icon-document"></i> 基础信息</el-divider>
        <el-row>
          <el-col :span="12">
            <el-form-item label="经办人" prop="userName">
              <el-input v-model="inputForm.userName" :disabled="true"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="报销编号" prop="no">
              <el-input v-model="inputForm.no" :disabled="true" placeholder="自动生成"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="所属部门" prop="departmentName">
              <el-input v-model="inputForm.departmentName" :disabled="true"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="报销日期" prop="reimDate" :rules="[{required: true, message:'请选择报销日期', trigger:'blur'}]">
              <el-date-picker
                placement="bottom-start"
                v-model="inputForm.reimDate"
                type="date"
                value-format="yyyy-MM-dd"
                style="width: 100%"
                placeholder="选择日期">
              </el-date-picker>
<!--                <el-input v-model="inputForm.reimDate" :disabled="true"></el-input>-->
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注" prop="remarks">
              <el-input v-model="inputForm.remarks"
                        type="textarea"
                        :rows="5"
                        maxlength="500"
                        placeholder="请输入简介"
                        show-word-limit>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-divider content-position="left"><i class="el-icon-document"></i>
          项目报销详情
          <!--        <el-button style="margin-left: 20px" type="primary" :disabled="method === 'view'" size="mini" @click="insertEvent('detail')" plain>-->
          <!--          新增-->
          <!--        </el-button>-->
        </el-divider>
        <el-row  :gutter="15" >
          <vxe-table
            border
            show-footer
            show-overflow="title"
            :footer-method="footerMethod"
            ref="detailTable"
            :key="detailKey"
            class="vxe-table-element"
            :data="inputForm.detailInfos"
            style="margin-left: 3em"
          >
            <vxe-table-column min-width="80" align="center" field="userName" title="报销人" ></vxe-table-column>
            <vxe-table-column min-width="80" align="center" field="deptName" title="报销部门" ></vxe-table-column>
            <vxe-table-column min-width="80" align="center" field="typeName" title="报销类别"  ></vxe-table-column>
            <vxe-table-column min-width="80" align="center" field="projectName" title="报销项目"  ></vxe-table-column>
            <vxe-table-column min-width="80" align="center" field="reportNumber" title="报告号" ></vxe-table-column>
            <vxe-table-column min-width="80" align="center" field="number" title="费用(元)"  ></vxe-table-column>
            <vxe-table-column min-width="80" align="center" field="receiptNumbers" title="收据张数" ></vxe-table-column>
            <vxe-table-column min-width="80" align="center" field="evectionNumber" title="出差天数" ></vxe-table-column>
            <vxe-table-column min-width="80" align="center" field="content" title="内容" ></vxe-table-column>
          </vxe-table>
        </el-row>

        <el-divider style="margin-top: 20px" content-position="left"><i class="el-icon-document"></i>
          专用发票信息
          <!--        <el-button style="margin-left: 20px" type="primary" :disabled="method === 'view'" size="mini" @click="insertEvent('amount')" plain>-->
          <!--          新增-->
          <!--        </el-button>-->
        </el-divider>
        <el-row  :gutter="15" >
          <vxe-table
            border
            show-overflow
            ref="amountTable"
            class="vxe-table-element"
            :data="inputForm.amountInfos"
            style="margin-left: 3em"
            :key="amountKey"
          >
            <vxe-table-column min-width="80" align="center" field="code" title="发票代码" ></vxe-table-column>
            <vxe-table-column min-width="80" align="center" field="number" title="发票号" ></vxe-table-column>
            <vxe-table-column min-width="80" align="center" field="amount" title="金额" ></vxe-table-column>
            <vxe-table-column min-width="80" align="center" field="taxAmount" title="税额" ></vxe-table-column>
            <vxe-table-column min-width="80" align="center" field="count" title="价税合计" ></vxe-table-column>
          </vxe-table>
        </el-row>

      </el-form>
      <!-- 附件 -->
      <UpLoadComponent ref="uploadComponent"></UpLoadComponent>

      <el-divider content-position="left"><i class="el-icon-document"></i>
        审批意见
      </el-divider>
      <el-input v-model="comment"
                type="textarea"
                :rows="6"
                maxlength="500"
                placeholder="请输入审批意见："
                show-word-limit>
      </el-input>

      <!--审批流程-->
      <FlowHisTableCcpm ref="flowHisTableCcpm"></FlowHisTableCcpm>

      <!--      <ProgramPageForm ref="programPageForm" @getProgram="getProgram"></ProgramPageForm>-->
      <ProgramPageForm ref="programPageForm" @getProgram="getProgram"></ProgramPageForm>
      <ProgramPageForm ref="programPageForm3" @getProgram="getProgram3"></ProgramPageForm>
      <ProgramPageForm ref="programPageForm4" @getProgram="getProgram4"></ProgramPageForm>
      <ProgramPageForm ref="programPageForm5" @getProgram="getProgram5"></ProgramPageForm>

      <!--      <ReimbursementTypePullForm ref="reimbursementTypePullForm" @getProgramForType="getProgramForType"></ReimbursementTypePullForm>-->
      <ReimbursementTypePullForm ref="cwReimbursementTypePullForm" @getProgramForType="getProgramForType"></ReimbursementTypePullForm>
      <ReimbursementTypePullForm ref="cwReimbursementTypePullForm2" @getProgramForType="getProgramForType2"></ReimbursementTypePullForm>
      <ReimbursementTypePullForm ref="cwReimbursementTypePullForm3" @getProgramForType="getProgramForType3"></ReimbursementTypePullForm>
      <ReimbursementTypePullForm ref="cwReimbursementTypePullForm4" @getProgramForType="getProgramForType4"></ReimbursementTypePullForm>
      <ReimbursementTypePullForm ref="cwReimbursementTypePullForm5" @getProgramForType="getProgramForType5"></ReimbursementTypePullForm>

      <!--      <UserPullForm ref="userPullForm" @getProgramForUser="getProgramForUser"></UserPullForm>-->
      <UserPullForm ref="userPullForm" @getProgramForUser="getProgramForUser"></UserPullForm>
      <UserPullForm ref="userPullForm2" @getProgramForUser="getProgramForUser2"></UserPullForm>
      <UserPullForm ref="userPullForm3" @getProgramForUser="getProgramForUser3"></UserPullForm>
      <UserPullForm ref="userPullForm4" @getProgramForUser="getProgramForUser4"></UserPullForm>
      <UserPullForm ref="userPullForm5" @getProgramForUser="getProgramForUser5"></UserPullForm>

      <WorkContractChooseCom ref="workContractChooseCom" @getContract="getContract"></WorkContractChooseCom>
      <PurchaseChooseForm  ref="purchaseChooseForm" @getProject="getPurChoose"></PurchaseChooseForm>
      <MaterialManagementDialog ref="materialManagementDialog" @getUpload="getUpload"></MaterialManagementDialog>

    </div>
</template>

<script>
  // import MakeFormService from '@/api/form/MakeFormService'
  import CommonApi from '@/api/cw/common/CommonApi'
  import ReimbursementApprovalTypeService from '@/api/cw/reimbursementApproval/ReimbursementApprovalTypeService'
  import ReimbursementTypeService from '@/api/sys/ReimbursementTypeService'
  import UpLoadComponent from '@/views/common/UpLoadComponentCcpm'
  import SelectUserTree from '@/views/modules/utils/treeUserSelect'
  import SelectTree from '@/components/treeSelect/treeSelect.vue'
  import XEUtils from 'xe-utils'
  import UserService from '@/api/sys/UserService'
  import ProgramPageForm from '@/views/modules/finance/invoice/ProgramPageForm'
  import ReimbursementTypePullForm from '@/views/modules/cw/reimbursementApproval/info/CwReimbursementTypePullForm'
  // import CwReimbursementTypePullForm from '@/views/modules/cw/reimbursementApproval/info/CwReimbursementTypePullForm'
  import UserPullForm from '@/views/modules/finance/invoice/UserPullForm'
  import WorkContractChooseCom from '@/views/modules/sys/workContract/WorkContractChooseCom'
  import PurchaseChooseForm from '@/views/modules/materialManagement/wareHouse/PurchaseChooseForm'
  import MaterialManagementService from '@/api/materialManagement/MaterialManagementService'
  import MaterialManagementDialog from '@/views/modules/materialManagement/file/MaterialManagementDialog'
  import ReimbursementService from '@/api/centerservice/ccpm/ReimbursementService'
  import FlowHisTableCcpm from '@/views/modules/flowable/task/FlowHisTableCcpm'
  export default {
    data () {
      return {
        validRules: {
          userName: [
            {required: true, message: '报销人不能为空'}
          ],
          deptName: [
            {required: true, message: '报销部门不能为空'}
          ],
          typeName: [
            {required: true, message: '报销类型不能为空'}
          ],
          projectName: [
            {required: true, message: '报销项目不能为空'}
          ],
          contractName: [
            {required: true, message: '报销合同不能为空'}
          ],
          reportNumber: [
            {required: true, message: '报告号不能为空'}
          ],
          number: [
            {required: true, message: '费用(元)不能为空'}
          ]
        },
        title: '',
        method: '',
        visible: false,
        loading: false,
        indexRow: '',
        detailKey: '',
        detailKeyContract: '',
        detailKeyReport: '',
        detailKeyOthers: '',
        detailKeyProcured: '',
        inputForm: {
          userId: '',
          userName: '',
          no: '',
          department: '',
          reimDate: '',
          remarks: '',
          detailInfos: [],
          detailInfoContracts: [],
          detailInfoReports: [],
          detailInfoOthers: [],
          detailInfoProcured: [],
          amountInfos: [],
          files: [], // 附件信息
          procInsId: '',
          sourceType: '',
          preList: [],
          purchaseNo: '',
          tradeTotalPrice: '',
          purchaseId: '',
          departmentName: '',
          histoicFlowList: [],
          flowChart: []
        },
        keyWatch: '',
        amountKey: '',
        flowHisKey: '',
        comment: ''
      }
    },
    // makeFormService: null,
    reimbursementApprovalTypeService: null,
    reimbursementTypeService: null,
    userService: null,
    commonApi: null,
    materialManagementService: null,
    reimbursementService: null,
    created () {
      // this.makeFormService = new MakeFormService()
      this.reimbursementApprovalTypeService = new ReimbursementApprovalTypeService()
      this.userService = new UserService()
      this.commonApi = new CommonApi()
      this.reimbursementTypeService = new ReimbursementTypeService()
      this.materialManagementService = new MaterialManagementService()
      this.reimbursementService = new ReimbursementService()
    },
    activated () {
      // this.createForm()
    },
    props: {
      businessId: {
        type: String,
        default: ''
      },
      processDefKey: {
        type: String,
        default: ''
      }
    },
    components: {
      UpLoadComponent,
      SelectUserTree,
      SelectTree,
      ProgramPageForm,
      UserPullForm,
      ReimbursementTypePullForm,
      WorkContractChooseCom,
      PurchaseChooseForm,
      MaterialManagementDialog,
      FlowHisTableCcpm
    },
    computed: {
      bus: {
        get () {
          return this.businessId
        },
        set (val) {
          this.businessId = val
        }
      },
      pdKey: {
        get () {
          return this.processDefKey
        },
        set (val) {
          this.processDefKey = val
        }
      },
      name () {
        return JSON.parse(localStorage.getItem('user')).name
      },
      officeName () {
        return JSON.parse(localStorage.getItem('user')).officeDTO.name
      },
      userId () {
        return JSON.parse(localStorage.getItem('user')).id
      }
    },
    watch: {
      'keyWatch': {
        handler (newVal) {
          if (this.commonJS.isNotEmpty(this.bus) && this.commonJS.isNotEmpty(this.pdKey)) {
            this.init('view', this.bus, this.pdKey)
          } else {
            this.$nextTick(() => {
              this.$refs.inputForm.resetFields()
            })
          }
        }
      },
      'loading': {
        handler (newVal) {
          this.$emit('changeLoading', newVal)
          this.$refs.uploadComponent.changeLoading(newVal)
          this.$refs.flowHisTableCcpm.changeLoading(newVal)
        }
      }
    },
    methods: {
      getKeyWatch (keyWatch) {
        this.keyWatch = keyWatch
      },
      init (method, id, processDefKey) {
        this.method = method
        // this.title = this.$route.query.title
        this.inputForm = {
          userId: '',
          userName: '',
          no: '',
          department: '',
          reimDate: '',
          remarks: '',
          detailInfos: [],
          detailInfoContracts: [],
          detailInfoReports: [],
          detailInfoOthers: [],
          detailInfoProcured: [],
          amountInfos: [],
          files: [], // 附件信息
          procInsId: '',
          sourceType: '',
          preList: [],
          purchaseNo: '',
          tradeTotalPrice: '',
          purchaseId: '',
          departmentName: '',
          histoicFlowList: [],
          flowChart: []
        }
        this.comment = ''
        this.inputForm.id = id
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.loading = true
          this.$refs.inputForm.resetFields()
          this.reimbursementService.getReimbursementById(this.inputForm.id, processDefKey).then(({data}) => {
            this.inputForm = this.recover(this.inputForm, data)
            this.inputForm = JSON.parse(JSON.stringify(this.inputForm))
            this.$refs.uploadComponent.clearUpload()
            if (this.commonJS.isEmpty(this.inputForm.files)) {
              this.inputForm.files = []
            }
            if (this.commonJS.isEmpty(this.inputForm.flowChart)) {
              this.inputForm.flowChart = []
            }
            if (this.commonJS.isEmpty(this.inputForm.histoicFlowList)) {
              this.inputForm.histoicFlowList = []
            }
            this.$refs.uploadComponent.newUpload(method, this.inputForm.files, 'reimbursement_ping_gu_ccpm')
            this.$refs.flowHisTableCcpm.setFlowHis(this.inputForm.flowChart, this.inputForm.histoicFlowList)
            this.loading = false
          })
        })
      },
      close () {
        this.inputForm = {
          userId: '',
          userName: '',
          no: '',
          department: '',
          reimDate: '',
          remarks: '',
          detailInfos: [],
          detailInfoContracts: [],
          detailInfoReports: [],
          detailInfoOthers: [],
          detailInfoProcured: [],
          amountInfos: [],
          files: [],
          procInsId: '',
          sourceType: '',
          preList: [],
          purchaseNo: '',
          tradeTotalPrice: '',
          purchaseId: '',
          departmentName: '',
          histoicFlowList: [],
          flowChart: []
        }
        this.comment = ''
        this.$refs.inputForm.resetFields()
        this.$refs.uploadComponent.clearUpload()
        this.visible = false
        // this.$store.dispatch('tagsView/delView', {fullPath: this.$route.fullPath})
        // this.$router.push(this.$route.query.backPath)
      },
      // 删除
      removeEvent (row, rowIndex, type) {
        if (type === 'detail') {
          this.$refs.detailTable.remove(row)
          this.inputForm.detailInfos.splice(rowIndex, 1)
        }
        if (type === 'amount') {
          this.$refs.amountTable.remove(row)
          this.inputForm.amountInfos.splice(rowIndex, 1)
        }
        if (type === 'contract_detail') {
          this.$refs.detailTableContract.remove(row)
          this.inputForm.detailInfoContracts.splice(rowIndex, 1)
        }
        if (type === 'report_detail') {
          this.$refs.detailTableReport.remove(row)
          this.inputForm.detailInfoReports.splice(rowIndex, 1)
        }
        if (type === 'others') {
          this.$refs.detailTableOthers.remove(row)
          this.inputForm.detailInfoOthers.splice(rowIndex, 1)
        }
        if (type === 'procured') {
          this.$refs.detailTableProcured.remove(row)
          this.inputForm.detailInfoProcured.splice(rowIndex, 1)
        }
      },
      // 新增
      insertEvent (type) {
        if (type === 'detail') {
          let d = {
            userName: JSON.parse(localStorage.getItem('user')).name,
            deptName: JSON.parse(localStorage.getItem('user')).officeDTO.name,
            userId: JSON.parse(localStorage.getItem('user')).id,
            deptId: JSON.parse(localStorage.getItem('user')).officeDTO.id
          }
          if (this.commonJS.isEmpty(this.inputForm.detailInfos)) {
            this.inputForm.detailInfos = []
          }
          this.$refs.detailTable.insertAt(d)
          this.inputForm.detailInfos.push(d)
          this.detailKey = Math.random()
        }
        if (type === 'amount') {
          let d = {}
          if (this.commonJS.isEmpty(this.inputForm.amountInfos)) {
            this.inputForm.amountInfos = []
          }
          this.$refs.amountTable.insertAt(d)
          this.inputForm.amountInfos.push(d)
          this.amountKey = Math.random()
        }
        if (type === 'contract_detail') {
          let d = {
            userName: JSON.parse(localStorage.getItem('user')).name,
            deptName: JSON.parse(localStorage.getItem('user')).officeDTO.name,
            userId: JSON.parse(localStorage.getItem('user')).id,
            deptId: JSON.parse(localStorage.getItem('user')).officeDTO.id
          }
          if (this.commonJS.isEmpty(this.inputForm.detailInfoContracts)) {
            this.inputForm.detailInfoContracts = []
          }
          this.$refs.detailTableContract.insertAt(d)
          this.inputForm.detailInfoContracts.push(d)
          this.detailKeyContract = Math.random()
        }
        if (type === 'report_detail') {
          let d = {
            userName: JSON.parse(localStorage.getItem('user')).name,
            deptName: JSON.parse(localStorage.getItem('user')).officeDTO.name,
            userId: JSON.parse(localStorage.getItem('user')).id,
            deptId: JSON.parse(localStorage.getItem('user')).officeDTO.id
          }
          if (this.commonJS.isEmpty(this.inputForm.detailInfoReports)) {
            this.inputForm.detailInfoReports = []
          }
          this.$refs.detailTableReport.insertAt(d)
          this.inputForm.detailInfoReports.push(d)
          this.detailKeyReport = Math.random()
        }
        if (type === 'others') {
          let d = {
            userName: JSON.parse(localStorage.getItem('user')).name,
            deptName: JSON.parse(localStorage.getItem('user')).officeDTO.name,
            userId: JSON.parse(localStorage.getItem('user')).id,
            deptId: JSON.parse(localStorage.getItem('user')).officeDTO.id
          }
          if (this.commonJS.isEmpty(this.inputForm.detailInfoOthers)) {
            this.inputForm.detailInfoOthers = []
          }
          this.$refs.detailTableOthers.insertAt(d)
          this.inputForm.detailInfoOthers.push(d)
          this.detailKeyOthers = Math.random()
        }
        if (type === 'procured') {
          let d = {
            userName: JSON.parse(localStorage.getItem('user')).name,
            deptName: JSON.parse(localStorage.getItem('user')).officeDTO.name,
            userId: JSON.parse(localStorage.getItem('user')).id,
            deptId: JSON.parse(localStorage.getItem('user')).officeDTO.id
          }
          if (this.commonJS.isEmpty(this.inputForm.detailInfoProcured)) {
            this.inputForm.detailInfoProcured = []
          }
          this.$refs.detailTableProcured.insertAt(d)
          this.inputForm.detailInfoProcured.push(d)
          this.detailKeyProcured = Math.random()
        }
      },
      footerMethod ({ columns, data }) {
        const footerData = [
          columns.map((column, columnIndex) => {
            if (columnIndex === 0) {
              return '总报销费用'
            }
            if (['number'].includes(column.property)) {
              // eslint-disable-next-line no-undef
              return XEUtils.sum(data, column.property)
            }
            return null
          })
        ]
        return footerData
      },
      twoDecimalPlaces (num) {
        let str = num.toString()
        var len1 = str.substr(0, 1)
        var len2 = str.substr(1, 1)
        // eslint-disable-next-line eqeqeq
        if (str.length > 1 && len1 == 0 && len2 != '.') {
          str = str.substr(1, 1)
        }
        // eslint-disable-next-line eqeqeq
        if (len1 == '.') {
          str = ''
        }
        // eslint-disable-next-line eqeqeq
        if (str.indexOf('.') != -1) {
          var str_ = str.substr(str.indexOf('.') + 1)
          // eslint-disable-next-line eqeqeq
          if (str_.indexOf('.') != -1) {
            str = str.substr(0, str.indexOf('.') + str_.indexOf('.') + 1)
          }
          if (str_.length > 2) {
            this.$message.warning(`金额小数点后只能输入两位，请正确输入！`)
            return (str = '')
          }
        }
        // eslint-disable-next-line no-useless-escape
        str = str.replace(/[^\d^\.]+/g, '') // 保留数字和小数点
        return str
      },
      countAmount (row) {
        let amount
        let taxAmount
        let count = 0
        if (!this.commonJS.isEmpty(row.amount)) {
          amount = parseFloat(row.amount)
          count = count + amount
        }
        if (!this.commonJS.isEmpty(row.taxAmount)) {
          taxAmount = parseFloat(row.taxAmount)
          count = count + taxAmount
        }
        row.count = parseFloat(count).toFixed(2)
      },
      openProgramPageForm (rowIndex, row) {
        if (this.commonJS.isEmpty(row.typeName)) {
          this.$message.error('请选择报销类型')
          return
        }
        this.indexRow = rowIndex
        this.reimbursementApprovalTypeService.findById(row.typeId).then(({data}) => {
          let i = data.sort.toString()
          i = i.substring(0, 1)
          // 非业务报销
          if (i !== '1') {
            this.$refs.programPageForm.init('2', false)
          } else {
            // 打开单选组件
            this.$refs.programPageForm.init('1', false)
          }
        })
      },
      openProgramPageForm3 (rowIndex, row) {
        if (this.commonJS.isEmpty(row.typeName)) {
          this.$message.error('请选择报销类型')
          return
        }
        this.indexRow = rowIndex
        this.reimbursementApprovalTypeService.findById(row.typeId).then(({data}) => {
          let i = data.sort.toString()
          i = i.substring(0, 1)
          // 非业务报销
          if (i !== '1') {
            this.$refs.programPageForm3.init('2', false)
          } else {
            // 打开单选组件
            this.$refs.programPageForm3.init('1', false)
          }
        })
      },
      openProgramPageForm4 (rowIndex, row) {
        if (this.commonJS.isEmpty(row.typeName)) {
          this.$message.error('请选择报销类型')
          return
        }
        this.indexRow = rowIndex
        this.$refs.programPageForm4.init('2', false)
      },
      openProgramPageForm5 (rowIndex, row) {
        if (this.commonJS.isEmpty(row.typeName)) {
          this.$message.error('请选择报销类型')
          return
        }
        this.indexRow = rowIndex
        this.$refs.programPageForm5.init('2', false)
      },
      getProgram (rows) {
        this.inputForm.detailInfos[this.indexRow].projectId = rows[0].id
        this.inputForm.detailInfos[this.indexRow].projectName = rows[0].name
        this.inputForm.detailInfos[this.indexRow].reportNumber = rows[0].reportNo
        this.indexRow = ''
        this.$forceUpdate()
      },
      getProgram3 (rows) {
        this.inputForm.detailInfoReports[this.indexRow].projectId = rows[0].id
        this.inputForm.detailInfoReports[this.indexRow].projectName = rows[0].name
        this.inputForm.detailInfoReports[this.indexRow].reportNumber = rows[0].reportNo
        this.indexRow = ''
        this.$forceUpdate()
      },
      getProgram4 (rows) {
        this.inputForm.detailInfoOthers[this.indexRow].projectId = rows[0].id
        this.inputForm.detailInfoOthers[this.indexRow].projectName = rows[0].name
        this.inputForm.detailInfoOthers[this.indexRow].reportNumber = rows[0].reportNo
        this.indexRow = ''
        this.$forceUpdate()
      },
      getProgram5 (rows) {
        this.inputForm.detailInfoProcured[this.indexRow].projectId = rows[0].id
        this.inputForm.detailInfoProcured[this.indexRow].projectName = rows[0].name
        this.inputForm.detailInfoProcured[this.indexRow].reportNumber = rows[0].reportNo
        this.indexRow = ''
        this.$forceUpdate()
      },
      // 报销类型下拉弹窗
      typePullForm (rowIndex, deptName) {
        this.indexRow = rowIndex
        // this.$refs.reimbursementTypePullForm.init()
        this.$refs.cwReimbursementTypePullForm.init('1', deptName)
      },
      typePullForm2 (rowIndex, deptName) {
        this.indexRow = rowIndex
        this.$refs.cwReimbursementTypePullForm2.init('2', deptName)
      },
      typePullForm3 (rowIndex, deptName) {
        this.indexRow = rowIndex
        this.$refs.cwReimbursementTypePullForm3.init('1', deptName)
      },
      typePullForm4 (rowIndex, deptName) {
        this.indexRow = rowIndex
        this.$refs.cwReimbursementTypePullForm4.init('2', deptName)
      },
      typePullForm5 (rowIndex, deptName) {
        this.indexRow = rowIndex
        this.$refs.cwReimbursementTypePullForm5.init('2', deptName)
      },
      // 报销内容详情
      getProgramForType (rows) {
        this.inputForm.detailInfos[this.indexRow].typeId = rows.id
        this.inputForm.detailInfos[this.indexRow].typeName = rows.name
        this.indexRow = ''
        this.$forceUpdate()
      },
      getProgramForType2 (rows) {
        this.inputForm.detailInfoContracts[this.indexRow].typeId = rows.id
        this.inputForm.detailInfoContracts[this.indexRow].typeName = rows.name
        this.indexRow = ''
        this.$forceUpdate()
      },
      getProgramForType3 (rows) {
        this.inputForm.detailInfoReports[this.indexRow].typeId = rows.id
        this.inputForm.detailInfoReports[this.indexRow].typeName = rows.name
        this.indexRow = ''
        this.$forceUpdate()
      },
      getProgramForType4 (rows) {
        this.inputForm.detailInfoOthers[this.indexRow].typeId = rows.id
        this.inputForm.detailInfoOthers[this.indexRow].typeName = rows.name
        this.indexRow = ''
        this.$forceUpdate()
      },
      getProgramForType5 (rows) {
        this.inputForm.detailInfoProcured[this.indexRow].typeId = rows.id
        this.inputForm.detailInfoProcured[this.indexRow].typeName = rows.name
        this.indexRow = ''
        this.$forceUpdate()
      },
      // 报销人下拉弹窗
      userPullListForm (rowIndex) {
        this.indexRow = rowIndex
        this.$refs.userPullForm.init()
      },
      userPullListForm2 (rowIndex) {
        this.indexRow = rowIndex
        this.$refs.userPullForm2.init()
      },
      userPullListForm3 (rowIndex) {
        this.indexRow = rowIndex
        this.$refs.userPullForm3.init()
      },
      userPullListForm4 (rowIndex) {
        this.indexRow = rowIndex
        this.$refs.userPullForm4.init()
      },
      userPullListForm5 (rowIndex) {
        this.indexRow = rowIndex
        this.$refs.userPullForm5.init()
      },
      getProgramForUser (rows) {
        this.inputForm.detailInfos[this.indexRow].userId = rows[0].id
        this.inputForm.detailInfos[this.indexRow].userName = rows[0].name
        this.inputForm.detailInfos[this.indexRow].deptId = rows[0].parentId
        this.inputForm.detailInfos[this.indexRow].deptName = rows[0].officeName
        this.indexRow = ''
        this.$forceUpdate()
      },
      getProgramForUser2 (rows) {
        this.inputForm.detailInfoContracts[this.indexRow].userId = rows[0].id
        this.inputForm.detailInfoContracts[this.indexRow].userName = rows[0].name
        this.inputForm.detailInfoContracts[this.indexRow].deptId = rows[0].parentId
        this.inputForm.detailInfoContracts[this.indexRow].deptName = rows[0].officeName
        this.indexRow = ''
        this.$forceUpdate()
      },
      getProgramForUser3 (rows) {
        this.inputForm.detailInfoReports[this.indexRow].userId = rows[0].id
        this.inputForm.detailInfoReports[this.indexRow].userName = rows[0].name
        this.inputForm.detailInfoReports[this.indexRow].deptId = rows[0].parentId
        this.inputForm.detailInfoReports[this.indexRow].deptName = rows[0].officeName
        this.indexRow = ''
        this.$forceUpdate()
      },
      getProgramForUser4 (rows) {
        this.inputForm.detailInfoOthers[this.indexRow].userId = rows[0].id
        this.inputForm.detailInfoOthers[this.indexRow].userName = rows[0].name
        this.inputForm.detailInfoOthers[this.indexRow].deptId = rows[0].parentId
        this.inputForm.detailInfoOthers[this.indexRow].deptName = rows[0].officeName
        this.indexRow = ''
        this.$forceUpdate()
      },
      getProgramForUser5 (rows) {
        this.inputForm.detailInfoProcured[this.indexRow].userId = rows[0].id
        this.inputForm.detailInfoProcured[this.indexRow].userName = rows[0].name
        this.inputForm.detailInfoProcured[this.indexRow].deptId = rows[0].parentId
        this.inputForm.detailInfoProcured[this.indexRow].deptName = rows[0].officeName
        this.indexRow = ''
        this.$forceUpdate()
      },
      // 报销类型change事件
      changeSourceType () {
        this.inputForm.detailInfos = []
        this.inputForm.detailInfoContracts = []
        this.inputForm.detailInfoReports = []
        this.inputForm.detailInfoOthers = []
        this.inputForm.detailInfoProcured = []
        this.inputForm.purchaseNo = ''
        this.inputForm.preList = ''
        this.inputForm.purchaseId = ''
        this.detailKey = Math.random()
        this.detailKeyContract = Math.random()
        this.detailKeyReport = Math.random()
        this.detailKeyOthers = Math.random()
        this.detailKeyProcured = Math.random()
      },
      openContractForm (rowIndex, row) {
        this.$refs.workContractChooseCom.init(rowIndex)
      },
      getContract (row, rowIndex) {
        this.inputForm.detailInfoContracts[rowIndex].contractId = row.id
        this.inputForm.detailInfoContracts[rowIndex].contractName = row.name
        this.$forceUpdate()
      },
      startPur (id) {
        this.materialManagementService.findById(id).then(({data}) => {
          this.inputForm.preList = data.detailInfos
          this.inputForm.purchaseNo = data.purchaseNo
          let i = this.inputForm.preList.length
          for (let j = 0; j < i; j++) {
            if (this.commonJS.isNotEmpty(this.inputForm.preList[j].tradePrice)) {
              if (this.commonJS.isNotEmpty(this.inputForm.preList[j].tradeNumber)) {
                this.inputForm.preList[j].priceSum = this.inputForm.preList[j].tradePrice * this.inputForm.preList[j].tradeNumber
              }
            }
          }
        })
        this.$forceUpdate()
      },
      openPurForm () {
        this.$refs.purchaseChooseForm.init()
      },
      getPurChoose (row) {
        this.inputForm.purchaseId = row.id
        this.startPur(row.id)
      },
      getUpload () {
      },
      footerMethod555 ({ columns, data }) {
        const footerData = [
          columns.map((column, columnIndex) => {
            if (columnIndex === 0) {
              return '商品总价'
            }
            if (['priceSum'].includes(column.property)) {
              // eslint-disable-next-line no-undef
              this.inputForm.tradeTotalPrice = XEUtils.sum(data, column.property)
              return XEUtils.sum(data, column.property)
            }
            return null
          })
        ]
        return footerData
      },
      seeFileInfo (index) {
        if (this.commonJS.isEmpty(this.inputForm.preList[index].fileInfoLost)) {
          this.inputForm.preList[index].fileInfoLost = []
        }
        this.$refs.materialManagementDialog.newUpload('view', this.inputForm.preList[index].fileInfoLost, null, null, null, null, null, false, index)
      },
      submitCheck () {
        if (this.commonJS.isEmpty(this.inputForm.sourceType)) {
          this.$message.error('请填写报销类型')
          this.loading = false
          throw new Error('请填写报销类型')
        } else {
          if (this.inputForm.sourceType === '1') {
            if (this.commonJS.isEmpty(this.inputForm.detailInfos)) {
              this.$message.error('至少填写一条报销详情信息')
              this.loading = false
              throw new Error('至少填写一条报销详情信息')
            } else {
              let i = this.inputForm.detailInfos.length
              for (let j = 0; j < i; j++) {
                let k = j + 1
                if (this.commonJS.isEmpty(this.inputForm.detailInfos[j].userName)) {
                  this.$message.error('报销详情第' + k + '行请选择报销人')
                  this.loading = false
                  throw new Error('报销详情第' + k + '行请选择报销人')
                }
                if (this.commonJS.isEmpty(this.inputForm.detailInfos[j].typeName)) {
                  this.$message.error('报销详情第' + k + '行请选择报销类型')
                  this.loading = false
                  throw new Error('报销详情第' + k + '行请选择报销类型')
                }
                if (this.commonJS.isEmpty(this.inputForm.detailInfos[j].projectName)) {
                  this.$message.error('报销详情第' + k + '行请选择报销项目')
                  this.loading = false
                  throw new Error('报销详情第' + k + '行请选择报销项目')
                }
                if (this.commonJS.isEmpty(this.inputForm.detailInfos[j].number)) {
                  this.$message.error('报销详情第' + k + '行请输入费用')
                  this.loading = false
                  throw new Error('报销详情第' + k + '行请输入费用')
                }
              }
            }
          } else if (this.inputForm.sourceType === '2') {
            if (this.commonJS.isEmpty(this.inputForm.detailInfoContracts)) {
              this.$message.error('至少填写一条报销详情信息')
              this.loading = false
              throw new Error('至少填写一条报销详情信息')
            } else {
              let i = this.inputForm.detailInfoContracts.length
              for (let j = 0; j < i; j++) {
                let k = j + 1
                if (this.commonJS.isEmpty(this.inputForm.detailInfoContracts[j].userName)) {
                  this.$message.error('报销详情第' + k + '行请选择报销人')
                  this.loading = false
                  throw new Error('报销详情第' + k + '行请选择报销人')
                }
                if (this.commonJS.isEmpty(this.inputForm.detailInfoContracts[j].typeName)) {
                  this.$message.error('报销详情第' + k + '行请选择报销类型')
                  this.loading = false
                  throw new Error('报销详情第' + k + '行请选择报销类型')
                }
                if (this.commonJS.isEmpty(this.inputForm.detailInfoContracts[j].contractName)) {
                  this.$message.error('报销详情第' + k + '行请选择报销合同')
                  this.loading = false
                  throw new Error('报销详情第' + k + '行请选择报销合同')
                }
                if (this.commonJS.isEmpty(this.inputForm.detailInfoContracts[j].number)) {
                  this.$message.error('报销详情第' + k + '行请输入费用')
                  this.loading = false
                  throw new Error('报销详情第' + k + '行请输入费用')
                }
              }
            }
          } else if (this.inputForm.sourceType === '3') {
            if (this.commonJS.isEmpty(this.inputForm.detailInfoReports)) {
              this.$message.error('至少填写一条报销详情信息')
              this.loading = false
              throw new Error('至少填写一条报销详情信息')
            } else {
              let i = this.inputForm.detailInfoReports.length
              for (let j = 0; j < i; j++) {
                let k = j + 1
                if (this.commonJS.isEmpty(this.inputForm.detailInfoReports[j].userName)) {
                  this.$message.error('报销详情第' + k + '行请选择报销人')
                  this.loading = false
                  throw new Error('报销详情第' + k + '行请选择报销人')
                }
                if (this.commonJS.isEmpty(this.inputForm.detailInfoReports[j].typeName)) {
                  this.$message.error('报销详情第' + k + '行请选择报销类型')
                  this.loading = false
                  throw new Error('报销详情第' + k + '行请选择报销类型')
                }
                if (this.commonJS.isEmpty(this.inputForm.detailInfoReports[j].projectName)) {
                  this.$message.error('报销详情第' + k + '行请选择报销项目')
                  this.loading = false
                  throw new Error('报销详情第' + k + '行请选择报销项目')
                }
                if (this.commonJS.isEmpty(this.inputForm.detailInfoReports[j].reportNumber)) {
                  this.$message.error('报销详情第' + k + '行请选择报告号')
                  this.loading = false
                  throw new Error('报销详情第' + k + '行请选择报告号')
                }
                if (this.commonJS.isEmpty(this.inputForm.detailInfoReports[j].number)) {
                  this.$message.error('报销详情第' + k + '行请输入费用')
                  this.loading = false
                  throw new Error('报销详情第' + k + '行请输入费用')
                }
              }
            }
          } else if (this.inputForm.sourceType === '4') {
            if (this.commonJS.isEmpty(this.inputForm.detailInfoOthers)) {
              this.$message.error('至少填写一条报销详情信息')
              this.loading = false
              throw new Error('至少填写一条报销详情信息')
            } else {
              let i = this.inputForm.detailInfoOthers.length
              for (let j = 0; j < i; j++) {
                let k = j + 1
                if (this.commonJS.isEmpty(this.inputForm.detailInfoOthers[j].userName)) {
                  this.$message.error('报销详情第' + k + '行请选择报销人')
                  this.loading = false
                  throw new Error('报销详情第' + k + '行请选择报销人')
                }
                if (this.commonJS.isEmpty(this.inputForm.detailInfoOthers[j].typeName)) {
                  this.$message.error('报销详情第' + k + '行请选择报销类型')
                  this.loading = false
                  throw new Error('报销详情第' + k + '行请选择报销类型')
                }
                if (this.commonJS.isEmpty(this.inputForm.detailInfoOthers[j].projectName)) {
                  this.$message.error('报销详情第' + k + '行请填写报销详情')
                  this.loading = false
                  throw new Error('报销详情第' + k + '行请填写报销详情')
                }
                if (this.commonJS.isEmpty(this.inputForm.detailInfoOthers[j].number)) {
                  this.$message.error('报销详情第' + k + '行请输入费用')
                  this.loading = false
                  throw new Error('报销详情第' + k + '行请输入费用')
                }
              }
            }
          } else if (this.inputForm.sourceType === '5') {
            if (this.commonJS.isEmpty(this.inputForm.detailInfoProcured)) {
              this.$message.error('至少填写一条报销详情信息')
              this.loading = false
              throw new Error('至少填写一条报销详情信息')
            } else {
              let i = this.inputForm.detailInfoProcured.length
              for (let j = 0; j < i; j++) {
                let k = j + 1
                if (this.commonJS.isEmpty(this.inputForm.detailInfoProcured[j].userName)) {
                  this.$message.error('报销详情第' + k + '行请选择报销人')
                  this.loading = false
                  throw new Error('报销详情第' + k + '行请选择报销人')
                }
                if (this.commonJS.isEmpty(this.inputForm.detailInfoProcured[j].typeName)) {
                  this.$message.error('报销详情第' + k + '行请选择报销类型')
                  this.loading = false
                  throw new Error('报销详情第' + k + '行请选择报销类型')
                }
                if (this.commonJS.isEmpty(this.inputForm.detailInfoProcured[j].projectName)) {
                  this.$message.error('报销详情第' + k + '行请选择报销项目')
                  this.loading = false
                  throw new Error('报销详情第' + k + '行请选择报销项目')
                }
                if (this.commonJS.isEmpty(this.inputForm.detailInfoProcured[j].number)) {
                  this.$message.error('报销详情第' + k + '行请输入费用')
                  this.loading = false
                  throw new Error('报销详情第' + k + '行请输入费用')
                }
              }
            }
          }
        }
      },
      // 同意
      agree (backPath) {
        this.loading = true
        this.reimbursementService.reimAudit(this.businessId, 'yes', this.comment, this.pdKey).then(({data}) => {
          if (data.success) {
            this.$message.success(data.message)
            this.closeBack(backPath)
          } else {
            this.$message.error(data.message)
          }
          this.loading = false
        }).catch(() => {
          this.loading = false
        })
      },
      // 驳回
      reject (backPath) {
        this.$confirm(`确定驳回此报销申请吗?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.loading = true
          this.reimbursementService.reimAudit(this.businessId, 'no', this.comment, this.pdKey).then(({data}) => {
            if (data.success) {
              this.$message.success(data.message)
              this.closeBack(backPath)
            } else {
              this.$message.error(data.message)
            }
            this.loading = false
          }).catch(() => {
            this.loading = false
          })
        })
      },
      closeBack (backPath) {
        this.$store.dispatch('tagsView/delView', {fullPath: this.$route.fullPath})
        if (backPath) {
          this.$router.push(backPath)
        } else {
          this.$router.push('/sys/dashboard/workBench/Pending')
        }
        this.close()
      },
      createForm () {
        console.log(1442846239199617026)
        this.makeFormService.queryById('1442846239199617026').then(({data}) => {
          if (data.source) {
            // this.options = JSON.parse(data.source)
          } else {
            // this.options = {'list': [], 'config': {'labelWidth': 100, 'labelPosition': 'right', 'size': 'small', 'customClass': ''}}
          }
          // this.generateModel(this.options.list)
        })
      }
    }
  }
</script>
<style scoped>
  /deep/  .el-divider__text {
    font-size: 16px;
    font-weight: bold;
  }
</style>
