<template>
  <div>
    <basicDetails
        ref="details"
        :titleText="mainData.enterprisename"
        formPath="salerPrivatecustomer"
        :editData="mainData"
        :mainAreaData="mainAreaData"
        turnPageId="20221012164402"
        idname="sa_customersid"
        tags=""
        :tabs="['详细信息','联系人信息','客户地址','客户财务信息','工商信息','项目商机','报价单','合同信息']"
        @pageChange="pageChange"
        @onEditSuccess="queryMainData($route.query.id)">
      <div slot="tags">
        <!-- 使用此插槽可不传[tags] -->
        <!-- :tabs="['经销商团队','代理区域','营销类别','账户余额']" -->
<!--        <tagPanl slot="tags" :data="tags" :id="mainData.sa_customersid" @onSuccess="queryMainData"/>-->
      </div>
      <div slot="customOperation" >
        <!-- 此区域提供了自定义操作按钮 -->
        <transaction_status class="inline-16" v-if="tool.checkAuth($route.name,'transaction')" :id="mainData.sa_customersid" @onshow="onSuccess" @shareSuccess="onSuccess"></transaction_status>
        <!--<lock class="inline-16" v-if="tool.checkAuth($route.name,'lock')"   :id="mainData.sa_customersid" @onshow="onSuccess"></lock>-->
         <!--<unlock class="inline-16" v-if="tool.checkAuth($route.name,'unlock')" :id="mainData.sa_customersid" @onshow="onSuccess"></unlock> -->
        <share class="inline-16" v-if="tool.checkAuth($route.name,'share') && mainData.poolname === ''" :id="mainData.sa_customersid" @onshow="onSuccess" @shareSuccess="onSuccess"></share>
        <send_back style="display:inline" v-if="tool.checkAuth($route.name,'back') "  :data="mainData" @onshow="onSuccess" @backSuccess="onSuccess"></send_back>
        <to_void class="inline-16" v-if="tool.checkAuth($route.name,'toVoid')" :id="mainData.sa_customersid" @onshow="onSuccess" @toVoidSuccess="onSuccess"></to_void>
        <recovery class="inline-16" v-if="tool.checkAuth($route.name,'recovery') "  :data="mainData" @onshow="onSuccess" @backSuccess="onSuccess"></recovery>
      </div>
      <div slot="slot0" >
        <detailed ref="detailed"></detailed>
      </div>
      <div slot="slot1" class="container normal-panel"  >
        <contacts :data="mainData"  @onSuccess="onSuccess" v-if="flag"></contacts>
      </div>
      <div slot="slot2" class="container normal-panel">
        <address_manage :data="mainData"  v-if="flag"></address_manage>
      </div>
    </basicDetails>
  </div>
</template>

<script>
import detailed from './modules/detailedData'
import contacts from './modules/contacts/list'
import address_manage from './modules/addressManage/list'
import transactionUser from "./modules/operation/transactionUser"
import lock from './modules/operation/lock'
import unlock from './modules/operation/unlock'
import share from './modules/operation/share'
import send_back from './modules/operation/sendBack'
import to_void from './modules/operation/toVoid'
import transaction_status from './modules/operation/transactionStatus'
import recovery from './modules/operation/recovery'
export default {
  name: "detail",
  data() {
    return {
      mainData:{},
      mainAreaData:[],
      tags:{},
      visible:false,
      dialogFormVisible:false,
      dialogFormLeader:false,
      form:{
        status:'',
        userid:''
      },
      users:[],
      flag:false
    }
  },
  components:{
    detailed,
    contacts,
    address_manage,
    transactionUser,
    lock,
    unlock,
    share,
    send_back,
    to_void,
    transaction_status,
    recovery
  },
  methods:{
    async queryMainData(id) {
      const res = await this.$api.requested({
        "id": 20221012164302,
        "content": {
          "sa_customersid": id
        },
      })
      this.mainData = res.data
      console.log("输出数据一")
      console.log(this.mainData)
      this.$refs['details'].param.content.type = this.$route.query.tabIndex
      this.$refs['details'].param.content.isExport = false
      this.changeDataStructure()
      this.$refs.detailed.detailedList(this.mainData)
      this.flag = true
    },
    show(){
      this.visible = false
    },
    changeDataStructure() {
      this.mainAreaData = [
        {
          label:'客户编号',
          value:this.mainData.sa_customersid
        },
        {
          label:'客户级别',
          value:this.mainData.grade
        },
        {
          label:'客户类型',
          value:this.mainData.type
        },
        {
          label:'上级企业',
          value:this.mainData.superiorenterprisename
        },
        {
          label:'成交状态',
          value:this.mainData.tradingstatus
        },
        {
          label:'负责人',
          value:this.mainData.leader.length === 0?"--":this.mainData.leader[0].name
        },
        {
          label:'最近跟近时间',
          value:''
        },
        {
          label:'来源公海',
          value:this.mainData.sourcepoolname
        }
      ]
    },
    // 监听切换数据,上一页,下一页
    pageChange (id,rowindex,tabIndex) {
      this.flag = false
      tabIndex = this.$route.query.tabIndex
      this.$router.replace({path:'/customerDetail',query:{id:id,rowindex:rowindex,tabIndex:tabIndex}})
      this.queryMainData(id)
    },
    async queryTags(id){
      const res = await this.$api.requested({
        "id": 20220929085401,
        "content": {
          "ownertable":'sa_customers',
          "ownerid":id
        }
      })
      this.tags = res.data
    },
    onSuccess(){
      this.visible = false
      this.queryMainData(this.$route.query.id)
      this.$emit('onSuccess')
    }
  },
  mounted () {
    this.queryMainData(this.$route.query.id)
  },
  created() {
    this.tool.checkAuth(this.$route.name,'update')?'':this.$router.go(-1)
  }
}
</script>

<style scoped>

</style>