<template>
  <div class="app-container">
    <div v-show="viewState == 1">
      <div class="tab-header webtop">
        <div>{{ viewTitle }}</div>
        <div>
          <el-button type="primary" size="small" :disabled="submitdisabled" @click="exportByKp()">索赔单开票明细导入</el-button>
          <el-button type="primary" size="small" :disabled="submitdisabled" @click="exportByTZ()">调增当月收入项目导入</el-button>
          <el-button type="primary" size="small" :disabled="submitdisabled" @click="exportByTJ()">调减当月收入项目导入</el-button>
          <el-button type="primary" size="small" :disabled="submitdisabled" @click="saveOrUpdate()">保存</el-button>
          <el-button type="primary" size="small" :disabled="submitdisabled" @click="submit()">提交</el-button>
          <el-button type="info" size="small" @click="handleReturn()">关闭</el-button>
        </div>
      </div>
      <div class="listconadd">
        <el-form ref="form_obj" :model="formobj" :rules="rules" class="formaddcopy02">
          <el-row style="border-top: 1px solid #e0e3eb">
            <el-col :span="8">
              <div class="span-sty">申请部门</div>
              <el-form-item><span class="addinputInfo">{{ formobj.deptName }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">申请人</div>
              <el-form-item><span class="addinputInfo">{{ formobj.createByName }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">申请日期</div>
              <el-form-item><span class="addinputInfo">{{ formobj.createTime }}</span></el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <div class="span-sty">开票单位</div>
              <el-form-item>
                <el-select class="addinputInfo" v-model="formobj.purchaseSystemName" placeholder="请选择" @change="changePurchase" filterable clearable>
                  <el-option v-for="item in purchase_list" :key="item.deptSid" :label="item.purchaseSystemName" :value="item.purchaseSystemName"/>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <div class="span-sty">开票名称</div>
              <el-form-item>
                <el-select class="addinputInfo" v-model="formobj.invoiceSid" placeholder="请选择" @change="supplierChange" clearable filterable>
                  <el-option v-for="item in supplier_list" :key="item.sid" :label="item.billingCompanyName" :value="item.sid"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">开票类型</div>
              <el-form-item><span class="addinputInfo">{{ formobj.invoiceValue }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">开票金额</div>
              <el-form-item><span class="addinputInfo">{{ kpjeTtotal }}</span></el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <div class="span-sty">备注</div>
              <el-form-item><el-input class="addinputInfo" style="width: 80%" v-model="formobj.remarks" clearable placeholder="" /></el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <div class="span-sty">附件</div>
              <el-form-item>
                <uploadImg ref="uploadImg" class="addinputInfo" v-model="formobj.fileList" :limit="50" bucket="map" :upload-data="{ type: '0001' }"/>
              </el-form-item>
            </el-col>
          </el-row>
          <div class="title">开票索赔单列表</div>
          <el-table :key="tableKey" :data="formobj.detailList" :index="index" border style="width: 100%" :cell-style="cellStyle" show-summary :summary-method="getSummaries">
            <el-table-column fixed width="60" label="序号" type="index" :index="index + 1" align="center"/>
            <el-table-column prop="claimBillNo" label="索赔单号" align="center" width="170" />
            <el-table-column prop="repairBillNo" label="维修单号" align="center" width="170" />
            <el-table-column prop="vehMark" label="车牌号" align="center" width="100" />
            <el-table-column prop="vinNo" label="车架号" align="center" width="100" />
            <el-table-column prop="claimManufacturer" label="索赔厂家" align="center" width="120" />
            <el-table-column prop="claimHourAmount" label="索赔工时费" align="center" width="120" />
            <el-table-column prop="claimGoodsAmount" label="索赔材料费" align="center" width="120" />
            <el-table-column prop="claimOutAmount" label="外出费" align="center" width="120" />
            <el-table-column prop="claimSubsidyAmount" label="厂家补助" align="center" width="120" />
            <el-table-column prop="claimRescueAmount" label="施救费" align="center" width="120" />
            <el-table-column prop="claimOtherAmount" label="其它费用" align="center" width="120" />
            <el-table-column prop="totalAmount" label="合计" align="center" width="120" />
            <el-table-column label="备注" align="center" min-width="200">
              <template slot-scope="scope">
                <el-input v-model="scope.row.remarks" clearable placeholder="" />
              </template>
            </el-table-column>
          </el-table>
          <el-row>
            <el-col :span="12">
              <div class="titleOne">调增当月收入项目列表(厂家开票明细中索赔单以外补款项目)</div>
              <el-table :key="bkxmKey" :data="formobj.supplementaryItems" :index="index" border style="width: 100%" show-summary :summary-method="getSummaries">
                <el-table-column fixed width="60" label="序号" type="index" :index="index + 1" align="center"/>
                <el-table-column prop="projectName" label="项目名称" align="center" width="170" />
                <el-table-column prop="amount" label="金额" align="center" width="100" />
                <el-table-column prop="remarks" label="补款原因" align="center" min-width="130" />
                <el-table-column label="附件" align="center" width="180">
                  <template slot-scope="scope">
                    <el-button type="primary" size="mini" @click="handleUpload(scope.row, scope.$index, 'tzdysr')">上传</el-button>
                    <el-button type="primary" size="mini" style="padding-left: 5px" v-show="scope.row.supplementaryFiles.length > 0" @click="handleLook(scope.row.supplementaryFiles)">查看</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </el-col>
            <el-col :span="12">
              <div class="titleOne">调减当月收入项目列表(厂家开票明细中索赔单以外扣款项目)</div>
              <el-table :key="kkxmKey" :data="formobj.deductionItems" :index="index" border style="width: 100%" show-summary :summary-method="getSummaries">
                <el-table-column fixed width="60" label="序号" type="index" :index="index + 1" align="center"/>
                <el-table-column prop="projectName" label="项目名称" align="center" width="170" />
                <el-table-column prop="amount" label="金额" align="center" width="100" />
                <el-table-column prop="remarks" label="扣款原因" align="center" min-width="130" />
                <el-table-column label="附件" align="center" width="180">
                  <template slot-scope="scope">
                    <el-button type="primary" size="mini" @click="handleUpload(scope.row, scope.$index, 'tjdysr')">上传</el-button>
                    <el-button type="primary" size="mini" style="padding-left: 5px" v-show="scope.row.deductionFiles.length > 0" @click="handleLook(scope.row.deductionFiles)">查看</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </el-col>
          </el-row>
        </el-form>
      </div>
    </div>
    <!-- 索赔单开票明细导入 -->
    <el-dialog :visible.sync="dialogVisibleByKP" width="70%" :show-close="false">
      <div>
        <el-button style="font-weight: bold" size="small" type="text" @click="downLoadByKP">下载厂家索赔单开票明细模板</el-button>
      </div>
      <el-card class="box-card">
        <div>
          <el-upload
            ref="upload"
            class="upload-demo"
            accept=".xls"
            name="file"
            :action="updateAction"
            :on-success="handleSuccess"
            :on-remove="handleRemove"
            :file-list="fileList"
            :auto-upload="false"
            :multiple="false"
            :limit="1"
            :data="uploadData"
            :headers="headers"
          >
            <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
            <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传</el-button>
          </el-upload>
        </div>
        <div>
          <h3>文件上传结果</h3>
          <el-card class="box-card">
            <div>{{ uploadResultMesssage }}</div>
          </el-card>
        </div>
      </el-card>
      <div slot="footer" class="dialog-footer" style="text-align: center">
        <el-button type="primary" size="small" @click="handleConfirmByKP">确定</el-button>
        <el-button size="small" @click="dialogVisibleByKP = false">取消</el-button>
      </div>
    </el-dialog>
    <!-- 调增当月收入项目导入 -->
    <el-dialog :visible.sync="dialogVisibleByTZ" width="70%" :show-close="false">
      <div>
        <el-button style="font-weight: bold" size="small" type="text" @click="downLoadByTZ">下载调增当月收入项目模板</el-button>
      </div>
      <el-card class="box-card">
        <div>
          <el-upload
            ref="upload"
            class="upload-demo"
            accept=".xls"
            name="file"
            :action="updateAction"
            :on-success="handleSuccess"
            :on-remove="handleRemove"
            :file-list="fileList"
            :auto-upload="false"
            :multiple="false"
            :limit="1"
            :data="uploadData"
            :headers="headers"
          >
            <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
            <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传</el-button>
          </el-upload>
        </div>
        <div>
          <h3>文件上传结果</h3>
          <el-card class="box-card">
            <div>{{ uploadResultMesssage }}</div>
          </el-card>
        </div>
      </el-card>
      <div slot="footer" class="dialog-footer" style="text-align: center">
        <el-button type="primary" size="small" @click="handleConfirmByTZ">确定</el-button>
        <el-button size="small" @click="dialogVisibleByTZ = false">取消</el-button>
      </div>
    </el-dialog>
    <!-- 调减当月收入项目导入 -->
    <el-dialog :visible.sync="dialogVisibleByTJ" width="70%" :show-close="false">
      <div>
        <el-button style="font-weight: bold" size="small" type="text" @click="downLoadByTJ">下载调减当月收入项目模板</el-button>
      </div>
      <el-card class="box-card">
        <div>
          <el-upload
            ref="upload"
            class="upload-demo"
            accept=".xls"
            name="file"
            :action="updateAction"
            :on-success="handleSuccess"
            :on-remove="handleRemove"
            :file-list="fileList"
            :auto-upload="false"
            :multiple="false"
            :limit="1"
            :data="uploadData"
            :headers="headers"
          >
            <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
            <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传</el-button>
          </el-upload>
        </div>
        <div>
          <h3>文件上传结果</h3>
          <el-card class="box-card">
            <div>{{ uploadResultMesssage }}</div>
          </el-card>
        </div>
      </el-card>
      <div slot="footer" class="dialog-footer" style="text-align: center">
        <el-button type="primary" size="small" @click="handleConfirmByTJ">确定</el-button>
        <el-button size="small" @click="dialogVisibleByTJ = false">取消</el-button>
      </div>
    </el-dialog>
    <!-- 附件上传 -->
    <el-dialog center :visible.sync="accessoryVisible" :show-close="false">
      <el-form class="formadd" :model="accessory">
        <el-row style="border-top: 1px solid #E0E3EB">
          <el-col :span="24">
            <el-form-item>
              <uploadImg ref="uploadImg" v-model="accessory.images" :limit="50" bucket="map" :upload-data="{ type: '0001' }"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" size="small" @click="handleFileConfirm">确定</el-button>
        <el-button size="small" @click="handleColse">取消</el-button>
      </span>
    </el-dialog>
    <!-- 查看 -->
    <el-dialog :visible.sync="dialogFileVisible">
      <el-image style="width: 150px; height: 150px" v-for="(item, index) in list" :key="index" :src="item" :preview-src-list="list"/>
    </el-dialog>
  </div>
</template>

<script>
import req from '@/api/operation/claimbilling'
import uploadImg from '@/components/uploadFile/uploadImg'
import { choiceSupplierInfo, fetchDetailsByUseOrgSid, getOrgSidByPath } from '@/api/Common/dictcommons'

export default {
  name: 'ClaimBillingAdd',
  components: {
    uploadImg
  },
  data() {
    return {
      viewTitle: '',
      viewState: 1,
      submitdisabled: false,
      tableKey: 1,
      bkxmKey: 2,
      kkxmKey: 3,
      index: 0,
      supplier_list: [],
      purchase_list: [],
      accessoryVisible: false,
      accessory: {
        index: '',
        images: [],
        type: ''
      },
      dialogFileVisible: false,
      list: [],
      formobj: {
        billNo: '',
        createByName: '',
        createBySid: '',
        deptName: '',
        deptSid: '',
        createOrgSid: '',
        createTime: '',
        purchaseSystemName: '',
        purchaseSystemSid: '',
        detailList: [],
        fileList: [],
        invoiceKey: '',
        invoiceMoney: '',
        invoiceName: '',
        invoiceSid: '',
        invoiceValue: '',
        nodeState: '',
        procDefId: '',
        procInstId: '',
        remarks: '',
        sid: '',
        taskDefKey: '',
        taskId: '',
        useOrgName: '',
        useOrgSid: '',
        supplementaryItems: [],
        deductionItems: []
      },
      rules: {},
      dialogVisibleByKP: false, // 索赔单开票明细导入弹框
      dialogVisibleByTZ: false, // 调增当月收入项目导入弹框
      dialogVisibleByTJ: false, // 调减当月收入项目导入弹框
      updateAction: '',
      fileList: [],
      upload_list: [],
      uploadResultMesssage: '',
      uploadData: {
        sid: ''
      },
      headers: {
        token: window.sessionStorage.getItem('token')
      }
    }
  },
  computed: {
    kpjeTtotal() {
      let kpje = '0'
      if (this.formobj.detailList.length > 0) {
        this.formobj.detailList.forEach((e) => {
          kpje = Math.round((parseFloat(kpje) + parseFloat(e.claimHourAmount) + parseFloat(e.claimGoodsAmount) + parseFloat(e.claimOutAmount) + parseFloat(e.claimSubsidyAmount) + parseFloat(e.claimRescueAmount) + parseFloat(e.claimOtherAmount)) * 100) / 100
        })
      }
      return kpje
    }
  },
  methods: {
    init() {
      getOrgSidByPath({ orgPath: window.sessionStorage.getItem('defaultOrgPath') }).then((res) => {
        if (res.success) {
          this.formobj.createOrgSid = res.data
          this.formobj.useOrgSid = res.data
          fetchDetailsByUseOrgSid(this.formobj.useOrgSid).then((resp) => {
            if (resp.success) {
              this.purchase_list = resp.data
            }
          })
        }
      })
      choiceSupplierInfo({ deptSid: window.sessionStorage.getItem('defaultOrgPath').substring(window.sessionStorage.getItem('defaultOrgPath').lastIndexOf('/') + 1) }).then((resp) => {
        if (resp.success) {
          this.supplier_list = resp.data
        }
      })
    },
    showAdd() {
      this.viewTitle = '【新增】索赔单开票申请'
      this.$nextTick(() => {
        this.$refs['form_obj'].clearValidate()
      })
      this.init()
      req.init({ deptSid: window.sessionStorage.getItem('defaultOrgPath').substring(window.sessionStorage.getItem('defaultOrgPath').lastIndexOf('/') + 1) }).then((res) => {
        if (res.success && res.data !== null) {
          this.formobj.invoiceName = res.data.invoiceName
          this.formobj.invoiceSid = res.data.invoiceSid
          this.formobj.invoiceValue = res.data.invoiceValue
          this.formobj.invoiceKey = res.data.invoiceKey
        }
      })
      this.formobj.createByName = window.sessionStorage.getItem('name')
      this.formobj.createBySid = window.sessionStorage.getItem('userSid')
      this.formobj.deptName = window.sessionStorage.getItem('defaultOrgPathName').substring(window.sessionStorage.getItem('defaultOrgPathName').lastIndexOf('/') + 1)
      this.formobj.deptSid = window.sessionStorage.getItem('defaultOrgPath').substring(window.sessionStorage.getItem('defaultOrgPath').lastIndexOf('/') + 1)
      var nowDate = new Date()
      var date = {
        year: nowDate.getFullYear(),
        month: nowDate.getMonth() + 1,
        day: nowDate.getDate()
      }
      this.formobj.createTime = date.year + '-' + (date.month >= 10 ? date.month : '0' + date.month) + '-' + (date.day >= 10 ? date.day : '0' + date.day)
    },
    showEdit(row) {
      this.viewTitle = '【编辑】索赔单开票申请'
      this.$nextTick(() => {
        this.$refs['form_obj'].clearValidate()
      })
      this.init()
      req.fetchDetailsBySid({ sid: row.sid }).then((res) => {
        if (res.success) {
          this.formobj = res.data
          this.formobj.instanceId = res.data.procInstId
        }
      })
    },
    changePurchase(value) {
      const choose = this.purchase_list.filter((item) => item.purchaseSystemName === value)
      if (choose.length > 0 && choose !== null) {
        this.formobj.purchaseSystemSid = choose[0].deptSid
      } else {
        this.formobj.purchaseSystemSid = ''
      }
    },
    supplierChange(value) {
      const choose = this.supplier_list.filter((item) => item.sid === value)
      if (choose !== null && choose.length > 0) {
        this.formobj.invoiceName = choose[0].billingCompanyName
        this.formobj.invoiceValue = choose[0].billingTypeValue
        this.formobj.invoiceKey = choose[0].billingTypeKey
      } else {
        this.formobj.invoiceName = ''
        this.formobj.invoiceValue = ''
        this.formobj.invoiceKey = ''
      }
    },
    exportByKp() {
      this.dialogVisibleByKP = true
      this.updateAction = process.env.VUE_APP_BASE_API + '/as/v1/AsBusclaimInvoiceBill/getExcelInfo'
      this.fileList = []
      this.upload_list = []
      this.uploadResultMesssage = ''
    },
    downLoadByKP() {
      const loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
      req.downloadExcel().then((resp) => {
        loading.close()
        const blob = new Blob([resp], {
          type: 'application/vnd.ms-excel'
        })
        const fileName = '厂家索赔单开票明细模板' + '.xls'
        const elink = document.createElement('a')
        elink.download = fileName
        elink.style.display = 'none'
        elink.href = URL.createObjectURL(blob)
        document.body.appendChild(elink)
        elink.click()
        URL.revokeObjectURL(elink.href)
        document.body.removeChild(elink)
      }).catch(() => {
        loading.close()
      })
    },
    exportByTZ() {
      this.dialogVisibleByTZ = true
      this.updateAction = process.env.VUE_APP_BASE_API + '/as/v1/AsBusclaimInvoiceBill/getExcelInfoBK'
      this.fileList = []
      this.upload_list = []
      this.uploadResultMesssage = ''
    },
    downLoadByTZ() {
      const loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
      req.downloadExcelBK().then((resp) => {
        loading.close()
        const blob = new Blob([resp], {
          type: 'application/vnd.ms-excel'
        })
        const fileName = '调增当月收入项目模板' + '.xls'
        const elink = document.createElement('a')
        elink.download = fileName
        elink.style.display = 'none'
        elink.href = URL.createObjectURL(blob)
        document.body.appendChild(elink)
        elink.click()
        URL.revokeObjectURL(elink.href)
        document.body.removeChild(elink)
      }).catch(() => {
        loading.close()
      })
    },
    exportByTJ() {
      this.dialogVisibleByTJ = true
      this.updateAction = process.env.VUE_APP_BASE_API + '/as/v1/AsBusclaimInvoiceBill/getExcelInfoKK'
      this.fileList = []
      this.upload_list = []
      this.uploadResultMesssage = ''
    },
    downLoadByTJ() {
      const loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
      req.downloadExcelKK().then((resp) => {
        loading.close()
        const blob = new Blob([resp], {
          type: 'application/vnd.ms-excel'
        })
        const fileName = '调减当月收入项目模板' + '.xls'
        const elink = document.createElement('a')
        elink.download = fileName
        elink.style.display = 'none'
        elink.href = URL.createObjectURL(blob)
        document.body.appendChild(elink)
        elink.click()
        URL.revokeObjectURL(elink.href)
        document.body.removeChild(elink)
      }).catch(() => {
        loading.close()
      })
    },
    handleRemove() {
      this.uploadResultMesssage = ''
    },
    submitUpload() {
      this.$refs.upload.submit()
    },
    handleSuccess(resp, file, fileList) {
      const _this = this
      if (resp.success) {
        _this.uploadResultMesssage = resp.msg
        // 上传文件数据成功后立即保存数据
        if (resp.data.length > 0 && resp.data !== null) {
          this.upload_list = resp.data
        }
      } else {
        _this.uploadResultMesssage = resp.msg
      }
    },
    handleConfirmByKP() {
      if (this.upload_list.length === 0) {
        this.$message({ showClose: true, type: 'error', message: '请先上传厂家索赔单开票明细' })
        return
      } else {
        this.formobj.detailList = []
        this.upload_list.forEach((e) => {
          this.formobj.detailList.push({
            claimBillNo: e.claimBillNo,
            repairBillNo: e.billNo,
            vehMark: e.vehMark,
            vinNo: e.vinNo,
            claimManufacturer: e.claimManufacturer,
            claimHourAmount: e.claimHourAmount,
            claimGoodsAmount: e.claimGoodsAmount,
            claimOutAmount: e.claimOutAmount,
            claimSubsidyAmount: e.claimSubsidyAmount,
            claimRescueAmount: e.claimRescueAmount,
            claimOtherAmount: e.claimOtherAmount,
            totalAmount: e.totalAmount,
            remarks: '',
            isUnanimous: e.isUnanimous
          })
        })
        this.dialogVisibleByKP = false
      }
    },
    handleConfirmByTZ() {
      if (this.upload_list.length === 0) {
        this.$message({ showClose: true, type: 'error', message: '请先上传调增当月收入项目' })
        return
      } else {
        this.formobj.supplementaryItems = []
        this.upload_list.forEach((e) => {
          this.formobj.supplementaryItems.push({
            sid: '',
            billSid: '',
            projectName: e.projectName,
            amount: e.amount,
            remarks: e.remarks,
            type: '1',
            supplementaryFiles: []
          })
        })
        this.dialogVisibleByTZ = false
      }
    },
    handleConfirmByTJ() {
      if (this.upload_list.length === 0) {
        this.$message({ showClose: true, type: 'error', message: '请先上传调减当月收入项目' })
        return
      } else {
        this.formobj.deductionItems = []
        this.upload_list.forEach((e) => {
          this.formobj.deductionItems.push({
            sid: '',
            billSid: '',
            projectName: e.projectName,
            amount: e.amount,
            remarks: e.remarks,
            type: '2',
            deductionFiles: []
          })
        })
        this.dialogVisibleByTJ = false
      }
    },
    cellStyle({ row, column, rowIndex, columnIndex }) {
      // 定义样式变量
      let cell = ''
      if (!row.isUnanimous) {
        cell = 'color: #ff6961;'
        return cell
      }
    },
    // 附件上传
    handleUpload(row, index, type) {
      this.accessoryVisible = true
      this.accessory.index = index
      this.accessory.type = type
      if (type === 'tzdysr') {
        // 调增当月收入项目列表--点击上传
        this.accessory.images = row.supplementaryFiles
      } else {
        // 调减当月收入项目列表--点击上传
        this.accessory.images = row.deductionFiles
      }
    },
    // 附件查看
    handleLook(row) {
      this.dialogFileVisible = true
      const aa = []
      if (row.length > 0) {
        row.forEach((e) => {
          aa.push(e.url)
        })
        this.list = aa
      }
    },
    // 附件上传--确定
    handleFileConfirm() {
      if (this.accessory.type === 'tzdysr') {
        // 调增当月收入项目列表 -- 附件信息
        this.formobj.supplementaryItems[this.accessory.index].supplementaryFiles = this.accessory.images
      } else {
        // 调减当月收入项目列表 -- 附件信息
        this.formobj.deductionItems[this.accessory.index].deductionFiles = this.accessory.images
      }
      this.handleColse()
    },
    // 附件上传--取消
    handleColse() {
      this.accessoryVisible = false
      this.accessory = {
        index: '',
        images: [],
        type: ''
      }
    },
    saveOrUpdate() {
      this.$refs['form_obj'].validate((valid) => {
        if (valid) {
          this.submitdisabled = true
          this.formobj.invoiceMoney = this.kpjeTtotal
          req.saveOrUpdate(this.formobj).then((res) => {
            if (res.success) {
              this.$message({ showClose: true, type: 'success', message: '保存成功' })
              this.handleReturn('true')
            } else {
              this.submitdisabled = false
            }
          }).catch(() => {
            this.submitdisabled = false
          })
        }
      })
    },
    submit() {
      this.$refs['form_obj'].validate((valid) => {
        if (valid) {
          this.submitdisabled = true
          this.formobj.invoiceMoney = this.kpjeTtotal
          req.submit(this.formobj).then((res) => {
            if (res.success) {
              this.$message({ showClose: true, type: 'success', message: '提交成功' })
              this.handleReturn('true')
            } else {
              this.submitdisabled = false
            }
          }).catch(() => {
            this.submitdisabled = false
          })
        }
      })
    },
    // 合计
    getSummaries(param) {
      const { columns, data } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = ''
          return
        }
        const values = data.map(item => Number(item[column.property]))
        if (column.property === 'totalAmount' || column.property === 'amount') {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr)
            if (!isNaN(value)) {
              return Math.round((parseFloat(prev) + parseFloat(curr)) * 100) / 100
            } else {
              return Math.round((parseFloat(prev)) * 100) / 100
            }
          }, 0)
          sums[index] += ''
        }
      })
      return sums
    },
    handleReturn(isreload) {
      if (isreload === 'true') this.$emit('reloadlist')
      this.formobj = {
        billNo: '',
        createByName: '',
        createBySid: '',
        deptName: '',
        deptSid: '',
        createOrgSid: '',
        createTime: '',
        purchaseSystemName: '',
        purchaseSystemSid: '',
        detailList: [],
        fileList: [],
        invoiceKey: '',
        invoiceMoney: '',
        invoiceName: '',
        invoiceSid: '',
        invoiceValue: '',
        nodeState: '',
        procDefId: '',
        procInstId: '',
        remarks: '',
        sid: '',
        taskDefKey: '',
        taskId: '',
        useOrgName: '',
        useOrgSid: '',
        supplementaryItems: [],
        deductionItems: []
      }
      this.submitdisabled = false
      this.$refs['form_obj'].resetFields()
      this.$emit('doback')
    }
  }
}
</script>

<style scoped>
.span-sty {
  width: 130px !important;
}
.addinputInfo {
  margin-left: 120px !important;
}
/deep/ .el-form-item__error {
  margin-left: 120px !important;
}
.titleOne {
  font-weight: bold;
  font-size: 16px;
  background-color: #0294d7;
  color: #ffffff;
  text-align: left;
}
</style>
