<template>
  <div>
    <basicDetails
        v-if="mainData"
        ref="details"
        :titleText="mainData.name"
        :oldFormPath="{
          edit:'SManagement/orderclue/components',
        }"
        :editData="mainData"
        :mainAreaData="mainAreaData"
        turnPageId="20221101094502"
        idname="sat_orderclueid"
        tags=""
        :tabs="['跟进记录','详细信息']"
        @pageChange="pageChange"
        @onEditSuccess="queryMainData($route.query.id)"
        @detailCreate="detailCreate">
      <div slot="customOperation">
        <follow :detailInfo="mainData" 
          v-if="tool.checkAuth($route.name,'follow')"
          @updataList="queryMainData();$refs.followDetail.getFollowDetail()" @onSuccess="$refs.followDetail.getFollowDetail()" :disabled="!isHandle"></follow>
        <!-- <move :data="mainData" 
          @updataList="queryMainData" 
          :teamList="teamList()"  
          v-if="userInfo.isAuth == 1 ? mainData.status == '待跟进' || mainData.status == '跟进中' : ''"></move> -->
        <changeData v-if="tool.checkAuth($route.name,'change')" :data="mainData" :disabled="!isHandle" class="inline-16"/>
        <noNull v-if="tool.checkAuth($route.name,'change')" class="inline-16" :disabled="!isHandle" @onSuccess="$store.dispatch('changeDetailDrawer',false);$router.replace('/orderclue')" :id="mainData.sat_orderclueid"/>
        <el-button v-if="tool.checkAuth($route.name,'goBack')" :disabled="!isHandle" class="inline-16" size="mini" @click="goBack">退 回</el-button>
        <Del v-if="tool.checkAuth($route.name,'delete')" class="inline-16" :disabled="!isHandle" :idName="20221123193702" @onSuccess="$store.dispatch('changeDetailDrawer',false);$router.replace('/orderclue')" :id="mainData.sat_orderclueid" idKey="sat_orderclueids"/>
      </div>
      <div slot="slot1" class="container normal-panel">
        <BaseInfo :detailInfo="detailInfo"/>
      </div>
      <div slot="slot0">
        <followDetail ref="followDetail"/>
      </div>
    </basicDetails>
  </div>
</template>

<script>
import BaseInfo from '@/HDrpManagement/projectChange/modules/modules/baseInfo/baseInfo'
import followDetail from '@/SManagement/orderclue_detail/components/followDetail'
import follow from '@/SManagement/orderclue/components/follow'
import move from '@/SManagement/orderclue/components/move'
import Del from './components/delete'
import noNull from './components/noNull'
import changeData from './components/changeData'
import { log } from '@antv/g2plot/lib/utils'
export default {
  name: "detail",
  inject:['teamList'],
  data() {
    return {
      mainData:{},
      mainAreaData:{},
      detailInfo:{},
      userInfo:JSON.parse(window.sessionStorage.getItem('userInfo')),
      isHandle:''
    }
  },
  components:{
    BaseInfo,
    followDetail,
    follow,
    move,
    Del,
    noNull,
    changeData
  },
  watch: {
   mainData(val) {
     let is 
      if(JSON.parse(window.sessionStorage.getItem('userInfo')).userid == this.mainData.leader[0].userid) {
        is = true
        if(this.mainData.status == '待跟进' || this.mainData.status == '跟进中') {
          is = true
        } else {
          is = false
        }
      } else {
        is = false
      }
      this.isHandle = is
      console.log(this.isHandle,'权限');
      
   }
  },
  methods:{
    detailCreate (param) {
      param.content.isAll = 0
    },
    async queryMainData(id) {
      const res = await this.$api.requested({
        "classname": "saletool.orderclue.web.orderclue",
        "method": "selectDetail",
        "content": {
            "sat_orderclueid": this.$route.query.id
        }
      })
      this.mainData = res.data
      console.log(this.mainData);
      
      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.leader[0].name
        },
        {
          label:'分配状态',
          value:this.mainData.allocationstatus
        },
        {
          label:'跟进状态',
          value:this.mainData.status
        },
        {
          label:'跟进次数',
          value:this.mainData.followcount
        },
        {
          label:'转化次数',
          value:this.mainData.changecount
        },
      ]
      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.leader[0].name
          // },
          
          {
            label:'跟进状态',
            value:this.mainData.status
          },
          {
            label:'分配状态',
            value:this.mainData.allocationstatus
          },
          {
            label:'备注',
            value:this.mainData.notes
          },
        ],
        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},
          {label:'最近编辑时间',value:this.mainData.editDate},
          {label:'最近编辑时间',value:this.mainData.editDate},
        ]
      }
    },
    goBack () {
      this.$confirm('退回该线索后无法撤销,是否继续','提示',{
        "confirmButtonText":'确定',
        "cancelButtonText":'取消'
      }).then(async confirm => {
        let res = await this.$api.requested({
          "id":20221207160802,
          "content": {
            sat_orderclueid: this.mainData.sat_orderclueid
          }
        })
        this.tool.showMessage(res , () => {
          this.$store.dispatch('changeDetailDrawer',false)
          this.$router.push('/orderclue')
        })
      })
    },
    // 监听切换数据,上一页,下一页
    pageChange (id,rowindex) {
      this.flag = false
      this.$router.replace({path:'/orderclue_detail',query:{id:id,rowindex:rowindex}})
      this.queryMainData(id)
    }
  },
  mounted () {
    this.queryMainData(this.$route.query.id)
  },
  created() {
  }
}
</script>

<style scoped>

</style>