<template>
  <div class="express-company-page">
<!--    快递公司-->
    <Card>
      <div class="add-con" style="margin-bottom: 20px;text-align:right">
        <Button type="primary" size="large" @click="handleAdd">+新增快递公司</Button>
      </div>
      <tables
        ref="tables"
        v-model="tableData"
        :columns="columns"
        :loading="loading"
      />
    </Card>
  </div>
</template>

<script>
import Tables from '_c/tables'
import { formatTime } from '@/libs/tools'
export default {
  name: 'address-list',
  components: {
    Tables
  },
  data () {
    return {
      tableData: [],
      columns: [
        { title: '编号', type: 'index', align: 'center', minWidth: 100 },
        { title: '快递名称', key: 'expName', align: 'center', minWidth: 150 },
        // { title: '快递代码', key: 'companyCode', align: 'center', minWidth: 150 },
        { title: '合作网点', key: 'cooperationNetwork', align: 'center', minWidth: 150 },
        { title: '网店地址', key: 'networkAddress', align: 'center', minWidth: 150 },
        { title: '网店电话', key: 'networkPhone', align: 'center', minWidth: 150 },
        { title: '操作',
          key: 'index',
          align: 'center',
          // fixed: 'right',
          minWidth: 100,
          render: (h, params) => {
            let deleteBtn = h(
              'Button',
              {
                props: {
                  type: 'error',
                  size: 'small'
                },
                on: {
                  click: this.handleDelete(params.row)
                }
              },
              '删 除'
            )
            return h('div', [deleteBtn])
          }
        }
      ],
      loading: false
    }
  },
  methods: {
    requestData () {
      this.loading = true
      this.api({
        apiName: 'getCompanyList',
        complete: () => {
          this.loading = false
        },
        success: (res) => {
          this.tableData = res.data
        }
      })
    },
    handleAdd () {
      if (this.tableData.length == 20) {
        this.$Message.warning('最多只能添加20条哦')
        return
      }
      this.$router.push({ name: 'add_company' })
    },
    handleDelete (row) {
      return () => {
        let { companyId } = row
        this.$Modal.confirm({
          title: '删除',
          content: `您确认要删除当前选择的数据吗？`,
          onOk: () => {
            this.api({
              apiName: 'deleteCompany',
              postdata: companyId,
              success: () => {
                this.requestData()
                this.$Notice.success({ title: `删除成功！` })
              }
            })
          }
        })
      }
    }
  },
  created () {
    this.requestData()
  }
}
</script>

<style scoped>

</style>
