<template>
  <div class="reform-bg" style="padding: 20px">
    <div class="reform-warp">
      <div class="reform-content">
        <el-form ref="dataForm" :rules="rules" :form="dataForm" :model="dataForm" label-width="200px">
          <div class="level-title">
            <h1>1、相关方单位基础信息</h1>
            <!-- <h1 style="margin-left: 1400px">审核状态：{{ formatAuditState(dataForm.STATE) }}</h1>-->
          </div>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="单位名称" prop="RELEVANT_UNIT_NAME">
                <el-input id="RELEVANT_UNIT_NAME" ref="RELEVANT_UNIT_NAME" v-model="dataForm.RELEVANT_UNIT_NAME" maxlength="255" placeholder="这里输入单位名称..." title="单位名称"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="企业状态:" prop="STATE">
                <div>
                  <span v-if="dataForm.STATE == '0'">未填报</span>
                  <span v-if="dataForm.STATE == '1'">待审核</span>
                  <span v-if="dataForm.STATE == '2'">已审核</span>
                  <span v-if="dataForm.STATE == '3'" style="color: red">已打回</span>
                  <span v-if="dataForm.STATE == '4'">已填报</span>
                </div>
                <!--                <el-input v-model="dataForm.STATE" disabled maxlength="255" title="企业状态"/>-->
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="股份监管部门" prop="MANAGER_DEPARTMENT_NAME">
                <el-input v-model="dataForm.MANAGER_DEPARTMENT_NAME" disabled/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="基层单位监管部门" prop="COMPETENT_DEPT_NAME">
                <el-input v-model="dataForm.COMPETENT_DEPT_NAME" disabled/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="股份主管部门" prop="MAIN_DEPARTMENT">
                <!--                <Treeselect
                  :options="treeData"
                  :disabled="true"
                  :normalizer="normalizer"
                  :flat="true"
                  :default-expand-level="0"
                  :props="defaultProps"
                  v-model="dataForm.MAIN_DEPARTMENT"
                  multiple
                  placeholder="请选择部门"
                  no-options-text="暂无数据"
                  no-children-text="暂无数据"
                  style="width: 100%;"
                />-->

                <el-input v-model="dataForm.MAIN_DEPARTMENT_NAME" disabled maxlength="255" title="单位名称"/>

              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="基层单位主管部门" prop="SUPERVISE_CORPINFO_DEPT_NAME">
                <el-input v-model="dataForm.SUPERVISE_CORPINFO_DEPT_NAME" disabled maxlength="255" title="单位名称"/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="集团单位" prop="corpTypeName">
                <el-input id="corpTypeName" ref="corpTypeName" v-model="dataForm.corpTypeName" disabled maxlength="255" placeholder="这里输入集团单位..." title="集团单位"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="开户人" prop="USER_NAME">
                <el-input id="USER_NAME" ref="USER_NAME" v-model="dataForm.USER_NAME" disabled maxlength="255" placeholder="这里输入开户人..." title="开户人"/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="统一社会信用代码" prop="SOCIAL_CODE">
                <el-input id="SOCIAL_CODE" ref="SOCIAL_CODE" v-model="dataForm.SOCIAL_CODE" maxlength="255" placeholder="这里输入统一社会信用代码..." title="统一社会信用代码"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item :key="dataForm.POSSESSION" label="属地" prop="POSSESSION">
                <el-cascader
                  id="POSSESSION"
                  ref="POSSESSION"
                  v-model="dataForm.POSSESSION"
                  :options="areaList"
                  :props="areaProps"
                  :append-to-body="false"
                  :placeholder="dataForm.COMPANY_AREA"
                  style="width: 100%"
                  @change="cascaderChange"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="所属行业" prop="INDUSTRY">
                <el-select v-model="dataForm.INDUSTRY" style="width: 100%">
                  <el-option v-for="item in industryList" :key="item.BIANMA" :label="item.NAME" :value="item.BIANMA"/>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item :key="dataForm.ECONOMIC_TYPE" label="经济类型" prop="ECONOMIC_TYPE">
                <el-select v-model="dataForm.ECONOMIC_TYPE" placeholder="请选择" style="width: 100%;">
                  <el-option v-for="item in ecnomicTypeList" :key="item.BIANMA" :label="item.NAME" :value="item.BIANMA" />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item :key="dataForm.LONGITUDE" label="经度" prop="LONGITUDE">
                <el-input v-model="dataForm.LONGITUDE" placeholder="请输入内容" disabled @focus="handleMap" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item :key="dataForm.LATITUDE" label="纬度" prop="LATITUDE">
                <div style="display: flex">
                  <el-input v-model="dataForm.LATITUDE" placeholder="请输入内容" disabled style="width: 100%" @focus="handleMap"/>
                  <el-button style="margin-left:10px" @click="handleMap">
                    <span class="svg-container">
                      <svg-icon icon-class="international" />
                    </span>
                  </el-button>
                </div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="单位经营地址" prop="BUSINESS_ADDRESS">
                <el-input id="BUSINESS_ADDRESS" ref="BUSINESS_ADDRESS" v-model="dataForm.BUSINESS_ADDRESS" maxlength="255" placeholder="这里输入单位经营地址..." title="单位经营地址"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item :key="dataForm.CORP_SIZE" label="企业规模" prop="CORP_SIZE">
                <el-select v-model="dataForm.CORP_SIZE" style="width: 100%;">
                  <el-option v-for="item in enterpriseSizeList" :key="item.BIANMA" :label="item.NAME" :value="item.BIANMA" />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="法人姓名" prop="LEGAL_PERSON">
                <el-input id="LEGAL_PERSON" ref="LEGAL_PERSON" v-model="dataForm.LEGAL_PERSON" maxlength="20" placeholder="这里输入法人姓名..." title="法人姓名"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="联系电话" prop="LEGAL_PERSON_TEL">
                <el-input id="LEGAL_PERSON_TEL" ref="LEGAL_PERSON_TEL" v-model="dataForm.LEGAL_PERSON_TEL" maxlength="11" placeholder="这里输入联系电话..." title="联系电话"/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="主要负责人" prop="CONTACT_PERSON">
                <el-input id="CONTACT_PERSON" ref="CONTACT_PERSON" v-model="dataForm.CONTACT_PERSON" maxlength="20" placeholder="这里输入主要负责人..." title="主要负责人"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="主要负责人联系电话" prop="CONTACT_TEL">
                <el-input id="CONTACT_TEL" ref="CONTACT_TEL" v-model="dataForm.CONTACT_TEL" maxlength="11" placeholder="这里输入主要负责人联系电话..." title="主要负责人联系电话"/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="成立日期" prop="ESTABLISHMENT_DATE">
                <el-date-picker v-model="dataForm.ESTABLISHMENT_DATE" type="date" value-format="yyyy-MM-dd" format="yyyy-MM-dd" placeholder="选择日期"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="职工人数（人）" prop="EMPLOY_NUM">
                <el-input id="EMPLOY_NUM" ref="EMPLOY_NUM" v-model="dataForm.EMPLOY_NUM" type="number" maxlength="11" placeholder="这里输入职工人数..." title="职工人数"/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="资产总额（万元）" prop="TOTAL_ASSETS">
                <el-input id="TOTAL_ASSETS" ref="TOTAL_ASSETS" v-model="dataForm.TOTAL_ASSETS" type="number" maxlength="11" placeholder="这里输入资产总额（万元）..." title="资产总额（万元）"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="注册资金(万元)" prop="REGISTERED_CAPITAL">
                <el-input id="REGISTERED_CAPITAL" ref="REGISTERED_CAPITAL" v-model="dataForm.REGISTERED_CAPITAL" type="number" maxlength="11" placeholder="这里输入注册资金..." title="注册资金"/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item :key="dataForm.EMPLOYMENT_FORM" label="用工形式" prop="EMPLOYMENT_FORM">
                <Treeselect
                  :options="employmentTypeList"
                  :normalizer="normalizer"
                  v-model="dataForm.EMPLOYMENT_FORM"
                  :disable-branch-nodes="true"
                  placeholder="请选择用工形式"
                  no-options-text="暂无数据"
                  no-children-text="暂无数据"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item :key="dataForm.SELECT_FORMS" label="选取形式" prop="SELECT_FORMS">
                <el-select v-model="dataForm.SELECT_FORMS" multiple style="width: 100%;" >
                  <el-option v-for="item in selectFormList" :key="item.BIANMA" :label="item.NAME" :value="item.BIANMA" />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="营业执照" class="is-required">
                <div class="disContent">
                  <el-upload
                    :auto-upload="false"
                    :file-list="businessLicenseImgs"
                    :on-change="handleEditChange"
                    :on-exceed="overFlow"
                    :limit="5"
                    action="#"
                    multiple
                    accept=".jpg,.png"
                    list-type="picture-card">
                    <i slot="default" class="el-icon-plus"/>
                    <div slot="file" slot-scope="{file}">
                      <img
                        v-if="file.FILEPATH"
                        :src="config.fileUrl + file.FILEPATH"
                        class="el-upload-list__item-thumbnail"
                        alt=""
                      >
                      <img
                        v-else
                        :src="file.url"
                        class="el-upload-list__item-thumbnail"
                        alt=""
                      >
                      <span class="el-upload-list__item-actions">
                        <span
                          class="el-upload-list__item-preview"
                          @click="handlePictureCardPreview(file)"
                        >
                          <i class="el-icon-zoom-in"/>
                        </span>
                        <span
                          class="el-upload-list__item-delete"
                          @click="handleRemove(file)"
                        >
                          <i class="el-icon-delete"/>
                        </span>
                      </span>
                    </div>
                  </el-upload>
                </div>
                <el-dialog :visible.sync="dialogVisible" append-to-body>
                  <img :src="dialogImageUrl" width="100%" alt="">
                </el-dialog>
                <div style="margin-top: 10px">
                  限制上传数量:{{ businessLicenseImgs.length +'/'+'5' }}
                </div>
                <div>
                  只能上传jpg/png文件，单张且不超过5mb
                </div>
              </el-form-item>

            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="营业执照有效期" prop="businessLicenseDate">
                <el-date-picker
                  v-model="dataForm.businessLicenseDate"
                  type="daterange"
                  clearable
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-form-item v-show="dataForm.STATE === '2'" :span="12" label="企业二维码" prop="">
            <span style="color: #04a9f5;cursor:pointer" @click="showQRCode(dataForm.CORPINFO_ID)">查看</span>
          </el-form-item>
          <div class="level-title">
            <h1>2、单位资质信息</h1>
            <el-button size="small" type="primary" icon="el-icon-plus" style="margin-left: 20px" @click="handleQualificationAdd">添加资质</el-button>
          </div>
          <el-table
            v-loading="listLoading"
            :data="qualificationList"
            :header-cell-style="{
              'font-weight': 'bold',
              'color': '#000'
            }"
            tooltip-effect="dark"
            border
            fit
            highlight-current-row
          >
            <el-table-column type="index" label="序号" width="50" align="center" />
            <el-table-column prop="QUALIFICATION_NAME" label="资质正式名称" width="400px" />
            <el-table-column prop="" label="证书有限期" width="400px">
              <template slot-scope="{row}">
                {{ row.START_DATE }} 至 {{ row.END_DATE }}
              </template>
            </el-table-column>
            <el-table-column prop="CERTIFICATE_NO" label="证书编号" width="400px" />
            <el-table-column label="操作" align="center">
              <template slot-scope="{row}">
                <el-button type="primary" icon="el-icon-view" size="mini" @click="handlePictureCardView(row)">预览</el-button>
                <el-button type="primary" icon="el-icon-edit" size="mini" @click="handleQualificationEdit(row.CORPQUALIFICATIONINFO_ID)">编辑</el-button>
                <el-button type="danger" icon="el-icon-delete" size="mini" @click="delQualification(row.CORPQUALIFICATIONINFO_ID)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-form>
      </div>
      <!--    <div class="ui-height" />-->
      <div class="ui-height"/>
      <div class="ui-foot">
        <!-- <el-button :loading="buttonloading" type="warning" icon="el-icon-document" @click="confirm('1')">保存并提交审核</el-button>-->
        <el-button :loading="buttonloading" type="primary" icon="el-icon-check" @click="confirm('0')">保存</el-button>
        <!--        <el-button icon="el-icon-arrow-left" @click="back">返回</el-button>-->
      </div>

      <!-- 上级企业 -->
      <el-dialog :visible.sync="dialogParentCorp" title="上级企业" width="1000px">
        <CorpSelect v-if="dialogParentCorp" ref="corpSelect" :corpid="CORPINFO_ID" @assignCorpParent="assignCorpParent" />
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogParentCorp = false">取 消</el-button>
          <el-button type="primary" @click="defineCorp">确 定</el-button>
        </div>
      </el-dialog>

      <!-- 坐标选择 -->
      <el-dialog :visible.sync="dialogFormMap" title="编辑坐标" width="800px" class="dy-dialog">
        <baidu-map
          v-loading="loadingMap"
          :zoom="zoom"
          :scroll-wheel-zoom="true"
          :style="{height: clientHeight+'px'}"
          @click="getClickInfo"
          @ready="handler">
          <bm-view style="width: 100%; height:100%; flex: 1" />
          <bm-control ref="control" :offset="{width: 10, height: 10}" anchor="BMAP_ANCHOR_TOP_LEFT">
            <div class="map-flex">

              <div class="map-lable">关键词：</div>
              <div style="flex:1;">
                <el-autocomplete v-model="addressKeyword" :fetch-suggestions="querySearch" :trigger-on-focus="false" placeholder="请输入详细地址" style="width:100%" @select="handleSelect" />
              </div>
              <!--            <el-input v-model="addressKeyword" style="width: 200px" placeholder="请输入内容" />-->
              <!--            <el-button slot="append" icon="el-icon-search" @click="mapNameChange"/>-->
            </div>
          </bm-control>
          <!--        <bm-local-search :keyword="addressKeyword" :auto-viewport="true"/>-->
        </baidu-map>
        <div slot="footer" class="dialog-footer">
          <span>经度：</span>
          <el-input v-model="LONGITUDE" style="width: 200px" placeholder="请输入内容" disabled />
          <span>纬度：</span>
          <el-input v-model="LATITUDE" style="width: 200px" placeholder="请输入内容" disabled />
          <el-button @click="dialogFormMap = false">取 消</el-button>
          <el-button type="primary" @click="setPosition">确 定</el-button>
        </div>
      </el-dialog>

      <!-- 图片上传预览 -->
      <el-dialog :visible.sync="dialogVisible" title="查看">
        <img :src="dialogImageUrl" width="100%" alt="">
      </el-dialog>
      <!-- 单位资质信息 编辑 -->
      <el-dialog :visible.sync="dialogQualificationEdit" :title="dialogQualificationType==='edit'?'修改单位资质信息':'新增单位资质信息'" width="600px">
        <el-form ref="formQualification" :rules="rulesQualification" :model="formQualification" label-width="140px" style="width: 500px;">
          <el-form-item label="资质正式名称" prop="QUALIFICATION_NAME">
            <el-input id="QUALIFICATION_NAME" ref="QUALIFICATION_NAME" v-model="formQualification.QUALIFICATION_NAME" maxlength="255" placeholder="这里输入资质正式名称..." title="资质正式名称"/>
          </el-form-item>
          <el-form-item label="证书有限期" prop="date">
            <el-date-picker
              v-model="formQualification.date"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              @change="handlePeriodChange"/>
          </el-form-item>
          <el-form-item label="证书编号" prop="CERTIFICATE_NO">
            <el-input id="CERTIFICATE_NO" ref="CERTIFICATE_NO" v-model="formQualification.CERTIFICATE_NO" maxlength="255" placeholder="这里输入证书编号..." title="证书编号"/>
          </el-form-item>
          <el-form-item label="照片" prop="QUALIFICATION_PIC">
            <el-upload
              ref="qualificationPicFileRef"
              :file-list="formQualification.QUALIFICATION_PIC"
              :multiple="false"
              :limit="1"
              :auto-upload="false"
              :on-change="qualificationPicFileChange"
              :on-remove="qualificationPicFileRemove"
              :class="{ hide: hideUploadBtn }"
              action="#"
              accept=".jpg,.jpeg,.png"
              list-type="picture-card"
            >
              <!-- <el-button size="small" type="primary">点击上传</el-button>-->
              <i class="el-icon-plus" />
            </el-upload>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogQualificationEdit = false">取 消</el-button>
          <el-button :loading="buttonloading" type="primary" @click="confirmQualification">确 定</el-button>
        </div>
      </el-dialog>
      <el-dialog :visible.sync="QRCodeDialog" title="查看二维码" width="680px" class="top-dialog">
        <div id="printTest" style="border: 1px solid #fff;">
          <div v-if="qrCodeUrl != ''" style="text-align: center;">
            <img :src="qrCodeUrl" width="300" height="300">
          </div>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button @click="QRCodeDialog = false">关 闭</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import { requestFN } from '@/utils/request'
import SelectTree from '@/components/SelectTree'
import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import { upload } from '@/utils/upload'
export default {
  components: { SelectTree, Treeselect },
  data() {
    var hasName = (rule, value, callback) => {
      requestFN(
        '/corpinfo/hasName',
        {
          RELEVANT_UNIT_NAME: value,
          CORPINFO_ID: ''

        }
      ).then((data) => {
        if (data.pd) {
          if (data.pd.CORPINFO_ID === this.$parent.CORPINFO_ID) {
            callback()
          } else {
            callback(new Error('单位名称重复'))
          }
        }
        callback()
      }).catch((e) => {
        callback()
      })
    }
    var hasSocialCode = (rule, value, callback) => {
      requestFN(
        '/corpinfo/hasSocialCode',
        {
          SOCIAL_CODE: value,
          CORPINFO_ID: ''

        }
      ).then((data) => {
        if (data.pd) {
          if (data.pd.CORPINFO_ID === this.$parent.CORPINFO_ID) {
            callback()
          } else {
            callback(new Error('统一社会信用代码重复'))
          }
        }
        callback()
      }).catch((e) => {
        callback()
      })
    }
    return {
      // 营业执照
      businessLicenseImgs: [],
      waitForDeleteImgs: [],
      firefightingPicture: false,

      hideUploadBtn: false,
      QRCodeDialog: false,
      qrCodeUrl: '',
      corpName: '',
      AUDIT_STATE: '',
      dataForm: {
        MAIN_DEPARTMENT: null,
        businessLicenseDate: [],
        STATE: '',
        SUPERVISE_CORPINFO_DEPT_NAME: '',
        MANAGER_DEPARTMENT_NAME: '',
        COMPETENT_DEPT_NAME: '',
        SUPERVISE_DEPARTMENT_ID: null,
        SUPERVISE_DEPARTMENT_NAME: '',
        RELEVANT_UNIT_NAME: '',
        SOCIAL_CODE: '',
        POSSESSION: [],
        INDUSTRY: '',
        ECONOMIC_TYPE: '',
        LONGITUDE: '',
        LATITUDE: '',
        BUSINESS_ADDRESS: '',
        CORP_SIZE: '',
        LEGAL_PERSON: '',
        LEGAL_PERSON_TEL: '',
        CONTACT_PERSON: '',
        CONTACT_TEL: '',
        ESTABLISHMENT_DATE: '',
        EMPLOY_NUM: '',
        TOTAL_ASSETS: '',
        REGISTERED_CAPITAL: '',
        EMPLOYMENT_FORM: '',
        SELECT_FORM: '',
        LICENSE_START: '',
        LICENSE_END: '',
        SELECT_FORMS: [],
        USER_NAME: ''
      },
      employmentTypeList: [], // 用工形式数据
      selectFormList: [], // 选取形式数据
      ecnomicTypeList: [], // 经济类型数据
      industryList: [], // 行业类型数据
      treeData: [], // 主管部门
      config: config,
      corpStateList: [], // 企业经营状态
      hylxList: [], // 国民经济行业分类 (GB-T4754-2017)
      enterpriseSizeList: [], // 企业规模
      /** 安全生产管理制度 Begin */
      dialogQualificationEdit: false,
      dialogQualificationType: 'add',
      qualificationList: [],
      formQualification: {
        date: [],
        FILE_NAME: '',
        CORPQUALIFICATIONINFO_ID: '',
        CERTIFICATE_PERIOD: '',
        QUALIFICATION_PIC: [],
        CORPINFO_ID: this.$parent.CORPINFO_ID,
        QUALIFICATION_NAME: '',
        START_DATE: '',
        END_DATE: '',
        CERTIFICATE_NO: '',
        IMG_URL: ''
      },
      rulesQualification: {
        QUALIFICATION_NAME: [{ required: true, message: '资质正式名称不能为空', trigger: 'blur' }],

        date: [
          {
            type: 'array',
            required: true,
            message: '请选择日期区间',
            fields: {
              // tpye类型试情况而定,所以如果返回的是date就改成date,如果返回的是string就改成string
              0: { type: 'string', trigger: 'change', required: true, message: '请选择开始日期' },
              1: { type: 'string', trigger: 'change', required: true, message: '请选择结束日期' }
            },
            trigger: 'blur'
          }
        ],
        CERTIFICATE_NO: [{ required: true, message: '证书编号不能为空', trigger: 'blur' }],
        QUALIFICATION_PIC: [
          {
            type: 'array',
            required: true,
            message: '请上传照片',
            trigger: 'blur'
          }
        ]
      },
      /** 安全生产管理制度 End */
      // 地图相关
      // clientHeight: document.documentElement.clientHeight - 250,
      CORPINFO_ID: this.$parent.CORPINFO_ID,
      clientHeight: 600,
      loadingMap: true,
      listLoading: false,
      buttonloading: false,
      BMap: '',
      map: '',
      showMap: false,
      addressKeyword: '',
      pointLngLat: '',
      zoom: 10,
      dialogFormMap: false,
      LATITUDE: '',
      LONGITUDE: '',
      dialogImageUrl: '',
      dialogVisible: false,
      provinceList: [],
      cityList: [],
      countyList: [],
      scaleList: [],
      areaList: [], // 属地
      jjlxList: [],
      corpFoTypeList: [],
      trainDicList: [],
      OLDFOURTYPE: '',
      normalizer(node) {
        return {
          id: node.id,
          label: node.name,
          children: node.nodes
        }
      },
      defaultProps: {
        children: 'nodes',
        label: 'name',
        value: 'id'
      },
      // 上级企业选择
      dialogParentCorp: false,
      ECO_TYPE: '',
      ecoArr: [],
      ecoNameArr: [],
      INDUSTRY: '',
      imgUrl: require('@/assets/images/map.png'),
      rules: {
        MAIN_DEPARTMENT: [{ required: false, message: '主管部门不能为空', trigger: 'blur' }],
        businessLicenseDate: [{
          type: 'array',
          required: true,
          message: '请选择日期区间',
          fields: {
            // tpye类型试情况而定,所以如果返回的是date就改成date,如果返回的是string就改成string
            0: { type: 'string', trigger: 'change', required: true, message: '请选择开始日期' },
            1: { type: 'string', trigger: 'change', required: true, message: '请选择结束日期' }
          },
          trigger: 'blur'
        }],
        RELEVANT_UNIT_NAME: [
          { required: true, message: '单位名字不能为空', trigger: 'blur' },
          { validator: hasName, trigger: 'blur' }
        ],
        SOCIAL_CODE: [
          { required: true, message: '统一社会信用代码不能为空', trigger: 'blur' },
          { validator: hasSocialCode, trigger: 'blur' },
          {
            pattern: /^[^_IOZSVa-z\W]{2}\d{6}[^_IOZSVa-z\W]{10}$/,
            message: '请输入正确的统一社会信用代码'
          }
        ],
        POSSESSION: [{ required: true, message: '属地不能为空', trigger: 'blur' }],
        // INDUSTRY: [{ required: true, message: '国民经济行业分类 (GB-T4754-2017)不能为空', trigger: 'blur' }],
        ECONOMIC_TYPE: [{ required: true, message: '请选择经济类型', trigger: 'blur' }],
        LONGITUDE: [{ required: false, message: '请选择经度', trigger: 'blur' }],
        LATITUDE: [{ required: false, message: '请选择纬度', trigger: 'blur' }],
        BUSINESS_ADDRESS: [{ required: true, message: '单位经营地址不能为空', trigger: 'blur' }],
        CORP_SIZE: [{ required: true, message: '企业规模不能为空', trigger: 'blur' }],
        LEGAL_PERSON: [{ required: true, message: '法人姓名不能为空', trigger: 'blur' }],
        LEGAL_PERSON_TEL: [
          { required: true, message: '法人电话不能为空', trigger: 'blur' },
          { min: 11, max: 11, message: '请输入11位手机号码', trigger: 'blur' },
          {
            pattern: /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/,
            message: '请输入正确的手机号码'
          }
        ],
        CONTACT_PERSON: [{ required: true, message: '主要负责人不能为空', trigger: 'blur' }],
        CONTACT_TEL: [
          { required: true, message: '主要负责人电话不能为空', trigger: 'blur' },
          { min: 11, max: 11, message: '请输入11位手机号码', trigger: 'blur' },
          {
            pattern: /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/,
            message: '请输入正确的手机号码'
          }
        ],
        ESTABLISHMENT_DATE: [{ required: true, message: '请选择成立日期', trigger: 'blur' }],
        EMPLOY_NUM: [
          { required: true, message: '职工人数不能为空', trigger: 'blur' },
          { min: 1, max: 5, message: '请正确的职工人数', trigger: 'blur' }
        ],
        TOTAL_ASSETS: [
          { required: true, message: '资产总额不能为空', trigger: 'blur' },
          { min: 1, max: 15, message: '请正确的资产总额', trigger: 'blur' }
        ],
        REGISTERED_CAPITAL: [
          { required: true, message: '注册资金不能为空', trigger: 'blur' },
          { min: 1, max: 15, message: '请正确的注册资金', trigger: 'blur' }
        ],
        EMPLOYMENT_FORM: [{ required: true, message: '请选择用工形式', trigger: 'blur' }],
        SELECT_FORMS: [{ required: true, message: '请选择选取形式', trigger: 'blur' }]
      },
      propsCorpFoType: { value: 'id', id: 'id', label: 'label', children: 'children' },

      ecoProps: {
        lazy: true,
        lazyLoad: this.lazyLoad,
        value: 'id',
        id: 'id',
        label: 'label',
        children: 'children'
      },
      industryProps: {
        lazy: true,
        lazyLoad: this.lazyLoad,
        value: 'id',
        id: 'id',
        label: 'label',
        children: 'children',
        checkStrictly: false
      },
      areaProps: {
        lazy: true,
        lazyLoad: async(node, resolve) => {
          const resData = await this.getAreaDict(
            (node.data && node.data.DICTIONARIES_ID) || 'e725d2a91b8248f4b8f49889038df7de'
          )
          const { level } = node
          resolve(
            resData.map((item) => {
              return {
                DICTIONARIES_ID: item.DICTIONARIES_ID,
                BIANMA: item.BIANMA,
                NAME: item.NAME,
                leaf: level >= 3
              }
            })
          )
        },
        value: 'BIANMA',
        id: 'DICTIONARIES_ID',
        label: 'NAME',
        children: 'children',
        checkStrictly: true
      },
      // 主管部门
      mainDepartment: '',
      // 监管部门
      regulatoryDepartment: ''
    }
  },
  watch: {
    'formQualification.QUALIFICATION_PIC': {
      handler: function() {
        if (this.formQualification.QUALIFICATION_PIC.length >= 1) {
          this.hideUploadBtn = true
        } else {
          this.hideUploadBtn = false
        }
      }
    }
  },
  async created() {
    const loading = this.$loading({
      lock: true,
      text: '读取中...',
      spinner: 'el-icon-loading',
      background: 'rgba(0, 0, 0, 0.7)'
    })
    // await this.getTreeList()
    await this.getDict()
    await this.getData()
    loading.close()
  },
  mounted() {
    // this.getNextTickData()
    this.getQualificationList()
  },
  methods: {
    handleRemove(file) {
      if (file.IMGFILES_ID) {
        // 已经上传过的 现在删除 记录这个id
        this.waitForDeleteImgs.push(file.IMGFILES_ID)
        this.businessLicenseImgs = this.businessLicenseImgs.filter(x => x.IMGFILES_ID != file.IMGFILES_ID)
      } else {
        this.businessLicenseImgs = this.businessLicenseImgs.filter(x => x.MATERIALS_ID != file.MATERIALS_ID)
      }
    },
    handlePictureCardPreview(file) {
      if (file.url) {
        this.dialogImageUrl = file.url
      }
      if (file.FILEPATH) {
        this.dialogImageUrl = config.fileUrl + file.FILEPATH
      }
      this.dialogVisible = true
    },
    overFlow(files, fileList) {
      this.$message.warning('最多上传5张图片')
    },
    handleEditChange(file, fileList) {
      file.MATERIALS_ID = Math.random()
      const is5M = file.size / 1024 / 1024 < 5
      if (is5M) this.businessLicenseImgs.push(file)
    },

    hiddenBeforeUpload(file) {
      const types = ['image/jpeg', 'image/jpg', 'image/png']
      const isImage = types.includes(file.type)
      if (!isImage) {
        this.$message.error('上传图片只能是 JPG、JPEG、PNG 格式!')
        return false
      } else if (this.businessLicenseImgs.length >= 4) {
        this.$message.error('最多上传4张图片')
        return false
      } else {
        this.businessLicenseImgs.push(file)
      }
    },
    handleChangeIMG(file, fileList) {
      const types = ['image/jpeg', 'image/jpg', 'image/png']
      const isImage = types.includes(file.raw.type)
      if (!isImage) {
        this.$message.error('上传图片只能是 JPG、JPEG、PNG 格式!')
        fileList.pop()
      }
      if (this.$refs.hiddenUpload) {
        this.firefightingPicture = this.businessLicenseImgs.length >= 4
      }
    },

    formatAuditState(state) {
      if (state == '0') {
        return '未填报'
      } else if (state == '1') {
        return '待审核'
      } else if (state == '2') {
        return '已审核'
      } else if (state == '3') {
        return '已打回'
      } else if (state == '4') {
        return '已填报'
      } else {
        return ''
      }
    },
    getTreeList() {
      return new Promise((resolve, reject) => {
        requestFN(
          '/corpinfo/getRegulatoryDepList',
          {}
        ).then((data) => {
          this.treeData = JSON.parse(data.zTreeNodes)
          this.treeData.push({
            id: '0',
            name: '无',
            nodes: []
          })
          resolve()
        }).catch((e) => {
          reject()
        })
      })
    },
    showQRCode(id) {
      id = this.$parent.CORPINFO_ID
      requestFN(
        '/corpinfo/generateQRCodeImage',
        {
          CORPINFO_ID: id,
          RELEVANT_UNIT_NAME: this.dataForm.RELEVANT_UNIT_NAME
        }
      ).then((data) => {
        this.qrCodeUrl = 'data:image/png;base64,' + data.code
        this.QRCodeDialog = true
      }).catch((e) => {
      })
    },
    getData() {
      return new Promise((resolve) => {
        requestFN(
          '/corpinfo/getDataForEditByCorpInfoId',
          {
            CORPINFO_ID: this.$parent.CORPINFO_ID,
            tm: new Date().getTime()
          }
        ).then((data) => {
          this.dataForm = Object.assign(this.dataForm, data.pd)
          this.dataForm.businessLicenseDate = []
          this.dataForm.businessLicenseDate.push(this.dataForm.LICENSE_START)
          this.dataForm.businessLicenseDate.push(this.dataForm.LICENSE_END)
          this.dataForm.USER_NAME = this.dataForm.USER_NAME ? this.dataForm.USER_NAME : this.dataForm.USER_NAME_B
          this.$forceUpdate()
          // 将对象中的 选取形式 转为数组以多选形式展现  2023-08-31  转换开始
          if (this.dataForm.SELECT_FORM) {
            var sz = this.dataForm.SELECT_FORM
            this.dataForm.SELECT_FORMS = sz.split(',')
          } else {
            this.dataForm.SELECT_FORMS = null
          }
          if (data.licenseImgs) {
            this.businessLicenseImgs = data.licenseImgs
          }
          this.dataForm.EMPLOYMENT_FORM = this.dataForm.EMPLOYMENT_FORM || null
          // 转换结束
          this.dataForm.POSSESSION = []
          if (data.pd.PROVINCE != '') this.dataForm.POSSESSION.push(data.pd.PROVINCE)
          if (data.pd.CITY != '') this.dataForm.POSSESSION.push(data.pd.CITY)
          if (data.pd.COUNTY != '') this.dataForm.POSSESSION.push(data.pd.COUNTY)
          if (data.pd.VILLAGE != '') this.dataForm.POSSESSION.push(data.pd.VILLAGE)
          this.AUDIT_STATE = this.dataForm.STATE
          if (this.dataForm.MAIN_DEPARTMENT.indexOf('[') > -1) {
            this.dataForm.MAIN_DEPARTMENT = JSON.parse(this.dataForm.MAIN_DEPARTMENT)
          } else {
            this.dataForm.MAIN_DEPARTMENT = [this.dataForm.MAIN_DEPARTMENT]
          }
          this.$forceUpdate()
          resolve()
        }).catch((e) => {
          console.log(e)
          this.$message({
            message: '操作失败',
            type: 'error'
          })
        })
      }).catch((e) => {
        this.listLoading = false
      })
    },
    getNextTickData() {
      if (this.form.CORP_OF_TYPE2 && this.form.CORP_OF_TYPE2 != '') {
        const node = {}
        node.id = this.form.CORP_OF_TYPE2
        this.$nextTick(() => {
          this.$refs.corpOfTypeRef.handleNodeClick(node)
        })
      } else if (this.form.CORP_OF_TYPE && this.form.CORP_OF_TYPE != '') {
        const node = {}
        node.id = this.form.CORP_OF_TYPE
        this.$nextTick(() => {
          this.$refs.corpOfTypeRef.handleNodeClick(node)
        })
      }
      this.$forceUpdate()
    },
    /** 上级企业选择 Begin */
    handleSelectParentCorp() {
      this.dialogParentCorp = true
    },
    defineCorp() {
      this.$refs.corpSelect.defineCorp()
    },
    assignCorpParent(corp) {
      this.form.CORP_PARENT = corp.CORPINFO_ID
      this.form.CORP_PARENT_NAME = corp.CORP_NAME
      this.form.CORP_GROUP = this.validStr(corp.CORP_GROUP) ? corp.CORP_GROUP : corp.CORPINFO_ID
      this.form.CORP_GROUP_NAME = this.validStr(corp.CORP_GROUP_NAME) ? corp.CORP_GROUP_NAME : corp.CORP_NAME
      this.form.CORP_PARENTS = (this.validStr(corp.CORP_PARENTS) ? corp.CORP_PARENTS : ',') + corp.CORPINFO_ID + ','
      // console.log('this.form.CORP_PARENT', this.form.CORP_PARENT)
      // console.log('this.form.CORP_PARENT_NAME', this.form.CORP_PARENT_NAME)
      // console.log('this.form.CORP_GROUP', this.form.CORP_GROUP)
      // console.log('this.form.CORP_GROUP_NAME', this.form.CORP_GROUP_NAME)
      // console.log('this.form.CORP_PARENTS', this.form.CORP_PARENTS)
      this.dialogParentCorp = false
    },
    /** 上级企业选择 End */
    // 加载级联的方法
    lazyLoad(nodeValue, resolve) {
      if (nodeValue.data && (!nodeValue.children || nodeValue.children.length == 0)) {
        this.getDictByDicId(nodeValue.data.id).then(data => {
          resolve(data)
        })
      } else {
        resolve(null)
      }
    },
    handleMap() {
      this.dialogFormMap = true
      this.LATITUDE = this.dataForm.LATITUDE
      this.LONGITUDE = this.dataForm.LONGITUDE
    },
    getClickInfo(e) {
      this.LONGITUDE = e.point.lng
      this.LATITUDE = e.point.lat
    },
    setPosition() {
      this.dialogFormMap = false
      this.dataForm.LATITUDE = this.LATITUDE
      this.dataForm.LONGITUDE = this.LONGITUDE
    },
    // 提交表单
    confirm(type) {
      // const _this = this
      this.$refs.dataForm.validate(valid => {
        if (valid) {
          if (!this.businessLicenseImgs.length > 0) {
            this.$message.warning('最少上传一张营业执照照片')
            return
          }
          this.buttonloading = true
          const loading = this.$loading({
            lock: true,
            text: '提交中...',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.7)'
          })
          if (this.dataForm.POSSESSION && this.dataForm.POSSESSION.length > 0) {
            this.dataForm.PROVINCE = this.dataForm.POSSESSION[0] || ''
            this.dataForm.CITY = this.dataForm.POSSESSION[1] || ''
            this.dataForm.COUNTY = this.dataForm.POSSESSION[2] || ''
            this.dataForm.VILLAGE = this.dataForm.POSSESSION[3] || ''
            // this.dataForm.STREET = this.dataForm.POSSESSION[4] || ''
            // this.dataForm.COMPANY_AREA = this.$refs.POSSESSION.getCheckedNodes()[0].pathLabels ? this.$refs.POSSESSION.getCheckedNodes()[0].pathLabels.join(',') : ''
          }
          /* if (_this.dataForm.INDUSTRYALL && _this.dataForm.INDUSTRYALL.length > 0) {
            _this.dataForm.CORP_TYPE = _this.dataForm.INDUSTRYALL[0] || ''
            _this.dataForm.CORP_TYPE2 = _this.dataForm.INDUSTRYALL[1] || ''
            _this.dataForm.CORP_TYPE3 = _this.dataForm.INDUSTRYALL[2] || ''
            _this.dataForm.CORP_TYPE4 = _this.dataForm.INDUSTRYALL[3] || ''
            _this.dataForm.CORP_TYPE_NAME = _this.$refs.industryCascader.getCheckedNodes()[0].pathLabels ? _this.$refs.industryCascader.getCheckedNodes()[0].pathLabels.join('/') : ''
          } */
          // 将数组转为字符串存入数据对象   2023-08-31  存入对象开始
          this.dataForm.SELECT_FORM = this.dataForm.SELECT_FORMS.join(',')
          this.dataForm.LICENSE_START = this.dataForm.businessLicenseDate[0]
          this.dataForm.LICENSE_END = this.dataForm.businessLicenseDate[1]
          this.dataForm.MAIN_DEPARTMENT = JSON.stringify(this.dataForm.MAIN_DEPARTMENT)
          // 存入对象结束
          const formData = new FormData()
          Object.keys(this.dataForm).map(key => {
            formData.append(key, this.dataForm[key])
          })
          for (let i = 0; i < this.businessLicenseImgs.length; i++) {
            if (this.businessLicenseImgs[i].raw) {
              formData.append('FFILE', this.businessLicenseImgs[i].raw)
            }
          }
          formData.append('saveType', type)
          formData.append('WAIT_REMOVE_DATA_IDS', this.waitForDeleteImgs.join(','))
          formData.append('checkState', this.AUDIT_STATE)
          this.buttonloading = true
          upload(
            '/corpinfo/saveEdit',
            formData
          ).then((data) => {
            loading.close()
            this.$message({
              message: '操作成功',
              type: 'success'
            })
            this.buttonloading = false
            this.waitForDeleteImgs = []
            if (data.changeName) {
              this.$alert('您修改了单位名称需使用新的单位名称重新登录', {
                confirmButtonText: '确定',
                callback: action => {
                  this.goOut()
                }
              })
            } else {
              this.getData()
            }
            // 20230613修改，不跳转页面
            // this.$router.push('/index')
            // this.$parent.activeName = 'CorpView'
          }).catch((e) => {
            loading.close()
            this.buttonloading = false
            this.$message({
              message: '操作失败',
              type: 'error'
            })
          })
        }
      })
    },
    goOut: function(msg) {
      requestFN(
        '/main/logout',
        {}
      ).then((data) => {
        sessionStorage.clear()
        location.reload()
      }).catch((e) => {
        sessionStorage.clear()
        location.reload()
      })
    },
    back() {
      this.$parent.activeName = 'CorpView'
    },

    getTrainDicList() {
      return new Promise(resolve => {
        requestFN(
          '/dictionaries/listAllDictToParId',
          {
            parentId: '052369aa22d242118236cde52d0c67ea'
          }
        ).then((data) => {
          resolve()
          this.trainDicList = JSON.parse(data.zTreeNodes)
        }).catch((e) => {
          this.listLoading = false
        })
      })
    },
    getProvinceList() {
      requestFN(
        '/dictionaries/getLevels',
        {
          DICTIONARIES_ID: 'e725d2a91b8248f4b8f49889038df7de'
        }
      ).then((data) => {
        this.provinceList = data.list
        // this.provinceList = [{ DICTIONARIES_ID: 'acd05c42faf346db9a0d067402b97c10', BIANMA: '130000', NAME: '河北省' }]
      }).catch((e) => {
      })
    },
    async getCityList() {
      var dictID = await this.getDictID(this.form.PROVINCE)
      requestFN(
        '/dictionaries/getLevels',
        {
          DICTIONARIES_ID: dictID
        }
      ).then((data) => {
        this.cityList = data.list
      }).catch((e) => {
      })
    },
    async getCountyList() {
      var dictID = await this.getDictID(this.form.CITY)
      requestFN(
        '/dictionaries/getLevels',
        {
          DICTIONARIES_ID: dictID
        }
      ).then((data) => {
        this.countyList = data.list
      }).catch((e) => {
      })
    },
    getDictID(BIANMA) {
      return new Promise((resolve) => {
        requestFN(
          '/dictionaries/findByBianma',
          {
            BIANMA: BIANMA
          }
        ).then((data) => {
          resolve(data.DICTIONARIES_ID)
        }).catch((e) => {
        })
      })
    },
    getDict() {
      return new Promise((resolve, reject) => {
        requestFN(
          '/dictionaries/listSelectTree',
          {
            DICTIONARIES_ID: '720992d898bf4fd7b44bf0ba1f1bbb88'
          }
        ).then((data) => {
          this.employmentTypeList = JSON.parse(data.zTreeNodes)
          resolve()
        })
        requestFN(
          '/dictionaries/getLevels',
          {
            DICTIONARIES_ID: '9ce2e9a4636b4d41b460ce16c346d497'
          }
        ).then((data) => {
          this.selectFormList = data.list
        })
        requestFN(
          '/dictionaries/getLevels',
          {
            DICTIONARIES_ID: '688d2cf1c6cd4dab999a0106e09aec83'
          }
        ).then((data) => {
          this.ecnomicTypeList = data.list
        })
        requestFN(
          '/dictionaries/getLevels',
          {
            DICTIONARIES_ID: '37b045e160c04ddba851073b4e510cc9'
          }
        ).then((data) => {
          this.enterpriseSizeList = data.list
        })
        requestFN(
          '/dictionaries/getLevels',
          {
            DICTIONARIES_ID: 'f2598ba72e864eadabf0ca4b664d26b9'
          }
        ).then((data) => {
          this.industryList = data.list
        })
        resolve()
      })
    },
    async getAreaDict(DICTIONARIES_ID) {
      const { list } = await requestFN(
        '/dictionarisearea/getLevels',
        {
          DICTIONARIES_ID
        }
      )
      return list
    },
    cascaderChange(e) {
      const newVal = e[e.length - 1]
      // console.log('选中', newVal[newVal.length - 1])
      if (newVal === '1' || newVal === '2' || newVal === '3' || newVal === '4') {
        this.$message({
          message: '请选择正确的属地...',
          type: 'error'
        })
        this.form.POSSESSION.pop()
        // console.log('移除', this.corpStateForm.REGULATORY_DEPARTMENT_ARR)
      }
    },
    getDictByDicId(id) {
      // console.log()
    },
    // 地图相关
    mapOpen() {
      this.top = this.getScrollTop()
      if (this.top) {
        this.setScrollTop(0)
      }
    },
    // 关闭地图后调用
    mapClose() {
      this.setScrollTop(this.top)
      this.top = 0
      this.showMap = false
    },
    getScrollTop() {
      let scrollTop = 0
      if (document.documentElement && document.documentElement.scrollTop) {
        scrollTop = document.documentElement.scrollTop
      } else if (document.body) {
        scrollTop = document.body.scrollTop
      }
      return scrollTop
    },
    setScrollTop(top) {
      if (!isNaN(top)) {
        if (document.documentElement && document.documentElement.scrollTop !== undefined) {
          document.documentElement.scrollTop = top
        } else if (document.body) {
          document.body.scrollTop = top
        }
      }
    },
    // 地图初始化
    handler({ BMap, map }) {
      this.mapOpen()
      this.BMap = BMap
      this.map = map
      this.loadingMap = true
      var geolocation = new BMap.Geolocation()
      const myGeo = new BMap.Geocoder()
      var $this = this
      // 调用百度地图api 中的获取当前位置接口
      geolocation.getCurrentPosition(function(r) {
        myGeo.getLocation(new BMap.Point(r.point.lng, r.point.lat), function(result) {
          if (result) {
            $this.loadingMap = false
            $this.$set($this, 'pointLngLat', { lng: result.point.lng, lat: result.point.lat })
            map.enableScrollWheelZoom(true) // 开启鼠标滚轮缩放,默认关闭
            $this.setCenter({ BMap, map })
          }
        })
      })
    },
    // 搜索地图
    querySearch(queryString, cb) {
      var options = {
        onSearchComplete: function(results) {
          if (local.getStatus() === 0) {
            // 判断状态是否正确
            var s = []
            for (var i = 0; i < results.getCurrentNumPois(); i++) {
              var x = results.getPoi(i)
              var item = { value: x.address + x.title, point: x.point }
              s.push(item)
              cb(s)
            }
          } else {
            cb()
          }
        }
      }
      var local = new this.BMap.LocalSearch(this.map, options)
      local.search(queryString)
    },
    handleSelect(item) {
      var { point } = item
      this.map.clearOverlays() // 清除地图上所有覆盖物
      this.map.centerAndZoom(point, this.zoom)
      const marker = new this.BMap.Marker(point) // 创建标注
      this.map.addOverlay(marker) // 将标注添加到地图中
      marker.enableDragging() // 可拖拽
      this.LONGITUDE = point.lng
      this.LATITUDE = point.lat
    },
    // 设置打开中心位置
    setCenter({ BMap, map }) {
      var lng = ''
      var lat = ''
      if (this.dataForm.LONGITUDE == '' || this.dataForm.LATITUDE == '') {
        lng = '119.525971'
        lat = '39.894727'
      } else {
        lng = this.dataForm.LONGITUDE
        lat = this.dataForm.LATITUDE
      }
      var point = new BMap.Point(lng, lat)
      // var point = new BMap.Point(this.form.LONGITUDE, this.form.LATITUDE)
      const zoom = map.getZoom()
      setTimeout(() => {
        map.centerAndZoom(point, zoom)
      }, 0)
      // var marker = new BMap.Marker(point) // 创建标注
      // map.addOverlay(marker) // 将标注添加到地图中
    },
    /** 资质信息 Begin */
    // 获取资质信息列表
    getQualificationList() {
      this.listLoading = true
      requestFN(
        '/corpqualificationinfo/listAll',
        {
          KEYWORDS: this.KEYWORDS
        }
      ).then((data) => {
        this.listLoading = false
        this.qualificationList = data.varList
      }).catch((e) => {
        this.listLoading = false
      })
    },
    // 添加资质信息dialog
    handleQualificationAdd() {
      this.dialogQualificationType = 'add'
      this.resetQualificationForm()
      this.dialogQualificationEdit = true
    },
    // 修改资质信息
    handleQualificationEdit(ID) {
      this.dialogQualificationType = 'edit'
      this.formQualification = {
        date: [],
        FILE_NAME: '',
        CORPQUALIFICATIONINFO_ID: '',
        CERTIFICATE_PERIOD: '',
        QUALIFICATION_PIC: [],
        CORPINFO_ID: this.$parent.CORPINFO_ID,
        QUALIFICATION_NAME: '',
        START_DATE: '',
        END_DATE: '',
        CERTIFICATE_NO: '',
        IMG_URL: ''
      }
      requestFN(
        '/corpqualificationinfo/goEdit',
        {
          CORPQUALIFICATIONINFO_ID: ID
        }
      ).then((data) => {
        this.formQualification = Object.assign(this.formQualification, data.pd) // copy obj
        this.$set(this.formQualification, 'date', [data.pd.START_DATE, data.pd.END_DATE])
        var url = config.fileUrl + data.pd.IMG_URL
        this.formQualification.QUALIFICATION_PIC.push({
          'url': url
        })
      }).catch((e) => {
        this.listLoading = false
      })
      this.dialogQualificationEdit = true
    },
    // 保存资质信息
    confirmQualification() {
      this.$refs.formQualification.validate(valid => {
        if (valid) {
          this.buttonloading = true
          this.dialogQualificationEdit = false
          this.listLoading = true
          const formData = new FormData()
          Object.keys(this.formQualification).map(key => {
            formData.append(key, this.formQualification[key])
          })
          // qualificationPicFileRef
          if (this.$refs['qualificationPicFileRef'].uploadFiles.length > 0) {
            for (let i = 0; i < this.$refs['qualificationPicFileRef'].uploadFiles.length; i++) {
              if (this.$refs['qualificationPicFileRef'].uploadFiles[i]) {
                formData.append('qualificationPic', this.$refs['qualificationPicFileRef'].uploadFiles[i].raw)
              }
            }
          }
          upload(
            '/corpqualificationinfo/' + this.dialogQualificationType,
            formData
          ).then((data) => {
            this.$message({
              message: '保存成功',
              type: 'success'
            })
            this.listLoading = false
            this.buttonloading = false
            this.formQualification = {
              date: [],
              FILE_NAME: '',
              CORPQUALIFICATIONINFO_ID: '',
              CERTIFICATE_PERIOD: '',
              QUALIFICATION_PIC: [],
              CORPINFO_ID: this.$parent.CORPINFO_ID,
              QUALIFICATION_NAME: '',
              START_DATE: '',
              END_DATE: '',
              CERTIFICATE_NO: '',
              IMG_URL: ''
            }
            this.getQualificationList()
          }).catch((e) => {
            this.listLoading = false
          })
        } else {
          return false
        }
      })
    },
    // 删除资质信息
    delQualification(id) {
      this.$confirm('确定要删除吗?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.listLoading = true
        requestFN(
          '/corpqualificationinfo/delete',
          {
            CORPQUALIFICATIONINFO_ID: id
          }
        ).then(() => {
          this.$message({
            message: '删除成功',
            type: 'success'
          })
          this.listLoading = false
          this.qualificationList = []
          this.getQualificationList()
        }).catch((e) => {
          this.listLoading = false
        })
      }).catch(() => {
      })
    },
    // 清空数据
    resetQualificationForm() {
      this.formQualification = {
        date: [],
        FILE_NAME: '',
        CORPQUALIFICATIONINFO_ID: '',
        CERTIFICATE_PERIOD: '',
        QUALIFICATION_PIC: [],
        CORPINFO_ID: this.$parent.CORPINFO_ID,
        QUALIFICATION_NAME: '',
        START_DATE: '',
        END_DATE: '',
        CERTIFICATE_NO: '',
        IMG_URL: ''
      }
    },
    // 资质证书照片change
    qualificationPicFileChange(file, fileList) {
      this.formQualification.FILE_NAME = file.name
      this.hideUploadBtn = fileList.length >= 1
      this.formQualification.QUALIFICATION_PIC.push(file)
    },
    // 资质图片移除
    qualificationPicFileRemove(file, fileList) {
      this.formQualification.FILE_NAME = ''
      this.hideUploadBtn = fileList.length >= 1
      this.formQualification.QUALIFICATION_PIC = fileList
    },
    // 资质图片预览
    handlePictureCardView(row) {
      this.dialogImageUrl = config.fileUrl + row.IMG_URL
      this.dialogVisible = true
    },
    // 资质有效期change事件
    handlePeriodChange(data) {
      this.formQualification.START_DATE = data[0]
      this.formQualification.END_DATE = data[1]
      this.formQualification.CERTIFICATE_PERIOD = data[0] + '-' + data[1]
    }
    /** 资质信息 End */
  } // methods 结束
}
</script>

<style lang="sass" scoped>
.avatar-uploader
  ul
    margin: 0
    li
      padding: 0
.el-dialog__body
  padding: 0
.map-flex
  display: flex
  width: 500px
  align-items: center

.ud-flex
  display: flex
.form-group
  display: flex
  align-items: center
  .form-label
    padding: 0px 15px
    font-size: 14px
    width: 240px
    font-weight: 400
    text-align: right
    margin-bottom: 18px
    .star
      color: red
      padding-right: 4px
  .input-block
    display: flex

.disContent
  display: flex
  align-items: center
  flex-wrap: wrap
  .img-div
    position: relative
    margin: 0 10px 0px 0
    width: 108px
    height: 108px
    border-radius: 4px
    overflow: hidden
    &>img
      width: 100%
      height: 100%

.disContent-hide
  position: absolute
  width: 100%
  height: 100%
  border-radius: 4px
  background-color: rgba(48, 48, 48, 0.59)
  display: none
  top: 0
  left: 0
  line-height: 32px

  .Delete
    position: absolute
    bottom: 14px
    right: 10px
    font-size: 16px
    color: white
    cursor: pointer
  .yuLan
    position: absolute
    bottom: 23px
    right: 50px
    font-size: 16px
    color: white
    cursor: pointer
    .yuLanImg
      position: absolute
      bottom: 0
      right: 0
      width: 100%
      height: 100%
      opacity: 0

.img-div:hover .disContent-hide
  display: block

  .pitchCss
    border: 1px solid #202e78
    transition: all linear 0.1s
    width: 116px
    height: 116px

</style>

<style lang="scss" scoped>
.uo-flex {
  display: flex;
}
// 隐藏上传组件
.hide {
  .el-upload--picture-card {
    display: none !important;
  }
}
.ui-height {
  height: 60px;
}
.ui-foot {
  position: fixed;
  width: calc(100% - 210px);
  bottom: 0;
  height: 60px;
  line-height: 60px;
  background-color: #f1f1f1;
  text-align: center;
  z-index: 99;
}
</style>

