<template>
<div> 
  <div class="flex-align-center flex-between normal-margin">
    <slot name="operation"></slot>
    <div class="flex-align-center">
      <el-input 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>&nbsp;
    </div>
  </div>
  <div class="produtMag-panel">
    <el-table
      ref="multipleTable"
      :data="tableData"
      style="width: 100%"
      :header-cell-style="{height:'50px',color:'#606266',fontWeight:'400'}"
      :cell-style="{height:'50px',color:'#666666',fontWeight:'400'}">
      <el-table-column
          align="center"
          label="产品图"
          width="80">
        <template slot-scope="scope">
          <div v-if="scope.row.attinfos[0]">
            <previewImage style="height:38px;width:38px" :image="scope.row.attinfos[0]" :list="scope.row.attinfos" :deletebtn="false"></previewImage>
          </div>
        </template>
      </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
          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
          prop="caliber"
          label="口径"
          width="180">
      </el-table-column>
      <el-table-column
          prop="pressure"
          label="压力"
          width="180">
      </el-table-column>
      <el-table-column
          prop="material"
          label="材质"
          width="180">
      </el-table-column>
      <el-table-column
          prop="brand"
          label="品牌"
          width="180">
        <template slot-scope="scope">
          <p v-for="(item,index) in scope.row.brand" :key="index">
            <span style="float: left" v-if="index === scope.row.brand.length -1">{{item?item.brandname+'':'--'}}</span>
            <span style="float: left" v-else>{{item?item.brandname+',':'--'}}</span>
          </p>
        </template>
      </el-table-column>
      <el-table-column
          prop="itemclass"
          label="类别"
          width="180">
        <template slot-scope="scope">
          <span v-for="(item,index) in scope.row.itemclass" :key="index">
            {{item?item.itemclassname+',':'--'}}
          </span>
        </template>
      </el-table-column>
      <el-table-column
          prop="unitid"
          label="计量单位"
          width="100">
        <template slot-scope="scope">
          <el-tag size="mini" type="info" effect="plain">{{scope.row.unitname}}/{{scope.row.axunitname}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
          prop="marketprice"
          label="牌价"
          width="100">
      </el-table-column>
      <el-table-column
          label="操作"
          fixed="right">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addProduct(scope.row)">添 加</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div style="margin-top:16px;float:right">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-size="params.content.pageSize"
        layout="total,sizes, 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'

export default {
  props:['id'],
  data () {
    return {
      params:{
        "id": 20220923112503,
        "content": {
          "nocache":true,
          "pageNumber": 1,
          "pageSize": 20,
            "sa_itemgroupid":0,
            "where": {
              "condition": ''
            }
        }
      },
      tableSelectData:[],
      tableData: [],
      total:0,
      currentPage:0
    }
  },
  components:{
    uploadFile,
    previewImage
  },
  methods:{
    async listData () {
      this.params.content.sa_itemgroupid = this.id ? this.id : 0
      const res = await this.$api.requested(this.params)
      this.tableData = res.data
      this.total = res.total
      this.currentPage = res.pageNumber
      console.log(this.tableData);
      
    },
    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
      this.$emit('selectionChange',val)
    },
    clearSelection () {
      this.$refs.multipleTable.clearSelection();
    },
    addProduct (row) {
      this.$emit('addProduct',row)
      this.tableData.splice(this.tableData.findIndex(item => item.itemid == row.itemid),1)
    }
  },
  mounted () {
    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;
}
</style>