
<template>
  <basicDetails 
    ref="details"
    :titleText="mainData.projectname"
    formPath="projectChange"
    :editData="mainData"
    :mainAreaData="mainAreaData" 
    :turnPageId="20221020143502" 
    idname="sa_projectid"
    tags=""
    :tabs="['详细信息','阶段任务','缔约信息','产品配置单','报价单','竞争对手']"
    @pageChange="pageChange"
    @onEditSuccess="queryMainData($route.query.id)">
    <!-- 使用此插槽可不传[tags] -->
    <tagPanl slot="tags" :data="tagObj" ownertable="sa_project" :id="mainData.sa_projectid" @onSuccess="queryMainData"/>
    <div slot="customOperation">
      <!-- 此区域提供了自定义操作按钮 -->
      <el-popover placement="bottom" style="20px">
        <putPeople 
          @onSuccess="queryMainData" 
          v-if="!mainData.reportby &&  tool.checkAuth($route.name,'put')" class="inline-16" 
          :data="putPeople" 
          :rowData="mainData"
          style="width:100%;margin-bottom:5px"
        />
        <Check 
          v-if="!mainData.reportcheckby && mainData.reportby == userInfo.name && tool.checkAuth($route.name,'check')" 
          @checkSuccess="queryMainData" 
          :rowData="mainData"
          style="width:100%;margin-bottom:5px"
        />
        <Locked style="width:100%;margin-bottom:5px" v-if="tool.checkAuth($route.name,'Locked')" :rowData="mainData" @onSuccess="queryMainData"/>
        <el-button size="mini" slot="reference" icon="el-icon-more"></el-button>
      </el-popover>
    </div>
    <div slot="slot0" class="container normal-panel">
      <BaseInfo v-if="detailInfo" :detailInfo="detailInfo"/>
    </div>
    <div slot="slot1" class="container normal-panel">
      <StageTask v-if="mainData" :rowData="mainData"/>
    </div>
    <div slot="slot2" class="container normal-panel">
      <andEnterprise :rowData="mainData"/>
    </div>
    <div slot="slot3" class="container normal-panel">
      <ProjectSet />
    </div>
    <div slot="slot4" class="container normal-panel">
      <quotation />
    </div>
    <div slot="slot5" class="container normal-panel">
      <Rival />
    </div>
  </basicDetails>
</template>

<script>
import Quotation from './modules/quotation/index'
import ProjectSet from './modules/projectSet/index'
import Rival from './modules/rival/index'
import BaseInfo from './modules/baseInfo/baseInfo'
import StageTask from './modules/stageTask/index'
import putPeople from '../components/putPeople'
import Check from '../components/check'
import Locked from '../components/Locked'
import andEnterprise from './modules/andEnterprise/index'
export default {
  components:{Quotation,ProjectSet,Rival,BaseInfo,StageTask,putPeople,Check,Locked,andEnterprise},
  data () {
    return {
      mainData:'',
      mainAreaData:'',
      /* 企业列表 */
      enterpriseList:'',
      /* 企业列表 */
      projectType:'',
      projectLead:'',
      projectPanl:'',
      projectAddress:'',
      detailInfo:'',
      tagObj:'',
      putPeople:'',
      userInfo:''
    }
  },
  provide () {
    return {
      enterpriseList:() => this.enterpriseList,
      projectType:() => this.projectType,
      projectLead:() => this.projectLead,
      projectPanl:() => this.projectPanl,
      detailData:() => this.mainData,
      projectAddress:() => this.projectAddress
    }
  },
  methods:{
    async queryMainData (id) {
      const res = await this.$api.requested({
        "id": "20221021103902",
        "version":1,
        "content": {
            "sa_projectid":this.$route.query.id
        }
      })
      this.mainData = res.data
      console.log(this.mainData);
      /* 获取标签数据 */
      this.tagObj = await this.$store.dispatch('queryTagList',{table:'sa_project',id:this.mainData.sa_projectid})
      this.getProjectAddres()
    },
    // 监听切换数据,上一页,下一页
    pageChange (id,rowindex) {
      this.$router.replace({path:'/projectChangeDetail',query:{id:id,rowindex:rowindex}})
      this.queryMainData(id)
    },
    /* 获取联系人:负责人列表 */
    async getAccount () {
      let res = await this.$api.requested({
        "id": "20221018150602",
        "content": {
            "sys_enterpriseid": 1,
            "pageNumber": 1,
            "pageSize": 20,
            "where": {
                "condition": ""
            }
        }
      })
    },
    /* 获取当前用户信息 */
    async getUserInfo() {
      let res = await this.$api.requested({
        "classname": "common.usercenter.usercenter",
        "method": "queryUserMsg",
        "content": {
        }
      })
      this.userInfo = res.data
      console.log(this.userInfo);
      
    },
    /* 可报备人 */
    async getPutPeople () {
      let res = await this.$api.requested({
        "id": 20221021093202,
        "content": {
          "pageNumber": 1,
          "pageSize": 999999,
          "where": {
              "condition": ""
          }
        },
      })
      this.putPeople = res.data
    },
    async getSysetms () {
      /* 获取项目类型 */
      let res = await this.$store.dispatch('optiontypeselect','projecttype')
      this.projectType = res.data
    },
    /** 获取公司数据 */
    async getEnterprise () {
      let res = await this.$api.requested({
        "id": 20221021095802,
        "content": {
            "pageNumber": 1,
            "pageSize": 99999,
            "where": {
                "condition": ""
            }
        },
      })
      this.enterpriseList = res.data
    },
    /* 获取项目模板 */
    async getProjectPanl () {
      let res = await this.$api.requested({
        "id": "20221019085604",
        "content": {
            "pageNumber": 1,
            "pageSize": 99999999,
            "where":{
                "condition":""
            }
        }
      })
      this.projectPanl = res.data
    },
    /* 获取项目地址 */
    async getProjectAddres () {
      let res = await this.$api.requested({
        "id": "20221022165503",
        "content": {
            "sys_enterpriseid": this.mainData.sys_enterpriseid,
            "pageNumber": 1,
            "pageSize": 999999,
            "where": {
                "condition": ""
            }
        }
      })
      this.projectAddress = res.data
      console.log(this.projectAddress);
      
      /* 获取项目等级 */
      let res2 = await this.$store.dispatch('optiontypeselect','projectgrade')
      this.projectLead = res2.data
      this.changeDataStructure()
    },
    changeDataStructure () {
      this.detailInfo = {
        baseInfo: [
          {label:'项目编号',value:this.mainData.projectnum ? this.mainData.projectnum : '--'},
          {label:'项目名称',value:this.mainData.projectname ? this.mainData.projectname : '--'},
          {label:'项目地址',value:`${this.mainData.province} - ${this.mainData.city} - ${this.mainData.county}`},
          {label:'详细地址',value:this.mainData.address},
          {label:'项目等级',value:this.projectLead.find(item => item.rowindex == this.mainData.grade).value},
          {label:'项目类型',value:this.mainData.projecttype ? this.mainData.projecttype : '--'},
          {label:'当前项目阶段',value:this.mainData.stagename ? this.mainData.stagename : '--'},
          {label:'项目报备时间',value:''},
          {label:'项目联系人',value:this.mainData.contact ? this.mainData.contact : '--'},
          {label:'联系人手机号',value:this.mainData.phonenumber ? this.mainData.phonenumber : '--'},
          {label:'项目规模',value:this.mainData.scale ? this.mainData.scale : '--'},
          {label:'项目状态',value:this.mainData.status ? this.mainData.status : '--'},
          {label:'项目折扣',value:this.mainData.discountrate ? this.mainData.discountrate : '--'},
          {label:'项目预算',value:this.mainData.budgetary ? this.mainData.budgetary : '--'},
          {label:'预计签约金额',value:this.mainData.signamount_due ? this.mainData.signamount_due : '--'},
          {label:'预计签约月份',value:this.mainData.signdate_due ? this.mainData.signdate_due : '--'},
          {label:'赢率',value:this.mainData.winrate ? this.mainData.winrate : '--'},
          {label:'负责人',value:this.mainData.name ? this.mainData.name : '--'},
        ],
        systemInfo: [
          {label:'创建人',value:this.mainData.createby ? this.mainData.createby : '--'},
          {label:'创建时间',value:this.mainData.createdate ? this.mainData.createdate : '--'},
          {label:'最近跟进人',value:this.mainData.followby ? this.mainData.followby : '--'},
          {label:'最近跟进时间',value:this.mainData.followdate ? this.mainData.followdate : '--'},
          {label:'锁定状态',value:this.mainData.locked == '0' ? '锁定' : '解锁'},
          {label:'最近编辑人',value:this.mainData.changeby ? this.mainData.changeby : '--'},
          {label:'最近编辑时间',value:this.mainData.changedate ? this.mainData.changedate : '--'},
          {label:'转手次数',value:this.mainData.changecount !== '' ? this.mainData.changecount : '--'},
          
        ]
      }
      this.mainAreaData = [
        {
          label:'项目名称',
          value: this.mainData.projectname
        },
        {
          label:'项目编号',
          value:this.mainData.projectnum
        },
        {
          label:'项目规模',
          value: this.mainData.scale
        },
        {
          label:'项目等级',
          value: this.projectLead.find(item => item.rowindex == this.mainData.grade).value
        },
        {
          label:'项目类型',
          value:this.mainData.projecttype
        },
        {
          label:'项目阶段',
          value: this.mainData.stagename
        },
        {
          label:'项目状态',
          value: this.mainData.status
        },
        {
          label:'项目状态',
          value: this.mainData.enterprisename
        },
        {
          label:'负责人',
          value: this.mainData.name
        },
      ]
    }
  },
  mounted () {
  },
  async created () {
    this.queryMainData(this.$route.query.id)
    this.getUserInfo()
    this.getPutPeople()
    this.getProjectPanl()
    this.getEnterprise()
    this.getSysetms()
    // 验证权限
    this.tool.checkAuth(this.$route.name,'update')?'':this.$router.go(-1)
  },
}

</script>
<style>
</style>