发票信息
<template>
  <div>
    <el-form :model="invoiceForm" ref="invoiceForm" :rules="formRules">
      <data-table operateBtnLayout
                  :columns="columns"
                  :sourceData.sync="invoiceForm.tableData"
                  :showPage="false"
                  :showSelection="true"
                  :selectTable="selectTable"
                  @selectRowChange="selectRowChange"
                  v-bind="elHeightObj">
        <template slot="headButton">
          <label>{{$t('factoringBusinessInfo.invoice_number')}}</label>
          <el-input v-model="queryParas.invoiceNo" class="margin10" placeholder="请输入" :disabled="isDisabled"></el-input>
          <!-- 查询 -->
          <auth-button size="medium"
                      :icon="'el-icon-search'"
                      type="primary"
                      :label="$t('common.search')"
                      @click="search()"
                      :menuCode="menuId"
                      perms="completion_refund"
                      :disabled="isDisabled">
          </auth-button>
          <div class="head_button_right">
            <!-- 发票导入清单模板 -->
<!--            <btn-download :xhr="$xhr"-->
<!--                          size="small"-->
<!--                          type="primary"-->
<!--                          :fileID="fileID"-->
<!--                          :store="$store"-->
<!--                          icon="iconfont iconxiazai1"-->
<!--                          :classType="true"-->
<!--                          :downloadButtonMsg="$t('factoringBusinessInfo.invoice_template')"-->
<!--                          :menuCode="menuId"-->
<!--                          perms="invoice_template">-->
<!--            </btn-download>-->
            <auth-button size="medium" type="primary"
                         :label="$t('projectCompany.downloadmeun')"
                         :icon="'iconfont iconycxiazai'"
                         :loading="downloadFileByTemplateCodeLoading"
                         @click="downloadFileByTemplateCode"
                         :disabled="isDisabled"></auth-button>
            <!-- 保存 -->
            <auth-button size="medium"
                        type="primary"
                        :label="$t('common.save')"
                        @click="save()"
                         icon="iconfont iconbaocun11"
                        :menuCode="menuId"
                        perms="completion_refund"
                        :disabled="isDisabled">
            </auth-button>

            <!-- 发票校验 -->
            <auth-button size="medium"
                        type="primary"
                        :label="$t('factoringBusinessInfo.invoice_check')"
                        @click="checkBatch"
                         icon="iconfont iconxiaoyan"
                        :menuCode="menuId"
                        perms="completion_refund"
                        :disabled="isDisabled">
            </auth-button>

            <!-- 导入清单 -->
            <btn-import btnSize="small"
                        :btnDisplay="true"
                        :menuCode="menuId"
                        perms="import_refunds"
                        :uploadName="$t('factoringBusinessInfo.import_list')"
                        :uploadApi="uploadApi"
                        @importSuccess="importSuccess"
                        type="primary"
                        class="margin_left10"
                        :importAttrs="btnAttrs"
                        :btnAttrs="btnAttrs">
            </btn-import>

            <!-- 新增 -->
            <auth-button size="medium"
                        type="primary"
                        :label="$t('common.create')"
                        @click="create()"
                         icon="iconfont iconxinzeng"
                        :menuCode="menuId"
                        perms="completion_refund"
                        class="margin_left10"
                        :disabled="isDisabled">
            </auth-button>

            <!-- 删除 -->
            <auth-button size="medium"
                        type="danger"
                        :label="$t('common.del')"
                        @click="del()"
                        :menuCode="menuId"
                         icon="iconfont iconshanchu"
                        perms="completion_refund"
                        :disabled="isDisabled">
            </auth-button>
          </div>
        </template>

        <!-- 发票号码 -->
        <template slot="invoiceNumber" slot-scope="scope">
          <el-form-item  v-if="scope.data.row.editFlag === true" :prop="'tableData.' + scope.data.$index + '.invoiceNo'" :rules="formRules.invoiceNo">
            <el-input v-model="scope.data.row.invoiceNo" @input="invoiceInput(scope.data.row)" maxlength="8"></el-input>
          </el-form-item>
          <span v-else>{{scope.data.row.invoiceNo}}</span>
        </template>

        <!-- 开票日期 -->
        <template slot="openDate" slot-scope="scope">
          <el-form-item  v-if="scope.data.row.editFlag === true" :prop="'tableData.' + scope.data.$index + '.openDate'" :rules="formRules.openDate">
            <el-date-picker v-model="scope.data.row.openDate" style="width: 135px"></el-date-picker>
          </el-form-item>
          <span v-else>{{scope.data.row.openDate | formatDateNull}}</span>
        </template>

        <!-- 发票金额 -->
        <template slot="invoiceAmount" slot-scope="scope">
          <el-form-item  v-if="scope.data.row.editFlag === true" :prop="'tableData.' + scope.data.$index + '.invoiceAmount'" :rules="formRules.invoiceAmount">
            <el-input v-model="scope.data.row.invoiceAmount"></el-input>
          </el-form-item>
          <span v-else>{{scope.data.row.invoiceAmount | thousandFilter}}</span>
        </template>

        <!-- 可抵扣金额 -->
        <template slot="availableAmount" slot-scope="scope">
          <el-form-item  v-if="scope.data.row.editFlag === true" :prop="'tableData.' + scope.data.$index + '.availableAmount'"
                         :rules="[{ validator: availableAmountCheck, trigger: 'blur', row: scope.data.row, index: scope.data.$index }]">
            <el-input v-model="scope.data.row.availableAmount"></el-input>
          </el-form-item>
          <span v-else>{{scope.data.row.availableAmount | thousandFilter}}</span>
        </template>

        <!-- 抵扣金额 -->
        <template slot="deduction_amount" slot-scope="scope">
          <el-form-item  v-if="scope.data.row.editFlag === true" :prop="'tableData.' + scope.data.$index + '.assetInvoiceRelDTO' + '.usedAmount'"
                         :rules="[{ validator: usedAmountCheck, trigger: 'blur', row: scope.data.row }]">
            <el-input v-model="scope.data.row.assetInvoiceRelDTO.usedAmount"></el-input>
          </el-form-item>
          <span v-else>{{scope.data.row.assetInvoiceRelDTO.usedAmount | thousandFilter}}</span>
        </template>

        <!-- 发票代码 -->
        <template slot="invoiceCode" slot-scope="scope">
          <el-form-item  v-if="scope.data.row.editFlag === true" :prop="'tableData.' + scope.data.$index + '.invoiceCode'" :rules="formRules.invoiceCode">
            <el-input v-model="scope.data.row.invoiceCode"></el-input>
          </el-form-item>
          <span v-else>{{scope.data.row.invoiceCode}}</span>
        </template>

        <!-- 不含税金额 -->
        <template slot="taxFreeAmount" slot-scope="scope">
          <el-form-item  v-if="scope.data.row.editFlag === true" :prop="'tableData.' + scope.data.$index + '.taxExcludingAmount'"
                         :rules="[{ required: (dataObj.assetPaymentPoolOperDTO.entryFlag ? dataObj.assetPaymentPoolOperDTO.sendBpoFlag ? [6, 7].includes(dataObj.assetPaymentPoolOperDTO.bpoStatus) : true : false) ? UtilJs.isEmpty(scope.data.row.verificationCode) : false, trigger: 'blur', message: $t('common.input') + $t('factoringBusinessInfo.no_tax_amount') },
                         { validator: yuanValidate, trigger: 'blur' }]">
            <el-input v-model="scope.data.row.taxExcludingAmount"></el-input>
          </el-form-item>
          <span v-else>{{scope.data.row.taxExcludingAmount | thousandFilter}}</span>
        </template>

        <!-- 校验码 -->
        <template slot="verificationCode" slot-scope="scope">
          <el-form-item  v-if="scope.data.row.editFlag === true" :prop="'tableData.' + scope.data.$index + '.verificationCode'"
                         :rules="[{ required: (dataObj.assetPaymentPoolOperDTO.entryFlag ? dataObj.assetPaymentPoolOperDTO.sendBpoFlag ? [6, 7].includes(dataObj.assetPaymentPoolOperDTO.bpoStatus) : true : false) ? UtilJs.isEmpty(scope.data.row.taxExcludingAmount) : false, trigger: 'blur', message: $t('common.input') + $t('factoringBusinessInfo.check_code') },
                         { validator: yuanValidate, trigger: 'blur' }]">
            <el-input v-model="scope.data.row.verificationCode"></el-input>
          </el-form-item>
          <span v-else>{{scope.data.row.verificationCode}}</span>
        </template>

        <!-- 操作 -->
        <el-table-column :label="$t('common.operate')" align="center" fixed="right" width="200px">
          <template slot-scope="scope">
            <!-- 发票校验 -->
            <auth-button size="small"
                         class="iconCircle"
                        @click="check(scope.row)"
                         :title="$t('factoringBusinessInfo.invoice_check')"
                         icon="iconfont iconxiaoyan1"
                        :menuCode="menuId"
                        perms="completion_refund"
                        :disabled="isDisabled">
            </auth-button>

            <!-- 编辑 -->
            <auth-button size="small"
                         class="iconCircle"
                        @click="edit(scope.row)"
                         :title="$t('common.edit')"
                         icon="iconfont iconbianji"
                        :menuCode="menuId"
                        perms="completion_refund"
                        :disabled="isDisabled">
            </auth-button>
          </template>
        </el-table-column>

        <template slot="paginationLeft">
          <el-row :gutter="10">
            <!-- 发票金额合计 -->
            <el-col :span="6">
              <el-form-item :label="$t('factoringBusinessInfo.invoice_amount_total')">
                <el-input v-model="amountTotal" :disabled="true" style="width: 200px"></el-input>
              </el-form-item>
            </el-col>
            <!-- 发票可抵扣金额 -->
            <el-col :span="6">
              <el-form-item :label="$t('factoringBusinessInfo.invoice_can_deduction_amount')">
                <el-input v-model="deductionAmount" :disabled="true" style="width: 200px"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </template>
      </data-table>
    </el-form>
  </div>
</template>
<script>
import { DataTable, authButton, btnDownload, btnImport, validate } from 'newepoch-components'
import { formatDateNull, formatDict, thousandFilter } from '@/filters/index'
import mixin from '@/pages/mixin'
import { IMPORT_API } from '@/constant'
import factoringBusinessInfoApi from '@/api/factoringBusinessInfoApi'
import { regExp } from '@/validator/index'
import fileApi from '@/api/fileApi'
import { downFile } from '@/utils/devUtils'
const bpoStatusArr = [6, 7]
export default {
  mixins: [mixin],
  components: {
    DataTable,
    authButton,
    btnDownload,
    btnImport
  },
  props: {
    sourceData: {
      type: Array,
      default () {
        return []
      }
    },
    assetInfoId: {
      type: String,
      default () {
        return ''
      }
    },
    initFlag: {
      type: Boolean,
      default () {
        return false
      }
    },
    isDisabled: {
      type: Boolean
    },
    dataObj: {
      type: Object,
      default: () => {}
    },
    payConfirmObj: {
      type: Object,
      default: () => {}
    }
  },
  computed: {
    amountTotal () {
      let total = 0
      this.sourceData.forEach(item => {
        if (!this.UtilJs.isEmpty(item.invoiceAmount)) {
          total += +item.invoiceAmount
        }
      })
      return thousandFilter(total)
    },
    deductionAmount () {
      let total = 0
      this.sourceData.forEach(item => {
        if (!this.UtilJs.isEmpty(item.availableAmount)) {
          total += +item.availableAmount
        }
      })
      return thousandFilter(total)
    },
    fileID () {
      return formatDict('invoice', 'L0008')
    },
    btnAttrs () {
      return {
        disabled: this.isDisabled
      }
    }
  },
  data () {
    const { common, factoringBusinessInfo } = this.$i18n.messages[this.$i18n.locale]
    return {
      downloadFileByTemplateCodeLoading: false,
      selectedRows: [],
      indexFlag: 0,
      menuId: '',
      uploadApi: IMPORT_API,
      queryParas: {
        invoiceNo: ''
      },
      invoiceForm: {
        tableData: []
      },
      form: {
        invoice_amount_total: '',
        invoice_can_deduction_amount: ''
      },
      columns: [
        // 发票号码
        {
          prop: 'invoiceNumber',
          align: 'right',
          width: '150px',
          label: factoringBusinessInfo.invoice_number,
          slot: true
        },
        // 开票日期
        {
          prop: 'openDate',
          align: 'center',
          width: '165px',
          label: factoringBusinessInfo.invoice_date,
          slot: true
        },
        // 发票金额
        {
          prop: 'invoiceAmount',
          align: 'right',
          width: '200px',
          label: factoringBusinessInfo.invoice_amount,
          slot: true
        },
        // 可抵扣金额
        {
          prop: 'availableAmount',
          align: 'right',
          width: '180px',
          label: factoringBusinessInfo.can_deduction_amount,
          slot: true
        },
        // 抵扣金额
        {
          prop: 'deduction_amount',
          align: 'right',
          width: '180px',
          label: factoringBusinessInfo.deduction_amount,
          slot: true
        },
        // 发票代码
        {
          prop: 'invoiceCode',
          align: 'left',
          width: '150px',
          label: factoringBusinessInfo.invoice_code,
          slot: true
        },
        // 不含税金额
        {
          prop: 'taxFreeAmount',
          align: 'right',
          width: '150px',
          label: factoringBusinessInfo.no_tax_amount,
          slot: true
        },
        // 校验码
        {
          prop: 'verificationCode',
          align: 'center',
          width: '150px',
          label: factoringBusinessInfo.check_code,
          slot: true
        },
        // 发票查验结果
        {
          prop: 'lastCheckResult',
          align: 'center',
          width: '150px',
          label: factoringBusinessInfo.invoices_check_result,
          format: (row) => {
            if (!this.UtilJs.isEmpty(row.state) && +row.state === 1) {
              return row.lastCheckResult
            } else if (+row.state === 2 || +row.state === 3) {
              return '发票已' + formatDict(row.state, 'SCRS0105')
            } else {
              return '-'
            }
          }
        },
        // 备注
        {
          prop: 'remark',
          align: 'center',
          width: '150px',
          label: factoringBusinessInfo.memo,
          format: row => row.remark === '' ? '—' : row.remark
        }
      ],
      formRules: {
        // 发票号码 1
        invoiceNo: [ { required: true, trigger: 'blur', message: common.input + factoringBusinessInfo.invoice_number }, { validator: validate.invoiceNumValidate, trigger: 'blur' } ],
        // 开票日期 1
        openDate: [ { required: this.dataObj.assetPaymentPoolOperDTO.entryFlag ? this.dataObj.assetPaymentPoolOperDTO.sendBpoFlag ? bpoStatusArr.includes(this.dataObj.assetPaymentPoolOperDTO.bpoStatus) : true : false,
          trigger: 'change',
          message: common.point + factoringBusinessInfo.invoice_date } ],
        // 发票金额 1
        invoiceAmount: [ { required: this.dataObj.assetPaymentPoolOperDTO.entryFlag ? this.dataObj.assetPaymentPoolOperDTO.sendBpoFlag ? bpoStatusArr.includes(this.dataObj.assetPaymentPoolOperDTO.bpoStatus) : true : false,
          trigger: 'blur',
          message: common.input + factoringBusinessInfo.invoice_amount }, { validator: validate.yuanValidate, trigger: 'blur' } ],
        // 发票代码 1
        invoiceCode: [ { required: this.dataObj.assetPaymentPoolOperDTO.entryFlag ? this.dataObj.assetPaymentPoolOperDTO.sendBpoFlag ? bpoStatusArr.includes(this.dataObj.assetPaymentPoolOperDTO.bpoStatus) : true : false,
          trigger: 'blur',
          message: common.input + factoringBusinessInfo.invoice_code }, { validator: validate.invoiceCodeValidate, trigger: 'blur' } ],
        // 票据名称
        invoiceName: [ { required: true, trigger: 'blur', message: common.input + factoringBusinessInfo.invoice_name } ],
        // 可抵扣金额
        availableAmount: [ { required: true, trigger: 'blur', message: common.input + factoringBusinessInfo.can_deduction_amount }, { validator: this.availableAmountCheck, trigger: 'blur' } ],
        // 抵扣金额
        usedAmount: [ { required: true, trigger: 'blur', message: common.input + factoringBusinessInfo.deduction_amount }, { validator: this.numberCheck, trigger: 'blur' } ]
      },
      yuanValidate: validate.yuanValidate
    }
  },
  mounted () {
    this.loadTableData()
  },
  methods: {
    invoiceInput (row) {
      console.log(this.formRules.invoiceAmount[0].required)
      if (regExp.contactNum.test(row.invoiceNo)) {
        let params = {
          creditorId: this.dataObj.assetPaymentInfoDTO.creditorId,
          invoiceNo: row.invoiceNo,
          assetInfoId: this.assetInfoId
        }
        factoringBusinessInfoApi.assetApi.getInvoice(params).then(res => {
          if (res && res.data) {
            if (!this.UtilJs.isEmpty(res.data)) {
              row.maxAvailableAmount = res.data.availableAmount
              Object.assign(row, res.data)
              row.assetInvoiceRelDTO.usedAmount = res.data.usedAmount
            } else {
              row.openDate = ''
              row.invoiceAmount = null
              row.assetInvoiceRelDTO.usedAmount = null
              row.availableAmount = null
              row.lastCheckResult = ''
              row.remark = ''
              row.maxAvailableAmount = ''
              row.invoiceCode = ''
              row.taxExcludingAmount = ''
              this.$set(row, 'state', '')
              row.verificationCode = ''
              if (row.keyId) {
                row.keyId = ''
              }
            }
            this.$refs['invoiceForm'].validate()
          }
        })
      }
    },
    availableAmountCheck (rule, value, callback) {
      if (!this.UtilJs.isEmpty(value) && !regExp.yuan.test(value)) {
        callback(new Error('请输入整数或两位小数'))
      } else {
        if (!this.UtilJs.isEmpty(rule.row.maxAvailableAmount) && rule.row.maxAvailableAmount !== 0 && +value > rule.row.maxAvailableAmount) {
          callback(new Error('可抵扣金额需不超过' + rule.row.maxAvailableAmount))
        } else {
          callback()
        }
      }
      this.$refs['invoiceForm'].validateField(`tableData.${rule.index}.assetInvoiceRelDTO.usedAmount`)
      // this.usedAmountCheck(rule, rule.row.assetInvoiceRelDTO.usedAmount, callback)
    },
    usedAmountCheck (rule, value, callback) {
      if (!this.UtilJs.isEmpty(value) && !regExp.yuan.test(value)) {
        callback(new Error('请输入整数或两位小数'))
      } else {
        if (+value > +rule.row.availableAmount) {
          callback(new Error('抵扣金额需不超过可抵扣金额'))
        } else {
          callback()
        }
      }
    },
    checkBatch () {
      if (this.selectedRows.length === 0) {
        this.warning('请选择要校验的发票')
        return
      }
      let arr = []
      this.selectedRows.forEach(it => {
        arr.push({
          invoiceCode: it.invoiceCode,
          invoiceDate: formatDateNull(it.openDate),
          invoiceNo: it.invoiceNo,
          taxFreeAmount: it.taxExcludingAmount,
          checkCode: it.verificationCode,
          creditor: this.dataObj.assetPaymentInfoDTO.creditor,
          debtor: this.dataObj.assetPaymentInfoDTO.debtor
        })
      })
      factoringBusinessInfoApi.assetApi.checkInvoice(arr).then(res => {
        if (res && res.success && res.data) {
          res.data.forEach(it => {
            this.sourceData.forEach(item => {
              if (it.invoiceNo === item.invoiceNo) {
                item.state = it.state
                item.lastCheckResult = it.resultTip
                item.remark = it.remark
              }
            })
          })
          this.success('发票校验成功！')
          this.loadTableData()
        }
      })
    },
    downloadFileByTemplateCode () {
      this.downloadFileByTemplateCodeLoading = true
      fileApi.file.downloadFileByTemplateCode({ templateCode: 'invoice' }).then(res => {
        downFile(res)
      }).finally(res => {
        this.downloadFileByTemplateCodeLoading = false
      })
    },
    formatDateNull (val) {
      formatDateNull(val)
    },
    // 查询
    search () {
      this.loadTableData(1)
    },
    validateInvoice () {
      let usedAmountTotal = 0
      this.sourceData.forEach(it => {
        usedAmountTotal = usedAmountTotal + +it.assetInvoiceRelDTO.usedAmount
      })
      if (usedAmountTotal !== +this.payConfirmObj.factoringMoney) {
        this.warning('发票的抵扣金额之和应等于应收账款金额！')
        return
      }
      if (+this.payConfirmObj.factoringMoney > +this.deductionAmount) {
        this.warning('发票的应收账款金额大于发票剩余可用抵扣金额！')
        return
      }
      return true
    },
    // 保存
    save () {
      // todo验证发票是否合格
      this.$refs['invoiceForm'].validate(valid => {
        if (valid) {
          if (this.validateInvoice()) {
            let saveDto = {
              assetInfoId: this.dataObj.assetPaymentInfoDTO.keyId,
              assetInvoiceInfoDtos: this.sourceData,
              assetOperId: this.dataObj.assetPaymentPoolOperDTO.keyId,
              assetPoolId: this.dataObj.assetPaymentPoolDTO.keyId,
              projectId: this.payConfirmObj.projectId,
              specialPlanPeriods: this.payConfirmObj.specialPlanPeriods
            }
            factoringBusinessInfoApi.assetApi.saveInvoice(saveDto).then(res => {
              if (res && res.success) {
                this.success('发票信息保存成功！')
                // 保存成功时初始化表格
                this.sourceData.forEach(item => {
                  item.editFlag = false
                })
                this.sourceData = this.sourceData.sort(function (a, b) {
                  return a.invoiceNo + '' - b.invoiceNo + ''
                })
                this.queryParas.invoiceNo = ''
                this.loadTableData()
              }
            })
          }
        } else {
          this.error('表单有误，请检查')
        }
      })
    },
    // 发票校验
    check (val) {
      let arr = []
      arr.push({
        invoiceCode: val.invoiceCode,
        invoiceDate: formatDateNull(val.openDate),
        invoiceNo: val.invoiceNo,
        taxFreeAmount: val.taxExcludingAmount,
        checkCode: val.verificationCode,
        creditor: this.dataObj.assetPaymentInfoDTO.creditor,
        debtor: this.dataObj.assetPaymentInfoDTO.debtor
      })
      factoringBusinessInfoApi.assetApi.checkInvoice(arr).then(res => {
        if (res && res.success && res.data) {
          val.state = res.data[0].state
          val.lastCheckResult = res.data[0].resultTip
          val.remark = res.data[0].remark
          this.success('发票校验成功！')
        }
      })
    },
    // 导入清单成功回调
    importSuccess (data) {
      data.forEach((item, index) => {
        if (index) {
          let newObj = {
            invoiceNo: item[0],
            openDate: item[2],
            invoiceAmount: item[3],
            availableAmount: item[4],
            assetInvoiceRelDTO: {
              usedAmount: item[5],
              availableAmount: null,
              invoiceName: item[1],
              assetInfoId: this.assetInfoId
            },
            lastCheckResult: '',
            remark: '',
            maxAvailableAmount: null,
            invoiceCode: item[6],
            taxExcludingAmount: item[7],
            verificationCode: item[8],
            editFlag: true
          }
          this.sourceData.splice(0, 0, newObj)
        }
      })
      this.addIndex()
      // 新增时初始化表格
      this.queryParas.invoiceNo = ''
      this.loadTableData()
      this.$nextTick(() => {
        this.$refs['invoiceForm'].validate()
      })
    },
    // 新增
    create () {
      this.sourceData.splice(0, 0,
      // this.invoiceForm.tableData.splice(0, 0,
        {
          invoiceNo: '',
          openDate: '',
          invoiceAmount: null,
          assetInvoiceRelDTO: {
            usedAmount: null,
            invoiceName: '',
            availableAmount: null,
            assetInfoId: this.assetInfoId
          },
          availableAmount: null,
          lastCheckResult: '',
          remark: '',
          maxAvailableAmount: null,
          invoiceCode: '',
          taxExcludingAmount: '',
          verificationCode: '',
          editFlag: true
        }
      )
      this.addIndex()
      // 新增时初始化表格
      this.queryParas.invoiceNo = ''
      this.loadTableData()
    },
    // 删除
    del () {
      let $this = this
      if (this.selectedRows.length === 0) {
        $this.warning(`请先勾选要删除的数据!`)
        return
      }
      $this.$confirm('此操作会删除选中数据，是否继续？', '提示', {
        type: 'warning'
      }).then(() => {
        this.selectedRows.forEach(item => {
          this.sourceData.forEach((issue, index) => {
            if (issue.index === item.index) {
              this.sourceData.splice(index, 1)
            }
          })
        })
        this.loadTableData(1)
      }, () => {})
    },
    // 编辑
    edit (row) {
      this.$set(row, 'editFlag', true)
    },
    // 勾选框
    selectRowChange (selectedRows) {
      this.selectedRows = selectedRows
      if (!this.indexFlag) {
        // 添加index属性便于删除
        this.addIndex()
        this.indexFlag += 1
      }
    },
    addIndex () {
      this.sourceData.forEach((item, index) => {
        item.index = index
      })
    },
    loadTableData (type) {
      // 根据筛选条件筛选
      if (type) {
        this.invoiceForm.tableData = this.sourceData.filter(item => {
          return (item.invoiceNo + '').indexOf(this.queryParas.invoiceNo) > -1
        })
      } else {
        this.invoiceForm.tableData = this.sourceData
      }
      this.$refs['invoiceForm'].clearValidate()
    },
    // 发票号码校验
    numberCheck (rule, value, callback) {
      if (!regExp.number.test(value) && value !== '') {
        callback(new Error('请输入数字'))
      } else {
        callback()
      }
    },
    selectTable () {
      if (this.isDisabled === true) {
        return false
      } else if (this.isDisabled === false) {
        return true
      }
    }
  },
  watch: {
    initFlag (val) {
      if (val) {
        // this.componentList.forEach((item, index) => {
        //   this.roleAuthority.forEach(value => {
        //     if (value.columnCode === item.prop) {
        //       if (value.roleAuthority === 2) {
        //         this.$set(this.componentList[index], 'disabled', false)
        //       } else if (value.roleAuthority === 1) {
        //         this.$set(this.componentList[index], 'disabled', true)
        //       } else if (value.roleAuthority === 0) {
        //         this.$set(this.componentList[index], 'showFlag', false)
        //       }
        //     }
        //   })
        // })
        this.loadTableData()
      }
    }
  }
}
</script>
