<!-- 让步接收列表 -->
<template>
  <div class="ele-body">
    <el-card shadow="never" v-loading="loading">
      <order-search @search="reload" ref="searchRef"> </order-search>
      <ele-pro-table
        ref="table"
        :columns="columns"
        :datasource="datasource"
        :selection.sync="selection"
        :page-size="20"
        @columns-change="handleColumnChange"
        :cache-key="cacheKeyUrl"
        row-key="id"
      >
        <!-- 表头工具栏 -->
        <template v-slot:toolbar>
          <el-button
            size="small"
            type="primary"
            icon="el-icon-plus"
            class="ele-btn-icon"
            @click="openEdit('add')"
            v-if="$hasPermission('qms:badname:save')"
          >
            新增
          </el-button>
        </template>
        <template v-slot:action="{ row }">
          <el-link
            type="primary"
            :underline="false"
            @click="openEdit('edit', row)"
            v-if="$hasPermission('qms:badname:update')"
          >
            修改
          </el-link>
          <el-popconfirm
            class="ele-action"
            title="确定要删除吗？"
            @confirm="remove(row)"
            v-if="$hasPermission('qms:badname:delete')"
          >
            <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="editRef" @done="reload"></edit>
  </div>
</template>

<script>
  import OrderSearch from './components/order-search.vue';
  import edit from './components/edit.vue';
  import tabMixins from '@/mixins/tableColumnsMixin';
  import { getList, deleteList } from '@/api/unacceptedProduct/unqualifiedName';
  export default {
    components: {
      OrderSearch,
      edit
    },
    mixins: [tabMixins],
    data() {
      return {
        cacheKeyUrl: 'qms-c2e9664a-unqualifiedName-index',
        loading: false,
        selection: []
      };
    },
    computed: {
      // 表格列配置
      columns() {
        return [
          {
            columnKey: 'index',
            label: '序号',
            type: 'index',
            width: 55,
            align: 'center',
            showOverflowTooltip: true,
            fixed: 'left'
          },
          {
            prop: 'code',
            label: '不良代码',
            align: 'center',
            showOverflowTooltip: true
          },
          {
            prop: 'name',
            label: '不良名称',
            align: 'center',
            showOverflowTooltip: true
          },

          {
            prop: 'badTypeName',
            label: '不良类型名称',
            align: 'center',
            showOverflowTooltip: true
          },
          {
            prop: 'badTypeCode',
            label: '不良类型编码',
            align: 'center',
            showOverflowTooltip: true
          },
          {
            prop: 'status',
            label: '启用状态',
            align: 'center',
            showOverflowTooltip: true,
            formatter: (_row, _column, cellValue) => {
              return cellValue == 1 ? '启用' : '禁用';
            }
          },
          {
            prop: 'remark',
            label: '备注',
            align: 'center',
            showOverflowTooltip: true
          },
          {
            prop: 'createUserName',
            label: '创建人',
            align: 'center'
          },
          {
            prop: 'createTime',
            label: '创建时间',
            align: 'center'
          },

          {
            columnKey: 'action',
            label: '操作',
            width: 150,
            align: 'center',
            resizable: false,
            fixed: 'right',
            slot: 'action',
            showOverflowTooltip: true
          }
        ];
      }
    },
    created() {},
    filters: {},
    methods: {
      /* 表格数据源 */
      datasource({ page, limit, where }) {
        return getList({
          pageNum: page,
          size: limit,
          ...where
        });
      },
      remove(row) {
        let ids = row ? [row.id] : this.selection.map((item) => item.id);
        deleteList(ids).then((res) => {
          this.$message.success('删除' + res);
          this.reload();
        });
      },
      openEdit(type, row = {}) {
        this.$refs.editRef.open(row, type);
      },

      /* 刷新表格 */
      reload(where) {
        this.$nextTick(() => {
          this.$refs.table.reload({ page: 1, where });
        });
      }
    }
  };
</script>

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