<template>
  <div class="ele-body">
    <el-card shadow="never" v-loading="loading">
      <productSearch @search="reload" ref="searchRef" >
      </productSearch>

      <!-- 数据表格 -->
      <ele-pro-table
        ref="table"
        :columns="columns"
        :datasource="datasource"
        row-key="id"
        cache-key="pickKey"
        :selection.sync="selection"
        autoAmendPage
        :parse-data="parseData"
        @update:selection="handleSelectionChange"
      >
        <template v-slot:toolbar>
 
          <el-button
            type="primary"
          
            size="mini"
            @click="handSelfPick"
            >自建处置单</el-button
          >
        </template>


        <template v-slot:formedNum="{ row }">
          {{  row.notFormedNum  || 0 }} /   {{  row.formedNum  || 0 }} 
        </template>

        <template v-slot:weight="{ row }">
          {{  row.weight  || 0 }} /   {{  row.weightUnit   }} 
        </template>


        <template v-slot:action="{ row }">
          <el-button type="text" size="mini" @click="handDetailed(row)"
            >详情</el-button
          >
        </template>
      </ele-pro-table>
    </el-card>

    <!-- <addPick v-if="addPickShow" @close="close"></addPick>
      <selfBuildPick v-if="selfBuildPickShow" @close="close"></selfBuildPick>
  
      <detailed
        @detailedClose="detailedClose"
        v-if="detailedShow"
        :detailedObj="detailedObj"
      ></detailed>
  
      <selfDetailed
        @detailedClose="detailedClose"
        v-if="selfDetailedShow"
        :detailedObj="detailedObj"
      ></selfDetailed> -->
  </div>
</template>

<script>
  import { getPage, returnPage } from '@/api/byProduct/index';

  import productSearch from './components/product-search.vue';

  // import addPick from './components/addPick.vue';
  // import selfBuildPick from './components/selfBuildPick.vue';

  // import detailed from '@/views/produce/components/picking/detailed.vue';
  // import selfDetailed from './components/selfDetailed.vue';

  export default {
    components: {
      productSearch
      // addPick,
      // selfBuildPick,
      // detailed,
      // selfDetailed
    },

    data() {
      return {
        // 加载状态
        loading: false,
        selection: [],

        addPickShow: false,
        selfBuildPickShow: false,

        detailedShow: false,
        detailedObj: null,

        selfDetailedShow: false,

        statusList: ['未领料', '领料中', '已出库', '已驳回']
      };
    },
    computed: {
      columns() {
        return [
        
          {
            prop: 'code',
            label: '处置单号',
            align: 'left',
            
          },

          {
            prop: 'workOrderCode',
            label: '工单编码',
            align: 'center'
          },
          {
            prop: 'taskName',
            label: '工序',
            align: 'center'
          },

          
          {
            prop: 'categoryCode',
            label: '物品编码',
            align: 'center'
          },

          {
            prop: 'categoryName',
            label: '物品名称',
            align: 'center'
          },


          {
            prop: 'formedNum',
            slot: 'formedNum',
            label: '不合格品/合格品数量',
            align: 'center',
            width: 140,
          },

          {
            prop: 'weight',
            slot: 'weight',
            label: '重量',
            align: 'center',
            width: 140,
          },

   
          {
            prop: 'executorName',
            label: '处置人',
            align: 'center',
            width: 95,
          },
          {
            prop: 'createTime',
            label: '创建时间',
            align: 'center',
            width: 95,
          },




          {
            prop: '',
            label: '操作',
            width: 80,
            align: 'center',
            resizable: false,
            fixed: 'right',
            slot: 'action'
          }
        ];
      }
    },
    created() {},
    methods: {
      /* 表格数据源 */
      async datasource({ page, limit, where }) {

        let parma = {
          ...where,
          pageNum: page,
          size: limit
        };
    

        let res = await getPage(parma);

        return res;
      },

      /* 数据转为树形结构 */
      parseData(data) {
        return {
          ...data,
          list: this.$util.toTreeData({
            data: data.list,
            count: data.total,

            idField: 'id',
            parentIdField: 'parentId'
          })
        };
      },

      handPick() {
        this.addPickShow = true;
      },

      close(val) {
        if (val) {
          this.reload();
        }
        this.addPickShow = false;
        this.selfBuildPickShow = false;
      },

      handSelfPick() {
        this.selfBuildPickShow = true;
      },

      selfClose(val) {
        if (val) {
          this.reload();
        }
        this.selfBuildPickShow = false;
      },

      handDetailed(row) {
        this.detailedObj = JSON.stringify(row);
        if (row.type == 1) {
          this.selfDetailedShow = true;
        } else {
          this.detailedShow = true;
        }
      },

      detailedClose() {
        this.detailedShow = false;
        this.selfDetailedShow = false;
      },

      handleSelectionChange(data) {
        let ids = [];
        ids = data.map((item) => item.id);
        this.$emit('selectionChange', ids);
      },
      /* 刷新表格 */
      reload(where = {}) {
        this.$refs.table.reload({ page: 1, where });
      }
    }
  };
</script>
