<template>
<div>
  <div class="flex-align-center flex-between mt-10">
    <div>
      <el-input class="inline-16" 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>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 -->
    </div>
    <el-button type="primary" size="small" :disabled="tableSelectData.length === 0" @click="onConfirm">添加选中商品</el-button>
  </div>
  <div>
    <el-table
      ref="multipleTable"
      :data="tableData"
      style="width: 100%"
      :header-cell-style="{height:'50px',color:'#768093',fontWeight:'400'}"
      :cell-style="{height:'50px',color:'#768093',fontWeight:'400'}"
      size="mini"
      height="calc(100vh - 260px)"
      border
      @selection-change="selectionChange">
      <el-table-column
        type="selection"
        width="55"
      fixed>
      </el-table-column>
      <el-table-column
        prop="itemname"
        label="商品名称"
        width="180">
      </el-table-column>
      <el-table-column
        prop="itemno"
        label="编码"
        width="180">
      </el-table-column>
      <el-table-column
        prop="erpitemname"
        label="品名"
        width="180">
        <template slot-scope="scope">
          {{ scope.row.erpitemname ? scope.row.erpitemname : '--' }}
        </template>
      </el-table-column>
      <el-table-column
        prop="erpitemno"
        label="品号"
        width="180">
        <template slot-scope="scope">
          {{ scope.row.erpitemno ? scope.row.erpitemno : '--' }}
        </template>
      </el-table-column>
      <el-table-column
        label="型号"
        width="180">
        <template slot-scope="scope">
          <p><span>{{scope.row.model}}</span></p>
        </template>
      </el-table-column>
      <el-table-column
          label="规格"
          width="180">
        <template slot-scope="scope">
          <p><span>{{scope.row.spec}}</span></p>
        </template>
      </el-table-column>
      <el-table-column
          label="材质"
          width="180">
        <template slot-scope="scope">
          <p><span>{{scope.row.material || '--'}}</span></p>
        </template>
      </el-table-column>
      <el-table-column
          label="标准"
          width="180">
        <template slot-scope="scope">
          <p><span>{{scope.row.standards || '--'}}</span></p>
        </template>
      </el-table-column>
      <el-table-column
        prop="unit"
        label="计量单位">
        <template slot-scope="scope">
          <el-tag size="mini" type="info" effect="plain">{{scope.row.unit}}/{{scope.row.auxunit}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="prodline"
        label="产线"
        width="100">
      </el-table-column>
      <el-table-column
        prop="device"
        label="装置"
        width="100">
      </el-table-column>
      <el-table-column
        prop="specalnote"
        label="特殊说明"
        width="100">
      </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>
</div>
</template>

<script>
import uploadFile from '@/components/upload/hw_obs_upload'
import previewImage from '@/components/previewImage/index'
import uploadAllData from '@/components/uploadAllData/index'

export default {
  props:['data','drawer'],
  data () {
    return {
      params:{
        "id": null,
        "content": {
            "sa_orderid": 0, //订单ID
            "pageNumber": 1,
            "pageSize": 20,
            "where": {
                "condition": ""
            }
        },
      },
      tableSelectData:[],
      tableData: [],
      total:0,
      currentPage:0,
      totalPage:0,
      progress:0,
      progressVisible:false,
      dataSize:200,
    }
  },
  components:{
    uploadFile,
    previewImage,
    uploadAllData
  },
  methods:{
    async listData () {
      switch (this.data.type) {
        case '标准订单':
          this.params.id = 20221109153502
          break;
        case '项目订单':
          this.params.id = 20230103155002
          break;
        case '促销订单':
          this.params.id = 20230107182302
          break;
        case '工具订单':
          this.params.id = 20221109153502
          break;
        default:
          this.params.id = 20221109153502
          break;
      } 
      this.params.content.sa_orderid = this.$route.query.id
      const res = await this.$api.requested(this.params)
      this.tableData = res.data
      this.total = res.total
      this.currentPage = res.pageNumber
      console.log(res,'mx')
    },
    handlePullApi (pullApi) {
      pullApi.content = JSON.parse(JSON.stringify(this.params.content))
      pullApi.id = JSON.parse(JSON.stringify(this.params.id))
      pullApi.content.sa_orderid = this.$route.query.id
    },
    handleUploadApi (uploadApi,data) {
      uploadApi.id = 20221109093602
      uploadApi.content = {
        "sa_orderid": this.$route.query.id, //订单ID
        "sys_enterpriseid": this.data.sys_enterpriseid, //企业ID
        "type": this.data.type, //订单类型
        "items": data.map(e=>{
          return {
            sa_orderitemsid:0,
            itemid:e.itemid,
            qty:e.orderminqty,
            needdate:e.deliverydate
          }
        })
      }
    },
    handleDelApi (delApi,data) {
      delApi.id = 20221109093702
      delApi.content = {
        "sa_orderid":this.$route.query.id,
        "sa_orderitemsids": data
      }
    },
    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.params.content.where.condition = ''
      this.$emit('onConfirm',this.tableSelectData,true)
      this.tableSelectData.forEach(v => {
        this.tableData.splice(this.tableData.findIndex(j => j.itemid == v.itemid),1)
      })
    },
    onSuccess () {
      this.tableData=[];
      this.$emit('onConfirm','1',false)
      this.total = 0
    },
    clearSelection () {
      this.$refs.multipleTable.clearSelection();
    }
  },
  mounted () {
    this.listData()
  },
  watch:{
    drawer (val) {
      val?this.listData():''
    }
  }
}

</script>
<style>
</style>
<style scoped>
.produtMag-panel{
  /* margin: 30px; */
  padding:0 10px 10px 10px;
  background: #fff;
  border-radius:5px;
  overflow: hidden;
  border:1px solid rgb(0 0 0 / 5%)
  /* box-shadow: 0 5px 5px rgb(0 0 0 / 10%);
  transform: translate3d(0,-2px,0); */
}
.image {
  width:40px;height:40px;margin:0px auto;
}
.el-table__fixed, .el-table__fixed-right{
height: calc(100% - 20px) !important;
}
/deep/.el-dialog__header {
  display: none !important;
}
</style>