<template>
  <div class="corePersonnel">
    <head-form
      title="同地区城投"
      :form-data="formData"
      :query-params="queryParams"
      :total="tableDataTotal"
      :isExcel="true"
      @handle-search="handleSearch"
    />

    <tables
      :tableLoading="tableLoading"
      :tableData="tableData"
      :forData="forData"
      :tableDataTotal="tableDataTotal"
      :queryParams="queryParams"
      @handle-current-change="handleCurrentChange"
      @sort-change="sortChange"
    />

  </div>
</template>

<script>
import mixin from '../mixins/mixin'
import dataRegion from '@/assets/json/dataRegion'
export default {
  name: 'SameRegion',
  mixins: [mixin],
  components: {

  },
  data() {
    return {
      queryParams: {
        cid: 6034,
        pageNum: 1,
        pageSize: 10
      },
      forData: [
        {label: '企业名称', prop: 'punishReason'},
        {label: '成员层级', prop: 'punishBegin', width: '120'},
        {label: '法定代表人', prop: 'punishResult', width: '120'},
        {label: '注册资本', prop: 'fileNum', width: '120', sortable:true},
        {label: '成立日期', prop: 'cgrdm', width: '120', sortable:true},
        {label: '实控人控股', prop: 'office', width: '130', sortable:true},
        {label: '行业类型', prop: 'dataId', width: '120'},
        {label: '所属省', prop: 'dataId', width: '120'},
        {label: '所属市', prop: 'dataId', width: '120'},
        {label: '所属区/县', prop: 'dataId', width: '120'}
      ],
      formData: [
        { type: 1, fieldName: 'penalizeReasonType', value: '', placeholder: '筛选',
          options: []
        },
        { type: 3, fieldName: 'keys', value: '', placeholder: '请输入关键词', options: []},
      ],
      props: {
        value: 'id',
        multiple: true,
      },
      addressList: [],
      //列表
      tableLoading:false,
      tableData:[],
      tableDataTotal:0,
    }
  },
  created() {
    this.dataRegion()
  },
  computed: {

  },
  methods: {
    async dataRegion() {
      // await axios.post("https://files.jiansheku.com/file/json/common/dataRegion.json", {}, {
      //   headers: {
      //     'Content-Type': 'application/json'
      //   }
      // }).then(res => {
      //   if (res.data.code == 200) {
      //     console.log(res.data.data)
      //   }
      // })
      var str = [];
      for (let x = 0; x < 3; x++) {
        for (let i = 0; i < dataRegion.length; i++) {
          if (dataRegion[i].regionLevel == x + 1 && x + 1 == 1) {
            str.push({
              'id': dataRegion[i].id,
              "label": dataRegion[i].regionName,
              "short": dataRegion[i].short,
              "value": dataRegion[i].parentId,
              "children": []
            });
          } else if (dataRegion[i].regionLevel == x + 1 && x + 1 == 2) {
            for (let j = 0; j < str.length; j++) {
              if (str[j].id == dataRegion[i].parentId) {
                str[j].children.push({
                  'id': dataRegion[i].id,
                  "label": dataRegion[i].regionName,
                  "short": dataRegion[i].short,
                  "value": dataRegion[i].parentId,
                  "children": []
                });
              }
            }
          } else if (dataRegion[i].regionLevel == x + 1 && x + 1 == 3) {
            for (let j = 0; j < str.length; j++) {
              for (let k = 0; k < str[j].children.length; k++) {
                if (str[j].children[k].id == dataRegion[i].parentId) {
                  str[j].children[k].children.push({
                    'id': dataRegion[i].id,
                    "label": dataRegion[i].regionName,
                    "short": dataRegion[i].short,
                    "value": dataRegion[i].parentId
                    // "children":[]
                  });
                }
              }
            }
          }
        }
      }
      this.addressList = str;
    },
    handleQuery() {

    },
    resetQuery() {

    },
    //分页
    handleCurrentChange(e){

    },
    handleSizeChange(e){

    }
  }
}
</script>
<style lang="scss" scoped>
.corePersonnel{
  background: #ffffff;
  border-radius: 4px;
  padding: 16px;
  .query-box{
    margin: 10px 0 20px;
  }
}
</style>
