<template>
  <div>
      <basicLayout
      ref="list"
      formPath="salerPrivatecustomer"
      tableName="salerPrivatecustomerTable"
      idName="sa_customersid"
      :apiId="{query:20221012164402,del:''}"
      :autoQuery="false"
      :detailPath="{path:'/customerDetail',param:{tabIndex:tabIndex}}">
      <!-- <template v-slot:tempChild="scope">
        <el-select v-if="scope.data === 'type'" class="inline-16" v-model="selectParam.type" size="mini" placeholder="请选择" @change="selectChange" clearable>
          <el-option
              v-for="item in option.typeData"
              :key="item.value"
              :label="item.value"
              :value="item.value">
          </el-option>
        </el-select>
        <el-select v-if="scope.data === 'customergrade'" v-model="selectParam.customergrade" size="mini" placeholder="请选择" @change="selectChange" clearable>
          <el-option
              v-for="item in option.gradeData"
              :key="item.value"
              :label="item.value"
              :value="item.value">
          </el-option>
        </el-select>
        <el-select v-if="scope.data === 'industry'" v-model="selectParam.industry" size="mini" placeholder="请选择" @change="selectChange" clearable>
          <el-option
              v-for="item in option.industryData"
              :key="item.value"
              :label="item.value"
              :value="item.value">
          </el-option>
        </el-select>
        <el-select v-if="scope.data === 'status'" v-model="selectParam.status" size="mini" placeholder="请选择" @change="selectChange" clearable>
          <el-option
              v-for="item in option.status"
              :key="item.value"
              :label="item.value"
              :value="item.value">
          </el-option>
        </el-select>
      </template> -->
      <template #custom>
        <div class="mt-10">
          <label class="search__label">范围:</label>
          <el-select class="inline-16" v-model="value" size="small" placeholder="请选择数据分类" @change="selectChange" clearable>
            <el-option
              v-for="item in editableTabs"
              :key="item.index"
              :label="item.title"
              :value="item.name">
            </el-option>
          </el-select>
        </div>
        <div  class="mt-10">
          <label class="search__label">客户类型:</label>
          <el-select class="inline-16" v-model="selectParam.type" size="small" placeholder="请选择" @change="selectChange" clearable>
            <el-option
                v-for="item in option.typeData"
                :key="item.value"
                :label="item.value"
                :value="item.value">
            </el-option>
          </el-select>
        </div>
        <div  class="mt-10">
          <label class="search__label">客户等级:</label>
          <el-select  class="inline-16" v-model="selectParam.customergrade" size="small" placeholder="请选择" @change="selectChange" clearable>
            <el-option
                v-for="item in option.gradeData"
                :key="item.value"
                :label="item.value"
                :value="item.value">
            </el-option>
          </el-select>
        </div>
        <div  class="mt-10">
          <label class="search__label">所属行业:</label>
          <el-select  class="inline-16" v-model="selectParam.industry" size="small" placeholder="请选择" @change="selectChange" clearable>
            <el-option
                v-for="item in option.industryData"
                :key="item.value"
                :label="item.value"
                :value="item.value">
            </el-option>
          </el-select>
        </div>
        <div  class="mt-10">
            <label class="search__label">合作状态:</label>
          <el-select  class="inline-16" v-model="selectParam.status" size="small" placeholder="请选择" @change="selectChange" clearable>
            <el-option
                v-for="item in option.status"
                :key="item.value"
                :label="item.value"
                :value="item.value">
            </el-option>
          </el-select>
        </div>
        <div  class="mt-10">
          <label class="search__label" >创建时间:</label>
          <el-date-picker
              style="margin-right: 24px !important;"
              size="small"
              @change="selectChange"
              value-format="yyyy-MM-dd"
              v-model="dateSelect"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              clearable>
          </el-date-picker>
        </div>
      </template>
      <template v-slot:tbList="scope">
        <div v-if="scope.data.column.columnname === 'isleader'">
          <span v-if="scope.data.column.data['leader'].length !== 0">已分配</span>
          <span v-else>未分配</span>
        </div>
        <div v-else-if="scope.data.column.columnname === 'contact'">
          <span>{{scope.data.column.data['leader'][0]?scope.data.column.data['leader'][0].name:'--'}}</span>
        </div>
        <div v-else>
          {{scope.data.column.data[[scope.data.column.columnname]]?scope.data.column.data[[scope.data.column.columnname]]:'--'}}
        </div>
      </template>
    </basicLayout>
  </div>
</template>

<script>
export default {
  name: "index",
  data() {
    return {
      value:'1',
      editableTabsValue: "我负责的",
      editableTabs: [{
        title: '我负责的',
        name: "1",
      }, {
        title: '我参与的',
        name: "2",
      }, {
        title: '我下属负责的',
        name: "3",
      }, {
        title: '我下属参与的',
        name: "4",
      }],
      tabIndex:"1",
      options:[],
      listData:[],
      option:{
        typeData:[],
        gradeData:[],
        industryData:[],
        status:[
          {
            value:'潜在'
          },
          {
            value:'合作中'
          },
          {
            value:'已终止'
          }
        ]
      },
      selectParam: {
        status:'',
        type:'',
        customergrade:'',
        industry:'',
        startdate:'',
        enddate:'',

      },
      dateSelect:''
    }
  },
  mounted() {
    this.queryData('1')
    this.typeList()
    this.gradeList()
    this.industryList()
  },
  methods:{
    queryData(id){
      this.$refs['list'].param.content.type = id
      this.$refs['list'].param.content.isExport = false
      this.$refs['list'].listData()
      // this.$store.dispatch('sendDataToForm',)
    },
    handleCommand(command){
      this.tabIndex = command.name
      this.editableTabsValue = command.title
      this.selectChange()
      /*this.$refs['list'].param.content.type = command.name
      this.$refs['list'].param.content.isExport = 0
      this.$refs['list'].listData()*/
      // this.$store.dispatch('sendDataToForm',)
    },
    /*客户类型列表*/
    async typeList(){
      const res = await this.$api.requested({
        "classname": "sysmanage.develop.optiontype.optiontype",
        "method": "optiontypeselect",
        "content": {
          "pageNumber": 1,
          "pageSize": 20,
          "typename": "customertypemx",
          "parameter": {
            "siteid": "YOSTEST2"
          }
        }
      })
      this.option.typeData = res.data
      console.log("客户类型",res.data)
      console.log(this.option.typeData)

    },
    /*客户等级*/
    async gradeList(){
      const res = await this.$api.requested({
        "classname": "sysmanage.develop.optiontype.optiontype",
        "method": "optiontypeselect",
        "content": {
          "pageNumber": 1,
          "pageSize": 20,
          "typename": "customergrade",
          "parameter": {
            "siteid": "YOSTEST2"
          }
        }
      })
      console.log("客户等级",res.data)
      /*for (var i=0;i<res.data.length; i++){
        if (res.data[i].remarks !== ''){
          this.options.gradeData[i] = res.data[i].value + "——" + res.data[i].remarks
        }else{
          this.options.gradeData[i] = res.data[i].value
        }
      }*/
      this.option.gradeData = res.data
      console.log("处理后客户等级",this.option.gradeData)
    },
    /*行业列表*/
    async industryList(){
      const res = await this.$api.requested({
        "classname": "sysmanage.develop.optiontype.optiontype",
        "method": "optiontypeselect",
        "content": {
          "pageNumber": 1,
          "pageSize": 20,
          "typename": "industry",
          "parameter": {
            "siteid": "YOSTEST2"
          }
        }
      })
      this.option.industryData = res.data
    },
    selectChange(){
      this.tabIndex = this.value
      if (this.dateSelect !== '' && this.dateSelect !== null){
        this.selectParam.startdate = this.dateSelect[0]
        this.selectParam.enddate = this.dateSelect[1]
      }else {
        this.selectParam.startdate = ''
        this.selectParam.enddate = ''
      }
      this.$refs.list.param.content.type = this.tabIndex
      this.$refs.list.param.content.where = Object.assign({},this.$refs.list.param.content.where,this.selectParam) 
      this.$refs.list.param.content.phonenumber = 1
      this.$refs['list'].listData()
    }
  },
  created() {

  },
}
</script>

<style scoped>
.el-dropdown-link {
  cursor: pointer;
  color: #151515;
  font-size: 16px;
}
.el-divider--vertical{
  margin: 0 16px;
}
.el-icon-arrow-down {
  font-size: 16px;
}
.s_panel {
  margin-bottom:10px
}
</style>