<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"
          
        >
     
   
          <!-- 操作列 -->
          <template v-slot:toolbar>
            <el-button type="success" @click="open()">新建</el-button>
          </template>
          <template v-slot:action="{ row }">
            <el-link
              type="primary"
              :underline="false"
              icon="el-icon-truck"
              v-if="row.status == 0"
              @click="open(row)"
            >
              编辑
            </el-link>
            <el-popconfirm
              class="ele-action"
              title="确定要删除吗？"
              v-if="row.status == 0"
              @confirm="remove(row)"
            >
              <template v-slot:reference>
                <el-link type="danger" :underline="false" icon="el-icon-delete">
                  删除
                </el-link>
              </template>
            </el-popconfirm>
            <el-link
              type="primary"
              :underline="false"
              icon="el-icon-edit"
              @click="detail(row)"
            >
              处置
            </el-link>
          </template>
        </ele-pro-table>
      </el-card>
      <Create ref="create" @refresh="reload" />
    </div>
  </template>
  
  <script>
  import OrderSearch from './components/order-search.vue';
  import dictMixins from '@/mixins/dictMixins';
  import { unacceptedProductStatus } from '@/utils/util';
  import Create from './components/create';
  
  import { getList,deleteUnacceptedProduct } from '@/api/unacceptedProduct/index';
  export default {
    components: {
      OrderSearch,
      Create
    },
    mixins: [dictMixins],
    data() {
      return {
        visible: false,
        loading: false,
        releasParams: {
          teamId: '',
          id: ''
        },
  
        current: null
      };
    },
    computed: {
      // 表格列配置
      columns() {
        return [
          {
            columnKey: 'index',
            label: '序号',
            type: 'index',
            width: 55,
            align: 'center',
            showOverflowTooltip: true,
            fixed: 'left'
          },
          {
            prop: 'code',
            label: '编码',
            align: 'center'
          },
          {
            prop: 'unqualifiedSourceCode',
            label: '来源编码',
            align: 'center'
          },
          {
            prop: 'batchNo',
            label: '批次号',
            align: 'center'
          },
          {
            prop: 'unqualifiedQuantity',
            label: '数量',
            align: 'center'
          },
          {
            prop: 'produceRoutingName',
            label: '工艺路线',
            align: 'center'
          },
          {
            prop: 'produceTaskName',
            label: '工序',
            align: 'center'
          },
      
          {
            prop: 'createTime',
            label: '创建时间',
            align: 'center'
          },
          {
            prop: 'reviewerName',
            label: '创建人',
            align: 'center'
          },
          // {
          //   prop: 'slottingType',
          //   label: '状态',
          //   align: 'center',
          //   slot: 'SlottingType'
          // },
          {
            prop: 'status',
            label: '状态',
            align: 'center',
            formatter: (row, column, cellValue) => {
              return unacceptedProductStatus(cellValue);
            }
          },
  
          {
            columnKey: 'action',
            label: '操作',
            width: 240,
            align: 'center',
            resizable: false,
            fixed: 'right',
            slot: 'action',
            showOverflowTooltip: true
          }
        ];
      }
    },
    created() {
    },
    filters: {
  
    },
    methods: {
      //处置
      detail(row) {
        this.$router.push({
          path: '/unacceptedProduct/detailList',
          query: {
            id: row.id
          }
        });
      },
      /* 表格数据源 */
      datasource({ page, limit, where }) {
        return getList({
          pageNum: page,
          size: limit,
          ...where
        });
      },
      open(row) {
        this.$refs.create.open(row?JSON.parse(JSON.stringify(row)):'');
      },
      remove(row) {
        deleteUnacceptedProduct(row.id).then((res) => {
          this.$message.success('删除'+res);
          this.reload();
        });
      },
      // // 下达
      // toRelease(row) {
      //   this.current = row;
      //   this.visible = true;
      // },
      // // 下达
      // confirm(row) {
      //   this.$confirm('确认下发选中的任务吗？', '提示', {
      //     confirmButtonText: '确定',
      //     cancleButtonText: '取消',
      //     type: 'warning'
      //   })
      //     .then(async () => {
      //       const res = await issuedPutMeshWorkOrder({
      //         id: [row.id],
      //         status: 1
      //       });
      //       this.$message.success('任务下发成功！');
      //       this.reload();
      //     })
      //     .catch(() => {});
      // },
      /* 刷新表格 */
      reload(where) {
        this.$nextTick(() => {
          this.$refs.table.reload({ page: 1, where });
        });
      }
    }
  };
  </script>
  
  <style lang="scss" scoped></style>