<template>
  <div class="ele-body">
    <el-card shadow="never">
      <search ref="search" @search="search"></search>
      <ele-pro-table
        ref="table"
        :columns="columns"
        :datasource="datasource"
      >
        <!-- 表头工具栏 -->
        <template v-slot:toolbar>
          <el-button
            size="small"
            type="primary"
            icon="el-icon-plus"
            class="ele-btn-icon"
            @click="openEdit('add')"
          >
            添加
          </el-button>
        </template>

        <!-- 操作列 -->
        <template v-slot:action="{ row }">
          <el-link
            type="primary"
            :underline="false"
            icon="el-icon-edit"
            @click="openEdit('edit', row)"
          >
            修改
          </el-link>
          <el-popconfirm
            class="ele-action"
            title="确定要删除吗？"
            @confirm="remove(row)"
          >
            <template v-slot:reference>
              <el-link type="danger" :underline="false" icon="el-icon-delete">
                删除
              </el-link>
            </template>
          </el-popconfirm>
        </template>
      </ele-pro-table>
    </el-card>
    <edit ref="edit" @done="done"></edit>
  </div>
</template>
<script>
import search from './components/search.vue';
import edit from './components/edit.vue';
import { getList, removeItem } from '@/api/inspectionProject';
import dictMixins from '@/mixins/dictMixins';
export default {
  mixins: [dictMixins],
  components: {
    search,
    edit
  },
  data() {
    return {
      columns: [
        {
          width: 45,
          type: 'index',
          columnKey: 'index',
          align: 'center'
        },

        {
          prop: 'inspectionCode',
          label: '编码'
        },
        {
          label: '名称',
          prop: 'inspectionName'
        },

        {
          label: '是否生成过程',
          prop: 'isCreateCourse',
          formatter: (row, column, cellValue) => {
            return cellValue==1?'是': cellValue===0?'否':''
          }
        },
        {
          label: '质检标准',
          prop: 'inspectionStandard'
        },

        {
          label: '质检工具',
          prop: 'inspectionTool'
        },
        {
          label: '状态',
          prop: 'status',
          formatter: (row, column, cellValue) => {
            return cellValue==1?'启用': cellValue===0?'停用':''
          }
        },
        {
          label: '描述',
          prop: 'description'
        },

        {
          label: '备注',
          prop: 'inspectionRemark'
        },
        {
          columnKey: 'action',
          label: '操作',
          width: 220,
          align: 'center',
          resizable: false,
          slot: 'action',
          showOverflowTooltip: true
        }
      ]
    };
  },
  created() {
    this.requestDict('质检标准类型');
  },
  methods: {
    datasource({ page, where, limit }) {
      return getList({
        ...where,
        pageNum: page,
        size: limit
      });
    },
    search(where) {
      this.$refs.table.reload({
        where: where,
        page: 1
      });
    },
    openEdit(type, row) {
      this.$refs.edit.open(type, row);
    },

    remove(row) {
      removeItem([row.id])
        .then((message) => {
          this.$message.success(message);
          this.done();
        })
        .catch((e) => {});
    },
    done() {
      this.$refs.search.search();
    }
  }
};
</script>
  