<template>
  <div>
    <div class="flex-align-center flex-between mt-10">
      <el-input style="width:200px" size="small"  suffix-icon="el-icon-search" v-model="params.content.where.condition" placeholder="产品名称,编号" @keyup.enter.native="listData(params.content.pageNumber = 1)" @clear="listData(params.content.pageNumber = 1)" clearable></el-input>
      <el-button type="primary" size="small" :disabled="tableSelectData.length === 0" @click="onConfirm">添加选中商品</el-button>
    </div>
    <el-table
      :data="tableData"
      style="width: 100%"
      size="small"
      border
      @selection-change="selectionChange">
      <el-table-column
        type="selection"
        width="55">
      </el-table-column>
      <el-table-column
        prop="itemno"
        label="产品编码"
        width="180">
      </el-table-column>
      <el-table-column
        prop="itemname"
        label="产品名称"
        width="180">
      </el-table-column>
      <el-table-column
        prop="model"
        label="型号"
        width="180">
      </el-table-column>
      <el-table-column
        prop="spec"
        label="规格尺寸"
        width="180">
      </el-table-column>
      <el-table-column
        prop="qty"
        label="装箱数量">
      </el-table-column>
    </el-table>
    <div style="margin-top:16px;text-align:right">
      <el-pagination
        background
        small
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-size="params.content.pageSize"
        layout="total, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  props:['sa_logistics_boxid'],
  data () {
    return {
      params:{
        "id": 20230110112204,
        "content": {
          "pageNumber": 1,
          "pageSize": 20,
          "sa_logisticsid":0,
          "sa_logistics_boxid":1,
          "where": {
            "condition": ""
          }
        }
      },
      tableSelectData:[],
      tableData:[],
      currentPage:0,
      total:0
    }
  },
  methods:{
    async listData () {
      this.params.content.sa_logisticsid = this.$route.query.id
      this.params.content.sa_logistics_boxid = this.sa_logistics_boxid
      const res = await this.$api.requested(this.params)
      res.data.forEach(e => {
        e.remarks = ''
      });
      this.tableData = res.data
      this.total = res.total
      this.currentPage = res.pageNumber
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.params.content.pageSize = val
      this.listData()
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.params.content.pageNumber = val
      this.listData()
    },
    selectionChange (val) {
      this.tableSelectData = val
    },
    onConfirm () {
      this.$emit('onConfirm',this.tableSelectData)
    },
  }
}

</script>
<style>
</style>