<template>
  <div>
    <el-button size="small" type="primary" icon="el-icon-plus" @click="query_arealist(dialogVisible = true)">新 建</el-button>
    <el-dialog title="新建管辖区域" :visible.sync="dialogVisible" width="400px">
      <el-cascader
        style="width:100%"
        class="width-240"
        v-model="value"
        :options="arealist"
        size="small"
        :props="{ checkStrictly: true }"
        @change="cascaderChange">
      </el-cascader>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="dialogVisible = false">取 消</el-button>
        <el-button size="small" type="primary" @click="submit()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props:['data'],
  data () {
    return {
      dialogVisible:false,
      value:[],
      arealist:[]
    }
  },
  methods:{
    async query_arealist() {
      const res = await this.$api.requested({
        "classname": "system.tools",
        "method": "query_arealist",
        "content": {
        }
      })
      this.arealist = this.tool.createMenu(res.data)
    },
    cascaderChange (val) {
      console.log(val)
    },
    async submit () {
      if(this.value.length === 0) return this.$message({
        message:'请选择省份',
        type:'warning'
      })
      const res = await this.$api.requested({
        "classname": "webmanage.sale.saleareascope.saleareascope",
        "method": "insertormodify_areascope",
        "content": {
            "sa_salearea_salescopeid":0,
            "sa_saleareaid":this.data.sa_saleareaid,
            "province":this.value[0],
            "city":this.value[1]?this.value[1]:'',
            "county":this.value[2]?this.value[2]:''
        }
      })
      
      this.tool.showMessage(res,()=>{
        this.dialogVisible = false
        this.$emit('onSuccess')
      })
    }
  }
}

</script>
<style>
</style>