<template>
  <el-dialog
    :visible.sync="equipmentdialog"
    :before-close="handleClose"
    :close-on-click-modal="true"
    :close-on-press-escape="false"
    append-to-body
    width="70%"
    title="采购收货单"
  >
    <div>
      <el-row>
        <el-col :span="24" class="table_col" v-if="equipmentdialog">
          <searchWarehousing ref="search" @search="reload"></searchWarehousing>
          <ele-pro-table
            ref="equiTable"
            :columns="columns"
            :datasource="datasource"
            :selection.sync="selection"
            :current.sync="current"
            highlight-current-row
            row-key="id"
            height="50vh"
            @done="onDone"
          >
          </ele-pro-table>
        </el-col>
      </el-row>
    </div>
    <div class="btns">
      <el-button type="primary" size="small" @click="selected">选择</el-button>
      <el-button size="small" @click="handleClose">关闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import {
    purchaseorderreceive,
    purchaseorderreceiveGetById
  } from '@/api/inspectionPlan/index.js';
  import searchWarehousing from './searchWarehousing.vue';

  export default {
    components: {
      searchWarehousing
    },
    props: {
      selectList: Array,
      type: {
        default: 2 //1多选 2单选
      }
    },
    data() {
      return {
        equipmentdialog: false,
        current: null,

        columns: [
          {
            width: 45,
            type: 'selection',
            columnKey: 'selection',
            align: 'center',
            reserveSelection: true,
            show: this.type == 1
          },
          {
            columnKey: 'index',
            label: '序号',
            type: 'index',
            width: 55,
            align: 'center',
            showOverflowTooltip: true
          },
          {
            prop: 'receiveNo',
            label: '收货单编码',
            align: 'center',
            slot: 'receiveNo',
            showOverflowTooltip: true,
            minWidth: 140
          },
          {
            prop: 'orderNo',
            label: '采购订单编码',
            align: 'center',
            slot: 'orderNo',
            showOverflowTooltip: true,
            minWidth: 140
          },
          {
            prop: 'batchNo',
            label: '批次号',
            align: 'center',
            slot: 'orderNo',
            showOverflowTooltip: true,
            minWidth: 140
          },

          {
            prop: 'productCode',
            label: '产品编号',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 140
          },
          {
            prop: 'productName',
            label: '产品名称',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 140
          },
          {
            prop: 'specification',
            label: '规格',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 140
          },
          {
            prop: 'modelType',
            label: '型号',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 140
          },
          {
            prop: 'productBrand',
            label: '牌号',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 140
          },

          {
            prop: 'supplierMark',
            label: '供应商代号',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 140
          },
          {
            prop: 'warehouseName',
            label: '仓库名称',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 140
          },
          {
            prop: 'totalCount',
            label: '进货数量',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 120
          },
          {
            prop: 'singlePrice',
            label: '单价',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 120
          },
          {
            prop: 'remark',
            label: '备注',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 120
          }
        ],
        categoryLevelId: null,
        code: null,
        selection: [],
        ids: []
      };
    },

    watch: {},
    methods: {
      datasource({ page, where, limit }) {
        return purchaseorderreceive({
          ...where,
          pageNum: page,
          reviewStatus: '2',
          size: limit,
          isQmsQuery:1
        });
      },
      open(ids) {
        this.equipmentdialog = true;
      },
      onDone() {
        this.$nextTick(() => {
          this.$refs.equiTable.setSelectedRowKeys(this.ids);
        });
      },
      handleClose() {
        this.equipmentdialog = false;
        this.$refs.equiTable.clearSelection();
      },
      // 选择
      async selected() {
        // let data = await purchaseorderreceiveGetById(this.current.id);

        // data['code'] = data.receiveNo;

        // data.productList = data.productList?.map((item) => {
        //   item['brandNo'] = item.productBrand;
        //   item['productNumber'] = item.totalCount;

        //   return item;
        // });
        this.$emit('choose', this.current);
        this.handleClose();
      },
      reload(where) {
        this.$refs.equiTable.reload({ page: 1, where });
      }
    }
  };
</script>

<style lang="scss" scoped>
  .tree_col {
    border: 1px solid #eee;
    padding: 10px 0;
    box-sizing: border-box;
    max-height: 530px;
    overflow: auto;
  }
  .table_col {
    padding-left: 10px;
    ::v-deep .el-table th.el-table__cell {
      background: #f2f2f2;
    }
  }
  .pagination {
    text-align: right;
    padding: 10px 0;
  }
  .btns {
    text-align: center;
    padding: 10px 0;
  }
  .topsearch {
    margin-bottom: 15px;
  }
</style>
