<template>
  <div>
    <basicDetails
        ref="details"
        :titleText="mainData.enterprisename"
        formPath="publicCustomer"
        :editData="mainData"
        :mainAreaData="mainAreaData"
        :turnPageId="20221011133602"
        idname="sa_customersid"
        tags=""
        :tabs="['详细信息','联系人信息','客户地址']"
        @pageChange="pageChange"
        @onEditSuccess="queryMainData($route.query.id)">
      <div slot="tags">
        <tagPanl slot="tags" :data="tagObj" :id="mainData.sa_customersid" @onSuccess="queryMainData"/>
        <!-- 使用此插槽可不传[tags] -->
        <!-- :tabs="['经销商团队','代理区域','营销类别','账户余额']" -->
      </div>
      <div slot="customOperation">
        <!-- 此区域提供了自定义操作按钮 -->
        <el-popover
            placement="bottom"
            width="50"
            trigger="focus"
            v-model="visible"
        >
          <div class="normal-margin" v-if="tool.checkAuth($route.name,'receive') && mainData.freeget === 1 && length === 0 ">
            <receive  :id="mainData.sa_customersid" @onshow="show"></receive>
          </div>
          <div class="normal-margin" v-if="tool.checkAuth($route.name,'distribution') && length === 0">
            <distribution  :data="mainData" @onshow="onSuccess" @setSuccess="onSuccess"></distribution>
          </div>
          <div class="normal-margin" v-if="tool.checkAuth($route.name,'toVoid')">
            <to_void  :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" v-if="flag"></contacts>
      </div>
      <div slot="slot2" class="container normal-panel">
        <address_manage :data="mainData"  v-if="flag"></address_manage>
      </div>
      <!-- <div slot="slot0" class="container normal-panel">
        <el-button size="small" type="primary" @click="createAgentAccount" class="normal-margin">创建经销商主账号</el-button>
        <tableLayout :layout="tablecols" :data="mainData.hrs" :custom="false" height="300px"></tableLayout>
      </div>
      <div slot="slot1" class="container normal-panel">
        <salescope :data="mainData"></salescope>
      </div>
      <div slot="slot2" class="container normal-panel">
        <SaleClass :data="mainData"></SaleClass>
      </div>
      <div slot="slot3" class="container normal-panel">
        <accountMoney :mainData="mainData"></accountMoney>
      </div> -->
    </basicDetails>
  </div>
</template>

<script>
import detailed from './detail/detailedData'
import contacts from './detail/contacts/list'
import address_manage from './detail/addressManage/list'
import receive from './detail/operation/receive'
import distribution from './detail/operation/distribution'
import to_void from './detail/operation/toVoid'
export default {
  data () {
    return {
      mainData:{},
      mainAreaData:[],
      customerType:'',
      customerLead:'',
      arealist:[],
      publicList:[],
      tagObj:{},
      visible:false,
      flag:false,
      length:''
    }
  },
  provide () {
    return {
      customerType:() => this.customerType,
      customerLead:() => this.customerLead,
      arealist:() => this.arealist,
      publicList:() => this.publicList
    }
  },
  components:{
    detailed,contacts,address_manage,receive,distribution,to_void
  },
  methods:{
    /* 获取系统选项数据 */
    async getSysOption() {
      /* 获取客户类型 */
      let res = await this.$store.dispatch('optiontypeselect','customertypemx')
      this.customerType = res.data
      /* 获取客户等级 */
      let res2 = await this.$store.dispatch('optiontypeselect','customergrade')
      this.customerLead = res2.data
    },
    /* 获取省市县 */
    async query_arealist() {
      const res = await this.$api.requested({
        "classname": "system.tools",
        "method": "query_arealist",
        "content": {
        }
      })
      this.arealist = this.tool.createMenu(res.data)
    },
    /* 获取公海数据 */
    async getPublicList() {
      const res = await this.$api.requested({
      "id": 20221009100702,
      "content": {
          "pageNumber": 1,
          "pageSize": 999999,
          "where": {
          }
      },
    })
      this.publicList = res.data
    },
    /* 获取数据标签 */
    async getDataTag (id) {
      let res = await this.$api.requested({
        "id": 20220929085401,
        "content": {
            "ownertable":"sa_customers",
            "ownerid":id
        }
      })
      this.tagObj = res.data
      console.log(this.tagObj);
      
    },
    async queryMainData (id) {
      const res = await this.$api.requested({
        "id": "20221012164302",

        "content": {
            "sa_customersid":id
        }
      })
      this.$refs.details.param.content.where.sa_customerpoolid = this.$route.query.tabIndex
      this.$refs.details.param.content.isExport = false
      this.mainData = res.data
      console.log("输出获取的数据")
      console.log(this.mainData.freeget)
      console.log(this.mainData);
      this.length = this.mainData.leader.length
      console.log(this.length)
      this.getDataTag(this.mainData.sa_customersid)
      this.changeDataStructure()
      this.$refs.detailed.detailedList(this.mainData)
      this.flag = true
    },
    // 监听切换数据,上一页,下一页
    pageChange (id,rowindex,tabIndex) {
      tabIndex = this.$route.query.tabIndex
      this.flag = false
      this.$router.replace({path:'/PublicCustomerDetail',query:{id:id,rowindex:rowindex,tabIndex:tabIndex}})
      this.queryMainData(id)
    },
    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.poolname
        }
      ]
    },
    show(){
      this.visible = false
    },
    onSuccess(){
      this.visible = false
      this.queryMainData(this.$route.query.id)
      this.$emit('onSuccess')
    }
  },
  mounted () {
  },
  created () {
    // 验证权限
    this.tool.checkAuth(this.$route.name,'update')?'':this.$router.go(-1)
    this.queryMainData(this.$route.query.id)
    this.getSysOption()
    this.query_arealist()
    this.getPublicList()
  },
}

</script>
<style>
</style>