
<template>
  <basicDetails 
    ref="details"
    :titleText="mainData.enterprisename"
    formPath="privateCustomer"
    :editData="mainData"
    :mainAreaData="mainAreaData" 
    :turnPageId="20221013102602" 
    idname="sa_customersid"
    tags=""
    @pageChange="pageChange"
    @onEditSuccess="queryMainData($route.query.id)">
    <!-- 使用此插槽可不传[tags] -->
    <tagPanl slot="tags" :data="tagObj" ownertable="sa_customers" :id="mainData.sa_customersid" @onSuccess="queryMainData"/>
    <div slot="customOperation">
      <!-- 此区域提供了自定义操作按钮 -->
    </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>
</template>

<script>
export default {
  data () {
    return {
      mainData:{},
      tagObj:{},
      mainAreaData:''
    }
  },
  provide () {
    return {
      customerType:() => this.customerType,
      customerLead:() => this.customerLead,
      arealist:() => this.arealist
    }
  },
  components:{
  },
  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 queryMainData (id) {
      const res = await this.$api.requested({
        "id": "20221011133502",
        "version":1,
        "content": {
            "sa_customersid":this.$route.query.id
        }
      })
      this.mainData = res.data
      this.$refs.details.param.content.isExport = false
      console.log(this.mainData);
      this.getDataTag(this.mainData.sa_customersid)
      this.changeDataStructure()
    },
    /* 获取数据标签 */
    async getDataTag (id) {
      let res = await this.$api.requested({
        "id": 20220929085401,
        "content": {
            "ownertable":"sa_customers",
            "ownerid":id
        }
      })
      this.tagObj = res.data
    },
    // 监听切换数据,上一页,下一页
    pageChange (id,rowindex) {
      this.$router.replace({path:'/PrivateCustomerDetail',query:{id:id,rowindex:rowindex}})
      this.queryMainData(id)
    },
    changeDataStructure () {
      this.mainAreaData = [
        {
          label:'客户名称',
          value: this.mainData.enterprisename
        },
        {
          label:'负责人',
          // value: this.mainData.leader.length > 0 ? scope.data.column.data[[scope.data.column.columnname]].name : '--'
          value:this.mainData.leadername
        },
        {
          label:'客户简称',
          value: this.mainData.abbreviation
        },
        {
          label:'用户类型',
          value: this.mainData.type
        },
        {
          label:'客户等级',
          // value: this.customerLead.find(item => item.rowindex == this.mainData.grade).value
          value:this.mainData.grade
        },
        {
          label:'客户来源',
          value: this.mainData.source
        },
        {
          label:'所在行业',
          value: this.mainData.industry
        },
        {
          label:'交易状态',
          value: this.mainData.tradingstatus
        },
        {
          label:'数据状态',
          value: this.mainData.datastatus == 0 ? '正常' : this.mainData.datastatus == 1 ? '作废' : '锁定'
        },
        {
          label:'客户状态',
          value: this.mainData.status
        },
        {
          label:'创建人',
          value: this.mainData.createby
        },
        {
          label:'创建时间',
          value: this.mainData.createdate
        },
      ]
    }
  },
  mounted () {
  },
  created () {
    // 验证权限
    // this.tool.checkAuth(this.$route.name,'update')?'':this.$router.go(-1)
    this.queryMainData(this.$route.query.id)
    this.getSysOption()
    this.query_arealist()
  },
}

</script>
<style>
</style>