<template>
  <div>
    <el-dialog
      :title="title"
      :close-on-click-modal="false"
      v-dialogDrag
      width="1200px"
      @close="close"
      append-to-body
      @keyup.enter.native="doSubmit"
      :visible.sync="visible">
      <el-form size="middle" :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
               label-width="100px" @submit.native.prevent>

        <el-divider content-position="left"><i class="el-icon-document"></i> 基础信息</el-divider>
        <el-row :gutter="26">
          <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"></el-input>
            </el-form-item>
          </el-col>
          <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">
              <el-date-picker
                v-model="inputForm.reimDate"
                type="date"
                value-format="yyyy-MM-dd"
                style="width: 100%"
                placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="报销类型" prop="sourceType">
              <el-select v-model="inputForm.sourceType" placeholder="请选择报销类型" style="width:100%;">
                <el-option
                  v-for="item in $dictUtils.getDictList('cw_reimbursement_source_type')"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="inputForm.sourceType === '5'">
            <el-form-item label="采购编号" prop="purchaseNo"
                          :rules="[{required: true, message:'采购编号不能为空', trigger:'blur'},
                              {required: true, message:'采购编号不能为空', trigger:'change'}]">
              <el-input size="medium" :readonly="true" @focus="openPurForm()" v-model="inputForm.purchaseNo" placeholder="请选择采购编号">
                <el-button slot="append" icon="el-icon-search" @click="openPurForm()"></el-button>
              </el-input>
            </el-form-item>
          </el-col>
          <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>
        <div v-if="inputForm.sourceType === '5'">
          <el-divider content-position="left"><i class="el-icon-document"></i>
            采购详情
          </el-divider>
          <el-row  :gutter="15" >
            <vxe-table
              border
              show-footer
              show-overflow
              :footer-method="footerMethod555"
              ref="preTable"
              class="vxe-table-element"
              :data="inputForm.preList"
              style="margin-left: 5em"
              @cell-click=""
              @edit-closed=""
              highlight-current-row
            >
              <vxe-table-column field="purchaserAgent" title="采购人" :edit-render="{}" :rules="[{required: true, message:'请选择采购人', trigger:'blur'}]"></vxe-table-column>
              <vxe-table-column field="procurementOffice" title="采购部门" :edit-render="{}"></vxe-table-column>
              <vxe-table-column field="procurementType" title="采购类型" :edit-render="{}" :rules="[{required: true, message:'请选择采购类型', trigger:'blur'}]"></vxe-table-column>
              <vxe-table-column field="tradeName" title="商品名称" :edit-render="{}" :rules="[{required: true, message:'请填写商品名称', trigger:'blur'}]"></vxe-table-column>
              <vxe-table-column field="tradePrice" title="商品单价(元)" :edit-render="{}" :rules="[{required: true, message:'请输入商品单价', trigger:'blur'}]"></vxe-table-column>
              <vxe-table-column field="tradeNumber" title="商品数量" :edit-render="{}"></vxe-table-column>
              <vxe-table-column field="priceSum" title="商品总价" :edit-render="{}"></vxe-table-column>
              <vxe-table-column field="company" title="单位" :edit-render="{}"></vxe-table-column>
              <vxe-table-column field="remarks" title="备注" :edit-render="{}"></vxe-table-column>
              <vxe-table-column title="操作">
                <template v-slot="scope">
                  <el-button size="mini" type="primary" :disabled="false" @click="seeFileInfo(scope.$rowIndex)">文件详情</el-button>
                </template>
              </vxe-table-column>
            </vxe-table>
          </el-row>
        </div>
        <div v-if="inputForm.sourceType === '1'">
          <el-divider content-position="left"><i class="el-icon-document"></i>
            项目报销详情
            <el-button style="margin-left: 20px" type="primary" :disabled="method==='view' || this.formReadOnly" size="mini" @click="insertEvent('detail')" plain>
              新增
            </el-button>
          </el-divider>
          <el-row  :gutter="15" >
            <vxe-table
              border
              show-footer
              show-overflow
              :footer-method="footerMethod"
              ref="detailTable"
              :key="detailKey"
              class="vxe-table-element"
              :data="inputForm.detailInfos"
              style="margin-left: 5em"
              @cell-click=""
              @edit-closed=""
              highlight-current-row
              :edit-config="{trigger: 'click', mode: 'row', showStatus: true, autoClear: true, icon:'_'}"
              :edit-rules="validRules"
            >
              <vxe-table-column field="userName" title="报销人" :edit-render="{}" :rules="[{required: true, message:'请选择报销人', trigger:'blur'}]">
                <template v-slot:edit="scope">
                  <el-input v-model="scope.row.userName" @focus="userPullListForm(scope.$rowIndex)"></el-input>
                  <!--              <UserSelectV2 :limit='1' :userName="scope.row.userName" @getValue='(value, label) => {scope.row.userName = label}'></UserSelectV2>-->
                </template>
              </vxe-table-column>
              <vxe-table-column field="deptName" title="报销部门" :edit-render="{}">
                <template v-slot:edit="scope">
                  <el-input :disabled='true' v-model="scope.row.deptName" ></el-input>
                </template>
              </vxe-table-column>
              <vxe-table-column field="typeName" title="报销类别" :edit-render="{}" :rules="[{required: true, message:'请选择报销类别', trigger:'blur'}]">
                <template v-slot:edit="scope">
                  <el-input v-model="scope.row.typeName" @focus="typePullForm(scope.$rowIndex)"></el-input>
                </template>
              </vxe-table-column>
              <vxe-table-column field="projectName" title="报销项目" :edit-render="{}" :rules="[{required: true, message:'请选择报销项目', trigger:'blur'}]">
                <template v-slot:edit="scope">
                  <el-input v-model="scope.row.projectName" @focus="openProgramPageForm(scope.$rowIndex, scope.row)"></el-input>
                </template>
              </vxe-table-column>
              <!--            <vxe-table-column field="reportNumber" title="报告号" :edit-render="{}">-->
              <!--              <template v-slot:edit="scope">-->
              <!--                <el-input :readonly="true" v-model="scope.row.reportNumber" @focus="openReportNoPageForm(scope.$rowIndex, scope.row)"></el-input>-->
              <!--              </template>-->
              <!--            </vxe-table-column>-->
              <vxe-table-column field="number" title="费用(元)" :edit-render="{}" :rules="[{required: true, message:'请输入费用', trigger:'blur'}]">
                <template v-slot:edit="scope">
                  <el-input maxlength="15" v-model="scope.row.number" @keyup.native="scope.row.number = twoDecimalPlaces(scope.row.number)"></el-input>
                </template>
              </vxe-table-column>
              <vxe-table-column field="receiptNumber" title="收据张数" :edit-render="{}">
                <template v-slot:edit="scope">
                  <el-input v-model="scope.row.receiptNumber" oninput ="value=value.replace(/\D|^0/g,'')" maxlength="10"></el-input>
                </template>
              </vxe-table-column>
              <vxe-table-column field="days" title="出差天数" :edit-render="{}">
                <template v-slot:edit="scope">
                  <el-input v-model="scope.row.days" oninput ="value=value.replace(/\D|^0/g,'')" maxlength="10"></el-input>
                </template>
              </vxe-table-column>
              <vxe-table-column field="content" title="内容" :edit-render="{}">
                <template v-slot:edit="scope">
                  <el-input v-model="scope.row.content" ></el-input>
                </template>
              </vxe-table-column>
              <vxe-table-column title="操作" width="100">
                <template v-slot="scope">
                  <el-button size="mini" type="danger" @click="removeEvent(scope.row,scope.$rowIndex,'detail')">删除</el-button>
                </template>
              </vxe-table-column>
            </vxe-table>
          </el-row>
        </div>
        <div v-if="inputForm.sourceType === '2'">
          <el-divider content-position="left"><i class="el-icon-document"></i>
            合同报销详情
            <el-button style="margin-left: 20px" type="primary" :disabled="method==='view' || this.formReadOnly" size="mini" @click="insertEvent('contract_detail')" plain>
              新增
            </el-button>
          </el-divider>
          <el-row  :gutter="15" >
            <vxe-table
              border
              show-footer
              show-overflow
              :footer-method="footerMethod"
              ref="detailTableContract"
              :key="detailKeyContract"
              class="vxe-table-element"
              :data="inputForm.detailInfoContracts"
              style="margin-left: 5em"
              @cell-click=""
              @edit-closed=""
              highlight-current-row
              :edit-config="{trigger: 'click', mode: 'row', showStatus: true, autoClear: true, icon:'_'}"
              :edit-rules="validRules"
            >
              <vxe-table-column field="userName" title="报销人" :edit-render="{}" :rules="[{required: true, message:'请选择报销人', trigger:'blur'}]">
                <template v-slot:edit="scope">
                  <el-input v-model="scope.row.userName" @focus="userPullListForm2(scope.$rowIndex)"></el-input>
                  <!--              <UserSelectV2 :limit='1' :userName="scope.row.userName" @getValue='(value, label) => {scope.row.userName = label}'></UserSelectV2>-->
                </template>
              </vxe-table-column>
              <vxe-table-column field="deptName" title="报销部门" :edit-render="{}">
                <template v-slot:edit="scope">
                  <el-input :disabled='true' v-model="scope.row.deptName" ></el-input>
                </template>
              </vxe-table-column>
              <vxe-table-column field="typeName" title="报销类别" :edit-render="{}" :rules="[{required: true, message:'请选择报销类别', trigger:'blur'}]">
                <template v-slot:edit="scope">
                  <el-input v-model="scope.row.typeName" @focus="typePullForm2(scope.$rowIndex)"></el-input>
                </template>
              </vxe-table-column>
              <vxe-table-column field="contractName" title="报销合同" :edit-render="{}" :rules="[{required: true, message:'请选择报销合同', trigger:'blur'}]">
                <template v-slot:edit="scope">
                  <el-input v-model="scope.row.contractName" @focus="openContractForm(scope.$rowIndex, scope.row)"></el-input>
                </template>
              </vxe-table-column>
              <!--            <vxe-table-column field="reportNumber" title="报告号" :edit-render="{}">-->
              <!--              <template v-slot:edit="scope">-->
              <!--                <el-input :readonly="true" v-model="scope.row.reportNumber" @focus="openReportNoPageForm(scope.$rowIndex, scope.row)"></el-input>-->
              <!--              </template>-->
              <!--            </vxe-table-column>-->
              <vxe-table-column field="number" title="费用(元)" :edit-render="{}" :rules="[{required: true, message:'请输入费用', trigger:'blur'}]">
                <template v-slot:edit="scope">
                  <el-input maxlength="15" v-model="scope.row.number" @keyup.native="scope.row.number = twoDecimalPlaces(scope.row.number)"></el-input>
                </template>
              </vxe-table-column>
              <vxe-table-column field="receiptNumber" title="收据张数" :edit-render="{}">
                <template v-slot:edit="scope">
                  <el-input v-model="scope.row.receiptNumber" oninput ="value=value.replace(/\D|^0/g,'')" maxlength="10"></el-input>
                </template>
              </vxe-table-column>
              <vxe-table-column field="days" title="出差天数" :edit-render="{}">
                <template v-slot:edit="scope">
                  <el-input v-model="scope.row.days" oninput ="value=value.replace(/\D|^0/g,'')" maxlength="10"></el-input>
                </template>
              </vxe-table-column>
              <vxe-table-column field="content" title="内容" :edit-render="{}">
                <template v-slot:edit="scope">
                  <el-input v-model="scope.row.content" ></el-input>
                </template>
              </vxe-table-column>
              <vxe-table-column title="操作" width="100">
                <template v-slot="scope">
                  <el-button size="mini" type="danger" @click="removeEvent(scope.row,scope.$rowIndex,'detail')">删除</el-button>
                </template>
              </vxe-table-column>
            </vxe-table>
          </el-row>
        </div>
        <div v-if="inputForm.sourceType === '3'">
          <el-divider content-position="left"><i class="el-icon-document"></i>
            报告报销详情
            <el-button style="margin-left: 20px" type="primary" :disabled="method==='view' || this.formReadOnly" size="mini" @click="insertEvent('report_detail')" plain>
              新增
            </el-button>
          </el-divider>
          <el-row  :gutter="15" >
            <vxe-table
              border
              show-footer
              show-overflow
              :footer-method="footerMethod"
              ref="detailTableReport"
              :key="detailKeyReport"
              class="vxe-table-element"
              :data="inputForm.detailInfoReports"
              style="margin-left: 5em"
              @cell-click=""
              @edit-closed=""
              highlight-current-row
              :edit-config="{trigger: 'click', mode: 'row', showStatus: true, autoClear: true, icon:'_'}"
              :edit-rules="validRules"
            >
              <vxe-table-column field="userName" title="报销人" :edit-render="{}" :rules="[{required: true, message:'请选择报销人', trigger:'blur'}]">
                <template v-slot:edit="scope">
                  <el-input v-model="scope.row.userName" @focus="userPullListForm3(scope.$rowIndex)"></el-input>
                  <!--              <UserSelectV2 :limit='1' :userName="scope.row.userName" @getValue='(value, label) => {scope.row.userName = label}'></UserSelectV2>-->
                </template>
              </vxe-table-column>
              <vxe-table-column field="deptName" title="报销部门" :edit-render="{}">
                <template v-slot:edit="scope">
                  <el-input :disabled='true' v-model="scope.row.deptName" ></el-input>
                </template>
              </vxe-table-column>
              <vxe-table-column field="typeName" title="报销类别" :edit-render="{}" :rules="[{required: true, message:'请选择报销类别', trigger:'blur'}]">
                <template v-slot:edit="scope">
                  <el-input v-model="scope.row.typeName" @focus="typePullForm3(scope.$rowIndex)"></el-input>
                </template>
              </vxe-table-column>
              <vxe-table-column field="projectName" title="报销项目" :edit-render="{}" :rules="[{required: true, message:'请选择报销项目', trigger:'blur'}]">
                <template v-slot:edit="scope">
                  <el-input v-model="scope.row.projectName" @focus="openProgramPageForm3(scope.$rowIndex, scope.row)"></el-input>
                </template>
              </vxe-table-column>
              <vxe-table-column field="reportNumber" title="报告号" :edit-render="{}">
                <template v-slot:edit="scope">
                  <el-input :readonly="true" v-model="scope.row.reportNumber" @focus="openReportNoPageForm(scope.$rowIndex, scope.row)"></el-input>
                </template>
              </vxe-table-column>
              <vxe-table-column field="number" title="费用(元)" :edit-render="{}" :rules="[{required: true, message:'请输入费用', trigger:'blur'}]">
                <template v-slot:edit="scope">
                  <el-input maxlength="15" v-model="scope.row.number" @keyup.native="scope.row.number = twoDecimalPlaces(scope.row.number)"></el-input>
                </template>
              </vxe-table-column>
              <vxe-table-column field="receiptNumber" title="收据张数" :edit-render="{}">
                <template v-slot:edit="scope">
                  <el-input v-model="scope.row.receiptNumber" oninput ="value=value.replace(/\D|^0/g,'')" maxlength="10"></el-input>
                </template>
              </vxe-table-column>
              <vxe-table-column field="days" title="出差天数" :edit-render="{}">
                <template v-slot:edit="scope">
                  <el-input v-model="scope.row.days" oninput ="value=value.replace(/\D|^0/g,'')" maxlength="10"></el-input>
                </template>
              </vxe-table-column>
              <vxe-table-column field="content" title="内容" :edit-render="{}">
                <template v-slot:edit="scope">
                  <el-input v-model="scope.row.content" ></el-input>
                </template>
              </vxe-table-column>
              <vxe-table-column title="操作" width="100">
                <template v-slot="scope">
                  <el-button size="mini" type="danger" @click="removeEvent(scope.row,scope.$rowIndex,'report_detail')">删除</el-button>
                </template>
              </vxe-table-column>
            </vxe-table>
          </el-row>
        </div>
        <div v-if="inputForm.sourceType === '4'">
          <el-divider content-position="left"><i class="el-icon-document"></i>
            其他报销详情
            <el-button style="margin-left: 20px" type="primary" :disabled="method==='view' || this.formReadOnly" size="mini" @click="insertEvent('others')" plain>
              新增
            </el-button>
          </el-divider>
          <el-row  :gutter="15" >
            <vxe-table
              border
              show-footer
              show-overflow
              :footer-method="footerMethod"
              ref="detailTableOthers"
              class="vxe-table-element"
              :data="inputForm.detailInfoOthers"
              style="margin-left: 5em"
              :key="detailKeyOthers"
              @cell-click=""
              @edit-closed=""
              highlight-current-row
              :edit-config="{trigger: 'click', mode: 'row', showStatus: true, autoClear: true, icon:'_'}"
              :edit-rules="validRules"
            >
              <vxe-table-column field="userName" title="报销人" :edit-render="{}" :rules="[{required: true, message:'请选择报销人', trigger:'blur'}]">
                <template v-slot:edit="scope">
                  <el-input v-model="scope.row.userName" @focus="userPullListForm4(scope.$rowIndex)"></el-input>
                  <!--              <UserSelectV2 :limit='1' :userName="scope.row.userName" @getValue='(value, label) => {scope.row.userName = label}'></UserSelectV2>-->
                </template>
              </vxe-table-column>
              <vxe-table-column field="deptName" title="报销部门" :edit-render="{}">
                <template v-slot:edit="scope">
                  <el-input :disabled='true' v-model="scope.row.deptName" ></el-input>
                </template>
              </vxe-table-column>
              <vxe-table-column field="typeName" title="报销类别" :edit-render="{}" :rules="[{required: true, message:'请选择报销类别', trigger:'blur'}]">
                <template v-slot:edit="scope">
                  <el-input v-model="scope.row.typeName" @focus="typePullForm4(scope.$rowIndex)"></el-input>
                </template>
              </vxe-table-column>
              <vxe-table-column field="projectName" title="报销详情" :edit-render="{}" :rules="[{required: true, message:'请田小娥报销详情', trigger:'blur'}]">
                <template v-slot:edit="scope">
                  <el-input v-model="scope.row.projectName" @focus="openProgramPageForm4(scope.$rowIndex, scope.row)"></el-input>
                </template>
              </vxe-table-column>
              <!--            <vxe-table-column field="reportNumber" title="报告号" :edit-render="{}">-->
              <!--              <template v-slot:edit="scope">-->
              <!--                <el-input :readonly="true" v-model="scope.row.reportNumber" @focus="openReportNoPageForm(scope.$rowIndex, scope.row)"></el-input>-->
              <!--              </template>-->
              <!--            </vxe-table-column>-->
              <vxe-table-column field="number" title="费用(元)" :edit-render="{}" :rules="[{required: true, message:'请输入费用', trigger:'blur'}]">
                <template v-slot:edit="scope">
                  <el-input maxlength="15" v-model="scope.row.number" @keyup.native="scope.row.number = twoDecimalPlaces(scope.row.number)"></el-input>
                </template>
              </vxe-table-column>
              <vxe-table-column field="receiptNumber" title="收据张数" :edit-render="{}">
                <template v-slot:edit="scope">
                  <el-input v-model="scope.row.receiptNumber" oninput ="value=value.replace(/\D|^0/g,'')" maxlength="10"></el-input>
                </template>
              </vxe-table-column>
              <vxe-table-column field="days" title="出差天数" :edit-render="{}">
                <template v-slot:edit="scope">
                  <el-input v-model="scope.row.days" oninput ="value=value.replace(/\D|^0/g,'')" maxlength="10"></el-input>
                </template>
              </vxe-table-column>
              <vxe-table-column field="content" title="内容" :edit-render="{}">
                <template v-slot:edit="scope">
                  <el-input v-model="scope.row.content" ></el-input>
                </template>
              </vxe-table-column>
              <vxe-table-column title="操作" width="100">
                <template v-slot="scope">
                  <el-button size="mini" type="danger" @click="removeEvent(scope.row,scope.$rowIndex,'others')">删除</el-button>
                </template>
              </vxe-table-column>
            </vxe-table>
          </el-row>
        </div>
        <div v-if="inputForm.sourceType === '5'">
          <el-divider content-position="left"><i class="el-icon-document"></i>
            采购报销详情
            <el-button style="margin-left: 20px" type="primary" :disabled="method==='view' || this.formReadOnly" size="mini" @click="insertEvent('procured')" plain>
              新增
            </el-button>
          </el-divider>
          <el-row  :gutter="15" >
            <vxe-table
              border
              show-footer
              show-overflow
              :footer-method="footerMethod"
              ref="detailTableProcured"
              class="vxe-table-element"
              :data="inputForm.detailInfoProcured"
              style="margin-left: 5em"
              :key="detailKeyProcured"
              @cell-click=""
              @edit-closed=""
              highlight-current-row
              :edit-config="{trigger: 'click', mode: 'row', showStatus: true, autoClear: true, icon:'_'}"
              :edit-rules="validRules"
            >
              <vxe-table-column field="userName" title="报销人" :edit-render="{}" :rules="[{required: true, message:'请选择报销人', trigger:'blur'}]">
                <template v-slot:edit="scope">
                  <el-input v-model="scope.row.userName" @focus="userPullListForm5(scope.$rowIndex)"></el-input>
                  <!--              <UserSelectV2 :limit='1' :userName="scope.row.userName" @getValue='(value, label) => {scope.row.userName = label}'></UserSelectV2>-->
                </template>
              </vxe-table-column>
              <vxe-table-column field="deptName" title="报销部门" :edit-render="{}">
                <template v-slot:edit="scope">
                  <el-input :disabled='true' v-model="scope.row.deptName" ></el-input>
                </template>
              </vxe-table-column>
              <vxe-table-column field="typeName" title="报销类别" :edit-render="{}" :rules="[{required: true, message:'请选择报销类别', trigger:'blur'}]">
                <template v-slot:edit="scope">
                  <el-input v-model="scope.row.typeName" @focus="typePullForm5(scope.$rowIndex)"></el-input>
                </template>
              </vxe-table-column>
              <vxe-table-column field="projectName" title="报销详情" :edit-render="{}" :rules="[{required: true, message:'请填写报销详情', trigger:'blur'}]">
                <template v-slot:edit="scope">
                  <el-input v-model="scope.row.projectName" @focus="openProgramPageForm5(scope.$rowIndex, scope.row)"></el-input>
                </template>
              </vxe-table-column>
              <!--            <vxe-table-column field="reportNumber" title="报告号" :edit-render="{}">-->
              <!--              <template v-slot:edit="scope">-->
              <!--                <el-input :readonly="true" v-model="scope.row.reportNumber" @focus="openReportNoPageForm(scope.$rowIndex, scope.row)"></el-input>-->
              <!--              </template>-->
              <!--            </vxe-table-column>-->
              <vxe-table-column field="number" title="费用(元)" :edit-render="{}" :rules="[{required: true, message:'请输入费用', trigger:'blur'}]">
                <template v-slot:edit="scope">
                  <el-input maxlength="15" v-model="scope.row.number" @keyup.native="scope.row.number = twoDecimalPlaces(scope.row.number)"></el-input>
                </template>
              </vxe-table-column>
              <vxe-table-column field="receiptNumber" title="收据张数" :edit-render="{}">
                <template v-slot:edit="scope">
                  <el-input v-model="scope.row.receiptNumber" oninput ="value=value.replace(/\D|^0/g,'')" maxlength="10"></el-input>
                </template>
              </vxe-table-column>
              <vxe-table-column field="days" title="出差天数" :edit-render="{}">
                <template v-slot:edit="scope">
                  <el-input v-model="scope.row.days" oninput ="value=value.replace(/\D|^0/g,'')" maxlength="10"></el-input>
                </template>
              </vxe-table-column>
              <vxe-table-column field="content" title="内容" :edit-render="{}">
                <template v-slot:edit="scope">
                  <el-input v-model="scope.row.content" ></el-input>
                </template>
              </vxe-table-column>
              <vxe-table-column title="操作" width="100">
                <template v-slot="scope">
                  <el-button size="mini" type="danger" @click="removeEvent(scope.row,scope.$rowIndex,'procured')">删除</el-button>
                </template>
              </vxe-table-column>
            </vxe-table>
          </el-row>
        </div>

        <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('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: 5em"
            @cell-click=""
            @edit-closed=""
            highlight-current-row
            :edit-config="{trigger: 'click', mode: 'cell', showStatus: true, autoClear: true}"
          >
            <vxe-table-column field="code" title="发票代码" :edit-render="{}">
              <template v-slot:edit="scope">
                <el-input v-model="scope.row.code" ></el-input>
              </template>
            </vxe-table-column>
            <vxe-table-column field="number" title="发票号" :edit-render="{}">
              <template v-slot:edit="scope">
                <el-input v-model="scope.row.number" ></el-input>
              </template>
            </vxe-table-column>
            <vxe-table-column field="amount" title="金额" :edit-render="{}">
              <template v-slot:edit="scope">
                <el-input v-model="scope.row.amount" ></el-input>
              </template>
            </vxe-table-column>
            <vxe-table-column field="taxAmount" title="税额" :edit-render="{}">
              <template v-slot:edit="scope">
                <el-input v-model="scope.row.taxAmount" ></el-input>
              </template>
            </vxe-table-column>
            <vxe-table-column field="count" title="价税合计" :edit-render="{}">
              <template v-slot:edit="scope">
                <el-input v-model="scope.row.count" ></el-input>
              </template>
            </vxe-table-column>
            <vxe-table-column title="操作" width="100">
              <template v-slot="scope">
                <el-button size="mini" type="danger" @click="removeEvent(scope.row,scope.$rowIndex,'amount')">删除</el-button>
              </template>
            </vxe-table-column>
          </vxe-table>
        </el-row>

        <!-- 附件 -->
        <UpLoadComponent ref="uploadComponent"></UpLoadComponent>
      </el-form>
      <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="close()" icon="el-icon-circle-close">关闭</el-button>
      <el-button size="small" type="primary" v-if="method != 'view'" @click="doSubmit()" icon="el-icon-circle-check" v-noMoreClick>确定</el-button>
    </span>
      <MaterialManagementDialog ref="materialManagementDialog" @getUpload="getUpload"></MaterialManagementDialog>
    </el-dialog>
  </div>
</template>

<script>
  // import ReimbursementService from '@/api/sys/ReimbursementService'
  import ReimbursementApprovalService from '@/api/cw/reimbursementApproval/ReimbursementApprovalService'
  import UpLoadComponent from '@/views/common/UpLoadComponent'
  import XEUtils from 'xe-utils'
  import MaterialManagementService from '@/api/materialManagement/MaterialManagementService'
  import MaterialManagementDialog from '../../../materialManagement/file/MaterialManagementDialog'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          userName: '',
          no: '',
          department: '',
          reimDate: '',
          remarks: '',
          detailInfos: [],
          detailInfoContracts: [],
          detailInfoReports: [],
          detailInfoOthers: [],
          detailInfoProcured: [],
          amountInfos: [],
          files: [], // 附件信息
          sourceType: '',
          preList: [],
          purchaseNo: '',
          tradeTotalPrice: '',
          purchaseId: '',
          departmentName: ''
        }
      }
    },
    // reimbursementService: null,
    reimbursementApprovalService: null,
    materialManagementService: null,
    created () {
      // this.reimbursementService = new ReimbursementService()
      this.reimbursementApprovalService = new ReimbursementApprovalService()
      this.materialManagementService = new MaterialManagementService()
    },
    components: {
      UpLoadComponent,
      MaterialManagementDialog
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm = {
          userName: '',
          no: '',
          department: '',
          reimDate: '',
          remarks: '',
          detailInfos: [],
          amountInfos: [],
          files: [], // 附件信息
          detailInfoContracts: [],
          detailInfoReports: [],
          detailInfoOthers: [],
          detailInfoProcured: [],
          sourceType: '',
          preList: [],
          purchaseNo: '',
          tradeTotalPrice: '',
          purchaseId: '',
          departmentName: ''
        }
        if (method === 'add') {
          this.title = `新建报销`
        } else if (method === 'edit') {
          this.inputForm.id = id
          this.title = '报销修改'
        } else if (method === 'view') {
          this.inputForm.id = id
          this.title = '报销详情'
        } else if (method === 'addChild') {
          this.title = '添加下级结构'
          this.inputForm.parentId = id
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$refs.inputForm.resetFields()
            this.reimbursementApprovalService.findById(this.inputForm.id).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data)
              this.$refs.uploadComponent.newUpload(method, this.inputForm.files, 'reimbursement')
              this.inputForm = JSON.parse(JSON.stringify(this.inputForm))
              if (this.commonJS.isNotEmpty(this.inputForm.purchaseId)) {
                this.startPur(this.inputForm.purchaseId)
              }
              this.loading = false
            })
            // this.reimbursementService.findById(this.inputForm.id).then(({data}) => {
            //   this.inputForm = this.recover(this.inputForm, data)
            //   this.$refs.uploadComponent.newUpload(method, this.inputForm.files, 'reimbursement')
            //   this.inputForm = JSON.parse(JSON.stringify(this.inputForm))
            //   this.loading = false
            // })
          }
        })
      },
      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
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            if (this.$refs.uploadComponent.checkProgress()) {
              this.loading = false
              return
            }
            if (this.commonJS.isEmpty(this.inputForm.files)) {
              this.inputForm.files = []
            }
            this.inputForm.files = this.$refs.uploadComponent.getDataList()
            this.reimbursementApprovalTypeService.save(this.inputForm).then(({data}) => {
              this.close()
              this.$message.success(data)
              this.$emit('refreshDataList')
              this.loading = false
            }).catch(() => {
              this.loading = false
            })
          }
        })
      },
      close () {
        this.$refs.inputForm.resetFields()
        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.inputForm.amountInfos = []
        this.$refs.uploadComponent.clearUpload()
        this.visible = false
      },
      // 删除
      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)
        }
      },
      // 新增
      async insertEvent (type) {
        if (type === 'detail') {
          await this.$refs.detailTable.insert().then((data) => {
            this.inputForm.detailInfos.push(data)
          })
        }
        if (type === 'amount') {
          await this.$refs.amountTable.insert().then((data) => {
            this.inputForm.amountInfos.push(data)
          })
        }
      },
      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()
      },
      getPurChoose (row) {
        this.inputForm.purchaseId = row.id
        this.startPur(row.id)
      },
      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)
      }
    }
  }
</script>
