
<template>
  <div class="app-container">
    <avue-crud
      ref="crud"
      :permission="permissionList"
      :data="tableData"
      :table-loading="tableLoading"
      :option="tableOption"
      @on-load="getPage"
      @row-del="handleDel"
    >
    </avue-crud>
  </div>
</template>

<script>
import { getList, delObj } from '@/api/wxmp/wxmptemp'
import { tableOption } from '@/const/crud/wxmp/wxmptemp'
import { checkPermi } from "@/utils/permission"
export default {
  name: 'wxmptemp',
  data () {
    return {
      tableData: [],
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 20, // 每页显示多少条
        ascs: [],
        descs: 'template_id'
      },
      paramsSearch: {},
      tableLoading: false,
      tableOption: tableOption,
      dialogMsgVisible: false,
      tempId:0
    }
  },
  created () {

  },
  mounted: function () { },
  computed: {
    permissionList () {
      return {
        delBtn: checkPermi(['wxmp:wxusertags:del'])
      }
    }
  },
  methods: {

    getPage (page, params) {
      this.tableLoading = true
      getList(Object.assign({

      }, params, this.paramsSearch)).then(response => {
        this.tableData = response.data.list
        this.tempId =  response.data.tempId
        this.tableLoading = false
      }).catch(() => {
        this.tableLoading = false
      })
    },
    handleDel: function (row, index) {
      var _this = this
    if(this.tempId == row.templateId){
        this.msgError("预警模板不能删除")
        return;
    }


      this.$confirm('是否确认删除', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function () {
        return delObj(row.templateId).then(data => {
        _this.$message({
          showClose: true,
          message: '删除成功',
          type: 'success'
        })
        _this.getPage(_this.page)
      }).catch(function (err) { })
    })
    },

    /**
     * 刷新回调
     */
    refreshChange (page) {
      this.getPage(this.page)
    }
  }
}
</script>

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