<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="130px">
      <!--      <el-form-item label="学习中心编号" prop="studyCenterNumber">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.studyCenterNumber"-->
      <!--          placeholder="请输入学习中心编号"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-date-picker-->
      <!--        type="years"-->
      <!--        v-model="value6"-->
      <!--        placeholder="选择一个或多个年">-->
      <!--      </el-date-picker>-->
      <el-form-item label="学习中心名" prop="studyCenterName">
        <el-input v-model="queryParams.studyCenterName" placeholder="请输入学习中心名" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="负责人" prop="superintendent">
        <el-input v-model="queryParams.superintendent" placeholder="请输入负责人" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="电话/手机" prop="phone">
        <el-input v-model="queryParams.phone" placeholder="请输入电话/手机" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="企业名称" prop="enterpriseName">
        <el-input v-model="queryParams.enterpriseName" placeholder="请输入企业名称" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="营业执照信用代码" prop="businessLicenseCreditCode">
        <el-input v-model="queryParams.businessLicenseCreditCode" placeholder="请输入营业执照信用代码" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!--      <el-form-item label="省ID" prop="provinceId">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.provinceId"-->
      <!--          placeholder="请输入省ID"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="市ID" prop="cityId">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.cityId"-->
      <!--          placeholder="请输入市ID"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="区" prop="areaId">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.areaId"-->
      <!--          placeholder="请输入区"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <el-form-item label="审核状态" prop="examineStatus">
        <el-select v-model="queryParams.examineStatus" placeholder="请选择审核状态" clearable>
          <el-option v-for="dict in dict.type.tb_examine_status" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <!--      <el-form-item label="冻结状态" prop="frozenStatus">-->
      <!--        <el-select v-model="queryParams.frozenStatus" placeholder="请选择冻结状态" clearable>-->
      <!--          <el-option-->
      <!--            v-for="dict in dict.type.tb_frozen_status"-->
      <!--            :key="dict.value"-->
      <!--            :label="dict.label"-->
      <!--            :value="dict.value"-->
      <!--          />-->
      <!--        </el-select>-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="推荐" prop="isRecommend">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.isRecommend"-->
      <!--          placeholder="请输入推荐"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
          <el-option v-for="dict in dict.type.tb_status" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-date-picker clearable v-model="queryParams.createTime" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择创建时间">
        </el-date-picker>
      </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-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="['hezhi:studyCenter: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="['hezhi:studyCenter: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="['hezhi:studyCenter: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="['hezhi:studyCenter:export']"-->
      <!--        >导出</el-button>-->
      <!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="studyCenterList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!--      <el-table-column label="学习中心主键ID" align="center" prop="studyCenterId" />-->
      <!--      <el-table-column label="系统用户ID" align="center" prop="sysUserId" />-->
      <el-table-column label="学习中心编号" align="center" prop="studyCenterNumber" width="120px">
        <template slot-scope="scope">
          <tooltip :contentName="scope.row.studyCenterNumber" />
        </template>
      </el-table-column>
      <el-table-column label="学习中心logo" align="center" prop="studyCenterLogo" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.studyCenterLogo" :width="50" :height="50" />
        </template>
      </el-table-column>
      <el-table-column label="学习中心背景" align="center" prop="studyCenterBackground" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.studyCenterBackground" :width="50" :height="50" />
        </template>
      </el-table-column>
      <el-table-column label="学习中心名" align="center" prop="studyCenterName" width="120px">
        <template slot-scope="scope">
          <tooltip :contentName="scope.row.studyCenterName" />
        </template>
      </el-table-column>
      <!--      <el-table-column label="学习中心标题" align="center" prop="studyCenterTitle" />-->
      <!--      <el-table-column label="学习中心描述" align="center" prop="studyCenterDescribe" />-->
      <!--      <el-table-column label="学习中心标签" align="center" prop="studyCenterTag" />-->
      <!--      <el-table-column label="学习中心简介" align="center" prop="studyCenterIntroduce" />-->
      <!--      <el-table-column label="推荐课程" align="center" prop="recommendCourse" />-->
      <el-table-column label="负责人" align="center" prop="superintendent" width="80">
        <template slot-scope="scope">
          <tooltip :contentName="scope.row.superintendent" />
        </template>
      </el-table-column>
      <el-table-column label="电话/手机" align="center" prop="phone" width="120px"><template slot-scope="scope">
          <tooltip :contentName="scope.row.phone" />
        </template>
      </el-table-column>
      <!--      <el-table-column label="老师名称" align="center" prop="teacherName" />-->
      <!--      <el-table-column label="老师电话" align="center" prop="teacherPhone" />-->
      <el-table-column label="企业名称" align="center" prop="enterpriseName" width="100px">
        <template slot-scope="scope">
          <tooltip :contentName="scope.row.enterpriseName" />
        </template>
      </el-table-column>
      <el-table-column label="营业执照信用代码" align="center" prop="businessLicenseCreditCode" width="130px"><template
          slot-scope="scope">
          <tooltip :contentName="scope.row.businessLicenseCreditCode" />
        </template>
      </el-table-column>
      <el-table-column label="营业执照" align="center" prop="businessLicenseImg" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.businessLicenseImg" :width="50" :height="50" />
        </template>
      </el-table-column>
      <!--      <el-table-column label="省ID" align="center" prop="provinceId" />-->
      <!--      <el-table-column label="市ID" align="center" prop="cityId" />-->
      <!--      <el-table-column label="区" align="center" prop="areaId" />-->
      <el-table-column label="省名" align="center" prop="provinceName" width="80px">
        <template slot-scope="scope">
          <tooltip :contentName="scope.row.provinceName"/>
        </template>
      </el-table-column>
      <el-table-column label="市名" align="center" prop="cityName" width="80px">
        <template slot-scope="scope">
          <tooltip :contentName="scope.row.cityName" />
        </template>
      </el-table-column>
      <el-table-column label="区名" align="center" prop="areaName" width="80px">
        <template slot-scope="scope">
          <tooltip :contentName="scope.row.areaName" />
        </template>
      </el-table-column>
      <el-table-column label="详细地址" align="center" prop="address" width="100px">
        <template slot-scope="scope">
          <tooltip :contentName="scope.row.address" />
        </template>
      </el-table-column>

      <el-table-column align="center" prop="studyCenterFile" width="50">
        <template slot-scope="scope">
          <el-link type="primary" @click="getStudyCenterFileList(scope.row)">
            <span>图片</span>
          </el-link>
        </template>
      </el-table-column>

      <!--      <el-table-column label="类型" align="center" prop="type" />-->
      <el-table-column label="审核状态" align="center" prop="examineStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.tb_examine_status" :value="scope.row.examineStatus" />
        </template>
      </el-table-column>
      <!--      <el-table-column label="审核反馈" align="center" prop="examineFeedback" />-->
      <!--      <el-table-column label="冻结状态" align="center" prop="frozenStatus">-->
      <!--        <template slot-scope="scope">-->
      <!--          <dict-tag :options="dict.type.tb_frozen_status" :value="scope.row.frozenStatus"/>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column label="冻结状态反馈" align="center" prop="frozenEedback" />-->
      <el-table-column label="推荐" align="center" prop="isRecommend">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.tb_is_recommend" :value="scope.row.isRecommend" />
        </template>
      </el-table-column>
      <!--      <el-table-column label="排序" align="center" prop="sort" />-->
      <!--      <el-table-column label="备注" align="center" prop="remarks" />-->
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.tb_status" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" width="150" show-overflow-tooltip />
      <el-table-column label="操作" align="center"  width="120" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['hezhi:studyCenter:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['hezhi:studyCenter:remove']">删除</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="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <!--        <el-form-item label="系统用户ID" prop="sysUserId">-->
        <!--          <el-input v-model="form.sysUserId" placeholder="请输入系统用户ID" />-->
        <!--        </el-form-item>-->
        <el-form-item label="学习中心分类" prop="studyCenterClassId">
          <el-select v-model="form.studyCenterClassId" placeholder="请选择学习中心分类">
            <el-option v-for="item in studyCenterClassList" :key="item.studyCenterClassId" :label="item.name"
              :value="item.studyCenterClassId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="继续教育分类" prop="continuingEducationClassId">
          <el-select v-model="form.continuingEducationClassId" placeholder="请选择继续教育分类" clearable>
            <el-option v-for="(item, index) in continuingEducationClassList" :key="index" :label="item.name"
              :value="item.continuingEducationClassId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="学习中心编号" prop="studyCenterNumber">
          <el-input v-model="form.studyCenterNumber" placeholder="请输入学习中心编号" />
        </el-form-item>
        <el-form-item label="学习中心logo" prop="studyCenterLogo">
          <image-upload v-model="form.studyCenterLogo" :limit="1" />
        </el-form-item>
        <el-form-item label="学习中心背景" prop="studyCenterBackground">
          <image-upload v-model="form.studyCenterBackground" :limit="1" />
        </el-form-item>
        <el-form-item label="学习中心名" prop="studyCenterName">
          <el-input v-model="form.studyCenterName" placeholder="请输入学习中心名" />
        </el-form-item>
        <el-form-item label="学习中心标题" prop="studyCenterTitle">
          <el-input v-model="form.studyCenterTitle" placeholder="请输入学习中心标题" />
        </el-form-item>
        <el-form-item label="学习中心描述" prop="studyCenterDescribe">
          <el-input v-model="form.studyCenterDescribe" placeholder="请输入学习中心描述" />
        </el-form-item>
        <el-form-item label="学习中心标签" prop="studyCenterTag">
          <el-input v-model="form.studyCenterTag" placeholder="请输入学习中心标签" />
        </el-form-item>
        <el-form-item label="职业名称">
          <exam-course :exam-course-list="form.examCourseList" />
        </el-form-item>
        <el-form-item label="学习中心简介">
          <editor v-model="form.studyCenterIntroduce" :min-height="192" />
        </el-form-item>
        <el-form-item label="推荐职业" prop="recommendCourse">
          <el-input v-model="form.recommendCourse" placeholder="请输入推荐职业" />
        </el-form-item>
        <el-form-item label="负责人" prop="superintendent">
          <el-input v-model="form.superintendent" placeholder="请输入负责人" />
        </el-form-item>
        <el-form-item label="电话/手机" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入电话/手机" />
        </el-form-item>
        <el-form-item label="老师" prop="teacherName">
          <study-center-teacher :study-center-teacher-list="form.studyCenterTeacherList" />
        </el-form-item>
        <!--        <el-form-item label="老师手机" prop="teacherPhone">-->
        <!--          <el-input v-model="form.teacherPhone" placeholder="请输入老师电话/手机" />-->
        <!--        </el-form-item>-->
        <el-form-item label="企业名称" prop="enterpriseName">
          <el-input v-model="form.enterpriseName" placeholder="请输入企业名称" />
        </el-form-item>
        <el-form-item label="营业执照信用代码" prop="businessLicenseCreditCode">
          <el-input v-model="form.businessLicenseCreditCode" placeholder="请输入营业执照信用代码" />
        </el-form-item>
        <el-form-item label="营业执照图" prop="businessLicenseImg">
          <image-upload v-model="form.businessLicenseImg" :limit="1" />
        </el-form-item>
        <el-form-item label="省" prop="provinceId">
          <el-select v-model="form.provinceId" placeholder="请选择省" @change="updateCityIdAreaIdNull()">
            <el-option v-for="item in getProvinceList" :key="item.name" :label="item.name" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="市" prop="cityId">
          <el-select v-model="form.cityId" placeholder="请选择市" @focus="getCityOrArea" @change="updateAreaIdNull()">
            <el-option v-for="item in getCityOrAreaList" :key="item.name" :label="item.name" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="区" prop="areaId">
          <el-select v-model="form.areaId" placeholder="请选择区" @focus="getCityOrAreacity">
            <el-option v-for="item in getCityOrAreacityList" :key="item.name" :label="item.name" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <!--        <el-form-item label="省名" prop="provinceName">-->
        <!--          <el-input v-model="form.provinceName" placeholder="请输入省名" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="市名" prop="cityName">-->
        <!--          <el-input v-model="form.cityName" placeholder="请输入市名" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="区名" prop="areaName">-->
        <!--          <el-input v-model="form.areaName" placeholder="请输入区名" />-->
        <!--        </el-form-item>-->
<!--        <el-form-item label="详细地址" prop="address">-->
<!--          <el-input v-model="form.address" placeholder="请输入详细地址" />-->
<!--        </el-form-item>-->

        <el-form-item label="详细地址" prop="address">
          <el-input
            v-model="form.address"
            placeholder="点击右侧选择地址后可进行编辑"
            :readonly="!form.address"
          >
            <template #append>
              <!-- 选择地址按钮 -->
              <el-button
                type="primary"
                @click="openMapPicker"
              >
                选择地址
              </el-button>
            </template>
          </el-input>
        </el-form-item>
        <MapPicker ref="mapPickerRef" @update-location="handleLocation" />

        <!--        <el-form-item label="审核反馈" prop="examineFeedback">-->
        <!--          <el-input v-model="form.examineFeedback" type="textarea" placeholder="请输入内容" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="冻结状态" prop="frozenStatus">-->
        <!--          <el-radio-group v-model="form.frozenStatus">-->
        <!--            <el-radio-->
        <!--              v-for="dict in dict.type.tb_frozen_status"-->
        <!--              :key="dict.value"-->
        <!--              :label="parseInt(dict.value)"-->
        <!--            >{{dict.label}}</el-radio>-->
        <!--          </el-radio-group>-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="冻结状态反馈" prop="frozenFeedback">-->
        <!--          <el-input v-model="form.frozenFeedback" placeholder="请输入冻结状态反馈" />-->
        <!--        </el-form-item>-->
        <el-form-item label="推荐" prop="isRecommend">
          <el-radio-group v-model="form.isRecommend">
            <el-radio v-for="dict in dict.type.tb_is_recommend" :key="dict.value" :label="parseInt(dict.value)">{{
              dict.label }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="排序" prop="sort">
          <el-input-number v-model="form.sort" :step="1" :min="0" step-strictly />
        </el-form-item>
        <!--        <el-form-item label="备注" prop="remarks">-->
        <!--          <el-input v-model="form.remarks" type="textarea" placeholder="请输入内容" />-->
        <!--        </el-form-item>-->
        <el-form-item label="状态" prop="status">
          <el-radio-group v-model="form.status">
            <el-radio v-for="dict in dict.type.tb_status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label
              }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="审核状态" prop="examineStatus">
          <el-radio-group v-model="form.examineStatus">
            <el-radio v-for="dict in dict.type.tb_examine_status" :key="dict.value" :label="parseInt(dict.value)">{{
              dict.label }}</el-radio>
          </el-radio-group>
        </el-form-item>
      </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>

    <!--图片列表-->
    <el-dialog title="图片列表" :visible.sync="openStudyCenterFile" @close="openStudyCenterFileCancel" width="1000px"
      append-to-body>
      <study-center-file :study-center-id="studyCenterId" :key="studyCenterId" />
      <div slot="footer" class="dialog-footer">
        <el-button @click="openStudyCenterFileCancel">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listStudyCenter,
  getStudyCenter,
  delStudyCenter,
  addStudyCenter,
  updateStudyCenter, getMapGeocoder,
} from "@/api/hezhi/studyCenter";
import { getAllStudyCenterClassList } from "@/api/hezhi/studyCenterClass";
import { getCityOrArea, getProvince } from "@/api/hezhi/region";
import StudyCenterFile from "@/views/hezhi/studyCenterFile";
import { getAllContinuingEducationClassList } from "@/api/hezhi/continuingEducationClass";
import ExamCourse from "@/components/ExamCourse/index.vue";
import StudyCenterTeacher from "@/views/hezhi/studyCenter/studyCenterTeacher.vue";
import MapPicker from "@/views/hezhi/studyCenter/MapPicker.vue";

export default {
  name: "StudyCenter",
  dicts: [
    "tb_examine_status",
    "tb_status",
    "tb_frozen_status",
    "tb_is_recommend",
  ],
  components: { StudyCenterTeacher, ExamCourse, StudyCenterFile, MapPicker },
  data() {
    return {
      value6: "",
      openStudyCenterFile: false,
      //省
      getProvinceList: [],
      //市
      getCityOrAreaList: [],
      //区
      getCityOrAreacityList: [],
      // 学习中心分类
      studyCenterClassList: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      numbers: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 学习中心表格数据
      studyCenterList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sysUserId: null,
        studyCenterNumber: null,
        studyCenterLogo: null,
        studyCenterBackground: null,
        studyCenterName: null,
        studyCenterTitle: null,
        studyCenterDescribe: null,
        studyCenterTag: null,
        studyCenterIntroduce: null,
        recommendCourse: null,
        superintendent: null,
        phone: null,
        enterpriseName: null,
        businessLicenseCreditCode: null,
        businessLicenseImg: null,
        provinceId: null,
        cityId: null,
        areaId: null,
        provinceName: null,
        cityName: null,
        areaName: null,
        address: null,
        type: null,
        examineStatus: null,
        examineFeedback: null,
        frozenStatus: null,
        frozenFeedback: null,
        isRecommend: null,
        sort: null,
        remarks: null,
        status: null,
        publicationTime: null,
        publisher: null,
        createTime: null,
        deleteTime: null,
        deleteBy: null,
        delFlag: null,
        schoolName: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        studyCenterName: [
          { required: true, message: "学习中心名称", trigger: "blur" },
        ],
        address: [
          { required: true, message: "地址不能为空", trigger: "change" },
        ],
      },
      studyCenterId: null,
      continuingEducationClassList: [],
    };
  },
  created() {
    this.getList();
    this.getAllStudyCenterClassList();
    this.getProvince();
    getAllContinuingEducationClassList().then((res) => {
      this.continuingEducationClassList = res.data;
    });
  },
  methods: {
    /** 列表弹窗 */
    getStudyCenterFileList(row) {
      this.studyCenterId = row.studyCenterId;
      this.openStudyCenterFile = true;
    },
    openStudyCenterFileCancel() {
      this.studyCenterId = null;
      this.openStudyCenterFile = false;
    },

    // 获取省
    getProvince() {
      this.loading = true;
      getProvince(this.queryParams).then((response) => {
        this.getProvinceList = response.data.data;
        this.loading = false;
      });
      this.loading = false;
    },
    // 获取市
    getCityOrArea() {
      this.loading = true;
      let ida = this.form.provinceId || this.queryParams.provinceId;
      getCityOrArea(ida).then((response) => {
        this.getCityOrAreaList = response.data.data;
        this.loading = false;
      });
      this.loading = false;
    },
    //区
    getCityOrAreacity() {
      this.loading = true;
      let ida = this.form.cityId || this.queryParams.cityId;
      getCityOrArea(ida).then((response) => {
        this.getCityOrAreacityList = response.data.data;
        this.loading = false;
      });
      this.loading = false;
    },
    /** 获取学习中心分类列表 */
    getAllStudyCenterClassList() {
      getAllStudyCenterClassList().then((response) => {
        this.studyCenterClassList = response.data;
      });
    },

    /** 查询学习中心列表 */
    getList() {
      this.loading = true;
      listStudyCenter(this.queryParams).then((response) => {
        this.studyCenterList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        studyCenterId: null,
        sysUserId: null,
        studyCenterNumber: null,
        studyCenterLogo: null,
        studyCenterBackground: null,
        studyCenterName: null,
        studyCenterTitle: null,
        studyCenterDescribe: null,
        studyCenterTag: null,
        studyCenterIntroduce: null,
        recommendCourse: null,
        superintendent: null,
        phone: null,
        enterpriseName: null,
        businessLicenseCreditCode: null,
        businessLicenseImg: null,
        provinceId: null,
        cityId: null,
        areaId: null,
        provinceName: null,
        cityName: null,
        areaName: null,
        address: null,
        latitude: null,
        longitude: null,
        type: null,
        examineStatus: null,
        examineFeedback: null,
        frozenStatus: null,
        frozenFeedback: null,
        isRecommend: 0,
        sort: null,
        remarks: null,
        status: 0,
        publicationTime: null,
        publisher: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
        deleteTime: null,
        deleteBy: null,
        delFlag: null,
        schoolName: null,
        examCourseList: [],
        studyCenterTeacherList: [],
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.studyCenterId);
      this.numbers = selection.map((item) => item.studyCenterNumber);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.getProvince();
      this.open = true;
      this.title = "添加学习中心";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const studyCenterId = row.studyCenterId || this.ids;
      getStudyCenter(studyCenterId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改学习中心";
      });

      this.getProvince();
      let ida = row.provinceId;
      getCityOrArea(ida).then((response) => {
        this.getCityOrAreaList = response.data.data;
      });
      let idb = row.cityId;
      getCityOrArea(idb).then((response) => {
        this.getCityOrAreacityList = response.data.data;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.studyCenterId != null) {
            updateStudyCenter(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addStudyCenter(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const studyCenterIds = row.studyCenterId || this.ids;
      const studyCenterNos = row.studyCenterNumber || this.numbers;
      this.$modal
        .confirm('是否确认删除学习中心编号为"' + studyCenterNos + '"的数据项？')
        .then(function () {
          return delStudyCenter(studyCenterIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "hezhi/studyCenter/export",
        {
          ...this.queryParams,
        },
        `studyCenter_${new Date().getTime()}.xlsx`
      );
    },
    // 调用子组件的 open 方法打开弹窗
    openMapPicker() {
      this.$refs.mapPickerRef.open();
    },
    handleLocation({lat, lng, address}) {
      console.log('lat:', lat, 'lng:', lng, 'address:', address);
      // 经纬度和地址名称
      this.form.latitude = lat;
      this.form.longitude = lng;
      this.form.address = address;

      // 逆地址解析
      // const params = {
      //   lat: lat,
      //   lng: lng
      // };

      // 模拟 homesApi.getMapGeocoder 的异步调用
      // getMapGeocoder(params)
      //   .then((res) => {
      //     console.log('逆地址解析结果:', res);
      //     if (res.status === 0) {
      //       const comp = res.result.address_component;
      //       // 赋值到 formData
      //       this.form.provinceName = comp.province || '';
      //       this.form.cityName = comp.city || '';
      //       this.form.areaName = comp.district || '';
      //
      //     } else {
      //       console.warn('逆地址解析失败:', res.data.message);
      //     }
      //   })
      //   .catch((err) => {
      //     console.log(err);
      //   });
    }
  },
};
</script>
