<template>
  <div>
    <basicDetails
        ref="details"
        :titleText="mainData.name"
        :oldFormPath="{
          edit:'HManagement/clueManage/m_activity/modules',
        }"
        :editData="mainData"
        :mainAreaData="mainAreaData"
        turnPageId="20221101095102"
        idname="sat_campaignid"
        :tabs="['活动线索','详细信息']"
        @pageChange="pageChange"
        @onEditSuccess="queryMainData($route.query.id)"
        @detailCreate="detailCreate">
      <div slot="tags">
      </div>
      <div slot="customOperation">
        <relase class="inline-16" v-if="tool.checkAuth($route.name,'relase') && mainData.status != '结束'" :data="mainData" @onSuccess="queryMainData"></relase>
        <finish class="inline-16" v-if="tool.checkAuth($route.name,'finish')  && mainData.status != '结束'" :data="mainData" @onSuccess="queryMainData"></finish>
      </div>
      <div slot="slot0" class="container normal-panel">
        <DetailTable ref="DetailTable">
          <addClue slot="addClue" :data="mainData" class="inline-16" v-if="tool.checkAuth($route.name,'clueManage')" @onSuccess="$refs.DetailTable.getList();queryMainData()"/>
          <template v-slot:editClue="scope">
            <editClue  v-if="tool.checkAuth($route.name,'clueManage')" :data="scope.data" @onSuccess="$refs.DetailTable.getList()"/>
          </template>
        </DetailTable>
      </div>
      <div slot="slot1" class="container normal-panel">
        <BaseInfo :detailInfo="detailInfo"/>
      </div>
    </basicDetails>
  </div>
</template>

<script>
import BaseInfo from '@/HDrpManagement/projectChange/modules/modules/baseInfo/baseInfo.vue'
import DetailTable from './detailTable'
import relase from './relase.vue'
import finish from './finish.vue'

import addClue from './addClue'
import editClue from './editClue'
export default {
  name: "detail",
  data() {
    return {
      mainData:{
        disabled:false
      },
      mainAreaData:{},
      detailInfo:{},
    }
  },
  provide () {
    return {
      status: () => this.mainData.status
    }
  },
  watch:{
    async mainData(val) {
      const res = await this.$api.requested({
        "id": 20220930103501,
        "content": {
          "ownertable":"sat_campaign",
          "ownerid":this.$route.query.id
        }
      })
      if (this.mainData.leader.length !== 0){
        if (JSON.parse(window.sessionStorage.getItem('active_account')).userid === this.mainData.leader[0].userid){
          /*是负责人*/
          this.mainData.disabled = true
        }else {
          let flag = 0
          for (var i=0;i<res.data[0].team.length;i++){
            if (res.data[0].team[i].userid === JSON.parse(window.sessionStorage.getItem('active_account')).userid){
              if (res.data[0].team[i].editable === 1){
                this.mainData.disabled = true
                flag =1
                break
              }else {
                flag = 0
                break
              }
            }
          }
          /*不是负责人*/
          flag === 0?this.mainData.disabled = false:this.mainData.disabled = true
        }
      }
      console.log("权限结果", this.mainData.disabled)
    }
  },
  components:{
    BaseInfo,
    DetailTable,
    relase,
    finish,
    addClue,
    editClue
  },
  methods:{
    async queryMainData(id) {
      const res = await this.$api.requested({
        "classname": "webmanage.saletool.orderclue.ordercluecampaign",
        "method": "queryCampaignMain",
        "content": {
            "sat_campaignid": this.$route.query.id

        }
      })
      this.mainData = Object.assign({},this.mainData,res.data)
      this.$refs.details.param.content.type = this.$route.query.tabIndex
      this.changeDataStructure()
      console.log(this.mainData);
      
    },
    changeDataStructure() {
      let that = this
      this.mainAreaData = [
          {
          label:'活动名称',
          value:this.mainData.name
        },
        {
          label:'活动类型',
          value:this.mainData.type
        },
        {
          label:'活动负责人',
          value:this.mainData.director
        },
        {
          label:'线索数',
          value:this.mainData.ordercluecount
        },
        {
          label:'状态',
          value:this.mainData.status,
          style:function () {
            let style = {}
            switch (that.mainData.status) {
              case '发布':
                style = {color:"rgb(82, 196, 26)"}
                break;
              case '结束':
                style = {color:"#cccccc"}
                break;
              default:
                break;
            }
            return style
          }
        },
      ]
      this.detailInfo = {
        baseInfo: [
          {
          label:'活动名称',
          value:this.mainData.name
        },
        {
          label:'活动类型',
          value:this.mainData.type
        },
        {
          label:'活动负责人',
          value:this.mainData.director
        },
        {
          label:'线索数',
          value:this.mainData.ordercluecount
        },
          {
            label:'开始日期',
            value:this.mainData.begdate
          },
          {
            label:'结束日期',
            value:this.mainData.enddate
          },
          {
            label:'地点',
            value:this.mainData.address
          },
          {
            label:'状态',
            value:this.mainData.status,
            style:function () {
              let style = {}
              switch (that.mainData.status) {
                case '发布':
                  style = {color:"rgb(82, 196, 26)"}
                  break;
                case '结束':
                  style = {color:"#cccccc"}
                  break;
                default:
                  break;
              }
              return style
            }
          },
          {
            label:'负责人',
            value:this.mainData.leader[0].name
          },

        ],
        systemInfo: [
          {label:'创建人',value:this.mainData.createby},
          {label:'创建时间',value:this.mainData.createdate},
          {label:'最近编辑人',value:this.mainData.changeby},
          {label:'最近编辑时间',value:this.mainData.changedate},
          {label:'发布人',value:this.mainData.checkby},
          {label:'发布时间',value:this.mainData.checkdate},
          {
            label:'转手次数',
            value:this.mainData.leader.length !== 0?this.mainData.leader[0].leadernum === 0?'0':this.mainData.leader[0].leadernum:'--'
          },
          /*{label:'最近跟进时间',value:this.mainData.followDate},*/

        ]
      }
    },
    detailCreate (param) {
      param.content.isAll = 0
    },
    // 监听切换数据,上一页,下一页
    pageChange (id,rowindex,tabIndex) {
      this.flag = false
      tabIndex = this.$route.query.tabIndex
      this.$router.replace({path:'/marketing_activityDetails',query:{id:id,rowindex:rowindex,tabIndex:tabIndex}})
      this.queryMainData(id)
    }
  },
  mounted () {
    this.queryMainData(this.$route.query.id)
  },
  created() {
  }
}
</script>

<style scoped>

</style>