<template>
  <div>
    <basicDetails
        ref="details"
        :titleText="mainData.name"
        :oldFormPath="{
          edit:'HManagement/clueManage/clue_private/modules',
          add:'HManagement/clueManage/clue_private/modules',
        }"
        :editData="mainData"
        :mainAreaData="mainAreaData"
        turnPageId="20221101094302"
        delApiId="20221101100502"
        idname="sat_orderclueid"
        :tabs="['详细信息','跟进记录']"
        @pageChange="pageChange"
        @onEditSuccess="queryMainData($route.query.id)">
      <div slot="tags">
      </div>
      <div slot="customOperation">
        <recall class="inline-16" v-if="mainData.status === '待跟进' || mainData.status === '跟进中' && mainData.isTeam !== '团队' && tool.checkAuth($route.name,'recall')" :data="mainData" @onSuccess="queryMainData"></recall>
      </div>
      <div slot="slot0" class="container normal-panel">
        <BaseInfo :detailInfo="detailInfo"/>
      </div>
      <div slot="slot1" class="container normal-panel">
        <el-descriptions>
          <div slot="title">跟进记录<i @click="followRecord(isdesc === 1?isdesc = 0:isdesc =1)" :class="isdesc === 1?'fa fa-sort-amount-asc':'fa fa-sort-amount-desc'"></i></div>
        </el-descriptions>
        <div class="flex-align-center normal-margin">
          <p>日期:&nbsp;</p>
          <el-date-picker
            v-model="value2"
            type="daterange"
            align="right"
            unlink-panels
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd"
            size="small"
            @change="dateChange"
            clearable>
          </el-date-picker>
        </div>
        <div v-for="(item,index) in recordlist" :key="item.index" class="follow-item">
          <p>{{index + 1}}.&nbsp;{{item.createdate}},由经销商端<b>{{item.createby}}</b>{{item.logtype}},跟进方式:<b>{{item.followupmode}}</b>,跟进内容:</p>
          <div class="content-panel">
          <p>{{item.content}}</p>
          <p>{{item.competitor}}</p> 
          </div>
        </div>
      </div>
    </basicDetails>
  </div>
</template>

<script>
import BaseInfo from '@/HDrpManagement/projectChange/modules/modules/baseInfo/baseInfo'
import recall from './recall.vue'
export default {
  name: "detail",
  data() {
    return {
      mainData:{},
      mainAreaData:{},
      detailInfo:{},
      recordlist:[],
      isdesc:1,
      value2:'',
      dateParam:{
        "start": "",
        "end": ""
      }
    }
  },
  components:{
    BaseInfo,recall
  },
  methods:{
    async followRecord () {
      const res = await this.$api.requested({
        "classname": "webmanage.saletool.orderclue.publicclue.PublicClue",
        "method": "getFollowList",
        "content": {
          "sat_orderclueid": this.$route.query.id,
          "isdesc": this.isdesc,
          "where": this.dateParam
        }
      })
      this.recordlist = res.data
    },
    dateChange (val) {
      if (!val) {val = []}
      this.dateParam.start = val[0]
      this.dateParam.end = val[1]
      this.followRecord()
    },
    async queryMainData(id) {
      const res = await this.$api.requested({
        "classname": "webmanage.saletool.orderclue.publicclue.PublicClue",
        "method": "selectDetail",
        "content": {
            "sat_orderclueid": this.$route.query.id

        }
      })
      this.mainData = res.data
      console.log(this.mainData);
      
      this.changeDataStructure()
    },
    changeDataStructure() {
      let that = this
      this.mainAreaData = [
          {
          label:'客户名称',
          value:this.mainData.enterprisename_customer
        },
        {
          label:'联系人',
          value:this.mainData.name
        },
        {
          label:'手机号',
          value:this.mainData.phonenumber
        },
        {
          label:'来源',
          value:this.mainData.cluesource
        },
        {
          label:'负责人',
          value:this.mainData.leadername
        },
        {
          label:'所属经销商',
          value:this.mainData.enterprisename
        },
        {
          label:'跟进状态',
          value:this.mainData.status,
          style:function () {
            let style = {}
            switch (that.mainData.status) {
              case '已过期':
                style = {color:'#999999'}
                break;
              case '跟进中':
                style = {color:'#52c41a'}
                break;
              case '待跟进':
                style = {color:'#3874f6'}
                break;
              case '已转化':
                style = {color:'#fa8c16'}
                break; 
              case '已无效':
                style = {color:'#333333'}
                break; 
              default:
                break;
            }
            return style
            
          }
        },
        {
          label:'分配状态',
          value:this.mainData.allocationstatus,
          style:function () {
            let style = {}
            switch (that.mainData.allocationstatus) {
              case '已分配':
                style = {color:'#333333'}
                break;
              case '待分配':
                style = {color:'#3874f6'}
                break;
              default:
                break;
            }
            return style
          }

        },
      ]
      this.detailInfo = {
        baseInfo: [
          {
            label:'客户名称',
            value:this.mainData.name
          },
          {
            label:'手机号',
            value:this.mainData.phonenumber
          },
          {
            label:'省市县',
            value:`${this.mainData.province}-${this.mainData.city}-${this.mainData.county}`
          },
          {
            label:'地址',
            value:this.mainData.address
          },
          {
            label:'来源',
            value:this.mainData.cluesource
          },
          {
            label:'负责人',
            value:this.mainData.leadername
          },
          {
            label:'备注',
            value:this.mainData.notes
          },
          {
            label:'所属经销商',
            value:this.mainData.enterprisename
          },
          {
            label:'状态',
            value:this.mainData.status
          },
        ],
        systemInfo: [
          {label:'创建人',value:this.mainData.createBy},
          {label:'分配人',value:this.mainData.assignedBy},
          {label:'最近跟进人',value:this.mainData.followBy},
          {label:'转移人',value:this.mainData.changeBy},
          {label:'最近编辑人',value:this.mainData.editBy},
          {label:'创建时间',value:this.mainData.createDate},
          {label:'分配时间',value:this.mainData.assignedDate},
          {label:'最近跟进时间',value:this.mainData.followDate},
          {label:'最近转移时间',value:this.mainData.changeDate},
          {label:'最近编辑时间',value:this.mainData.editDate},
        ]
      }
    },
    // 监听切换数据,上一页,下一页
    pageChange (id,rowindex) {
      this.flag = false
      this.$router.replace({path:'/clueDetail_private',query:{id:id,rowindex:rowindex}})
      this.queryMainData(id)
    },
    async followRecord () {
      const res = await this.$api.requested({
        "classname": "webmanage.saletool.orderclue.publicclue.PublicClue",
        "method": "getFollowList",
        "content": {
          "sat_orderclueid": this.$route.query.id,
          "isdesc": 1,
          "where": this.dateParam
        }
      })
      this.recordlist = res.data
    },
    dateChange (val) {
      console.log(val)
      if (!val) {val = []}
      this.dateParam.start = val[0]
      this.dateParam.end = val[1]
      this.followRecord()
    },
  },
  mounted () {
    this.queryMainData(this.$route.query.id)
  },
  created() {
    this.followRecord()
    
  }
}
</script>

<style scoped>

</style>