<template>
  <div>
    <div>
      <el-input style="width:200px;" placeholder="搜索" :suffix-icon="params.content.where.condition?params.content.where.condition.length > 0?'':'':'el-icon-search'" v-model="params.content.where.condition" @keyup.native.enter="listData(params.content.pageNumber = 1)" @clear="clearSearchValue" size="small" class="input-with-select inline-16 layout_search__panel" clearable>
      </el-input>
    </div>
    <div style="margin-top: 15px">
      <tableLayout :layout="tablecols" :data="list" :opwidth="200" :custom="true"  fixedName="operation" :height="tableHieght">
        <template v-slot:customcol="scope">
          <div v-if="scope.column.columnname === 'status'">
            <span style="color:#3874f6" v-if="scope.column.data[[scope.column.columnname]] == '新建'">{{scope.column.data[[scope.column.columnname]]}}</span>
            <span style="color:#52c41a" v-else-if="scope.column.data[[scope.column.columnname]] == '已提交'">{{scope.column.data[[scope.column.columnname]]}}</span>
            <span style="color:#333333" v-else-if="scope.column.data[[scope.column.columnname]] == '审核'">{{scope.column.data[[scope.column.columnname]]}}</span>
            <span style="color:#000000" v-else>{{scope.column.data[[scope.column.columnname]]}}</span>
          </div>
          <div v-else-if="scope.column.columnname === 'operation'">
            <span>{{scope.column.data[scope.column.columnname]}}</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 :data="scope.data" class="inline-16" @editSuccess="onSuccess"></edit>
           <delContact :data="scope.data" @delSuccess="onSuccess" class="inline-16"></delContact> -->
          <el-button   type="text" size="mini" @click="goDetail(scope.data)">详 情</el-button>
        </template>
      </tableLayout>
    </div>
    <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>
export default {
  name: "index",
  props:["data"],
  data(){
    return {
      tablecols:[],
      tableHieght:600,
      list:[],
      total:0,
      currentPage:0,
      params:{
        "content": {
          "sys_enterpriseid": '',
          "pageNumber": 1,
          "pageSize": 20,
          "where": {
            "condition": "",
            "tablefilter": {}
          }
        },
        "id": 20230214163402,
      }
    }
  },
  methods:{
    async listData(){
      this.params.content.sys_enterpriseid = this.data.sys_enterpriseid
      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()
    },
    goDetail (data) {
      let type
      data.type == '项目'
          ? data.typemx == '直销'
              ? type = '直销项目' : type = '经销项目'
          : type = data.type
      JSON.parse(sessionStorage.getItem('module_info')).forEach(item1 => {
        item1.modules.forEach(item2 => {
          if(item2.systemmodulename == "合同管理") {
            let route = this.$route
            if (route.path !== '/contractDetail') {
              this.oldRoute = {path:route.path,query:route.query}
              this.$store.dispatch('setHistoryRouter',this.oldRoute)
            }
            sessionStorage.setItem('active_modules',JSON.stringify(item2))
            this.$router.push({path:'/contractDetail',query:{id:data.sa_contractid,type:type}})
            return
          }
        })
      })
    },
    clearSearchValue(){
      this.listData(this.params.content.pageNumber = 1)
    }
  },
  mounted() {
    this.listData()
  },
  created() {
    this.tablecols = this.tool.tabelCol(this.$route.name).contractTable.tablecols
  }
}
</script>

<style scoped>

</style>