<template>
  <div>
<!--    <add class="normal-margin" :data="data" @insertSuccess="onSuccess" style="float: left;"></add>-->
    <div class="normal-margin" style="width: 20%;">
      <el-input
          placeholder="请输入内容"
          v-model="search"
          clearable
          @clear="clearData()"
          size="small"
          @keyup.enter.native="queryClick()">
        <i slot="prefix" class="el-icon-search" @click="queryClick()"></i>
      </el-input>
    </div>
    <tableLayout :layout="tablecols" :data="list" :opwidth="200" :custom="true"  height="calc(100vh - 340px)" fixedName="important,operation">
      <template v-slot:customcol="scope">
        <div v-if="scope.column.columnname === 'important'">
          <p v-if="scope.column.data.important === 0">否</p>
          <p v-else-if="scope.column.data.important === 1">是</p>
        </div>
        <div v-else-if="scope.column.columnname === 'tag'">
          <div v-for="item in scope.column.data.tag_sys" :key="item.index"  style="float: left;margin-left: 5px;margin-bottom: 5px">
            <el-tag  color="#FA8C16" size="mini" type="warning" effect="dark">
              <span>{{item}}</span>
            </el-tag>
          </div>
          <div v-for="item in scope.column.data.tag" :key="item.index"  style="float: left;margin-left: 5px;margin-bottom: 5px">
            <el-tag color="#FAAB16" size="mini" type="warning" effect="dark">
              <span>{{item}}</span>
            </el-tag>
          </div>
        </div>
        <p v-else>{{scope.column.data[scope.column.columnname]}}</p>
      </template>
      <template v-slot:opreation="scope">
        <el-button  size="mini" type="text" @click="detailGo(scope.data)">详 情</el-button>
      </template>
<!--      <template v-slot:opreation="scope">
        <edit v-if="tool.checkAuth($route.name,'update')" :data="scope.data" @updateSuccess="onSuccess"></edit>
        <toVoid v-if="tool.checkAuth($route.name,'toVoid')" :data="scope.data" @toVoidSuccess="onSuccess"></toVoid>
      </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 add from './modules/add'
import edit from './modules/edit'
import toVoid from './modules/toVoid'
export default {
  name: "list",
  props:["data"],
  data() {
    return {
      tableHieght:520,
      tablecols:[],
      list:[],
      total:0,
      currentPage:0,
      search:"",
      params:{
        "id": 20221019170002,
        "content": {
          "sa_competitorid": '',
          "pageNumber": 1,
          "pageSize": 20,
          "where": {
            "condition": ""
          }
        },
      }
    }
  },
  components:{
    add,edit,toVoid
  },
  methods:{
    async listData(){
      console.log("项目商机")
      console.log(this.data)
      this.params.content.sa_competitorid = this.data.sa_competitorid
      const res = await this.$api.requested(this.params)
      console.log("输出项目商机")
      console.log(res)
      this.list = res.data
      this.total = res.total
      /*this.currentPage = res.pageTotal*/
    },
    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()
    },
    clearData(){
      this.search = ""
    },
    queryClick(){
      this.params.content.where.condition = this.search
      this.listData()
    },
    detailGo(row){
      console.log(row)
      let route = this.$route
      if (route.path !== '/projectChangeDetail') {
        this.oldRoute = {path:route.path,query:route.query}
        this.$store.dispatch('setHistoryRouter',this.oldRoute)
      }
      this.$router.push({
        path:'/projectChangeDetail',
        query:{
          id:row.sa_projectid,
          rowindex:row.rowindex
        }
      })
    },
  },
  mounted() {
    this.listData()
  },
  created() {
    this.tablecols = this.tool.tabelCol(this.$route.name).projectOpportunitiesTable.tablecols
  }
}
</script>

<style scoped>
/deep/.el-input__prefix {
  display: flex;
  align-items: center;
}

</style>