<template>
  <!-- // kd 保留了初版矿山添加、编辑的功能，隐藏了功能入口。后续需要时添加enterpriseId参数即可使用（具体是应急局直管矿山还是为其他公司编辑矿山）-->
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div>
        <el-input v-model="searchParam.code" clearable size="small" placeholder="矿山编号" style="width: 200px;" class="filter-item" />
        <el-input v-model="searchParam.nameLike" clearable size="small" placeholder="矿山名称" style="width: 200px;" class="filter-item" />
        <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="searchSubmit">搜索</el-button>
        <el-button class="filter-item" size="mini" type="warning" icon="el-icon-refresh-left" @click="searchParamReset">重置</el-button>
        <el-tooltip class="item" effect="dark" content="按当前查询条件导出" placement="top">
          <el-button :loading="exporting" class="filter-item" size="mini" type="info" plain icon="el-icon-download" @click="exportSubmit">导出</el-button>
        </el-tooltip>
      </div>
      <!-- <el-button class="filter-item" size="mini" type="primary" icon="el-icon-plus" @click="beginAdd">新增</el-button> -->
    </div>
    <!--详情窗口-->
    <el-dialog append-to-body :close-on-click-modal="true" :visible.sync="dialog1Show" :title="(editState==1?'新增':editState==2?'修改':'查看')+'露天矿山'" width="1160px">
      <el-form ref="dialog1Form" :hide-required-asterisk="!editing" :model="dialog1Data" size="mini" :rules="dialog1FormRules" label-width="220px" style="margin-right: 80px;">
        <el-divider content-position="left">基础信息</el-divider>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="矿山名称：" prop="name">
              <span v-show="!editing">{{ dialog1Data.name }}</span>
              <el-input v-show="editing" v-model="dialog1Data.name" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="矿山编号：" prop="code">
              <span v-show="!editing">{{ dialog1Data.code }}</span>
              <el-input v-show="editing" v-model="dialog1Data.code" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="所属行政区划：" prop="_administrativeAreaCascade">
              <span v-show="!editing">{{ dialog1Data.administrativeAreaName }}</span>
              <el-cascader v-show="editing" v-model="dialog1Data._administrativeAreaCascade" style="width: 100%;" :options="administrativeAreaList" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="矿山地址：" prop="address">
              <span v-show="!editing">{{ dialog1Data.address }}</span>
              <el-input v-show="editing" v-model="dialog1Data.address" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="矿山成立日期：" prop="setupDate">
              <span v-show="!editing">{{ dialog1Data.setupDate }}</span>
              <el-date-picker v-show="editing" v-model="dialog1Data.setupDate" value-format="yyyy-MM-dd" type="date" placeholder="选择日期" style="width: 100%;" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="建矿日期：" prop="buildDate">
              <span v-show="!editing">{{ dialog1Data.buildDate }}</span>
              <el-date-picker v-show="editing" v-model="dialog1Data.buildDate" value-format="yyyy-MM-dd" type="date" placeholder="选择日期" style="width: 100%;" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="矿山投产日期：" prop="productionDate">
              <span v-show="!editing">{{ dialog1Data.productionDate }}</span>
              <el-date-picker v-show="editing" v-model="dialog1Data.productionDate" value-format="yyyy-MM-dd" type="date" placeholder="选择日期" style="width: 100%;" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="设计服务年限：" prop="designUseYear">
              <span v-show="!editing">{{ dialog1Data.designUseYear }}</span>
              <el-input-number v-show="editing" v-model="dialog1Data.designUseYear" :controls="false" style="width: 100%;" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="矿山类别：" prop="dict12">
              <span v-show="!editing">{{ dialog1Data.dict12Name }}</span>
              <el-select v-show="editing" v-model="dialog1Data.dict12" placeholder="请选择" style="width: 100%;">
                <el-option v-for="item in dict12List" :key="item.id" :label="item.value" :value="item.id" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-divider content-position="left">责任信息</el-divider>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="主要负责人：" prop="liablePerson">
              <span v-show="!editing">{{ dialog1Data.liablePerson }}</span>
              <el-input v-show="editing" v-model="dialog1Data.liablePerson" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="主要负责人联系方式：" prop="liablePersonPhone">
              <span v-show="!editing">{{ dialog1Data.liablePersonPhone }}</span>
              <el-input v-show="editing" v-model="dialog1Data.liablePersonPhone" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="分管安全负责人：" prop="managedPerson">
              <span v-show="!editing">{{ dialog1Data.managedPerson }}</span>
              <el-input v-show="editing" v-model="dialog1Data.managedPerson" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="分管安全负责人联系方式：" prop="managedPersonPhone">
              <span v-show="!editing">{{ dialog1Data.managedPersonPhone }}</span>
              <el-input v-show="editing" v-model="dialog1Data.managedPersonPhone" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="安全总监：" prop="safetyPerson">
              <span v-show="!editing">{{ dialog1Data.safetyPerson }}</span>
              <el-input v-show="editing" v-model="dialog1Data.safetyPerson" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="安全总监联系方式：" prop="safetyPersonPhone">
              <span v-show="!editing">{{ dialog1Data.safetyPersonPhone }}</span>
              <el-input v-show="editing" v-model="dialog1Data.safetyPersonPhone" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-divider content-position="left">规模信息</el-divider>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="从业人数：" prop="employeesNumber">
              <span v-show="!editing">{{ dialog1Data.employeesNumber }}</span>
              <el-input-number v-show="editing" v-model="dialog1Data.employeesNumber" :controls="false" style="width: 100%;" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="技术人员数：" prop="technicianNumber">
              <span v-show="!editing">{{ dialog1Data.technicianNumber }}</span>
              <el-input-number v-show="editing" v-model="dialog1Data.technicianNumber" :controls="false" style="width: 100%;" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="专职安全管理人员数量：" prop="safetyPersonNumber">
              <span v-show="!editing">{{ dialog1Data.safetyPersonNumber }}</span>
              <el-input-number v-show="editing" v-model="dialog1Data.safetyPersonNumber" :controls="false" style="width: 100%;" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="可开采储量（吨）：" prop="exploitableStorage">
              <span v-show="!editing">{{ dialog1Data.exploitableStorage }}</span>
              <el-input-number v-show="editing" v-model="dialog1Data.exploitableStorage" :precision="4" :controls="false" style="width: 100%;" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="实际生产规模（吨/年）：" prop="scale">
              <span v-show="!editing">{{ dialog1Data.scale }}</span>
              <el-input-number v-show="editing" v-model="dialog1Data.scale" :precision="4" :controls="false" style="width: 100%;" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="开采深度（米）：" prop="deepMeter">
              <span v-show="!editing">{{ dialog1Data.deepMeter }}</span>
              <el-input-number v-show="editing" v-model="dialog1Data.deepMeter" :precision="4" :controls="false" style="width: 100%;" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="开采方式：" prop="dict15">
              <span v-show="!editing">{{ dialog1Data.dict15Name }}</span>
              <el-select v-show="editing" v-model="dialog1Data.dict15" placeholder="请选择" style="width: 100%;">
                <el-option v-for="item in dict15List" :key="item.id" :label="item.value" :value="item.id" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="开采顺序：" prop="dict16">
              <span v-show="!editing">{{ dialog1Data.dict16Name }}</span>
              <el-select v-show="editing" v-model="dialog1Data.dict16" placeholder="请选择" style="width: 100%;">
                <el-option v-for="item in dict16List" :key="item.id" :label="item.value" :value="item.id" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="水文地质条件：" prop="dict13">
              <span v-show="!editing">{{ dialog1Data.dict13Name }}</span>
              <el-select v-show="editing" v-model="dialog1Data.dict13" placeholder="请选择" style="width: 100%;">
                <el-option v-for="item in dict13List" :key="item.id" :label="item.value" :value="item.id" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工程地质条件：" prop="dict14">
              <span v-show="!editing">{{ dialog1Data.dict14Name }}</span>
              <el-select v-show="editing" v-model="dialog1Data.dict14" placeholder="请选择" style="width: 100%;">
                <el-option v-for="item in dict14List" :key="item.id" :label="item.value" :value="item.id" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="矿区面积（平方千米）：" prop="measureArea">
              <span v-show="!editing">{{ dialog1Data.measureArea }}</span>
              <el-input-number v-show="editing" v-model="dialog1Data.measureArea" :precision="4" :controls="false" style="width: 100%;" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="上一年产值（元）：" prop="lastYearOutMoney">
              <span v-show="!editing">{{ dialog1Data.lastYearOutMoney }}</span>
              <el-input-number v-show="editing" v-model="dialog1Data.lastYearOutMoney" :precision="2" :controls="false" style="width: 100%;" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-divider content-position="left">其他信息</el-divider>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="相邻矿权：" prop="hasAdjacentOwnership" label-width="260px">
              <span v-show="!editing">
                {{ dialog1Data.hasAdjacentOwnership === true ? '有' : '' }}
                {{ dialog1Data.hasAdjacentOwnership === false ? '无' : '' }}
              </span>
              <el-radio-group v-show="editing" v-model="dialog1Data.hasAdjacentOwnership" size="mini">
                <el-radio-button :label="true">有</el-radio-button>
                <el-radio-button :label="false">无</el-radio-button>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="在线边坡稳定性监测系统：" prop="hasStabilitySystem" label-width="260px">
              <span v-show="!editing">
                {{ dialog1Data.hasStabilitySystem === true ? '有' : '' }}
                {{ dialog1Data.hasStabilitySystem === false ? '无' : '' }}
              </span>
              <el-radio-group v-show="editing" v-model="dialog1Data.hasStabilitySystem" size="mini">
                <el-radio-button :label="true">有</el-radio-button>
                <el-radio-button :label="false">无</el-radio-button>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="爆破警戒距离（米）：" prop="dict17">
              <span v-show="!editing">{{ dialog1Data.dict17Name }}</span>
              <el-select v-show="editing" v-model="dialog1Data.dict17" placeholder="请选择" style="width: 100%;">
                <el-option v-for="item in dict17List" :key="item.id" :label="item.value" :value="item.id" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="300米内居民区数量：" prop="apartment300Number">
              <span v-show="!editing">{{ dialog1Data.apartment300Number }}</span>
              <el-input-number v-show="editing" v-model="dialog1Data.apartment300Number" :controls="false" style="width: 100%;" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="300米内居民人数：" prop="people300Number">
              <span v-show="!editing">{{ dialog1Data.people300Number }}</span>
              <el-input-number v-show="editing" v-model="dialog1Data.people300Number" :controls="false" style="width: 100%;" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="300米内建筑物数量：" prop="building300Number">
              <span v-show="!editing">{{ dialog1Data.building300Number }}</span>
              <el-input-number v-show="editing" v-model="dialog1Data.building300Number" :controls="false" style="width: 100%;" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="300米内重要设置情况（如学校、厂矿、道路、铁路、桥梁情况等）：" prop="important300Note" label-width="260px">
              <span v-show="!editing">{{ dialog1Data.important300Note }}</span>
              <el-input v-show="editing" v-model="dialog1Data.important300Note" type="textarea" :rows="3" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="排土场：" prop="hasWastedump" label-width="260px">
              <span v-show="!editing">
                {{ dialog1Data.hasWastedump === true ? '有' : '' }}
                {{ dialog1Data.hasWastedump === false ? '无' : '' }}
              </span>
              <el-radio-group v-show="editing" v-model="dialog1Data.hasWastedump" size="mini">
                <el-radio-button :label="true">有</el-radio-button>
                <el-radio-button :label="false">无</el-radio-button>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否为独立的生产系统：" prop="hasIndependentSystem" label-width="260px">
              <span v-show="!editing">
                {{ dialog1Data.hasIndependentSystem === true ? '是' : '' }}
                {{ dialog1Data.hasIndependentSystem === false ? '否' : '' }}
              </span>
              <el-radio-group v-show="editing" v-model="dialog1Data.hasIndependentSystem" size="mini">
                <el-radio-button :label="true">是</el-radio-button>
                <el-radio-button :label="false">否</el-radio-button>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="是否持有独立的采矿许可证：" prop="hasIndependentLicense" label-width="260px">
              <span v-show="!editing">
                {{ dialog1Data.hasIndependentLicense === true ? '是' : '' }}
                {{ dialog1Data.hasIndependentLicense === false ? '否' : '' }}
              </span>
              <el-radio-group v-show="editing" v-model="dialog1Data.hasIndependentLicense" size="mini">
                <el-radio-button :label="true">是</el-radio-button>
                <el-radio-button :label="false">否</el-radio-button>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否持有独立的安全生产许可证：" prop="hasIndependentSafetyLicense" label-width="260px">
              <span v-show="!editing">
                {{ dialog1Data.hasIndependentSafetyLicense }}
                {{ dialog1Data.hasIndependentSafetyLicense === true ? '是' : '' }}
                {{ dialog1Data.hasIndependentSafetyLicense === false ? '否' : '' }}
              </span>
              <el-radio-group v-show="editing" v-model="dialog1Data.hasIndependentSafetyLicense" size="mini">
                <el-radio-button :label="true">是</el-radio-button>
                <el-radio-button :label="false">否</el-radio-button>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="运行状况：" prop="runState">
              <span v-for="item in mineApi.runStates()" v-show="!editing && item.key==dialog1Data.runState" :key="item.key">
                {{ item.value }}
              </span>
              <el-select v-show="editing" v-model="dialog1Data.runState" placeholder="请选择" style="width: 100%;">
                <el-option label="基建" :value="1" />
                <el-option label="生产" :value="3" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="矿山平面图：" prop="floorPlanPath">
              <el-link v-for="file in dialog1Data._fileList" :key="file.url" @click="openFile(file)">{{ file.name }}</el-link>
              <el-upload
                v-show="editing"
                class="upload-demo"
                action="/api/file/upload"
                multiple
                :headers="httpHeaders"
                :limit="1"
                :on-success="upFloorPlanSuccess"
                :on-remove="upFloorPlanRemove"
                :on-error="upFloorPlanError"
                :on-exceed="upFloorPlanExceed"
                :before-upload="upFloorPlanBefore"
                :on-preview="openFile"
                :file-list="dialog1Data._fileList"
              >
                <el-button size="small" type="primary">点击上传</el-button>
                <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过20M</div>
              </el-upload>
            </el-form-item>
          </el-col>
        </el-row>
        <el-divider content-position="left">位置</el-divider>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="经度：" prop="longitude">
              <span v-show="!editing">{{ dialog1Data.longitude }}</span>
              <el-input-number v-show="editing" v-model="dialog1Data.longitude" :precision="6" :controls="false" style="width: 100%;" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="纬度：" prop="latitude">
              <span v-show="!editing">{{ dialog1Data.latitude }}</span>
              <el-input-number v-show="editing" v-model="dialog1Data.latitude" :precision="6" :controls="false" style="width: 100%;" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item v-show="editing || dialog1Data.longitude && dialog1Data.latitude" label="位置地图：">
              <AMapSearchPoint :is-search="editing" :point="mapPoint" @choosePoint="choosePoint" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button v-show="editing" type="text" @click="dialog1Show=false">取消</el-button>
        <el-button v-show="editing" :loading="dialog1Saving" type="primary" @click="dialog1Submit">保存</el-button>
      </div>
    </el-dialog>
    <!--表格-->
    <el-table ref="table" v-loading="searching" :data="tableData" row-key="id">
      <!-- <el-table-column type="selection" width="55" /> -->
      <el-table-column :show-overflow-tooltip="true" label="编号" prop="id" width="100px" align="center" />
      <el-table-column :show-overflow-tooltip="true" label="所属企业" prop="enterpriseName" align="center" />
      <el-table-column :show-overflow-tooltip="true" label="矿山名称" prop="name" align="center" />
      <el-table-column :show-overflow-tooltip="true" label="矿山编号" prop="code" align="center" />
      <el-table-column :show-overflow-tooltip="true" label="矿山地址" prop="address" align="center" />
      <el-table-column :show-overflow-tooltip="true" label="建矿时间" prop="buildDate" align="center" />
      <el-table-column :show-overflow-tooltip="true" label="运行状态" prop="runState" align="center">
        <template slot-scope="scope">
          <span v-for="item in mineApi.runStates()" v-show="item.key==scope.row.runState" :key="item.key">
            {{ item.value }}
          </span>
        </template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" label="主要负责人" prop="liablePerson" align="center" />
      <el-table-column :show-overflow-tooltip="true" label="联系方式" prop="liablePersonPhone" align="center" />
      <el-table-column label="操作" width="200px" align="center" fixed="right">
        <template slot-scope="scope">
          <el-button size="mini" round @click="beginLook(scope.row.id)">查看</el-button>
          <!-- <el-button size="mini" round @click="beginEdit(scope.row.id)">编辑</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <!--分页-->
    <el-pagination
      :page-sizes="[10, 20, 50, 100]"
      :current-page.sync="searchParam.page"
      :page-size.sync="searchParam.count"
      :total="searchResult.total"
      layout="total, sizes, prev, pager, next, jumper"
      @size-change="searchSubmit"
      @current-change="searchSubmit"
    />
  </div>
</template>

<script>
import mineApi from '@/api/kd/mine'
import dictionaryApi from '@/api/kd/dictionary'
import administrativeAreaApi from '@/api/kd/administrativeArea'
import AMapSearchPoint from '@/components/AMap/AMapSearchPoint'
import { getToken } from '@/utils/auth'
import { mapGetters } from 'vuex'
import { downloadFile } from '@/utils'

const searchParam = {// 默认搜索条件
  page: 1,
  count: 10,
  searchCount: true
}
export default {
  name: 'EOpencast', // 本页面名
  components: { AMapSearchPoint },
  data() {
    return {
      httpHeaders: {
        'Authorization': getToken()
      },
      administrativeAreaList: [],
      dict12List: [],
      dict13List: [],
      dict14List: [],
      dict15List: [],
      dict16List: [],
      dict17List: [],
      mineApi: mineApi,
      editing: true,
      searching: false,
      exporting: false,
      searchParam: {},
      searchResult: {
        total: 0,
        results: [] // 搜索结果
      },
      dialog1Show: false,
      dialog1Saving: false,
      dialog1Data: {},
      dialog1FormRules: {
        name: [{ required: true, message: '请输入' }],
        code: [{ required: true, message: '请输入' }],
        address: [{ required: true, message: '请输入' }],
        designUseYear: [{ required: true, message: '请输入' }]
      },
      editState: 0, // （刚打开窗口时）记录了上次窗口作用；（保存编辑时）记录了当前窗口作用； 0无 1新增 2修改 3查看
      addingData: {} // 上次正在新增时的内容，下次打开dialog1窗口时记录下来
    }
  },
  computed: {
    ...mapGetters([
      'baseApi'
    ]),
    tableData() {
      // 将返回结果转换为可展示文本
      return this.searchResult.results
    },
    mapPoint() {
      if (this.dialog1Data.longitude && this.dialog1Data.latitude) {
        return [this.dialog1Data.longitude * 1, this.dialog1Data.latitude * 1]
      }
      return null
    }
  },
  mounted() {
    administrativeAreaApi.cascadeElementUI().then(response => {
      this.administrativeAreaList = response.results
    })
    const dictGroups = [12, 13, 14, 15, 16, 17]
    dictGroups.forEach(i => {
      dictionaryApi.getList({ 'groupCode': i }).then(response => {
        this['dict' + i + 'List'] = response.results
      })
    })
    this.searchParamReset()
    this.searchSubmit()
  },
  methods: {
    searchParamReset() {
      this.searchParam = JSON.parse(JSON.stringify(searchParam))
    },
    beforeDialog1Open() { // 窗口打开前的统一操作
      if (this.editState === 1) {
        this.addingData = this.dialog1Data
      }
    },
    dialog1DataInit() { // 窗口赋值dialog1Data后的data初始化操作
      this.$set(this.dialog1Data, 'longitude', this.dialog1Data.longitude)
      if (this.dialog1Data) {
        if (this.dialog1Data.administrativeAreaCode) {
          administrativeAreaApi.cascadeUpElementUI(this.dialog1Data.administrativeAreaCode).then(response => {
            this.$set(this.dialog1Data, '_administrativeAreaCascade', response.cascade)
            this.$set(this.dialog1Data, '_administrativeAreaAreaCode', response.areaCode)
          })
        }
        if (this.dialog1Data.floorPlanPath) {
          this.dialog1Data._fileList = JSON.parse(this.dialog1Data.floorPlanPath)
        }
      }
    },
    beginAdd() {
      this.beforeDialog1Open()
      this.editState = 1
      this.dialog1Data = this.addingData // 初始值：上次编辑的内容
      this.dialog1DataInit()
      this.editing = true
      this.dialog1Show = true
      this.$nextTick(() => {
        this.$refs['dialog1Form'].clearValidate()
      })
    },
    beginEdit(id) {
      this.beforeDialog1Open()
      this.editState = 2
      mineApi.getOpencastById(id).then(response => { // 初始值：从服务器查询到的内容
        this.dialog1Data = response
        this.dialog1DataInit()
        this.editing = true
        this.dialog1Show = true
        this.$nextTick(() => {
          this.$refs['dialog1Form'].clearValidate()
        })
      })
    },
    beginLook(id) {
      this.beforeDialog1Open()
      this.editState = 3
      mineApi.getOpencastById(id).then(response => { // 初始值：从服务器查询到的内容
        this.dialog1Data = response
        this.dialog1DataInit()
        this.editing = false
        this.dialog1Show = true
        this.$nextTick(() => {
          this.$refs['dialog1Form'].clearValidate()
        })
      })
    },
    searchSubmit() {
      this.searching = true
      mineApi.getOpencastPage(this.searchParam).then(response => {
        this.searchResult = response
        this.searching = false
      }).catch(() => {
        this.searching = false
      })
    },
    exportSubmit() {
      this.exporting = true
      mineApi.exportOpencast(this.searchParam).then(response => {
        downloadFile(response, '露天矿山', 'xlsx')
        this.exporting = false
      }).catch(() => {
        this.exporting = false
      })
    },
    dialog1Submit() {
      this.$refs['dialog1Form'].validate(valid => {
        if (!valid) {
          this.$message.error('填写不满足要求，请检查')
          return
        } else {
          this.dialog1Saving = true
          if (this.dialog1Data._administrativeAreaCascade && this.dialog1Data._administrativeAreaCascade.length > 0) {
            this.dialog1Data.administrativeAreaCode = this.dialog1Data._administrativeAreaCascade[this.dialog1Data._administrativeAreaCascade.length - 1]
          }
          if (this.dialog1Data._fileList) {
            this.dialog1Data.floorPlanPath = JSON.stringify(this.dialog1Data._fileList)
          }
          if (this.editState === 1) { // 新增
            mineApi.addOpencast(this.dialog1Data).then(() => {
              this.dialog1Saving = false
              this.$message.success('保存成功')
              this.dialog1Show = false
              this.dialog1Data = {}
              this.searchSubmit()
            }).catch(() => {
              this.dialog1Saving = false
            })
          } else if (this.editState === 2) { // 修改
            mineApi.setOpencast(this.dialog1Data).then(() => {
              this.dialog1Saving = false
              this.$message.success('保存成功')
              this.dialog1Show = false
              this.dialog1Data = {}
              this.searchSubmit()
            }).catch(() => {
              this.dialog1Saving = false
            })
          } else {
            this.dialog1Saving = false
            this.$message.success('出错啦，请刷新页面重试')
          }
        }
      })
    },
    upFloorPlanSuccess(response, file, fileList) {
      if (!this.dialog1Data._fileList) {
        this.dialog1Data._fileList = []
      }
      this.dialog1Data._fileList.push({
        name: file.name,
        url: response.result
      })
    },
    upFloorPlanError() {
      this.$message.error('上传失败，请稍后再试')
    },
    upFloorPlanRemove() {
      this.$set(this.dialog1Data, '_fileList', [])
    },
    upFloorPlanBefore(file) {
      const isIMG = file.type === 'image/jpeg' || file.type === 'image/png'
      const isLtSize = file.size / 1024 / 1024 < 20
      if (!isIMG) {
        this.$message.error('上传图片只能是 JPG/JPEG/PNG 格式')
        return false
      }
      if (!isLtSize) {
        this.$message.error('上传图片大小不能超过 20MB')
        return false
      }
      return true
    },
    upFloorPlanExceed() {
      this.$message.error('您已经上传了一张图，请删除后重新上传')
    },
    openFile(file) {
      if (file.url) {
        window.open(this.baseApi + '/file' + file.url)
      } else if (file.response && file.response.result) {
        window.open(this.baseApi + '/file' + file.response.result)
      }
    },
    choosePoint(lnglat) {
      if (lnglat) {
        this.$set(this.dialog1Data, 'longitude', lnglat[0])
        this.$set(this.dialog1Data, 'latitude', lnglat[1])
      } else {
        this.$set(this.dialog1Data, 'longitude', null)
        this.$set(this.dialog1Data, 'latitude', null)
      }
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  ::v-deep .el-input-number .el-input__inner {
    text-align: left;
  }
  ::v-deep .vue-treeselect__control,::v-deep .vue-treeselect__placeholder,::v-deep .vue-treeselect__single-value {
    height: 30px;
    line-height: 30px;
  }
</style>
