<template>
  <div>
    <basicDetails
        ref="details"
        :titleText="mainData.name"
        formPath="marketing2/saler"
        :editData="mainData"
        :mainAreaData="mainAreaData"
        turnPageId="20221011144603"
        idname="sa_salearea_hrid"
        ownertable="sa_salearea_hr"
        tags=""
        :tabs="['详细信息']"
        @pageChange="pageChange"
        @onEditSuccess="queryMainData($route.query.id)">
      <div slot="tags">
      </div>
      <div slot="customOperation" >
        <el-button v-if="tool.checkAuth($route.name,'delete')" type="primary" size="mini" @click="deleteSaler">删 除</el-button>
      </div>
      <div slot="slot0" >
        <detailed :detailData="mainData"></detailed>
      </div>
    </basicDetails>
  </div>
</template>

<script>
import detailed from './modules/detailedData'
export default {
  components:{detailed},
  data () {
    return {
      mainData:{},
      mainAreaData:{}
    }
  },
  methods:{
    async deleteSaler () {
      this.$confirm('确定删除当前业务员吗?','提示',{
        confirmButtonText:'确定',
        cancelButtonText:'取消',
        type:'warning'
      }).then(async() => {
        let res = await this.$api.requested({
          "id":20221011144803,
          "content": {
            sa_saleareaids: [
              {
                sa_saleareaid: this.mainData.sa_saleareaid,
                hrid: this.mainData.hrid
              }
            ]
          }
        })
        this.tool.showMessage(res,() => {
          this.$store.dispatch('changeDetailDrawer',false)
        })
      })
    },
    async queryMainData (id) {
      const res = await this.$api.requested({
        "classname": "webmanage.sale.salearea.salearea",
        "method": "query_salermain",
        "content": {
          "sa_salearea_hrid":id
        }
      })
      this.mainData = res.data
      this.$refs['details'].param.content.sa_saleareaid = this.mainData.sa_saleareaid
      this.changeDataStructure()
    },
    // 监听切换数据,上一页,下一页
    pageChange (id,rowindex) {
      this.$router.replace({path:'/saler_detail',query:{id:id,rowindex:rowindex}})
      this.queryMainData(id)
    },
    changeDataStructure () {
      this.mainAreaData = [
        {
          label:'编号',
          value:this.mainData.hrcode
        },
        {
          label:'登录账号',
          value:this.mainData.accountno
        },
        {
          label:'业务员',
          value:this.mainData.name
        },
        {
          label:'部门',
          value:this.mainData.depname
        },
        {
          label:'手机号',
          value:this.mainData.phonenumber
        },
        {
          label:'邮箱',
          value:this.mainData.email
        },
        {
          label:'负责区域',
          value:this.mainData.areaname
        },
        {
          label:'汇报对象',
          value:this.mainData.reporthrname
        },
        {
          label:'最低授权折扣(%)',
          value:Math.round((this.mainData.discountrate*100)*100)/100
        }
      ]
    },
  },
  mounted () {
    /*this.query_salermain()*/

    console.log("id"+'_____'+this.$route.query.id)
    this.queryMainData(this.$route.query.id)
  }
}

</script>
<style>
</style>