<template>
  <div class="table-box">
    <div class="block-title">
      发票销售方列表
      <el-button
        type="primary"
        style="margin-right:10px"
        @click="$refs.modal.show(null,'add')"
      >
        新增
      </el-button>
    </div>
    <el-table
      ref="table"
      border
      stripe
      v-loading="loading"
      :data="tableData">
      <el-table-column
        prop="invoiceSellerName"
        label="销售方名称">
      </el-table-column>

      <el-table-column
        prop="invoiceSellerTaxpayerNum"
        label="纳税人识别号">
      </el-table-column>

      <el-table-column
        label="操作"
        width="160"
        fixed="right">
        <template slot-scope="scope">
          <el-button
            type="primary"
            size="small"
            @click="$refs.modal.show(scope.row,'edit')"
            style="margin-right:5px"
          >
            编辑
          </el-button>

          <el-popconfirm
            title="确定删除吗？"
            @confirm="confirm(scope.row.id)"
          >
            <el-button slot="reference">
              删除
            </el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>

    <Modal
      ref="modal"
      @update="getList"></Modal>
  </div>
</template>
<script>
import { getInvoiceSellerList, deleteInvoiceSeller } from '@/api/invoice'
import Modal from './Modal'

export default {
  components: {
    Modal
  },
  data () {
    return {
      loading: false,
      tableData: []
    }
  },
  created () {
    this.getList()
  },
  methods: {
    getList () {
      this.loading = true
      getInvoiceSellerList({}).then(res => {
        this.tableData = res?.data || []
      }).finally(() => {
        this.loading = false
      })
    },
    confirm (id) {
      deleteInvoiceSeller(id).then(res => {
        this.$message.success('删除成功')
        this.getList()
      })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
