<template>
  <dialog-edit
    :visible.sync="dialogVisible"
    :title="$t('chargeback.check_confirmation_payment')"
    editModel="V"
    :form="form"
    :api="api"
  >
    <data-table
      :api="api"
      :headTitle="$t('chargeback.check_confirmation_payment_title')"
      operateBtnLayout
      :sourceData.sync="sourceData"
      :columns="columns"
      :loadCount.sync="loadCount"
      :showPage="false"
      :queryParas="queryParas"
      :showSelection="true"
      :selectedRows.sync="selectedRows"
    >
      <template slot="headButton">
        <auth-button
          style="float: right;margin: 8px 0px;"
          size="small"
          type="primary"
          :label="$t('common.del')"
          @click="delitems"
          :menuCode="menuId"
          perms="del"
        ></auth-button>
      </template>
    </data-table>
  </dialog-edit>
</template>

<script>
import BaseEditPage from '@/pages/baseEditPage'
import chargebackApi from '@/api/chargeback'
import {
  DialogEdit,
  dymForm,
  DataTable,
  authButton
} from 'newepoch-components'
export default {
  extends: new BaseEditPage(''),
  components: {
    DialogEdit,
    dymForm,
    DataTable,
    authButton
  },
  data () {
    return {
      queryParas: {},
      sourceData: [],
      selectedRows: [],
      columns: [
        {
          // 付款确认书编号
          prop: 'assetCode',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].chargeback.pay_code
        },
        {
          // 区域编号
          prop: 'regionCode',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].chargeback.area_number
        },
        {
          // 项目公司名称
          prop: 'projectName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].chargeback.project_company
        },
        {
          // 供应商名称
          prop: 'creditor',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].chargeback.creditor
        },
        {
          // 合同名称
          prop: 'contractName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].chargeback.contract_name
        },
        {
          // 账款到期日
          prop: 'dueDate',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].chargeback
            .amountMaturity
        },
        {
          // 应收账款金额
          prop: 'factoringMoney',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].chargeback
            .account_receivable
        },
        {
          // 保理专员
          prop: 'factoringCommissioner',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].chargeback.factoring_commissioner
        },
        {
          // 区域专员
          prop: 'regionAttacheName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].chargeback.regional_commissioner
        },
        {
          // 业务人员
          prop: 'operational_personne',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].chargeback.operational_personne
        }
      ],
      loadCount: 0
    }
  },
  computed: {
    api () {
      return chargebackApi.pauseApi
    }
  },
  methods: {
    delitems () {
      if (!this.selectedRows.length) {
        return this.warning('请选择')
      }
      let $this = this
      $this.$confirm('确认删除？', '提示', {
        type: 'warning'
      }).then(() => {
        $this.api.del().then(() => {
          $this.warning('删除成功')
        }).catch(() => {
          $this.fail('删除失败')
        })
      }).catch()
    }
  },
  watch: {
    visible (val) {
      if (val) {
        console.log(this.form)
        const { selectedRows } = this.form
        this.sourceData = selectedRows
      } else {
        this.sourceData = []
      }
    }
  }
}
</script>
