<template>
  <div class="app-container coupon-list">
    <el-row :gutter="10" class="mb8">
      <el-col :span="10">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="$router.push({ name: 'TemplateCreate' })"
          v-hasPermi="['setting:template:add']"
        >添加运费模板</el-button>
      </el-col>
    </el-row>
    <el-table v-loading="loading" :data="tableData">
      <el-table-column label="模板编号" prop="id" width="280" />
      <el-table-column label="模板名称" prop="title" />
      <el-table-column fixed="right" align="right" label="操作" width="150">
        <template slot-scope="{row}">
          <el-button v-hasPermi="['setting:template:edit']" type="text" @click="$router.push({ name: 'TemplateEdit', query: { id: row.id } })">编辑</el-button>
          <el-button v-if="1 === 1" v-hasPermi="['setting:template:remove']" class="del" type="text" @click="del(row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { getTemplateList, delTemplate } from '@/api/business/template'
export default {
  data() {
    return {
      loading: false,
      queryParams: {},
      tableData: [],
      total: 0
    };
  },
  created() {
    this.getList(true)
  },
  methods: {
    getList(reset) {
      if (this.loading) {
        return
      }
      this.loading = true
      if (reset) {
        this.queryParams = { pageNum: 1, pageSize: 20 }
      }
      getTemplateList('pageNum='+this.queryParams.pageNum + '&pageSize='+this.queryParams.pageSize+'&', this.queryParams).then(res => {
        this.loading = false
        if (res.code === 0) {
          this.tableData = res.rows
          // this.total = res.total
        }
      }).catch(() => {
        this.loading = false
      })
    },

    del(item) {
      this.$confirm(`确认删除券 “${item.title}” 吗？`, '删除券', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delTemplate(item.id).then(res => {
          if (res.code === 0) {
            this.$message.success('操作已完成！')
            this.getList()
          }
        })
      })
    },

  },
};
</script>
<style>
</style>
