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

      <!-- 数据表格 -->
      <ele-pro-table
        ref="table"
        :columns="columns"
        :datasource="datasource"
        row-key="id"
        cache-key="pickKey"
        :selection.sync="selection"
        autoAmendPage
        :parse-data="parseData"
      >
      </ele-pro-table>
    </el-card>
  </div>
</template>

<script>
  import { getPage } from '@/api/pick/pickApply';

  import pickSearch from './components/pick-search.vue';

  export default {
    components: {
      pickSearch
    },
    data() {
      return {
        // 加载状态
        loading: false,
        selection: []
      };
    },
    computed: {
      columns() {
        return [
          {
            prop: 'code',
            label: '领料单编号',
            align: 'center'
          },

          {
            prop: 'joinWorkOrderCode',
            label: '关联工单编号',
            align: 'center'
          },

          {
            prop: 'joinWarehouseName',
            label: '关联仓库名称',
            align: 'center'
          },

          {
            prop: 'joinWarehouseName',
            label: '关联仓库名称',
            align: 'center'
          },

          {
            prop: 'joinReviewerName',
            label: '关联审核人',
            align: 'center'
          },

          {
            prop: 'executorName',
            label: '领料人',
            align: 'center'
          },

          {
            prop: 'createTime',
            label: '领料时间',
            align: 'center'
          },
          {
            prop: 'status',
            slot: 'status',
            label: '状态',
            align: 'center'
          },

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

          pageNum: page,
          size: limit
        });

        return res;
      },

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

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

      /* 数据转为树形结构 */

      createSuccess() {
        this.reload();
      },
      handleCreate() {
        this.$refs.createRef.open(0);
      },
      // 发布工单
      handleOrderPublish(type, row) {
        this.$router.push({
          path: '/produceOrder/report',
          query: {
            type,
            id: row.id
          }
        });
      },

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