
<template>
  <div>
    <div style="margin-bottom: 15px">
      <add v-if="tool.checkAuth($route.name,'rivalManage') && data.disabled" class="inline-16" :data="data" @addSuccess="onSuccess"></add>
      <el-input
          size="small"
          style="width: 200px;"
          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>
    <tableLayout :layout="tablecols" :data="list" :opwidth="200" :custom="true"  fixedName="operation">
      <template v-slot:customcol="scope">
        <div v-if="scope.column.columnname === 'important'">
          <span>{{scope.column.data[scope.column.columnname] === 1 ? '是' : '否'}}</span>
        </div>
        <div v-else-if="scope.column.columnname === 'operation'">
          <span></span>
        </div>
        <p v-else>{{scope.column.data[scope.column.columnname]?scope.column.data[scope.column.columnname]:'--'}}</p>
      </template>
      <template v-slot:opreation="scope">
        <edit class="inline-16" :data="scope.data" @updateSuccess="onSuccess"></edit>
        <el-popconfirm
            confirm-button-text='确定'
            cancel-button-text='取消'
            icon="el-icon-info"

            title="确定删除该竞争对手吗？"
            @confirm="onDel(scope.data.sa_project_competeid)"
        >
          <el-button slot="reference" size="mini" type="text" >删 除</el-button>
        </el-popconfirm>

      </template>
    </tableLayout>
    <div class="container normal-panel" style="text-align:right">
      <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[20, 50, 100, 200]"
          layout="total,sizes, prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import add from './modules/add'
import edit from './modules/edit'
export default {
  props:["data"],
  data () {
    return {
      options:[],
      tablecols:[],
      list:[],
      total:0,
      currentPage:0,
      params:{
        "id": 20221027165402,
        "content": {
          "sa_projectid":"",
          "pageNumber": 1,
          "pageSize": 20,
          "where": {
            "condition": ""
          }
        }
      }
    }
  },
  provide () {
    return {

    }
  },
  components:{add,edit},
  methods:{
    /*list (param) {
      param.content.sa_projectid = this.$route.query.id
    },*/
    async listData(){
      this.params.content.sa_projectid = this.data.sa_projectid
      const res = await this.$api.requested(this.params)
      this.list = res.data
      this.total = res.total
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.params.content.pageSize = val
      this.listData()
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.params.content.pageNumber = val
      this.listData()
    },
    onSuccess(){
      this.listData()
    },
    async onDel(id){
      console.log(id)
      const res = await this.$api.requested({
        "id": 20221019165902,
        "content": {
          "sa_project_competeids": [id],
          "deletereason":""
        },
      })
      this.tool.showMessage(res,()=>{
        this.listData()
      })
    }
  },
  mounted() {
    this.listData()
  },
  created() {
    this.tablecols = this.tool.tabelCol(this.$route.name).rivalTable.tablecols
  }
}

</script>
<style scoped>
/* /deep/.el-table__cell .cell {
  display: flex;
  justify-content: s;
} */
</style>