<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="98px">
      <!--      <el-form-item label="数据所属部门(政或党的id)" prop="dataDeptId">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.dataDeptId"-->
      <!--          placeholder="请输入数据所属部门(政或党的id)"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <el-row :gutter="16">
        <el-form-item label="企业名称" prop="name">
          <el-input
            v-model="queryParams.name"
            placeholder="请输入企业名称"
            clearable
            @input="handleQuery"
          />
        </el-form-item>
        <!--      <el-form-item label="生产经营单位经营地址" prop="enterpriseAddress">-->
        <!--        <el-input-->
        <!--          v-model="queryParams.enterpriseAddress"-->
        <!--          placeholder="请输入生产经营单位经营地址"-->
        <!--          clearable-->
        <!--          @keyup.enter.native="handleQuery"-->
        <!--        />-->
        <!--      </el-form-item>-->
        <!--      <el-form-item label="生产经营单位办公地址" prop="enterpriseWorkaddress">-->
        <!--        <el-input-->
        <!--          v-model="queryParams.enterpriseWorkaddress"-->
        <!--          placeholder="请输入生产经营单位办公地址"-->
        <!--          clearable-->
        <!--          @keyup.enter.native="handleQuery"-->
        <!--        />-->
        <!--      </el-form-item>-->
        <el-form-item label="组织机构代码" prop="organizationCode">
          <el-input
            v-model="queryParams.organizationCode"
            placeholder="请输入组织机构代码"
            clearable
            @input="handleQuery"
          />
        </el-form-item>
        <!--      <el-form-item label="所属部门id" prop="deptId">-->
        <!--        <el-input-->
        <!--          v-model="queryParams.deptId"-->
        <!--          placeholder="请输入所属部门id"-->
        <!--          clearable-->
        <!--          @keyup.enter.native="handleQuery"-->
        <!--        />-->
        <!--      </el-form-item>-->
        <el-form-item label="所属部门名称" prop="deptName">
          <el-input
            v-model="queryParams.deptName"
            placeholder="请输入所属部门名称"
            clearable
            @input="handleQuery"
          />
        </el-form-item>
        <el-form-item label="主要负责人" prop="charger">
          <el-input
            v-model="queryParams.charger"
            placeholder="请输入主要负责人"
            clearable
            @input="handleQuery"
          />
        </el-form-item>
        <!--      <el-form-item label="主要负责人电话" prop="chargerPhone">-->
        <!--        <el-input-->
        <!--          v-model="queryParams.chargerPhone"-->
        <!--          placeholder="请输入主要负责人电话"-->
        <!--          clearable-->
        <!--          @keyup.enter.native="handleQuery"-->
        <!--        />-->
        <!--      </el-form-item>-->
        <el-form-item label="安全负责人" prop="secCharger">
          <el-input
            v-model="queryParams.secCharger"
            placeholder="请输入安全负责人"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <!--      <el-form-item label="安全负责人电话" prop="secChargerPhone">-->
        <!--        <el-input-->
        <!--          v-model="queryParams.secChargerPhone"-->
        <!--          placeholder="请输入安全负责人电话"-->
        <!--          clearable-->
        <!--          @input="handleQuery"-->
        <!--        />-->
        <!--      </el-form-item>-->
        <!--      <el-form-item label="经度" prop="longitude">-->
        <!--        <el-input-->
        <!--          v-model="queryParams.longitude"-->
        <!--          placeholder="请输入经度"-->
        <!--          clearable-->
        <!--          @keyup.enter.native="handleQuery"-->
        <!--        />-->
        <!--      </el-form-item>-->
        <!--      <el-form-item label="纬度" prop="latitude">-->
        <!--        <el-input-->
        <!--          v-model="queryParams.latitude"-->
        <!--          placeholder="请输入纬度"-->
        <!--          clearable-->
        <!--          @keyup.enter.native="handleQuery"-->
        <!--        />-->
        <!--      </el-form-item>-->
        <!--      <el-form-item label="属地监管人员" prop="management">-->
        <!--        <el-input-->
        <!--          v-model="queryParams.management"-->
        <!--          placeholder="请输入属地监管人员"-->
        <!--          clearable-->
        <!--          @keyup.enter.native="handleQuery"-->
        <!--        />-->
        <!--      </el-form-item>-->
        <!--      <el-form-item label="区县行业主管部门" prop="industryManagement">-->
        <!--        <el-input-->
        <!--          v-model="queryParams.industryManagement"-->
        <!--          placeholder="请输入区县行业主管部门"-->
        <!--          clearable-->
        <!--          @keyup.enter.native="handleQuery"-->
        <!--        />-->
        <!--      </el-form-item>-->
        <!--      <el-form-item label="企业邮箱" prop="email">-->
        <!--        <el-input-->
        <!--          v-model="queryParams.email"-->
        <!--          placeholder="请输入企业邮箱"-->
        <!--          clearable-->
        <!--          @keyup.enter.native="handleQuery"-->
        <!--        />-->
        <!--      </el-form-item>-->
        <!--        <el-form-item>-->
        <!--          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>-->
        <!--          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
        <!--        </el-form-item>-->
      </el-row>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['enterprise:enterprise:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['enterprise:enterprise:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['enterprise:enterprise:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['enterprise:enterprise:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="enterpriseList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <!--      <el-table-column label="主键ID" align="center" prop="id" />-->
      <!--      <el-table-column label="数据所属部门(政或党的id)" align="center" prop="dataDeptId" />-->
      <!--      <el-table-column label="数据状态(1-可用 2-不可用 )" align="center" prop="dataStatus" />-->
      <el-table-column label="企业名称" align="center" prop="name"/>
      <el-table-column label="经营地址" align="center" prop="enterpriseAddress"/>
      <el-table-column label="办公地址" align="center" prop="enterpriseWorkaddress"/>
      <el-table-column label="组织机构代码" align="center" prop="organizationCode"/>
      <!--      <el-table-column label="所属部门id" align="center" prop="deptId" />-->
      <el-table-column label="所属部门名称" align="center" prop="deptName"/>
      <el-table-column label="主要负责人" align="center" prop="charger"/>
      <el-table-column label="创建人" align="center" prop="createName"/>
      <el-table-column label="创建时间" align="center" prop="createTime"/>
      <el-table-column label="修改人" align="center" prop="updateName"/>
      <el-table-column label="修改时间" align="center" prop="updateTime"/>
      <!--      <el-table-column label="主要负责人电话" align="center" prop="chargerPhone" />-->
      <!--      <el-table-column label="安全负责人" align="center" prop="secCharger" />-->
      <!--      <el-table-column label="安全负责人电话" align="center" prop="secChargerPhone" />-->
      <!--      <el-table-column label="经度" align="center" prop="longitude" />-->
      <!--      <el-table-column label="纬度" align="center" prop="latitude" />-->
      <!--      <el-table-column label="属地监管人员" align="center" prop="management" />-->
      <!--      <el-table-column label="区县行业主管部门" align="center" prop="industryManagement" />-->
      <!--      <el-table-column label="企业邮箱" align="center" prop="email" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['enterprise:enterprise:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['enterprise:enterprise:remove']"
          >删除
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon=""
            @click="inspection(scope.row)"
          >巡检
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改企业信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="180px">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="企业名称" prop="name">
              <el-input v-model="form.name" placeholder="请输入企业名称" maxlength="50"/>
            </el-form-item>
            <el-form-item label="安全负责人" prop="secCharger">
              <el-input v-model="form.secCharger" placeholder="请输入安全负责人" maxlength="50"/>
            </el-form-item>
            <el-form-item label="生产经营单位经营地址" prop="enterpriseAddress">
              <el-input v-model="form.enterpriseAddress" placeholder="请输入生产经营单位经营地址" maxlength="100"/>
            </el-form-item>
            <el-form-item label="生产经营单位办公地址" prop="enterpriseWorkaddress">
              <el-input v-model="form.enterpriseWorkaddress" placeholder="请输入生产经营单位办公地址" maxlength="100"/>
            </el-form-item>
            <el-form-item label="经度" prop="longitude" @dblclick.native="showMap">
              <el-input v-model="form.longitude" placeholder="鼠标双击此处以选择经纬度" maxlength="32"/>
            </el-form-item>
            <el-form-item label="区县行业主管部门" prop="industryManagement">
              <el-input v-model="form.industryManagement" placeholder="请输入区县行业主管部门" maxlength="50"/>
            </el-form-item>
            <el-form-item label="属地监管人员" prop="management">
              <el-input v-model="form.management" placeholder="请输入属地监管人员" maxlength="50"/>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="组织机构代码" prop="organizationCode">
              <el-input v-model="form.organizationCode" placeholder="请输入组织机构代码" maxlength="18"/>
            </el-form-item>
            <el-form-item label="主要负责人" prop="charger">
              <el-input v-model="form.charger" placeholder="请输入主要负责人" maxlength="50"/>
            </el-form-item>
            <el-form-item label="主要负责人电话" prop="chargerPhone">
              <el-input v-model="form.chargerPhone" placeholder="请输入主要负责人电话" maxlength="13"/>
            </el-form-item>
            <el-form-item label="安全负责人电话" prop="secChargerPhone">
              <el-input v-model="form.secChargerPhone" placeholder="请输入安全负责人电话" maxlength="13"/>
            </el-form-item>
            <el-form-item label="纬度" prop="latitude" @dblclick.native="showMap">
              <el-input v-model="form.latitude" placeholder="鼠标双击此处以选择经纬度" maxlength="32"/>
            </el-form-item>
            <el-form-item label="企业邮箱" prop="email">
              <el-input v-model="form.email" placeholder="请输入企业邮箱" maxlength="50"/>
            </el-form-item>
            <el-form-item label="所属部门" prop="deptId" class="form-style">
              <treeselect v-model="form.deptId" :options="deptOptions" multiple:false :show-count="true" placeholder="请选择部门" @select="hx" :noResultsText="'空'" :noOptionsText="'空'"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <ISuperMap ref="ISuperMap" v-if="ISuperMapvisible" @send="send"/>

    <!-- 企业巡检项对话框 -->
    <el-dialog :title="inspectionTitle" :visible="inspectionOpen" width="500px">
      <el-form ref="inspectionForm" label-width="80px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="企业名称" prop="name">
              <el-input
                v-model="inspectionForm.name"
                :disabled="true" maxlength="255"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="巡检类" prop="pkId">
              <el-tree :data="inspectionOptions" :props="defaultProps" :render-content="renderNodeContent"
                       node-key="sId" ref="treeRef"/>

              <!--              <el-cascader
                              :options="inspectionOptions"
                              :props="{ multiple: true, checkStrictly: true }"
                              clearable></el-cascader>-->

              <!--              <Treeselect v-model="inspectionForm.id" :multiple="multiple" ref="treeSelect"-->
              <!--                          :options="inspectionOptions" :flat="true"-->
              <!--                          :normalizer="inspectionNormalizer"/>-->
              <!--&lt;!&ndash;                          :show-count="true" placeholder="请选择"/>&ndash;&gt;-->
              <!--              <el-select v-model="inspectionForm.id" placeholder="请选择">-->
              <!--                <el-option v-for="item in [{inspectionName:'AAA',id:'4367b565a36644daace30b9f8f4e3c4d'}]" :key="item.id"-->
              <!--                           :label="item.inspectionName" :value="item.id">-->
              <!--                </el-option>-->
              <!--              </el-select>-->
            </el-form-item>
          </el-col>
          <!--<el-col :span="12">
            <el-form-item label="巡检项">
              <el-select v-model="form.pkIds" multiple placeholder="请选择">
                <el-option
                  v-for="item in itemOptions"
                  :key="item.pkId"
                  :label="item.itemName"
                  :value="item.itemName"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>-->
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitInspectionForm">确 定</el-button>
        <el-button @click="cancelInspection">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listEnterprise,
  getEnterprise,
  delEnterprise,
  addEnterprise,
  updateEnterprise
} from "@/api/centerdata_emergency/enterprise/enterprise";
import {fatherList} from "@/api/centerdata_emergency/inspectiontype/inspectiontype";
import deptselector from '@/views/components/deptselector.vue'
import supermap from '@/views/components/supermap.vue'
import {
  selectEnterindesmap,
  aEnterindesmap,
  uEnterindesmap
} from '@/api/centerdata_emergency/enterindesmap/enterindesmap'
import {inspectionTreeselect} from '@/api/centerdata_emergency/inspectiontype/inspectiontype'
import {inspectionitems} from '@/api/centerdata_emergency/inspectionitem/inspectionitem'
import {validPhoneMobile} from "@/api/rules/rules";
import {checkLon, checkLat} from "@/api/rules/rules";
import {treeselect} from "@/api/system/dept";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import ISuperMap from "@/views/data/common/ISuperMap";

export default {
  components: {
    Treeselect,
    deptselector,
    supermap,
    ISuperMap
  },
  name: "Enterprise",
  data() {
    return {
      // 是否显示巡检项弹出层
      inspectionOpen: false,
      // inspectionTitle: '',
      titleLongitude: '经纬度',
      sign: 1,
      ISuperMapvisible: false,
      // 遮罩层
      loading: true,
      showLongitude: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 企业信息表格数据
      enterpriseList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        dataDeptId: null,
        dataStatus: null,
        name: null,
        enterpriseAddress: null,
        enterpriseWorkaddress: null,
        organizationCode: null,
        deptId: null,
        deptName: null,
        charger: null,
        chargerPhone: null,
        secCharger: null,
        secChargerPhone: null,
        longitude: null,
        latitude: null,
        management: null,
        industryManagement: null,
        email: null
      },
      name: '',
      //巡检项弹出层标题
      inspectionTitle: '',
      inspectiontypeList: [],
      //巡检项选择
      itemOptions: [],
      // 巡检类树选项
      inspectionOptions: undefined,
      deptOptions: undefined,
      inspectionNormalizer(node) {
        //去掉children=[]的children属性
        /*if(node.children && !node.children.length){
          delete node.children;
        }*/
        return {
          id: node.sId,
          label: node.label,
          children: node.children,
          isDisabled: node.level != 3 ? true : false
        }

      },
      // 表单参数
      form: {},
      inspectionForm: {name: '', id: ''},
      validPhoneMobile: validPhoneMobile,
      defaultProps: {
        children: 'children',
        label: 'label'
      },
      arr: [],
      hgjArray: [],
      // 表单校验
      rules: {
        name: [
          {required: true, message: '企业名称不能为空', trigger: 'blur'}
        ],
        organizationCode: [
          {required: true, message: '组织机构代码不能为空', trigger: 'blur'}
        ],
        secCharger: [
          {required: true, message: '安全负责人不能为空', trigger: 'blur'}
        ],
        secChargerPhone: [
          {required: true, message: '安全负责人电话不能为空', trigger: 'blur'},
          {validator: validPhoneMobile, trigger: 'blur'}
        ],
        chargerPhone: [
          {required: true, message: '主要负责人电话不能为空', trigger: 'blur'},
          {validator: validPhoneMobile, trigger: 'blur'}
        ],
        deptId: [
          {required: true, message: '所属部门不能为空', trigger: 'blur'}
        ],
        email: [
          {required: true, message: '电子邮箱格式错误', validator: this.validateEmail, trigger: 'blur'}
        ],
        longitude: [
          {required: true, message: "经度不能为空", trigger: ["blur", "change"]},
          {validator: checkLon, trigger: 'blur'}
        ],
        latitude: [
          {required: true, message: "纬度不能为空", trigger: ["blur", "change"]},
          {validator: checkLat, trigger: 'blur'}
        ]

      }

    };
  },
  created() {
    this.getList();
    this.fatherList();
    this.getTreeselect()
    this.getInspectionitems()
    this.a()
  },
  methods: {
    /**所属部门下拉菜单*/
    hx(node) {
      this.form.deptId = node.id
      this.form.deptName = node.label
      this.$refs.form.validateField("deptId")
    },
    /** 查询部门下拉树结构 */
    getTreeselect() {
      treeselect().then(response => {
        this.deptOptions = response.data;
      });
    },
    a() {
      inspectionTreeselect().then(response => {
        this.inspectionOptions = response.data;
      });
    },

    renderNodeContent(h, { node, data }) {
      const targetLevel = 3;
      // 判断当前节点是否应该被勾选
      const isChecked =  this.arr.includes(data.sId);
      return (
        <span>
          {node.level === targetLevel && (
            <el-checkbox
               checked={isChecked}
              onChange={(checked) => this.handleCheckboxChange(data, checked)}
            ></el-checkbox>
            )}
          {data.label}
        </span>
      );
    },

    handleCheckboxChange(data, checked) {
      // 手动更新选中状态
      this.handleCheckChange(data, checked);
      // 同步树组件的选中状态
      this.$nextTick(() => {
        if (this.$refs.treeRef) {
          this.$refs.treeRef.setCheckedKeys(this.hgjArray);
        }
      });
    },

    handleCheckChange(data, checked) {
      if (checked) {
        if (!this.hgjArray.includes(data.sId)) {
          this.hgjArray.push(data.sId);
        }
      } else {
        const index = this.hgjArray.indexOf(data.sId);
        if (index > -1) {
          this.hgjArray.splice(index, 1);
        }
      }
      this.inspectionForm.id = this.hgjArray;
    },

    fatherList() {
      this.loading = true;
      fatherList(this.queryParams).then(response => {
        this.inspectiontypeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //获取巡检项信息
    getInspectionitems() {
      inspectionitems().then(response => {
        this.itemOptions = response.data
      })
    },
    // 取消巡检项按钮
    cancelInspection() {
      this.inspectionOpen = false
    },
    /** 巡检项按钮操作 */
    inspection(row) {
      this.inspectionForm.name = row.name
       const name = this.inspectionForm.name
       // this.$refs.treeSelect.setCheckedKeys('c48a953cb9f64ca9a7384d2df06bb721')
       selectEnterindesmap(name).then(response => {
         var code = response.code
         if (code === 200) {
           if (response.data == null) {
            this.inspectionForm.id = null
           } else {
             this.inspectionForm.name = row.name
            let that = this
             that.inspectionForm.id = []
             response.data.forEach(function (item, index) {
               that.inspectionForm.id.push(item.inspectiontypeId)
               that.arr.push(item.inspectiontypeId)
             })
           }
           this.inspectionForm.name = row.name
         } else {
           this.$modal.msgSuccess(response.msg)
         }
       })
      this.inspectionOpen = true
      this.inspectionTitle = '添加企业巡检'
    },
    showMap() {
      this.ISuperMapvisible = true;
      this.$nextTick(() => {
        this.$refs.ISuperMap.init(this.sign, {
          id: this.form.id,
          longitude: this.form.longitude,
          latitude: this.form.latitude,
          xiantude: this.form.longitude//this.form.longitude换成每个页面对应线或者面对应的字段
        })
      })
    },
    showLatLng: function (lat, lng) {
      this.form.latitude = lat
      this.form.longitude = lng
    },
    setDataDeptId(e) {
      this.form.deptId = e.deptId
      this.form.deptName = e.deptName
    },
    /** 查询企业信息列表 */
    getList() {
      this.loading = true;
      listEnterprise(this.queryParams).then(response => {
        this.enterpriseList = response.rows;
        this.total = response.total;
        this.loading = false;
      });

    },
    // getLists() {
    //   this.loading = true;
    //   fatherList(this.queryParams).then(response => {
    //     this.inspectiontypeList = response.rows;
    //     this.total = response.total;
    //     this.loading = false;
    //   });
    // },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        dataDeptId: null,
        dataStatus: "0",
        name: null,
        enterpriseAddress: null,
        enterpriseWorkaddress: null,
        organizationCode: null,
        deptId: null,
        deptName: null,
        charger: null,
        chargerPhone: null,
        secCharger: null,
        secChargerPhone: null,
        longitude: null,
        latitude: null,
        management: null,
        industryManagement: null,
        email: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    validateEmail: function (rule, value, callback) {
      if (value === '') {
        callback(new Error('请正确填写邮箱'));
      } else {
        if (value !== '') {
          var reg = /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
          if (!reg.test(value)) {
            callback(new Error('请输入有效的邮箱'));
          }
        }
        callback();
      }
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加企业信息";
    },
    send(val) {
      if (val === true) {
        this.ISuperMapvisible = false;
        return;
      }
      if (this.sign === 1) {
        this.form.longitude = val.longitude;
        this.form.latitude = val.latitude;
      }
      if (this.sign === 2 || this.sign === 3) this.form.longitude = val.xiantude;//this.form.longitude 换成对应的线或区域的字段
      this.ISuperMapvisible = false
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getEnterprise(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改企业信息";
      });
    },
    submitInspectionForm() {
      const params = Object.assign({})
      params.enterpriseName = this.inspectionForm.name
      params.id = this.inspectionForm.id
      selectEnterindesmap(params.name).then(response => {
        var code = response.code
        console.log(response.data)
        if (code === 200) {
            uEnterindesmap(params).then(response => {
              this.$modal.msgSuccess('修改成功')
              this.inspectionOpen = false
            })
        } else {
          this.$modal.msgSuccess(response.msg)
        }
      })
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateEnterprise(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addEnterprise(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除选中的数据项？').then(function () {
        return delEnterprise(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('/center-data/emergency/enterprise/export', {
        ...this.queryParams
      }, `企业信息_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
