<template>
  <div>
    <basicDetails
        ref="details"
        :titleText="mainData.name"
        :oldFormPath="{
          edit:'HManagement/clueManage/clue_public/modules',
        }"
        :editData="mainData"
        :mainAreaData="mainAreaData"
        turnPageId="20221101094402"
        idname="sat_orderclueid"
        tags=""
        :tabs="['详细信息','跟进记录']"
        @pageChange="pageChange"
        delApiId="20221101100502"
        @onEditSuccess="queryMainData($route.query.id)">
      <div slot="tags">
      </div>
      <div slot="customOperation">
        <recall v-if="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">跟进记录 &nbsp;<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 class="item" v-for="(item,index) in recordlist" :key="index">
          <p>{{index + 1}}.{{item.createdate}},由经销商端<span style="font-weight:bold;margin:0 6px;font-size:13px">{{item.createby}}</span>开始跟进,跟进方式:<span style="font-weight:bold;margin:0 5px">{{item.followupmode}}</span>,{{handleTxt[item.logtype]}}</p>
          <div class="content">
            <div style="margin-bottom:10px">
              <p v-if="item.competitor">已购买品牌:{{item.competitor}}</p>
              {{item.content}}
            </div>
            <file-item 
              :rowCount="5"
              :isDownLoad="true" 
              :fileData="item.attinfo"
              @deleteSuccess="deleteFile">
            </file-item>
          </div>
        </div>
      </div>
    </basicDetails>
  </div>
</template>

<script>
import FileItem from '@/SManagement/orderclue/components/file/index2'
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": ""
      },
      handleTxt:{
        '跟进中':'跟进内容',
        '成交':'成交操作，添加备注',
        '丢单':'丢单操作，具体原因如下',
        '无效':'无效操作，具体原因如下',
      },
    }
  },
  components:{
    BaseInfo,recall,
    FileItem
  },
  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
      this.recordlist.forEach(item => {
        item.attinfo = this.fileType.fileList(item.attinfo)
      })
    },
    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
      this.changeDataStructure()
    },
    changeDataStructure() {
      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.enterprisename
        },
        {
          label:'负责人',
          value:this.mainData.leader ? this.mainData.leader[0].name : ''
        },
        {
          label:'分配状态',
          value:this.mainData.allocationstatus
        },
        {
          label:'跟进状态',
          value:this.mainData.status
        },
      ]
      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.allocationstatus
        },
        {
          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',query:{id:id,rowindex:rowindex}})
      this.queryMainData(id)
    }
  },
  mounted () {
    this.queryMainData(this.$route.query.id)
  },
  created() {
    this.followRecord()
  }
}
</script>

<style scoped>
.content {
  margin: 10px 0 16px 0;
  background: #F2F2F2;
  padding: 16px;
  border-radius: 5px;
  font-size: 14px;
}
</style>