<template>
  <div>
    <basicLayout
        ref="basicLayout"
        tableName="customerTable"
        idName="sa_customersid"
        :apiId="{query:20221012164402,del:''}"
        :autoQuery="false"
        @checkboxCallBack="checkboxCallBack"
    >
      <template #titleLight>
        <batchDeletion v-if="tool.checkAuth($route.name,'batchDeletion')" ref="batchDeletion" :ownerids="selectData" :sys_object="application" @delSuccess="queryData"></batchDeletion>
        <batchRecovery v-if="tool.checkAuth($route.name,'batchRecovery')" ref="batchRecovery" :ownerids="selectData" :sys_object="application" @recoverySuccess="queryData"></batchRecovery>
      </template>
      <template #custom>
        <div class="mt-10">
          <p class="search__label">应用:</p>
          <el-select
              class="inline-24"
              size="small"
              v-model="application"
              placeholder="请选择范围"
              @change="applicationChange"
          >
            <el-option
                v-for="item in applicationList"
                :key="item.index"
                :label="item.label"
                :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.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 === 'tag'">
          <div v-for="item in scope.data.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.data.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>
        <div v-else-if="scope.data.column.columnname === 'tradingstatus'">
          <span style="color:#3874f6" v-if="scope.data.column.data[[scope.data.column.columnname]] == '未成交'">{{scope.data.column.data[[scope.data.column.columnname]]}}</span>
          <span style="color:#fa8c16" v-else-if="scope.data.column.data[[scope.data.column.columnname]] == '已成交'">{{scope.data.column.data[[scope.data.column.columnname]]}}</span>
          <span style="color:#333333" v-else-if="scope.data.column.data[[scope.data.column.columnname]] == '多次成交'">{{scope.data.column.data[[scope.data.column.columnname]]}}</span>
        </div>
        <div v-else-if="scope.data.column.columnname === 'status'">
          <span style="color:#3874f6" v-if="scope.data.column.data[[scope.data.column.columnname]] == '潜在'">{{scope.data.column.data[[scope.data.column.columnname]]}}</span>
          <span style="color:#52c41a" v-else-if="scope.data.column.data[[scope.data.column.columnname]] == '合作中'">{{scope.data.column.data[[scope.data.column.columnname]]}}</span>
          <span style="color:#999999" v-else-if="scope.data.column.data[[scope.data.column.columnname]] == '已终止'">{{scope.data.column.data[[scope.data.column.columnname]]}}</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>
      <template v-slot:tbOpreation="scope">
        <delData class="inline-16" :ownerid="scope.data.data.sa_customersid" :sys_object="application" @delSuccess="queryData"></delData>
        <recovery class="inline-16" :ownerid="scope.data.data.sa_customersid" :sys_object="application" @recoverySuccess="queryData"></recovery>
      </template>
    </basicLayout>
  </div>
</template>

<script>
import recovery from "@/HManagement/ecycle/modules/recovery";
import delData from "@/HManagement/ecycle/modules/delData";
import batchDeletion from "@/HManagement/ecycle/modules/batchDeletion";
import batchRecovery from "@/HManagement/ecycle/modules/batchRecovery";

export default {
  name: "index",
  data () {
    return {
      application:'2',
      applicationList:[
        {
          label: '销售线索',
          value: "1",
        },
        {
          label: '客户',
          value: "2",
        },
        {
          label: '合同',
          value: "3",
        },
        {
          label: '项目商机',
          value: "4",
        },
        {
          label: '报价单',
          value: "5",
        }
      ],
      option:{
        typeData:[],
        gradeData:[],
        industryData:[],
        status:[
          {
            value:'潜在'
          },
          {
            value:'合作中'
          },
          {
            value:'已终止'
          }
        ]
      },
      selectParam: {
        status:'',
        type:'',
        customergrade:'',
        industry:'',
        startdate:'',
        enddate:'',

      },
      dateSelect:'',
      selectData:[]
    }
  },
  components:{recovery,delData,batchDeletion,batchRecovery},
  methods:{
    queryData(){
      this.$refs.basicLayout.param.content.isAll = 0
      this.$refs.basicLayout.param.content.type = 0
      this.$refs.basicLayout.param.content.deleted = 1
      this.$refs.basicLayout.listData()
    },
    applicationChange(val){
      console.log(val)
      this.$emit("changeApplication",val)
    },
    /*客户类型列表*/
    async typeList(){
      const siteid = JSON.parse(sessionStorage.getItem('active_account')).siteid
      const res = await this.$api.requested({
        "classname": "sysmanage.develop.optiontype.optiontype",
        "method": "optiontypeselect",
        "content": {
          "pageNumber": 1,
          "pageSize": 20,
          "typename": "customertypemx",
          "parameter": {
            "siteid": siteid
          }
        }
      })
      this.option.typeData = res.data
      console.log("客户类型",res.data)
      console.log(this.option.typeData)

    },
    /*客户等级*/
    async gradeList(){
      const siteid = JSON.parse(sessionStorage.getItem('active_account')).siteid
      const res = await this.$api.requested({
        "classname": "sysmanage.develop.optiontype.optiontype",
        "method": "optiontypeselect",
        "content": {
          "pageNumber": 1,
          "pageSize": 20,
          "typename": "customergrade",
          "parameter": {
            "siteid": siteid
          }
        }
      })
      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 siteid = JSON.parse(sessionStorage.getItem('active_account')).siteid
      const res = await this.$api.requested({
        "classname": "sysmanage.develop.optiontype.optiontype",
        "method": "optiontypeselect",
        "content": {
          "pageNumber": 1,
          "pageSize": 20,
          "typename": "industry",
          "parameter": {
            "siteid": siteid
          }
        }
      })
      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.basicLayout.param.content.type = 0
      this.$refs.basicLayout.param.content.where = Object.assign({},this.$refs.basicLayout.param.content.where,this.selectParam)
      this.$refs.basicLayout.param.content.phonenumber = 1
      this.$refs['basicLayout'].listData()
    },
    checkboxCallBack(val){
      console.log(val,"客户")
      this.selectData = []
      val.forEach((item,index) => {
        this.selectData[index] = item.sa_customersid
      })
      this.$refs.batchDeletion.length = this.selectData.length
      this.$refs.batchRecovery.length = this.selectData.length
      console.log(this.selectData)
    }
  },
  mounted() {
    this.queryData()
    this.typeList()
    this.gradeList()
    this.industryList()
  },
}
</script>

<style scoped>

</style>