<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"
      >
        <template v-slot:action="{ row }">
          <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>
  </div>
</template>

<script>
  import OrderSearch from './components/search.vue';
  import dictMixins from '@/mixins/dictMixins';

  import { deleteLine, getList } from '@/api/sample/index';
  export default {
    components: {
      OrderSearch
    },
    mixins: [dictMixins],
    data() {
      return {
        loading: false,
        dialogVisible: false,
        current: null,
        selection: []
      };
    },
    computed: {
      // 表格列配置
      columns() {
        return [
          {
            columnKey: 'index',
            label: '序号',
            type: 'index',
            width: 55,
            align: 'center',
            showOverflowTooltip: true,
            fixed: 'left'
          },
          {
            prop: 'categoryCode',
            width: 160,
            label: '编码',
            align: 'center'
          },
          {
            prop: 'brandNum',
            label: '牌号',
            align: 'center'
          },
          {
            prop: 'deviceName',
            label: '设备名称',
            align: 'center'
          },
          {
            prop: 'feedQuantity',
            label: '投料数量',
            align: 'center'
          },
          {
            prop: 'modelType',
            label: '型号',
            align: 'center'
          },

          {
            prop: 'name',
            label: '物品名称',
            align: 'center'
          },
          {
            prop: 'notType',
            label: '处置类型',
            align: 'center',
            slot: 'notType',
            width: 100,
            showOverflowTooltip: true,
            formatter: (row, column, cellValue) => {
              return cellValue == 1
                ? '返工'
                : cellValue == 2
                ? '返修'
                : cellValue == 3
                ? '报废'
                : cellValue == 4
                ? '降级使用'
                : cellValue == 5
                ? '让步接收'
                : cellValue == 6
                ? '留样'
                : cellValue == 7
                ? '消耗'
                : cellValue == 8
                ? '回用'
                : cellValue == 9
                ? '转试销'
                : '';
            }
          },
          {
            prop: 'specification',
            label: '规格',
            align: 'center'
          },
          {
            prop: 'unit',
            label: '计量单位',
            align: 'center'
          },

          {
            prop: 'createTime',
            label: '创建时间',
            align: 'center',
            width: 160
          },

          {
            columnKey: 'action',
            label: '操作',
            width: 100,
            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);
        deleteLine(ids).then((res) => {
          this.$message.success('删除' + res);
          this.reload();
        });
      },
      /* 刷新表格 */
      reload(where) {
        this.$nextTick(() => {
          this.$refs.table.reload({ page: 1, where });
        });
      }
    }
  };
</script>

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