<!-- 报损报溢 -->
<template>
  <div id="reportLoss">
    <el-form label-width="100px">
      <el-row>
        <el-col :span="5">
          <el-form-item label="盈/损/亏"
            ><el-select
              filterable
              placeholder="请选择"
              v-model="searchForm.status"
              class="w100"
              clearable
            >
              <el-option
                v-for="item in statusList"
                :key="item.code"
                :value="item.code"
                :label="item.label"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="盘点工单号" prop="workOrderCode">
            <el-input
              v-model="searchForm.planOrderCode"
              placeholder="请输入"
              size="small"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="报损溢单号" prop="breakageCode">
            <el-input
              v-model="searchForm.planProfitLossCode"
              placeholder="请输入"
              size="small"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4" 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="盘点工单号"
        width="220"
        prop="planOrderCode"
      ></el-table-column>
      <el-table-column
        width="200"
        label="物品名称"
        prop="categoryName"
      ></el-table-column>
      <el-table-column label="批次号" prop="batchNo"></el-table-column>
      <el-table-column
        label="盘点人"
        prop="planOrderUserName"
      ></el-table-column>
      <el-table-column label="盈/损/亏" prop="">
        <template slot-scope="{ row }">
          <span :style="{ color: statusColor[row.status] }">{{
            statusOpt[row.status]
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="数量">
        <template slot-scope="{ row }">
          <span>{{ row[countKey[row.status]] }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="报损溢单号"
        width="220"
        prop="planProfitLossCode"
      ></el-table-column>
      <el-table-column
        label="报损报溢人"
        prop="planProfitLossUserName"
      ></el-table-column>
      <el-table-column
        label="审核时间"
        prop="auditTime"
        width="150"
      ></el-table-column>
    </el-table>
    <div class="pagination"
      ><Pagination
        :total="total"
        :page.sync="page"
        :size.sync="size"
        @pagination="handlePageChange"
    /></div> -->
  </div>
</template>

<script>
  import storageApi from '@/api/warehouseManagement';
  import Pagination from '@/components/Pagination';
  // import { getBreakageOverflowDetail } from '@/api/stockManagement/stockLedger'
  // import dictMixin from '@/mixins/dictMixins'
  export default {
    components: { Pagination },
    // mixins: [dictMixin],
    props: {
      baseParams: {
        type: Object,
        default: () => ({})
      }
    },
    data() {
      return {
        searchForm: {
          status: '',
          planOrderCode: '',
          planProfitLossCode: ''
        },
        statusList: [
          { label: '所有', code: '' },
          { label: '盘盈', code: 2 },
          { label: '盘亏', code: 3 },
          { label: '盘损', code: 4 }
        ],
        statusOpt: {
          2: '盘盈',
          3: '盘亏',
          4: '盘损'
        },
        countKey: {
          2: 'surplusQuantity',
          3: 'loseQuantity',
          4: 'wornQuantity'
        },
        statusColor: {
          2: 'red',
          3: '#70B603',
          4: ''
        },
        columns: [
          {
            prop: 'planOrderCode',
            label: '盘点工单号',
            showOverflowTooltip: true,
            align: 'center',
            minWidth: 220
          },
          {
            align: 'center',
            prop: 'categoryName',
            label: '物品名称',
            showOverflowTooltip: true,
            minWidth: 200
          },
          {
            prop: 'batchNo',
            label: '批次号',
            align: 'center',
            showOverflowTooltip: true
          },
          {
            slot: 'status',
            prop: 'status',
            label: '盈/损/亏',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'count',
            label: '数量',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110,
            formatter: (_row) => {
              return _row[this.countKey[_row.status]];
            }
          },
          {
            prop: 'planProfitLossCode',
            label: '报损溢单号',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 220
          },
          {
            prop: 'planProfitLossUserName',
            label: '报损报溢人',
            align: 'center',
            showOverflowTooltip: true
          },
          {
            prop: 'auditTime',
            label: '审核时间',
            align: 'center',
            showOverflowTooltip: true
          }
        ],
        tableData: [],
        size: 20,
        page: 1,
        total: 0
      };
    },
    created() {
      // this.requestDict('类型用途')
      this.getList();
    },
    computed: {
      dimension() {
        return this.$route.query.dimension;
      }
    },
    methods: {
      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();
      },
      reset() {
        this.searchForm = {};
        this.getList();
      },
      handlePageChange() {
        this.getList();
      },
      async getList() {
        console.log(this.baseParams);
        try {
          let res = await storageApi.getPlandetails({
            size: this.size,
            pageNum: this.page,
            ...this.baseParams,
            ...this.searchForm
          });
          return res.list;
        } catch (error) {
          return [];
        }
      }
    }
  };
</script>
<style lang="scss" scoped>
  #reportLoss {
    height: 100%;
    width: 100%;
    padding-top: 10px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    :deep(.ele-pro-table) {
      flex: 1;
      display: flex;
      flex-direction: column;
      .el-table {
        flex: 1;
        // display: flex;
        // flex-direction: column;
        // .el-table__body-wrapper {
        //   flex: 1;
        // }
      }
    }
    .el-form-item {
      margin-bottom: 5px !important;
    }
    .pagination {
      padding: 10px 0;
      box-sizing: border-box;
      display: flex;
      align-items: center;
      justify-content: center;
    }
  }
</style>
