<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" >
        <!-- 此区域提供了自定义操作按钮 -->
        <el-popover
            placement="bottom"
            width="50"
            trigger="focus"
            v-model="visible"
        >
          <div class="normal-margin">
            <transactionUser v-if="tool.checkAuth($route.name,'responsible')" @onshow="show"></transactionUser>
          </div>
          <div class="normal-margin">
            <transaction_status v-if="tool.checkAuth($route.name,'transaction')" :id="mainData.sa_customersid" @onshow="onSuccess" @shareSuccess="onSuccess"></transaction_status>
          </div>
          <div class="normal-margin" v-show="mainData.datastatus === 0">
            <lock v-if="tool.checkAuth($route.name,'lock')"   :id="mainData.sa_customersid" @onshow="onSuccess"></lock>
          </div>
          <div class="normal-margin" v-show="mainData.datastatus === 2">
            <unlock v-if="tool.checkAuth($route.name,'unlock')" :id="mainData.sa_customersid" @onshow="onSuccess"></unlock>
          </div>
          <div class="normal-margin">
            <share v-if="tool.checkAuth($route.name,'share') && mainData.poolname === ''" :id="mainData.sa_customersid" @onshow="onSuccess" @shareSuccess="onSuccess"></share>
          </div>
          <div class="normal-margin" >
<<<<<<< HEAD
              <send_back v-if="tool.checkAuth($route.name,'back') "  :data="mainData" @onshow="onSuccess" @backSuccess="onSuccess"></send_back>
=======
            <send_back v-if="tool.checkAuth($route.name,'back') "  :data="mainData" @onshow="onSuccess" @backSuccess="onSuccess"></send_back>
>>>>>>> 8be118da8263bf7cea1e45cdd92c84cc2cd45a40
          </div>
          <div class="normal-margin" v-show="mainData.datastatus !== 1">
            <to_void v-if="tool.checkAuth($route.name,'toVoid')" :id="mainData.sa_customersid" @onshow="onSuccess" @toVoidSuccess="onSuccess"></to_void>
          </div>
          <el-button size="mini" slot="reference" icon="el-icon-more" @click="visible = !visible"></el-button>
        </el-popover>
      </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'
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
  },
  methods:{
    async queryMainData(id) {
      const res = await this.$api.requested({
        "id": 20221012164302,
        "content": {
          "sa_customersid": id
        },
      })
      this.mainData = res.data
      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:'负责人',
<<<<<<< HEAD
          value:this.mainData.leader[0]?this.mainData.leader[0].name:""
=======
          value:this.mainData.leader[0].name
>>>>>>> 8be118da8263bf7cea1e45cdd92c84cc2cd45a40
        },
        {
          label:'最近跟近时间',
          value:''
        },
        {
          label:'所属公海',
          value:this.mainData.poolname
        }
      ]
    },
    // 监听切换数据,上一页,下一页
    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>