<template>
    <div>
      <add v-if="tool.checkAuth($route.name,'areaAuthAdd')" @onSuccess="alreadyAuthField" class="mt-10" />
      <el-table
        :data="alfield"
        style="width: 100%"
        size="small"
        border>
        <el-table-column
          prop="tradefield"
          label="授权领域">
        </el-table-column>
        <el-table-column
          prop="tradefieldmx"
          label="领域明细">
        </el-table-column>
        <el-table-column
          prop="name"
          label="业务员">
        </el-table-column>
        <el-table-column
          prop="areaname"
          label="营销区域">
        </el-table-column>
        <el-table-column
          label="操作">
          <template slot-scope="scope">
            <el-popconfirm
              title="确定删除吗？"
              @confirm="deleteField(scope.row)">
              <el-button v-if="tool.checkAuth($route.name,'areaAuthDel')" slot="reference" type="text" size="mini">删除</el-button>
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>
    </div>
</template>
<script>
import add from './add'
  export default {
    components: {add},
    props:['data'],
    data () {
      return {
        alfield:[],
        dialogVisible:false,
        param:{
          "id": 20221223141802,
          "content": {
              "sys_enterpriseid": 0,
              "pageNumber": 1,
              "pageSize": 100,
              "where": {
                "condition": ""
              }
          },
        }
      }
    },
    methods:{
      async authField (row) {
        const res = await this.$api.requested({
          "id":20221223141602,
          "content": {
            "sys_enterpriseid": this.data.sys_enterpriseid,
            "tradefield":row.value
          },
        })
        this.tool.showMessage(res,()=>{
          this.dialogVisible = false
          this.alreadyAuthField()
        })
      },
      async alreadyAuthField () {
        this.param.content.sys_enterpriseid = this.data.sys_enterpriseid
        const res = await this.$api.requested(this.param)
        this.alfield = res.data
        console.log(res.data);
        
      },
      async deleteField (row) {
        const res = await this.$api.requested({
          "id":20221223141702,
          "content": {
            "sys_enterprise_tradefieldids": [row.sys_enterprise_tradefieldid]
          },
        })
        this.tool.showMessage(res,()=>{
          this.alreadyAuthField()
        })
      },
    },
    mounted () {
      this.alreadyAuthField()
    }
  }
</script>