<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">
          <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 { warehousing} from '@/api/aps/index.js';


export default {
  components: {},
  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,
          fixed: 'left'
        },
        {
          prop: 'code',
          label: '编码',
          align: 'center',
          minWidth: 110
        },
        {
          prop: 'workOrderCode',
          label: '工单编码',
          align: 'center',
          minWidth: 110
        },
        {
          prop: 'warehouseName',
          label: '仓库名称	',
          align: 'center'
        },

        {
          prop: 'categoryLevelName',
          label: '物品分类',
          align: 'center'
        },
        {
          prop: 'categoryName',
          label: '名称',
          align: 'center'
        },
        { label: '型号', prop: 'modelType', width: '150' },
        { label: '规格', prop: 'specification', width: '150' },
        { label: '牌号', prop: 'brandNum', width: '50' },
        {
          slot: 'totalCount',
          label: '总数量',
          align: 'center'
        },

        {
          slot: 'totalPackage',
          label: '总包装',
          align: 'center'
        },

        {
          slot: 'totalWeight',
          label: '总重量',
          align: 'center'
        },
        {
          prop: 'type',
          label: '入库类型',
          align: 'center',
          formatter: (row, column, cellValue) => {
            return cellValue==1?'生产入库':""
          }
        },
        {
          prop: 'approvalUserName',
          label: '审核人',
          align: 'center'
        },

        {
          prop: 'createTime',
          label: '创建时间',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 110
        },
      ],
      categoryLevelId: null,
      code: null,
      selection: [],
      ids:[]
    };
  },

  watch: {},
  methods: {
    datasource({ page, where, limit }) {
      return warehousing({
        ...where,
        pageNum: page,
        size: limit
      });
    },
    open(ids) {
    
      this.equipmentdialog = true;

    
    },
    onDone(){
      this.$nextTick(() => {
        this.$refs.equiTable.setSelectedRowKeys(this.ids);
      });
    },
    handleClose() {
      this.equipmentdialog = false;
      this.$refs.equiTable.clearSelection();
    },
    // 选择
    selected() {
      let data=this.type==1?JSON.parse(JSON.stringify(this.selection)):JSON.parse(JSON.stringify(this.current))
      data['model']=data.specification
      data['productName']=data.categoryName
      data['productNumber']=data.totalCount
      data['productCode']=data.categoryCode
      
      this.$emit('choose', data);
      this.handleClose();
    }
  }
};
</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>
