<template>
  <div>
    <search :placeholder="placeholder" @searchActive="searchActive"></search>
    <tableLayout :layout="tablecols" :data="list" :opwidth="200" :custom="true" :height="tableHieght">
      <template v-slot:customcol="scope">
        <div v-if="scope.column.columnname === 'isonsale' ">
          <span v-if="scope.column.data[scope.column.columnname] === 0"
          >下架
          </span>
          <span v-if="scope.column.data[scope.column.columnname] === 1"
          >上架
          </span>
        </div>
        <p v-else-if="scope.column.columnname === 'status'">
          <span style="color:#52C41A" v-if="scope.column.data[[scope.column.columnname]] == '审核'">{{scope.column.data[[scope.column.columnname]]}}</span>
          <span style="color:#000000" v-else-if="scope.column.data[[scope.column.columnname]] == '新建'">{{scope.column.data[[scope.column.columnname]]}}</span>
        </p>
        <p v-else>{{scope.column.data[scope.column.columnname]}}</p>
      </template>
      <template v-slot:opreation="scope">
        <div>
          <slot name="del" :data="scope.data"></slot>
        </div>
      </template>
    </tableLayout>
    <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>
import search from './search'
export default {
  name: "relationList",
  props:["id"],
  data(){
    return {
      placeholder:'商品名称',
      tableHieght:420,
      list:[],
      tablecols:[],
      total:0,
      currentPage:0,
      params:{
        "id": "20220926102103",
        "version":1,
        "content": {
          "plm_technicalinfoid":this.id,
          "where":{
            "condition":"",
            "itemid":""
          }
        }
      }
    }
  },
  components:{
    search
  },
  mounted() {
    this.listData()
  },
  methods:{
    async listData(){
      const res = await this.$api.requested(this.params)
      this.list = res.data
      this.total = res.total
      this.currentPage = res.pageNumber
      console.log(this.currentPage);
      
      console.log(res)
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.params.content.pageSize = val
      this.listData()
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.params.content.pageNumber = val
      this.listData()
    },
    searchActive(data){
      this.params.content.where.condition = data
      this.listData()
    }
  },
  created() {
    this.tablecols = this.tool.tabelCol(this.$route.name).relationProductTable.tablecols
  }
}
</script>

<style scoped>

</style>