<template>
  <div>
    <seek-page :seekList="seekList" @search="search"></seek-page>
    <ele-pro-table
      ref="table"
      row-key="id"
      :columns="columns"
      :datasource="datasource"
      :cache-key="cacheKeyUrl"
      autoAmendPage
      height="calc(86vh - 230px)"
    >
      <template v-slot:action="{ row }">
        <el-link type="primary" :underline="false" @click="goToDetail(row)">
          详情
        </el-link>
      </template>

      <template v-slot:bizNo="{ row }">
        <el-link type="primary" @click="goToDetail(row)">{{
          row.bizNo
        }}</el-link>
      </template>
    </ele-pro-table>
  </div>
</template>

<script>
  import dictMixins from '@/mixins/dictMixins';
  import tableColumnsMixin from '@/mixins/tableColumnsMixin';
  import { getPages } from '@/api/wms/index';
  import { sceneState } from '@/utils/dict/index';

  export default {
    mixins: [dictMixins, tableColumnsMixin],
    props: {
      tableQuery: {
        type: Object,
        default: () => {
          return {};
        }
      }
    },
    data() {
      return {
        sceneState,
        columns: [
          {
            width: 50,
            type: 'index',
            columnKey: 'index',
            align: 'center',
            label: '序号'
          },
          {
            prop: 'bizNo',
            label: '单号',
            align: 'center',
            minWidth: 110,
            showOverflowTooltip: true,
            slot: 'bizNo'
          },
          {
            prop: 'warehouseName',
            label: '仓库名称',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 150
          },
          {
            prop: 'bizType',
            label: '入库类型',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 150,
            formatter: (row) => {
              for (const key in this.sceneState) {
                if (this.sceneState[key].code == row.bizType) {
                  return this.sceneState[key].label;
                }
              }
            }
          },
          {
            prop: 'sourceBizNo',
            label: '来源单据',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 150
          },
          {
            prop: 'createUserName',
            label: '入库人',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 150
          },
          {
            prop: 'storageTime',
            label: '入库时间',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 150
          },
          {
            prop: 'outInStatus',
            label: '入库状态',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 150,
            formatter: (row) => {
              if (row.verifyStatus == 2) {
                switch (row.outInStatus) {
                  case '1':
                    return '预入库';
                  case '2':
                    return '部分入库';
                  case '3':
                    return '已入库';
                  default:
                    return '';
                }
              }
            }
          },
          {
            label: '操作',
            columnKey: 'action',
            slot: 'action',
            showOverflowTooltip: true,
            minWidth: 110,
            align: 'center',
            fixed: 'right'
          }
        ],
        cacheKeyUrl: 'mes-259231507-mwmsoutint-table'
      };
    },
    computed: {
      seekList() {
        return [
          {
            label: '工单编码：',
            value: 'workOrderCode',
            type: 'input',
            placeholder: '请输入'
          },
          {
            label: '入库时间',
            value: 'time',
            type: 'date',
            dateType: 'daterange',
            placeholder: '请输入'
          },
          {
            label: '入库单号',
            value: 'sourceBizNo',
            type: 'input',
            placeholder: '请输入'
          }
        ];
      }
    },
    methods: {
      // 刷新表格
      reload(where = {}) {
        this.$refs.table.reload({
          where,
          ...this.tableQuery
        });
      },
      /* 表格数据源 */
      datasource({ page, limit, where, order }) {
        // 参数
        const body = {
          ...where,
          ...order,
          pageNum: page,
          size: limit,
          ...this.tableQuery
        };
        return getPages(body);
      },
      search(where) {
        console.log('where', where);
        if (where.time) {
          where.startTime = where.time[0];
          where.endTime = where.time[1];
        }
        // 覆盖时间
        this.reload({ ...where, time: null });
      },
      goToDetail(row) {
        const path = `/page-wms/warehouseManagement/stockManagement/details?id=${row.id}&verifyStatus=${row.verifyStatus}`;
        window.history.pushState(null, '', path);
      }
    }
  };
</script>

<style></style>
