<template>
  <div class="changeinfo-wrapper">
    <div class="el-search-wrapper">
      <el-row>
        <el-col :span="9">
          <el-input v-model="enterSearchInfo" placeholder="请输入企业信息" />
        </el-col>
        <el-col :span="5">
          &nbsp;&nbsp;<el-button type="success" @click="searchEnterprise">搜索</el-button>
        </el-col>
        <el-col :span="8">
          <div style="display: flex">
            <el-button type="primary"  @click="exportEnters" v-loading="isExportLoading" :disabled="isExportLoading">导出</el-button>
            <!-- <el-progress style="flex-grow: 1;margin-left: 20px;margin-top: 10px;" :percentage="curExportProgress" status="success"></el-progress> -->
          </div>
        </el-col>
        <el-col :span="2">
          <div class="import-file-risk-wrapper" @click="importEnter">
            <label class="import-file-risk">
              导入
              <input ref="fileuploadEnter" type="file" multiple hidden @change="realImportEnter">
            </label>
          </div>
        </el-col>
      </el-row>
    </div>
    <el-table
      v-loading="isEnterloading"
      :data="coms"
      style="width: 100%"
    >
      <el-table-column
        prop="companyName"
        label="企业名称"
      />
      <el-table-column
        prop="companyStatus"
        label="企业状态"
      />
      <el-table-column
        prop="companyIndustryName"
        label="行业类型"
      />
      <el-table-column
        prop="companyCounty"
        label="所属区域"
      />
      <el-table-column
        prop="companyChargePer"
        label="主要负责人"
      />
      <el-table-column
        prop="companyChargeTel"
        label="联系电话"
      />
      <el-table-column>
        <template slot-scope="scope">
          <el-button size="mini" type="warning" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :current-page="curPageDegree"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="curPageSum"
      layout="total, sizes, prev, pager, next, jumper"
      :total="curSumDegree"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
    <el-dialog
      title="修改企业信息"
      :visible.sync="dialogVisible"
      width="60%"
      @opened="openDialog"
    >
      <el-form ref="formenterinfo1" :rules="formenterinforules" :model="formenterinfo" label-width="180px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="企业名称:" prop="companyName">
              <el-input v-model="formenterinfo.companyName" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="企业状态:" prop="companyStatus">
              <el-select v-model="formenterinfo.companyStatus" placeholder="请选择企业状态">
                <el-option label="正常生产" value="正常生产" />
                <el-option label="停产企业" value="停产企业" />
                <el-option label="已经注销" value="已经注销" />
                <el-option label="基建企业" value="基建企业" />
                <el-option label="停建企业" value="停建企业" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="行业类型:" prop="companyIndustryName">
              <el-select v-model="formenterinfo.companyIndustryName" placeholder="请选择行业类型">
                <el-option v-for="(item, index) in industryNames" :key="index" :label="item.industryName" :value="item.industryName" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否化工" prop="companyChemical">
              <el-radio-group v-model="formenterinfo.companyChemical">
                <el-radio label="1" value="1">是</el-radio>
                <el-radio label="0" value="0">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="国民行业类型" prop="companyDimTwoIndustryName">
          <el-select v-model="curNationIndusLevel1" @change="nationInduschangelevel1">
            <el-option v-for="(item, index) in nationindusNames" :key="index" :label="item.name" :value="item.name" />
          </el-select>
          <el-select v-if="nationindusSecondNames.length > 0" v-model="curNationIndusLevel2" @change="nationInduschangelevel2">
            <el-option v-for="(item, index) in nationindusSecondNames" :key="index" :label="item.name" :value="item.name" />
          </el-select>
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="统一社会信用代码:" prop="companyCode">
              <el-input v-model="formenterinfo.companyCode" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="总人数" prop="companyPeople">
              <el-input v-model="formenterinfo.companyPeople" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="所属地区" prop="companyCounty">
          <el-select v-model="region1model" @change="region1schange">
            <el-option v-for="(item, index) in regionlevel1" :key="index" :label="item.name" :value="item.areaCode" />
          </el-select>
          <el-select v-if="regionlevel2.length > 0" v-model="region2model" @change="region2schange">
            <el-option v-for="(item, index) in regionlevel2" :key="index" :label="item.name" :value="item.areaCode" />
          </el-select>
          <el-select v-if="regionlevel3.length > 0" v-model="region3model" @change="region3schange">
            <el-option v-for="(item, index) in regionlevel3" :key="index" :label="item.name" :value="item.areaCode" />
          </el-select>
          <el-select v-if="regionlevel4.length > 0" v-model="region4model" @change="region4schange">
            <el-option v-for="(item, index) in regionlevel4" :key="index" :label="item.name" :value="item.areaCode" />
          </el-select>
          <el-select v-if="regionlevel5.length > 0" v-model="region5model" @change="region5schange">
            <el-option v-for="(item, index) in regionlevel5" :key="index" :label="item.name" :value="item.areaCode" />
          </el-select>
        </el-form-item>
        <el-form-item label="值班电话" prop="dutytel">
          <el-input v-model="formenterinfo.companyDutyTel" />
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="主要负责人" prop="companyChargePer">
              <el-input v-model="formenterinfo.companyChargePer" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="主要负责人电话" prop="companyChargeTel">
              <el-input v-model="formenterinfo.companyChargeTel" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="安全负责人">
              <el-input v-model="formenterinfo.companySecurityPer" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="安全负责人电话">
              <el-input v-model="formenterinfo.companySecurityTel" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="企业简介">
          <el-input v-model="formenterinfo.companyIntroduction" type="textarea" />
        </el-form-item>
        <el-form-item label="通讯地址">
          <el-input v-model="formenterinfo.companyCommunicationAddr" />
        </el-form-item>
        <el-form-item label="经营范围">
          <el-input v-model="formenterinfo.companyBusinessNature" type="textarea" />
        </el-form-item>
        <el-form-item label="原料">
          <el-input v-model="formenterinfo.companyRawMaterial" />
        </el-form-item>
        <el-form-item label="主要产品">
          <el-input v-model="formenterinfo.companyMainProduct" />
        </el-form-item>
        <el-form-item label="地理坐标">
          <el-row>
            <el-col :span="8">
              <el-input v-model="tochoosecomregion" size="mini" placeholder="请输入公司名称或公司所在地" />
            </el-col>
            <el-col :span="16">
              <el-button size="mini" type="primary" @click="searchcom">搜索</el-button>
            </el-col>
          </el-row>
          <el-row>
            <el-select v-if="companyregions.length > 0" v-model="comrealpos" style="width: 40%;" @change="comrealposselect">
              <el-option v-for="(item, index) in companyregions" :key="index" :label="item.name + '-' + item.address" :value="item.location.lng + ',' + item.location.lat" />
            </el-select>
          </el-row>
        </el-form-item>
      </el-form>
      <div class="submit-map-wrapper">
        <div id="submitformmap" />
        <div class="pos-info-wrapper">
          <div>坐标经纬度:&nbsp;</div>
          <div class="submitoriginpos" />
          <div>&nbsp;&nbsp;鼠标经纬度:&nbsp;</div>
          <div class="submitmousepos" />
        </div>
      </div>
      <div class="submitbtnwrapper">
        <el-button type="primary" @click="submitlittleform">提交</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import axiosFile from '@/utils/requestfile.js'
import axios from 'axios'
import { getindustry, getAllProvince, findAreaByCode, findCompanyCounty, findAllByCompanyCounty, changeCompanyInfo, deleteCompanyInfo, findDimindustry, getAllCompanyInfo } from '../api/industry'
export default {
  data() {
    return {
      // 当前页码
      curPageDegree: 1,
      // 当前一页的数量
      curPageSum: 10,
      // 当前企业总数
      curSumDegree: 0,
      // 查询企业信息
      enterSearchInfo: '',
      // 所有企业
      coms: [],
      comsreplace: [],
      dialogVisible: false,
      formenterinfo: {
        companyName: '',
        companyStatus: '正常生产',
        companyIndustryName: '一般化工行业',
        companyChemical: '1',
        companyCode: '',
        companyPeople: '',
        companyDutyTel: '',
        companyChargePer: '',
        companyChargeTel: '',
        companySecurityPer: '',
        companySecurityTel: '',
        companyIntroduction: '',
        companyCommunicationAddr: '',
        companyBusinessNature: '',
        companyRawMaterial: '',
        companyMainProduct: '',
        companyLng: '',
        companyLat: '',
        companyProvince: '',
        companyCity: '',
        companyCounty: '',
        companyCommunity: '',
        companyTown: '',
        companyEnclosureAddr: 'aaa',
        companyDimOneIndustryName: '',
        companyDimTwoIndustryName: ''
      },
      formenterinforules: {
        companyName: [
          { required: true, message: '请输入企业名称', trigger: 'blur' },
          { min: 2, message: '长度须大于2个字符', trigger: 'blur' }
        ],
        companyCounty: [
          { required: true, message: '请输入地址', trigger: 'change' }
        ],
        companyIndustryName: [
          { required: true, message: '请输入行业类型', trigger: 'blur' }
        ],
        companyChargePer: [
          { required: true, message: '请输入主要负责人', trigger: 'blur' },
          { min: 1, message: '长度须大于1个字符', trigger: 'blur' }
        ],
        companyChargeTel: [
          { required: true, message: '请输入主要负责人电话', trigger: 'blur' },
          { min: 1, message: '长度须大于1个字符', trigger: 'blur' }
        ],
        companyDimTwoIndustryName: [
          { required: true, message: '请输入国民经济行业类型', trigger: 'change' }
        ],
        companyCode: [
          { required: true, message: '请输入统一信用代码', trigger: 'blur' }
        ]
      },
      // 当前输入的地点
      tochoosepos: '',
      map: null,
      industryNames: [],
      region1model: '',
      region2model: '',
      region3model: '',
      region4model: '',
      region5model: '',
      regionlevel1: [],
      regionlevel2: [],
      regionlevel3: [],
      regionlevel4: [],
      regionlevel5: [],
      companyregions: [],
      // input选择的坐标
      tochoosecomregion: '',
      // 公司选择的坐标
      comrealpos: '',
      // 5个当前地点的总计
      completeposname: '',
      // 国民经济行业第一级别列表
      nationindusNames: [],
      // 国民经济行业第二级别列表
      nationindusSecondNames: [],
      // 当前选择的国民经济行业第一级别
      curNationIndusLevel1: '',
      // 当前选择的国民经济行业第二级别
      curNationIndusLevel2: '',
      // 当前是否正在加载
      isEnterloading: false,
      // 是否显示提示框
      isShowAlert: false,
      curExportProgress: 0,
      isExportLoading: false,
      curExportTimer: null
    }
  },
  mounted() {
    // this.getAllInfo()
    this.getAllInfo2()
    getindustry().then(res => {
      this.industryNames = [...res.content]
    })
  },
  methods: {
    async getAllInfo() {
      let county = []
      await findCompanyCounty().then(res => {
        county = [...res]
      })
      const countryComArr = []
      const promiseArray = []
      county.forEach((item) => {
        const promise1 = findAllByCompanyCounty(item).then(res => {
          // countryComArr.push(res)
          // Array.prototype.push.apply(countryComArr, ...item)
          for (const item1 of res) {
            countryComArr.push(item1)
          }
        })
        promiseArray.push(promise1)
      })
      Promise.all(promiseArray).then(res => {
        this.coms = [...countryComArr]
      })
    },
    async getAllInfo2() {
      this.isEnterloading = true
      await getAllCompanyInfo({
        page: this.curPageDegree - 1,
        size: this.curPageSum
      }).then(res => {
        this.curSumDegree = res.totalElements
        this.coms = [...res.content]
        this.isEnterloading = false
      }, () => {
        this.isEnterloading = false
      })
    },
    handleEdit(index, row) {
      // 编辑
      this.formenterinfo = { ...row }
      // console.log(typeof this.formenterinfo.companyChemical, 'dfdffdfdfdfdfdfdfdfdfdfdf')
      this.formenterinfo.companyChemical = this.formenterinfo.companyChemical + ''
      this.dialogVisible = true
    },
    handleDelete(index, row) {
      this.$confirm('此操作将删除企业相关信息, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // 删除
        this.isEnterloading = true
        deleteCompanyInfo(row.companyId).then(res => {
          this.$message({
            type: 'success',
            message: '删除成功'
          })
          this.isEnterloading = false
          this.getAllInfo2()
        }, () => {
          this.isEnterloading = false
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    async openDialog() {
      this.nationindusNames = []
      // console.log(this.nationindusNames, '好奇1')
      // 初始化国民经济行业
      setTimeout(async() => {
        await findDimindustry().then(res => {
          this.nationindusNames = [...res]
          this.curNationIndusLevel1 = this.formenterinfo.companyDimOneIndustryName
          console.log(res, '国民第一经济行业1111111')
        })
        // 初始化国民第二经济行业
        if (this.curNationIndusLevel1 !== '') {
          this.formenterinfo.companyDimOneIndustryName = this.curNationIndusLevel1
          await findDimindustry(this.nationindusNames.filter(item => item.name === this.curNationIndusLevel1)[0].industryId).then(res => {
            this.nationindusSecondNames = [...res]
            this.curNationIndusLevel2 = this.formenterinfo.companyDimTwoIndustryName
            console.log(res, '国民第二经济行业1111111')
          })
        }
      }, 1)
      // 获取所有省份信息
      setTimeout(async() => {
        await getAllProvince().then(res => {
          this.regionlevel1 = [...res]
        })
        const areaCode1 = this.regionlevel1.filter(item => item.name === this.formenterinfo.companyProvince)[0].areaCode
        await findAreaByCode(areaCode1, 1).then(res => {
          this.regionlevel2 = [...res]
        })
        const areaCode2 = this.regionlevel2.filter(item => item.name === this.formenterinfo.companyCity)[0].areaCode
        await findAreaByCode(areaCode2, 2).then(res => {
          this.regionlevel3 = [...res]
        })
        const areaCode3 = this.regionlevel3.filter(item => item.name === this.formenterinfo.companyCounty || (item.name === '威海经济技术开发区' && this.formenterinfo.companyCounty === '经济技术开发区'))[0].areaCode
        await findAreaByCode(areaCode3, 3).then(res => {
          this.regionlevel4 = [...res]
        })
        let areaCode4 = ''
        if (this.formenterinfo.companyCommunity) {
          areaCode4 = this.regionlevel4.filter(item => item.name === this.formenterinfo.companyCommunity)[0].areaCode
          await findAreaByCode(areaCode4, 4).then(res => {
            this.regionlevel5 = [...res]
          })
        }
        let areaCode5 = ''
        if (this.formenterinfo.companyTown) {
          areaCode5 = this.regionlevel5.filter(item => item.name === this.formenterinfo.companyTown)[0].areaCode
        }
        this.region1model = areaCode1
        this.region2model = areaCode2
        this.region3model = areaCode3
        this.region4model = areaCode4
        this.region5model = areaCode5
      })
      this.tochoosecomregion = this.formenterinfo.companyProvince + this.formenterinfo.companyCity + this.formenterinfo.companyCounty + this.formenterinfo.companyCommunity + this.formenterinfo.companyTown
      // 在这里画地图
      const AMap = window.AMap || {}
      const satellite = new AMap.TileLayer.Satellite()
      const roadNet = new AMap.TileLayer.RoadNet()
      this.map = new AMap.Map('submitformmap', {
        resizeEnable: true, // 是否监控地图容器尺寸变化
        zoom: 16, // 初始化地图层级
        center: [Number(this.formenterinfo.companyLng), Number(this.formenterinfo.companyLat)],
        layers: [
          satellite,
          roadNet
        ]
      })
      const marker = new AMap.Marker({
        icon: 'https://webapi.amap.com/theme/v1.3/markers/n/mark_r.png',
        position: [Number(this.formenterinfo.companyLng), Number(this.formenterinfo.companyLat)],
        // anchor: 'bottom-center'
        offset: new AMap.Pixel(-10, -31)
      })
      this.marker = marker
      this.map.on('mousemove', (e) => {
        document.querySelector('.submitmousepos').innerHTML = e.lnglat.getLng() + ',' + e.lnglat.getLat()
      })
      document.querySelector('.submitoriginpos').innerHTML = this.formenterinfo.companyLng + ',' + this.formenterinfo.companyLat
      // this.formenterinfo.companyLng = '122.086287'
      // this.formenterinfo.companyLat = '37.493758'
      this.map.add(marker)
      this.map.on('click', (e) => {
        document.querySelector('.submitoriginpos').innerHTML = e.lnglat.getLng() + ',' + e.lnglat.getLat()
        // document.querySelector('.submitoriginpos').innerHTML = '122.086287, 37.493758'
        // map.remove(marker)
        // marker = new AMap.Marker({

        // })
        this.map.setCenter([e.lnglat.getLng(), e.lnglat.getLat()])
        marker.setPosition(e.lnglat)
        this.formenterinfo.companyLng = '' + e.lnglat.getLng()
        this.formenterinfo.companyLat = '' + e.lnglat.getLat()
        AMap.plugin('AMap.Geocoder', () => {
        // 在这里面获取到点击经纬度的所对应的地理信息
          const geocoder = new AMap.Geocoder({
            radius: 1000
          })
          geocoder.getAddress(e.lnglat, (status, result) => {
            if (status === 'complete' && result && result.info === 'OK' && result.regeocode) {
              this.setRegionSelect(result.regeocode.addressComponent.province, result.regeocode.addressComponent.city, result.regeocode.addressComponent.district)
              this.comrealpos = result.regeocode.formattedAddress
              this.tochoosecomregion = this.comrealpos
              AMap.plugin('AMap.PlaceSearch', () => {
                const placesearch = new AMap.PlaceSearch({})
                placesearch.search(this.comrealpos, (status, result) => {
                  if (status === 'complete' && result.info === 'OK' && result.poiList.pois && result.poiList.pois.length > 0) {
                    this.companyregions = [...result.poiList.pois]
                  }
                })
              })
            }
          })
        })
      })
      AMap.plugin('AMap.Geocoder', () => {
      // 在这里面获取到点击经纬度的所对应的地理信息
        const geocoder = new AMap.Geocoder({
          radius: 1000
        })
        geocoder.getAddress(new AMap.LngLat(Number(this.formenterinfo.companyLng), Number(this.formenterinfo.companyLat)), (status, result) => {
          if (status === 'complete' && result && result.info === 'OK' && result.regeocode) {
            this.comrealpos = result.regeocode.formattedAddress
            AMap.plugin('AMap.PlaceSearch', () => {
            // 查询公司地点
              const placesearch = new AMap.PlaceSearch({})
              placesearch.search(this.comrealpos, (status, result) => {
                if (status === 'complete' && result.info === 'OK' && result.poiList.pois && result.poiList.pois.length > 0) {
                  this.companyregions = [...result.poiList.pois]
                }
              })
            })
          }
        })
      })
    },
    searchpos() {
      // const AMap = window.AMap || {}
      const tochoosepos = this.tochoosepos
      // const map = this.map || {}
      if (tochoosepos === '') {
        return
      }
      if (tochoosepos !== '') {

      }
    },
    searchcom() {
      // 搜索公司
      // companyregions
      const AMap = window.AMap || {}
      const tochoosecomregion = this.tochoosecomregion
      // const map = this.map || {}
      if (tochoosecomregion === '') {
        return
      }
      if (tochoosecomregion !== '') {
        AMap.plugin('AMap.PlaceSearch', () => {
          // 查询公司地点
          const placesearch = new AMap.PlaceSearch({
            // map: map
          })
          placesearch.search(tochoosecomregion, (status, result) => {
            if (status === 'complete' && result.info === 'OK' && result.poiList.pois && result.poiList.pois.length > 0) {
              this.companyregions = [...result.poiList.pois]
              // console.log(this.companyregions, 'this.companyregions, this.companyregions, this.companyregions')
            }
          })
        })
      }
    },
    region1schange() {
      // 根据region1model选择区域
      // this.regionlevel2 =
      findAreaByCode(Number(this.region1model), 1).then(res => {
        this.regionlevel2 = [...res]
      })
      this.completeposname = this.regionlevel1.filter(item => {
        return item.areaCode === Number(this.region1model)
      })[0].name
      this.tochoosecomregion = this.completeposname
      this.searchPosPro(this.tochoosecomregion)
      this.formenterinfo.companyProvince = this.regionlevel1.filter(item => {
        return item.areaCode === Number(this.region1model)
      })[0].name
    },
    region2schange() {
      findAreaByCode(Number(this.region2model), 2).then(res => {
        this.regionlevel3 = [...res]
      })
      this.completeposname = this.regionlevel1.filter(item => {
        return item.areaCode === Number(this.region1model)
      })[0].name
      this.completeposname += this.regionlevel2.filter(item => {
        return item.areaCode === Number(this.region2model)
      })[0].name
      this.tochoosecomregion = this.completeposname
      this.searchPosPro(this.tochoosecomregion)
      this.formenterinfo.companyCity = this.regionlevel2.filter(item => {
        return item.areaCode === Number(this.region2model)
      })[0].name
    },
    region3schange() {
      findAreaByCode(Number(this.region3model), 3).then(res => {
        this.regionlevel4 = [...res]
      })
      this.completeposname = this.regionlevel1.filter(item => {
        return item.areaCode === Number(this.region1model)
      })[0].name
      this.completeposname += this.regionlevel2.filter(item => {
        return item.areaCode === Number(this.region2model)
      })[0].name
      this.completeposname += this.regionlevel3.filter(item => {
        return item.areaCode === Number(this.region3model)
      })[0].name
      this.tochoosecomregion = this.completeposname
      this.searchPosPro(this.tochoosecomregion)
      this.formenterinfo.companyCounty = this.regionlevel3.filter(item => {
        return item.areaCode === Number(this.region3model)
      })[0].name
    },
    region4schange() {
      findAreaByCode(Number(this.region4model), 4).then(res => {
        this.regionlevel5 = [...res]
      })
      this.completeposname = this.regionlevel1.filter(item => {
        return item.areaCode === Number(this.region1model)
      })[0].name
      this.completeposname += this.regionlevel2.filter(item => {
        return item.areaCode === Number(this.region2model)
      })[0].name
      this.completeposname += this.regionlevel3.filter(item => {
        return item.areaCode === Number(this.region3model)
      })[0].name
      this.completeposname += this.regionlevel4.filter(item => {
        return item.areaCode === Number(this.region4model)
      })[0].name
      this.tochoosecomregion = this.completeposname
      this.searchPosPro(this.tochoosecomregion)
      this.formenterinfo.companyCommunity = this.regionlevel4.filter(item => {
        return item.areaCode === Number(this.region4model)
      })[0].name
    },
    region5schange() {
      this.completeposname = this.regionlevel1.filter(item => {
        return item.areaCode === Number(this.region1model)
      })[0].name
      this.completeposname += this.regionlevel2.filter(item => {
        return item.areaCode === Number(this.region2model)
      })[0].name
      this.completeposname += this.regionlevel3.filter(item => {
        return item.areaCode === Number(this.region3model)
      })[0].name
      this.completeposname += this.regionlevel4.filter(item => {
        return item.areaCode === Number(this.region4model)
      })[0].name
      this.completeposname += this.regionlevel5.filter(item => {
        return item.areaCode === Number(this.region5model)
      })[0].name
      this.tochoosecomregion = this.completeposname
      this.searchPosPro(this.tochoosecomregion)
      this.formenterinfo.companyTown = this.regionlevel5.filter(item => {
        return item.areaCode === Number(this.region5model)
      })[0].name
    },
    // 获取公司选中的位置，差一个定位中心
    comrealposselect(e) {
      console.log(this.comrealpos, 'what happen')
      const AMap = window.AMap || {}
      this.formenterinfo.companyLng = this.comrealpos.split(',')[0]
      this.formenterinfo.companyLat = this.comrealpos.split(',')[1]
      this.map.setCenter([Number(this.comrealpos.split(',')[0]), Number(this.comrealpos.split(',')[1])])
      this.marker.setPosition(new AMap.LngLat(Number(this.comrealpos.split(',')[0]), Number(this.comrealpos.split(',')[1])))
      document.querySelector('.submitoriginpos').innerHTML = this.comrealpos
    },
    // 获取公司的位置
    // 一个专门查询的方法
    clickComPos(item) {
      console.log(item, '别出问题啊啊 啊啊啊啊 啊啊啊啊啊啊啊')
    },
    searchPosPro(tochoosecomregion, isToCenter) {
      // 搜索公司
      // companyregions
      const AMap = window.AMap || {}
      // const tochoosecomregion = this.tochoosecomregion
      // const map = this.map || {}
      if (tochoosecomregion === '') {
        return
      }
      if (tochoosecomregion !== '') {
        AMap.plugin('AMap.PlaceSearch', () => {
          // 查询公司地点
          const placesearch = new AMap.PlaceSearch({
            // map: this.map
          })
          placesearch.search(tochoosecomregion, (status, result) => {
            if (status === 'complete' && result.info === 'OK' && result.poiList.pois && result.poiList.pois.length > 0) {
              this.companyregions = [...result.poiList.pois]
              if (this.companyregions.length > 0) {
                this.comrealpos = this.companyregions[0].location.lng + ',' + this.companyregions[0].location.lat
                this.marker.setPosition(new AMap.LngLat(Number(this.comrealpos.split(',')[0]), Number(this.comrealpos.split(',')[1])))
                if (typeof isToCenter === undefined) {
                  this.map.setCenter(new AMap.LngLat(Number(this.comrealpos.split(',')[0]), Number(this.comrealpos.split(',')[1])))
                  this.formenterinfo.companyLng = this.comrealpos.split(',')[0]
                  this.formenterinfo.companyLat = this.comrealpos.split(',')[1]
                }
              }
            }
          })
        })
      }
    },
    submitlittleform() {
      this.$refs.formenterinfo1.validate((valid) => {
        if (valid) {
          // 在这里判断this.formenterinfo
          // this.formenterinfo.com
          // let isFormValid = false
          if (this.formenterinfo.companyLng === '') {
            this.$message.error('请填写经纬度')
            return
          }
          if (this.formenterinfo.companyLat === '') {
            this.$message.error('请填写经纬度')
            return
          }
          changeCompanyInfo(this.formenterinfo).then(res => {
            this.$message({
              showClose: true,
              message: '编辑成功',
              type: 'success'
            })
            this.getAllInfo2()
          }, () => {
            this.$message({
              showClose: true,
              message: '编辑失败',
              type: 'error'
            })
          })
          this.dialogVisible = false
        } else {
          this.$message({
            message: '请传入正确数值',
            type: 'warning'
          })
        }
      })
    },
    // 根据省市区设置
    async setRegionSelect(province, city, district) {
      if (this.formenterinfo.companyProvince === province && this.formenterinfo.companyCity === city && this.formenterinfo.companyCounty === district) {
        console.log('')
      } else {
        this.regionlevel4 = []
        this.regionlevel5 = []
        this.region4model = ''
        this.region5model = ''
        // 获取所有省份信息
        await getAllProvince().then(res => {
          this.regionlevel1 = [...res]
        })
        const areaCode1 = this.regionlevel1.filter(item => item.name === province)[0].areaCode
        await findAreaByCode(areaCode1, 1).then(res => {
          this.regionlevel2 = [...res]
        })
        const areaCode2 = this.regionlevel2.filter(item => item.name === city)[0].areaCode
        await findAreaByCode(areaCode2, 2).then(res => {
          this.regionlevel3 = [...res]
        })
        const areaCode3 = this.regionlevel3.filter(item => item.name === district)[0].areaCode
        await findAreaByCode(areaCode3, 3).then(res => {
          this.regionlevel4 = [...res]
        })
        this.region1model = areaCode1
        this.region2model = areaCode2
        this.region3model = areaCode3
        this.formenterinfo.companyProvince = province
        this.formenterinfo.companyCity = city
        this.formenterinfo.companyCounty = district
        this.formenterinfo.companyCommunity = ''
        this.formenterinfo.companyTown = ''
      }
    },
    // 选择当前的国民第一行业
    nationInduschangelevel1() {
      // 动态获取国民第二行业
      // nationindusSecondNames
      findDimindustry(this.nationindusNames.filter(item => item.name === this.curNationIndusLevel1)[0].industryId).then(res => {
        // console.log(res, '国民第二行业')
        this.nationindusSecondNames = [...res]
      })
      this.formenterinfo.companyDimOneIndustryName = this.curNationIndusLevel1
    },
    // 选择当前的国民第二行业
    nationInduschangelevel2() {
      // 改变当前的国民第二行业
      // console.log(this.curNationIndusLevel2, '当前的第二行业')
      this.formenterinfo.companyDimTwoIndustryName = this.curNationIndusLevel2
    },
    // 一页内的个数变化
    handleSizeChange(val) {
      // console.log(`每页${val}条`)
      this.curPageSum = val
      getAllCompanyInfo({
        page: this.curPageDegree,
        size: this.curPageSum
      }).then(res => {
        this.curSumDegree = res.totalElements
        this.coms = [...res.content]
      })
    },
    // 当前页码变化
    handleCurrentChange(val) {
      // console.log(`当前第几页: ${val}`)
      this.curPageDegree = val
      // 去查询结果
      getAllCompanyInfo({
        page: this.curPageDegree - 1,
        size: this.curPageSum
      }).then(res => {
        this.curSumDegree = res.totalElements
        this.coms = [...res.content]
      })
    },
    // 模糊搜索企业
    searchEnterprise() {
      // console.log('模糊搜索企业')
      getAllCompanyInfo({
        page: 0,
        size: this.curPageSum,
        companyName: this.enterSearchInfo
      }).then(res => {
        this.curSumDegree = res.totalElements
        this.coms = [...res.content]
      })
    },
    // 导入企业信息
    importEnter($event) {
      // if (this.isShowAlert === false) {
      //   $event.stopPropagation()
      //   $event.preventDefault()
      //   this.$alert('请先将文件另存为97-2003(xls)格式', '请注意', {
      //     confirmButtonText: '确定',
      //     callback: action => {
      //       console.log(action, 'helloworld')
      //       this.isShowAlert = true
      //       $event.target.click()
      //       setTimeout(() => {
      //         this.isShowAlert = false
      //       }, 0)
      //     }
      //   })
      // }
    },
    // 导入企业信息
    realImportEnter(index, row) {
      console.log(index, row, '导入风险文件')
      // 调用提交按钮
      // console.log(this.$refs['fileuploadEnter'].files, 'helloworld helloworld helloworld helloworld')
      if (this.$refs['fileuploadEnter'].files.length === 0) {
        return
      }
      const formdata = new FormData()
      for (let i = 0; i < this.$refs['fileuploadEnter'].files.length; i++) {
        formdata.append('files', this.$refs['fileuploadEnter'].files[i])
      }
      this.isEnterloading = true
      axiosFile({
        url: '/api/thCompany/batchImportCompany',
        method: 'POST',
        data: formdata
      }).then(res => {
        this.$message({
          message: '上传成功',
          type: 'success'
        })
        this.getAllInfo2()
      }, () => {
        this.$message.error('上传失败')
        this.isEnterloading = false
      })
    },
    exportStatus() {
      axios({
        url: process.env.VUE_APP_BASE_API + '/api/thCompany/export',
        method: 'get',
        responseType: 'blob',
        params: {
          hdStatus: 1
        }
      }).then((response) => {
        const url = window.URL.createObjectURL(new Blob([response.data]))
        const link = document.createElement('a')
        link.href = url
        link.setAttribute('download', 'export.xls')
        document.body.appendChild(link)
        link.click()
        link.remove()
        window.URL.revokeObjectURL(link.href)
      })
    },
    exportNoStatus() {
      axios({
        url: process.env.VUE_APP_BASE_API + '/api/thCompany/export',
        method: 'get',
        responseType: 'blob',
        params: {
          hdStatus: 0
        }
      }).then((response) => {
        const url = window.URL.createObjectURL(new Blob([response.data]))
        const link = document.createElement('a')
        link.href = url
        link.setAttribute('download', 'export.xls')
        document.body.appendChild(link)
        link.click()
        link.remove()
        window.URL.revokeObjectURL(link.href)
      })
    },
    exportEnters() {
      // this.isExportLoading = true
      axios({
        url: process.env.VUE_APP_BASE_API + '/api/thCompany/export',
        method: 'get',
        responseType: 'blob',
        onDownloadProgress: (progressEvent) => {
          // this.isExportLoading = true
          // if (this.curExportTimer) {
          //   clearTimeout(this.curExportTimer)
          //   this.curExportTimer = setTimeout(() => {
          //     this.isExportLoading = false
          //     console.log('被执行了吗')
          //     clearTimeout(this.curExportTimer)
          //   }, 1000)
          // }
          
        }
      }).then((response) => {
        const url = window.URL.createObjectURL(new Blob([response.data]))
        const link = document.createElement('a')
        link.href = url
        link.setAttribute('download', 'export.xls')
        document.body.appendChild(link)
        link.click()
        link.remove()
        window.URL.revokeObjectURL(link.href)
      })
    }
  }
}
</script>

<style lang="scss">
  .changeinfo-wrapper {
    padding: 30px;
    .el-search-wrapper {
      font-size: 16px;
    }
  }
  .submitbtnwrapper {
    display: flex;
    flex-direction: row;
    justify-content: flex-end;
    margin-right: 20px;
  }
  .submit-map-wrapper {
    margin-left: 180px;
    margin-right: 20px;
    #submitformmap {
      width: 100%;
      height: 450px;
    }
    .pos-info-wrapper {
      display: flex;
      flex-direction: row;
    }
  }
  .import-file-risk-wrapper {
    display: inline-block;
    margin: 0 20px;
    .import-file-risk {
      color: white;
      border-radius: 3px;
      background-color: #1890ff;
      text-align: center;
      width: 56px;
      height: 28px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 14px;
      &:hover {
        background-color: #46a6ff;
      }
    }
  }
  /* .import-file-risk-wrapper {
    display: inline-block;
    margin: 0 20px;
    .import-file-risk {
      color: white;
      border-radius: 3px;
      background-color: #ccc;
      text-align: center;
      width: 56px;
      height: 28px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 14px;
      &:hover {
        background-color: #ccc;
      }
    }
  } */
</style>
