<template>
  <div>
    <div>
      <add class="inline-16" v-if="tool.checkAuth($route.name,'andEnterpriseManage') && rowData.disabled"  :data="rowData" @addSuccess="onSuccess"></add>
      <el-input
          placeholder="请输入搜索内容"
          :suffix-icon="params.content.where.condition?params.content.where.condition.length > 0?'':'':'el-icon-search'"
          v-model="params.content.where.condition"
          style="width:200px"
          size="small"
          class="input-with-select inline-16"
          @keyup.native.enter="listData(params.content.pageNumber = 1)"
          @clear="clearData"
          clearable>
      </el-input>
    </div>
    <div style="margin-top: 15px">
      <tableLayout :layout="tablecols" :data="list" :opwidth="200" :custom="true"  :height="tableHieght" fixedName="operation">
        <template v-slot:customcol="scope">
          <div v-if="scope.column.columnname === 'province'">
            <p>{{ scope.column.data.province + '-' + scope.column.data.city + '-' + scope.column.data.county}}</p>
          </div>
          <div v-else-if="scope.column.columnname === 'operation'">
            <span>{{scope.column.data[scope.column.columnname]}}</span>
          </div>
          <div v-else-if="scope.column.columnname === 'enterprisename'">
            <span v-if="scope.column.data.sa_agentsid === 0">{{scope.column.data[scope.column.columnname]}}</span>
            <span v-else>
              {{scope.column.data[scope.column.columnname]}}
              <el-tag style="margin-left: 5px" type="warning" size="mini">经销商</el-tag>
            </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" :disabled="rowData.disabled"></edit>-->
          <set_customer_type  class="inline-16" :data="scope.data" @setSuccess="onSuccess" :disabled="rowData.disabled"></set_customer_type>
          <to_del  class="inline-16" :data="scope.data" @toDelSuccess="onSuccess" :disabled="rowData.disabled"></to_del>
        </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>
/*import Contact from './components/Contact'*/
import add from './components/add'
import edit from './components/edit'
import to_del from './components/toDel'
import set_customer_type from './components/setCustomerType'
export default {
  components:{add,edit,to_del,set_customer_type},
  name: "index",
  props:["rowData"],
  data() {
    return {
      enterpriseTypeList:'',
      tableHieght:"600px",
      tablecols:[],
      list:[],
      total:0,
      currentPage:0,
      search:"",
      params:{
        "id": 20221027143702,
        "content": {
          "sa_projectid":'',
          "pageNumber": 1,
          "pageSize": 20,
          "where": {
            "condition": ""
          }
        },
      }
    }
  },
  provide(){
    return {
      enterpriseType:() => this.enterpriseTypeList
    }
  },
  methods: {
    /*list (param) {
      param.content.sa_projectid = this.$route.query.id
    },*/
    async listData(){
      console.log(this.rowData)
      this.params.content.sa_projectid = this.rowData.sa_projectid
      const res = await this.$api.requested(this.params)
      this.list = res.data
      this.total = res.total
      console.log(this.list)
    },
    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()
      this.$emit("changeSuccess")
    },
    clearData(){
      this.params.content.pageNumber = 1
      this.listData()
    },
    /*获取客户类型*/
    async enterpriseType(){
      const res = await this.$api.requested({
        "classname": "sysmanage.develop.optiontype.optiontype",
        "method": "optiontypeselect",
        "content": {
          "pageNumber": 1,
          "pageSize": 20,
          "typename": "customertypemx",
          "parameter": {
          }
        }
      })
      this.enterpriseTypeList = res.data
      console.log(this.enterpriseTypeList,"客户类型")
    }
  },
  mounted() {
    this.listData()
  },
  created() {
    this.tablecols = this.tool.tabelCol(this.$route.name).andEnterpriseTable.tablecols
    console.log(this.tablecols,"tablecols")
    this.enterpriseType()
  },
}
</script>

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