<template>
  <div>
      <basicLayout
      ref="list"
      formPath="salerPrivatecustomer"
      tableName="salerPrivatecustomerTable"
      idName="sa_customersid"
      :apiId="{query:20221012164402,del:''}"
      :autoQuery="false"
      :detailPath="{path:'/customerDetail',param:{tabIndex:tabIndex}}"
      @listCreate="list">
      <template #custom>
        <div class="mt-10">
          <label class="search__label">范围:</label>
          <el-select class="inline-16" v-model="value" size="small" placeholder="请选择数据分类" @change="selectChange" >
            <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-select  class="inline-16" v-model="selectParam.tradingstatus" size="small" placeholder="请选择" @change="selectChange" clearable>
            <el-option
                v-for="item in option.tradingstatus"
                :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 === 'industry'">
          <span v-if="JSON.stringify(scope.data.column.data.industry) !== '[]' && scope.data.column.data.industry">
            <div v-for="item in scope.data.column.data.industry" :key="item.index"  style="float: left;margin-left: 5px;margin-bottom: 5px">
              <el-tag size="mini"  effect="dark">
                <span>{{item}}</span>
              </el-tag>
            </div>
          </span>
          <div v-else>
            {{'--'}}
          </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>
    </basicLayout>
  </div>
</template>

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

      },
      dateSelect:''
    }
  },
  mounted() {
    this.queryData('1')
    this.typeList()
    this.gradeList()
    this.industryList()
  },
  methods:{
    list (param) {
      param.content.isend = 0
      param.content.type = 0
      param.content.isExport = 0
    },
    queryData(id){
      this.$refs['list'].param.content.type = id
      this.$refs['list'].param.content.isExport = false
      this.$refs.list.param.content.deleted = 0
      this.$refs.list.param.content.isend = 0
      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()
    },
    async queryUserInfo() {
      let res = await this.$api.requested({
        "classname": "common.usercenter.usercenter",
        "method": "queryUserMsg",
        "content": {
        }
      })
      console.log(res.data);

      this.userInfo = {
        isAuth : res.data.hr.isleader,
        userid: res.data.hr.userid
      }
      console.log(this.userInfo,'user')
      window.sessionStorage.setItem('userInfo',JSON.stringify(this.userInfo))
      console.log(JSON.parse(window.sessionStorage.getItem('userInfo')));

    },
  },
  created() {
    this.queryUserInfo()
  },
}
</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>