<!-- 调拨 -->
<template>
  <div class="inventoryAllocation">
    <!-- <el-form label-width="70px">
      <el-row>
        <el-col :span="6">
          <el-form-item label="关键字">
            <el-input
              placeholder="请输入"
              v-model="searchForm.key"
              size="small"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="18" style="text-align: right">
          <el-button
            @click="search"
            type="primary"
            icon="el-icon-search"
            size="small"
            >搜索</el-button
          >
          <el-button @click="reset" icon="el-icon-refresh-left" size="small"
            >重置</el-button
          >
        </el-col>
      </el-row>
    </el-form> -->
    <ele-pro-table
      class="table_list"
      ref="table"
      height="calc(100vh - 300px)"
      :columns="columns"
      :datasource="datasource"
      :pageSize="20"
      row-key="id"
    >
      <template v-slot:status="{ row }">
        <span :style="{ color: statusColor[row.status] }">{{
          statusOpt[row.status]
        }}</span>
      </template>
    </ele-pro-table>
    <!-- <el-table
      class="table"
      :data="tableData"
      :header-cell-style="{ background: '#EEEEEE', border: 'none' }"
    >
      <el-table-column label="序号" type="index"></el-table-column>
      <el-table-column label="调拔单号" prop="code"></el-table-column>
      <el-table-column label="调拔名称" prop="name"></el-table-column>
      <el-table-column label="物品名称" prop="categoryName"></el-table-column>
      <el-table-column label="批次号" prop="batchNo"></el-table-column>
      <el-table-column label="包装编码" prop="packageNo"></el-table-column>
      <el-table-column
        label="包装数量"
        prop="packingQuantity"
      ></el-table-column>
      <el-table-column label="包装单位" prop="packingUnit"></el-table-column>
      <el-table-column
        label="计量数量"
        prop="measureQuantity"
      ></el-table-column>
      <el-table-column label="计量单位" prop="measureUnit"></el-table-column>
      <el-table-column label="重量" prop="weight"></el-table-column>
      <el-table-column label="重量单位" prop="weightUnit"></el-table-column>
      <el-table-column label="调出区域" prop="warehouseName">
        <template slot-scope="{ row }">
          {{ warehouseLabel(row) }}
        </template>
      </el-table-column>
      <el-table-column label="调入区域" prop="inWarehouseName">
        <template slot-scope="{ row }">
          {{ targetWarehouseLabel(row) }}
        </template>
      </el-table-column>
      <el-table-column label="创建时间" prop="createTime"></el-table-column>
    </el-table>
    <div class="pagination"
      ><Pagination
        :total="total"
        :page.sync="page"
        :size.sync="size"
        @pagination="handlePageChange"
    /></div> -->

    <!-- <InventoryAllocationDialog
      ref="detailRef"
      :assetCode="baseInfo.assetCode"
      :isUnpack="baseInfo.isUnpack"
    /> -->
  </div>
</template>

<script>
  import storageApi from '@/api/warehouseManagement';
  import Pagination from '@/components/Pagination';
  // import { getTransferDetail } from '@/api/stockManagement/stockLedger'
  import InventoryAllocationDialog from './InventoryAllocationDialog';
  import { inventorybookPage } from '@/api/classifyManage/itemInformation';
  // import dictMixins from '@/mixins/dictMixins'
  export default {
    components: { Pagination, InventoryAllocationDialog },
    // mixins: [dictMixins],
    props: {
      baseInfo: {
        type: Object,
        default: () => ({})
      },
      baseParams: {
        type: Object,
        default: () => ({})
      }
    },
    data() {
      return {
        searchForm: {
          key: ''
        },
        columns: [
          {
            prop: 'code',
            label: '调拔单号',
            showOverflowTooltip: true,
            align: 'center',
            minWidth: 220
          },
          {
            align: 'center',
            prop: 'name',
            label: '调拔名称',
            showOverflowTooltip: true,
            minWidth: 200
          },
          {
            prop: 'categoryName',
            label: '物品名称',
            align: 'center',
            showOverflowTooltip: true
          },
          {
            prop: 'batchNo',
            label: '批次号',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 80
          },
          {
            prop: 'packageNo',
            label: '包装编码',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 200
          },
          {
            prop: 'packingQuantity',
            label: '包装数量',
            align: 'center',
            showOverflowTooltip: true
          },
          {
            prop: 'packingUnit',
            label: '包装单位',
            align: 'center',
            showOverflowTooltip: true
          },
          {
            prop: 'measureQuantity',
            label: '计量数量',
            align: 'center',
            showOverflowTooltip: true
          },
          {
            prop: 'measureUnit',
            label: '计量单位',
            align: 'center',
            showOverflowTooltip: true
          },
          {
            prop: 'weight',
            label: '重量',
            align: 'center',
            showOverflowTooltip: true
          },
          {
            prop: 'weightUnit',
            label: '重量单位',
            align: 'center',
            showOverflowTooltip: true
          },
          {
            prop: 'warehouseName',
            label: '调出区域',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110,
            formatter: (_row) => {
              return this.warehouseLabel(_row);
            }
          },
          {
            prop: 'inWarehouseName',
            label: '调入区域',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110,
            formatter: (_row) => {
              return this.targetWarehouseLabel(_row);
            }
          },
          {
            prop: 'createTime',
            label: '创建时间',
            showOverflowTooltip: true,
            align: 'center',
            minWidth: 110
          }
        ],
        tableData: [],
        size: 20,
        page: 1,
        total: 0
      };
    },
    created() {
      // this.requestDict('类型用途')
      this.getList();
    },
    methods: {
      warehouseLabel(row) {
        if (
          row.warehouseName &&
          row.areaName &&
          row.goodsShelfName &&
          row.goodsAllocationName
        ) {
          return (
            row.warehouseName +
            '/' +
            row.areaName +
            '/' +
            row.goodsShelfName +
            '/' +
            row.goodsAllocationName
          );
        } else if (row.warehouseName && row.areaName && row.goodsShelfName) {
          return (
            row.warehouseName + '/' + row.areaName + '/' + row.goodsShelfName
          );
        } else if (row.warehouseName && row.areaName) {
          return row.warehouseName + '/' + row.areaName;
        } else {
          return row.warehouseName;
        }
      },
      targetWarehouseLabel(row) {
        if (
          row.targetWarehouseName &&
          row.targetAreaName &&
          row.targetGoodsShelfName &&
          row.targetGoodsAllocationName
        ) {
          return (
            row.targetWarehouseName +
            '/' +
            row.targetAreaName +
            '/' +
            row.targetGoodsShelfName +
            '/' +
            row.targetGoodsAllocationName
          );
        } else if (
          row.targetWarehouseName &&
          row.targetAreaName &&
          row.targetGoodsShelfName
        ) {
          return (
            row.targetWarehouseName +
            '/' +
            row.targetAreaName +
            '/' +
            row.targetGoodsShelfName
          );
        } else if (row.targetWarehouseName && row.targetAreaName) {
          return row.targetWarehouseName + '/' + row.targetAreaName;
        } else {
          return row.targetWarehouseName;
        }
      },
      async datasource({ page, limit, where, order }) {
        console.log(page);
        console.log(limit);
        this.pageNum = page;
        this.size = limit;
        return await this.getList();
      },
      search() {
        this.page = 1;
        this.getList();
      },
      handleCellClick(row) {
        this.$refs.detailRef.open(row);
      },
      reset() {
        this.searchForm = {};
        this.search();
      },
      handlePageChange() {
        this.getList();
      },
      async getList() {
        console.log(this.baseParams);
        try {
          let res = await storageApi.getAllotDetails({
            size: this.size,
            pageNum: this.page,
            ...this.baseParams
          });
          return res.list;
        } catch (error) {
          return [];
        }
      }
    }
  };
</script>
<style lang="scss" scoped>
  .inventoryAllocation {
    height: 100%;
    width: 100%;
    padding-top: 20px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    :deep(.table) {
      flex: 1;
      display: flex;
      flex-direction: column;
      .el-table__body-wrapper {
        flex: 1;
      }
    }
    .pagination {
      padding: 10px 0;
      box-sizing: border-box;
      display: flex;
      align-items: center;
      justify-content: center;
    }
  }
</style>
