<template>
  <div>
    <el-dialog
      :title="title"
      :close-on-click-modal="false"
	  draggable
      width="500px"
      height="500px"
      @close="close"
      append-to-body
	  v-model="visible">
		<div v-if="isShow">
			<el-radio v-model="checkType" label="1" style="margin-right: 20px">所内</el-radio>
			<el-radio v-model="checkType" label="2" style="margin-right: 20px">所外</el-radio>
		</div>
      <div style="height: calc(100% - 80px);" v-if="checkType === '2'">
        <el-form :inline="true" class="query-form" ref="searchForm" :model="searchForm" @keyup.enter.native="refreshList()" @submit.native.prevent>
          <!-- 搜索框-->
          <el-form-item label="" prop="name">
            <el-input v-model="searchForm.name" placeholder="请输入地区名称" clearable></el-input>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" @click="list()" icon="el-icon-search">查询</el-button>
            <el-button @click="resetSearch()" icon="el-icon-refresh-right">重置</el-button>
          </el-form-item>
        </el-form>
        <vxe-table
          border="inner"
          auto-resize
          resizable
          height="300px"
          :loading="loading"
          size="small"
          ref="userTable"
          show-header-overflow
          show-overflow
          highlight-hover-row
          :menu-config="{}"
          :sort-config="{remote:true}"
          :data="dataList"
          :row-config="{isCurrent: true}"
          :radio-config="{trigger: 'row'}"
          :tree-config="{transform: true, rowField: 'id', parentField: 'parentId',expandAll: true}"
          :checkbox-config="{}">
          <vxe-column type="radio" width="50" ></vxe-column>

          <vxe-column title="地区" min-width="180" field="name" align="left" tree-node></vxe-column>
        </vxe-table>
      </div>
		<template #footer>
			<span class="dialog-footer">
			  <el-button @click="close()" icon="el-icon-circle-close">关闭</el-button>
			  <el-button type="primary" v-if="method != 'view'" @click="getProgramForUser()" icon="el-icon-circle-check" v-noMoreClick>确定</el-button>
			</span>
		</template>

    </el-dialog>
  </div>
</template>

<script>
  import areaService from '@/api/sys/areaService'
  export default {
    data () {
      return {
        title: '',
        method: '',
		  checkType: '',
		  isShow: true,
        visible: false,
        loading: false,
		  dataList: [],
		  searchForm: {
          name: ''
        }
      }
    },
    created () {
    },
    components: {
    },
    methods: {
      init () {
		  this.checkType = '1'
        this.title = '地区选择'
        this.visible = true
        this.list()
      },
      // 表单提交
      getProgramForUser () {
		  if (this.checkType === '1') {
			  let rows = []
			  rows.bj1 = 'bj1'
			  rows.checkType = this.checkType
			  this.close()
			  this.$emit('getProgramForUser', rows)
		  }else if (this.checkType === '2') {
			let rows = []
			if (this.commonJS.isEmpty(this.$refs.userTable.getRadioRecord())) {
				this.$message.error('请选择一条数据')
				return
			}
			let row = this.$refs.userTable.getRadioRecord()
			console.log('row.code', row.code)
			if (row.code === '100000' || row.code === 100000) {
				this.$message.error('请选择子集数据')
				return
			}
			this.close()
			rows.push(row)
			  rows.checkType = this.checkType
			this.$emit('getProgramForUser', rows)
		}

      },
      list () {
        this.loading = true
		  areaService.getAllArea(this.searchForm.name).then((data) => {
          this.dataList = data
          this.loading = false
          this.$nextTick(() => {
            this.$refs.userTable.setAllTreeExpand(true)
          })
        })
      },
      // 当前页
      currentChangeHandle ({currentPage, pageSize}) {
        this.tablePage.currentPage = currentPage
        this.tablePage.pageSize = pageSize
        this.list()
      },
      resetSearch () {
        this.$refs.searchForm.resetFields()
        this.list()
      },
      close () {
        this.detail = ''
        this.visible = false
      }
    }
  }
</script>
<style>
  .messageZindex {
    z-index:9999 !important;
  }
</style>
<style scoped>
  /deep/ .el-dialog__body {
    padding-top: 0px;
  }
</style>
