<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="项目名称" prop="projectName">
        <el-input v-model="queryParams.projectName" placeholder="请输入项目名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="项目地址" prop="projectAddress">
        <el-input v-model="queryParams.projectAddress" placeholder="请输入项目地址" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="项目分类" prop="projectType">
        <el-select v-model="queryParams.projectType" placeholder="请选择项目分类" clearable>
          <el-option v-for="dict in dict.type.project_category" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>

      <el-form-item label="项目等级" prop="projiectLevel">
        <el-select v-model="queryParams.projiectLevel" placeholder="请选择项目等级" clearable>
          <el-option v-for="dict in dict.type.project_level" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>

      <el-form-item label="建设类型" prop="projectNature">
        <el-select v-model="queryParams.projectNature" placeholder="请选择项目建设类型" clearable>
          <el-option v-for="dict in dict.type.project_build_type" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>

      <el-form-item label="重要等级" prop="weightType">
        <el-select v-model="queryParams.weightType" placeholder="请选择重要等级" clearable>
          <el-option v-for="dict in dict.type.sur_project_weight" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>

      <el-form-item label="责任主体" prop="deptId" v-hasPermi="['project:project:zgs']">
        <el-select v-model="queryParams.deptId" placeholder="请选择责任主体" clearable>
          <el-option v-for="dict in depts" :key="dict.deptId" :label="dict.deptName" :value="dict.deptId"></el-option>
        </el-select>
      </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="['project:surProject: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="['project:surProject: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="['project:surProject: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="['project:surProject:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="surProjectList" @selection-change="handleSelectionChange" stripe>
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="项目名称" align="left" prop="projectName" width="200" class-name="small-padding fixed-width"
        fixed="left" show-overflow-tooltip />
      <el-table-column label="责任主体" align="center" prop="deptName" />
      <el-table-column label="父级项目" align="left" prop="paretProjectName" width="200" show-overflow-tooltip />
      <el-table-column label="项目简称" align="left" prop="simpleName" width="200" show-overflow-tooltip />
      <el-table-column label="项目分类" align="center" prop="projectType">
        <template slot-scope="scope">          
          <dict-tag :options="dict.type.project_category" :value="scope.row.projectType" />
        </template>
      </el-table-column>
      <el-table-column label="项目等级" align="center" prop="projiectLevel">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.project_level" :value="scope.row.projiectLevel" />
        </template>
      </el-table-column>
      <el-table-column label="项目区域" align="center" prop="projectRegionalName" />
      <el-table-column label="进度展示" align="center" v-if="checkPermi(['project:surProject:progressVisible'])">
        <template slot-scope="scope">
          <el-switch v-model="scope.row.progressVisible" active-value="0" inactive-value="1"
            @change="setVisibleStatus(scope.row, $event)"></el-switch>
        </template>
      </el-table-column>
      <el-table-column label="项目排序" align="center" width="150" v-if="checkPermi(['project:surProject:projectSort'])">
        <template slot-scope="scope">
          <el-input-number size="mini" v-model="scope.row.projectSort" :min="1" :max="999"
            @change="setProjectSort(scope.row, $event)"></el-input-number>
        </template>
      </el-table-column>
      <el-table-column label="建设类型" align="left" prop="projectNature" width="120" show-overflow-tooltip>
        <template slot-scope="scope">
          <dict-tag :options="dict.type.project_build_type" :value="scope.row.projectNature" />
        </template>
      </el-table-column>
      <el-table-column label="重要等级" align="left" prop="weightType" width="120" show-overflow-tooltip>
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sur_project_weight" :value="scope.row.weightType" />
        </template>
      </el-table-column>
      <el-table-column label="项目地址" align="left" prop="projectAddress" width="200" show-overflow-tooltip />
      <el-table-column label="项目负责人" align="center" prop="projectPerson" width="100" />
      <el-table-column label="负责人电话" align="center" prop="projectPhone" width="110" />
      <el-table-column label="工程期限" align="center" prop="projectTimeLimit" />
      <el-table-column label="总投资" align="center" prop="totalInvestment" />
      <el-table-column label="开累产值" align="center" prop="totalOutputValue" />
      <el-table-column label="计划完成时间" align="center" prop="plannedCompletionTime" width="120" show-overflow-tooltip>
        <template slot-scope="{ row }">{{ row.plannedCompletionTime }}</template>
      </el-table-column>
      <el-table-column label="计划开工时间" align="center" prop="scheduledStartTime" width="120" show-overflow-tooltip>
        <template slot-scope="{ row }">{{ row.scheduledStartTime }}</template>
      </el-table-column>
      <el-table-column label="实际开工时间" align="center" prop="actualOperatingTime" width="120" show-overflow-tooltip>
        <template slot-scope="{ row }">{{ row.actualOperatingTime }}</template>
      </el-table-column>
      <el-table-column label="实际完工时间" align="center" prop="actualCompletionTime" width="120" show-overflow-tooltip>
        <template slot-scope="{ row }">{{ row.actualCompletionTime }}</template>
      </el-table-column>
      <el-table-column label="合同总额" align="center" prop="contractAmount" width="80" />
      <el-table-column label="付款金额" align="center" prop="paidAmount" width="80" />
      <el-table-column label="挂账金额" align="center" prop="onAccountAmount" width="80" />
      <el-table-column label="劳务人员" align="center" prop="servicePersonnel" />
      <el-table-column label="监理人员" align="center" prop="supervisorPersonnel" />
      <el-table-column label="总包人员" align="center" prop="generalContractor" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="240">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-time" @click="prjProcessMgr(scope.row)"
            v-hasPermi="['project:surProject:edit']">进度管理</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['project:surProject:edit']">修改项目</el-button>
          <el-button size="mini" type="text" icon="el-icon-user-solid" @click="handleProjectUserinfo(scope.row)"
            v-hasPermi="['project:surProjectUserInfo:list']">项目人员</el-button>
          <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)" v-hasPermi="[
      'project:assess:list',
      'project:build_node_data:list',
      'project:projectChecking:list',
      'project:projectFunVerify:list',
      'work:workTrain:list',
      'work:emergencyDrill:list',
      'project:surProjectInsurance:list',
      'project:surProjectSpecial:list',
      'project:projectMeasure:list',
      'project:materialSeal:list',
      'project:projectDeptWroks:list',
      'project:surProjectAttendance:add',
      'video:videoConfig:list',
      'video:aiBoxProjectConfig:list',
      'project:checkDetection:list',
      'project:costOutput:edit',
      'project:projectStandard:edit',
      'project:attendanceWorker:list',
      'project:attendance:list',
      'project:surProject:remove',
      'project:projectCommittee:list',
    ]">
            <el-button size="mini" type="text" icon="el-icon-d-arrow-right">更多操作</el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="handleAssess" icon="el-icon-coordinate"
                v-hasPermi="['project:assess:list']">季度考核管理</el-dropdown-item>
              <el-dropdown-item command="handleBuildNode" icon="el-icon-data-analysis"
                v-hasPermi="['project:build_node_data:list']">计划节点管理</el-dropdown-item>
              <el-dropdown-item command="handleCommittee" icon="el-icon-s-order" v-if="1==1"
                v-hasPermi="['project:projectCommittee:list']">工委会管理</el-dropdown-item>
              <el-dropdown-item v-if="1 == 2" command="handleDesign" icon="el-icon-orange"
                v-hasPermi="['project:projectDesign:list']">设计管理</el-dropdown-item>
              <el-dropdown-item command="handleProjectChecking" icon="el-icon-s-help"
                v-hasPermi="['project:projectChecking:list']">举牌验收管理</el-dropdown-item>
                <el-dropdown-item command="handleProjectFunVerify" icon="el-icon-s-help"
                v-hasPermi="['project:projectFunVerify:list']">工程功能检验</el-dropdown-item>
              <el-dropdown-item command="handleWorkTrain" icon="el-icon-notebook-2"
                v-hasPermi="['work:workTrain:list']">项目教育培训</el-dropdown-item>
              <el-dropdown-item command="handleEmergencyDrill" icon="el-icon-first-aid-kit"
                v-hasPermi="['work:emergencyDrill:list']">项目应急演练</el-dropdown-item>
              <el-dropdown-item command="handleProjectInsurance" icon="el-icon-star-on"
                v-hasPermi="['project:surProjectInsurance:list']">项目保险管理</el-dropdown-item>
              <el-dropdown-item command="handleProjectSpecial" icon="el-icon-user"
                v-hasPermi="['project:surProjectSpecial:list']">项目特种人员</el-dropdown-item>
              <el-dropdown-item command="handleProjectMeasure" icon="el-icon-s-operation"
                v-hasPermi="['project:projectMeasure:list']">实测实量管理</el-dropdown-item>
              <el-dropdown-item command="handleProjectMaterialSeal" icon="el-icon-s-ticket"
                v-hasPermi="['project:materialSeal:list']">材料封样管理</el-dropdown-item>
              <el-dropdown-item command="handleAttendanceData" icon="el-icon-s-grid"
                v-hasPermi="['project:attendance:list']">劳务实名管理</el-dropdown-item>
              <el-dropdown-item command="handleVideoConfig" icon="el-icon-video-camera-solid"
                v-hasPermi="['video:videoConfig:list']">视频配置</el-dropdown-item>
              <el-dropdown-item command="handleAiBoxVideoConfig" icon="el-icon-camera"
                v-hasPermi="['video:aiBoxProjectConfig:list']">AI视频配置</el-dropdown-item>
              <el-dropdown-item command="handlePrjPhotography" icon="el-icon-camera"
                v-hasPermi="['video:prjphotography:list']">项目全景</el-dropdown-item>
              <el-dropdown-item command="handleCheckDetection" icon="el-icon-c-scale-to-original"
                v-hasPermi="['project:checkDetection:list']">材料取样复试</el-dropdown-item>
              <el-dropdown-item command="handleCostOutput" icon="el-icon-money"
                v-hasPermi="['project:costOutput:edit']">项目成本产值管理</el-dropdown-item>
              <el-dropdown-item command="handleStandard" icon="el-icon-s-grid"
                v-hasPermi="['project:projectStandard:list']">标准化管理</el-dropdown-item>
              <el-dropdown-item command="handleDelete" icon="el-icon-delete"
                v-hasPermi="['project:surProject:remove']">删除项目</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </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" v-if="open" :visible.sync="open" width="1200px" append-to-body
      custom-class="prj-suprj-edit-dialog" :close-on-click-modal="false" :close-on-press-escape="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="责任主体" prop="deptId">
              <el-select v-model="form.deptId" placeholder="请选择责任主体" style="width: 100%"
                :disabled="getDeptIdDisabled()">
                <el-option v-for="dict in depts" :key="dict.deptId" :label="dict.deptName"
                  :value="dict.deptId"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="项目名称" prop="projectName">
              <el-input v-model="form.projectName" placeholder="请输入项目名称" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="父级项目" prop="paretProjectName">
              <el-input v-model="form.paretProjectName" placeholder="请输入父级项目名称" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="项目建设类型" prop="projectNature">
              <el-select v-model="form.projectNature" placeholder="请选择项目建设类型" style="width: 100%">
                <el-option v-for="dict in dict.type.project_build_type" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="项目简称" prop="simpleName">
              <el-input v-model="form.simpleName" placeholder="请输入项目简称" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="项目分类" prop="projectType">
              <el-select v-model="form.projectType" placeholder="请选择项目分类" style="width: 100%">
                <el-option v-for="dict in dict.type.project_category" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select> </el-form-item></el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="经纬度" prop="longitude" class="fi-longitude">
              <div>
                <div>({{ form.longitude }},{{ form.latitude }})</div>
                <el-button @click="getMapInfo">选择经纬度</el-button>
              </div>
              <div style="margin-left: 12px; flex-grow: 1">
                <el-input type="textarea" :rows="3" placeholder="请输入地址" v-model="form.projectAddress">
                </el-input>
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="项目等级" prop="projiectLevel">
              <el-select v-model="form.projiectLevel" placeholder="请选择项目等级" style="width: 100%">
                <el-option v-for="dict in dict.type.project_level" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="工程期限" prop="projectTimeLimit">
              <el-input v-model="form.projectTimeLimit" placeholder="请输入工程期限">
                <i slot="suffix">天</i>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="建筑面积" prop="floorArea">
              <el-input v-model="form.floorArea" placeholder="请输入建筑面积">
                <i slot="suffix">平方米</i>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>


          <el-col :span="8">
            <el-form-item label="计划完成时间" prop="plannedCompletionTime">
              <el-date-picker v-model="form.plannedCompletionTime" type="month" placeholder="选择计划完成时间"
                style="width: 100%">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="计划开工时间" prop="scheduledStartTime">
              <el-date-picker v-model="form.scheduledStartTime" type="month" placeholder="选择计划开工时间" style="width: 100%">
              </el-date-picker> </el-form-item></el-col>
          <el-col :span="8">
            <el-form-item label="实际开工时间" prop="actualOperatingTime">
              <el-date-picker v-model="form.actualOperatingTime" type="month" placeholder="选择实际开工时间"
                style="width: 100%">
              </el-date-picker> </el-form-item></el-col>
        </el-row>
        <el-row>


          <el-col :span="8"><el-form-item label="实际完工时间" prop="actualCompletionTime">
              <el-date-picker v-model="form.actualCompletionTime" type="month" placeholder="选择实际完工时间"
                style="width: 100%">
              </el-date-picker> </el-form-item></el-col>
          <el-col :span="8"><el-form-item label="形象进度" prop="projectSchedule">
              <el-select v-model="form.projectSchedule" placeholder="请选择形象进度" style="width: 100%">
                <el-option v-for="dict in dict.type.sur_project_xmjd" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>

        </el-row>
        <!-- <el-row>
          <el-col :span="8"
            ><el-form-item label="劳务人员数" prop="servicePersonnel">
              <el-input v-model="form.servicePersonnel" placeholder="请输入劳务人员数">
                <i slot="suffix">人</i>
              </el-input>
            </el-form-item></el-col
          >
          <el-col :span="8"
            ><el-form-item label="监理人员数" prop="supervisorPersonnel">
              <el-input v-model="form.supervisorPersonnel" placeholder="请输入监理人员数">
                <i slot="suffix">人</i>
              </el-input>
            </el-form-item></el-col
          >
          <el-col :span="8">
            <el-form-item label="总包人员数" prop="generalContractor">
              <el-input v-model="form.generalContractor" placeholder="请输入总包人员数">
                <i slot="suffix">人</i>
              </el-input>
            </el-form-item></el-col
          >
        </el-row> -->
        <el-form-item label="项目概述" prop="projectSummarize">
          <el-input v-model="form.projectSummarize" type="textarea" :rows="5" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </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>
    <ProjectScheduleDlg ref="prjSchDlg"></ProjectScheduleDlg>
    <projectUserInfoDrawer size="50%" :visible.sync="projectUserInfoDrawerVisible" :form-data="formData" />
    <assess-drawer ref="assessDrawer"></assess-drawer>
    <baidu-map ref="map" @success="mapSuccess"></baidu-map>
    <build-node-drawer ref="nodeDrawer"></build-node-drawer>
    <workTrainDrawer ref="workTrainDrawer"></workTrainDrawer>
    <emergencyDrillDrawer ref="emergencyDrillDrawer"></emergencyDrillDrawer>
    <surProjectSpecialDrawer ref="projectSpecial"></surProjectSpecialDrawer>
    <insuranceDrawer ref="insurance"></insuranceDrawer>
    <projectCheckingDrawer ref="projectChecking"></projectCheckingDrawer>
    <projectFunVerifyDrawer ref="projectFunVerify"></projectFunVerifyDrawer>
    <materialSealDrawer ref="materialSeal"></materialSealDrawer>
    <projectMeasureDrawer ref="projectMeasure"></projectMeasureDrawer>
    <videoConfigDrawer ref="videoConfig"></videoConfigDrawer>
    <costOutputDrawer ref="costOutput"></costOutputDrawer>
    <checkDetectionDrawer ref="checkDetection"></checkDetectionDrawer>
    <standardDrawer ref="standard"></standardDrawer>
    <attendanceDataDrawer ref="attendanceData"></attendanceDataDrawer>
    <aiBoxVideoConfigDrawer ref="aiBoxVideoConfigDrawer"></aiBoxVideoConfigDrawer>
    <prjPhotographyDrawer ref="prjPhotographyDrawer"></prjPhotographyDrawer>
    <projectDesignDrawer ref="designDrawer"></projectDesignDrawer>
    <CommitteeDrawer ref="committeeDrawer"></CommitteeDrawer>
  </div>
</template>

<script>
import {
  listSurProject,
  getSurProject,
  delSurProject,
  addSurProject,
  updateSurProject,
  updateSurProjectProgressVisible,
  updateSurProjectSort,
} from "@/api/project/surProject";
import ProjectScheduleDlg from "../surProjectSchedule/ProjectScheduleDlg.vue";
import projectUserInfoDrawer from "../surProjectUserInfo/projectUserInfoDrawer.vue";
import BaiduMap from "@/components/BaiduMap/Map.vue";
import AssessDrawer from "../surProjectQuarterlyAssess/assessDrawer.vue";
import buildNodeDrawer from "../surBuildNode/buildNodeDrawer.vue";
import workTrainDrawer from "../../work/workTrain/workTrainDrawer.vue";
import emergencyDrillDrawer from "../../work/emergencyDrill/emergencyDrillDrawer.vue";
import surProjectSpecialDrawer from "../surProjectSpecial/surProjectSpecialDrawer.vue";
import insuranceDrawer from "../surProjectInsurance/insuranceDrawer.vue";
import projectCheckingDrawer from "../projectChecking/projectCheckingDrawer.vue";
import projectFunVerifyDrawer from "../projectFunVerify/projectFunVerifyDrawer.vue";
import materialSealDrawer from "@/views/project/materialSeal/projectMaterialSealDrawer.vue";
import projectMeasureDrawer from "../projectMeasure/projectMeasureDrawer.vue";
import videoConfigDrawer from "@/views/video/videoConfig/videoConfigDrawer";
import costOutputDrawer from "@/views/project/costOutput/costOutputDrawer.vue";
import checkDetectionDrawer from "../checkDetection/checkDetectionDrawer.vue";
import standardDrawer from '@/views/project/projectStandard/projectStandardDrawer.vue';
import attendanceDataDrawer from '@/views/project/attendance/attendanceDrawer.vue';
import aiBoxVideoConfigDrawer from '@/views/video/aiBoxProjectConfig/aiBoxVideoConfigDrawer';
import prjPhotographyDrawer from '@/views/video/prjphotography/prjPhotographyDrawer.vue'
import projectDesignDrawer from '@/views/project/projectDesign/projectDesignDrawer.vue';
import CommitteeDrawer from '@/views/project/projectCommittee/projectCommitteeDrawer.vue'
import { checkPermi, checkRole } from "@/utils/permission"; // 权限判断函数

export default {
  name: "SurProject",
  components: {
    ProjectScheduleDlg,
    projectUserInfoDrawer,
    BaiduMap,
    AssessDrawer,
    buildNodeDrawer,
    workTrainDrawer,
    emergencyDrillDrawer,
    surProjectSpecialDrawer,
    insuranceDrawer,
    projectCheckingDrawer,
    projectFunVerifyDrawer,
    materialSealDrawer,
    projectMeasureDrawer,
    videoConfigDrawer,
    costOutputDrawer,
    checkDetectionDrawer,
    standardDrawer,
    attendanceDataDrawer,
    aiBoxVideoConfigDrawer,
    prjPhotographyDrawer,
    projectDesignDrawer,
    CommitteeDrawer
  },
  dicts: [
    "sur_project_xmjd",
    "project_build_type",
    "sys_common_isdel",
    "project_category",
    "project_level",
    "sur_project_weight",
  ],
  data() {
    return {
      projectUserInfoDrawerVisible: false,
      projectSpecialDrawerVisible: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 项目管理表格数据
      surProjectList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      formData: {
        projectId: null,
        projectName: null,
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        deptId: null,
        projectName: null,
        projectCode: null,
        paretProjectName: null,
        paretProjectCode: null,
        simpleName: null,
        projectType: null,
        projiectLevel: null,
        projectRegional: null,
        projectAddress: null,
        projectNature: null,
        licenceNumber: null,
        projectApproval: null,
        projectPerson: null,
        projectPhone: null,
        longitude: null,
        latitude: null,
        projectTimeLimit: null,
        totalInvestment: null,
        floorArea: null,
        totalOutputValue: null,
        plannedCompletionTime: null,
        scheduledStartTime: null,
        actualOperatingTime: null,
        actualCompletionTime: null,
        contractAmount: null,
        paidAmount: null,
        onAccountAmount: null,
        projectSchedule: null,
        projectSummarize: null,
        isDel: null,
        projectStatus: null,
        servicePersonnel: null,
        supervisorPersonnel: null,
        generalContractor: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        deptId: [{ required: true, message: "请选择责任主体", trigger: "blur" }],
        projectName: [{ required: true, message: "请输入项目名称", trigger: "blur" }],
      },
      depts: [],
    };
  },
  created() {
    this.getList();
    this.$api.publics.getZgsDeptList().then((d) => {
      this.depts = d?.data || [];
    });
  },
  methods: {
    checkPermi,
    mapSuccess(pt, city) {
      this.form.longitude = pt.lng.toFixed(3);
      this.form.latitude = pt.lat.toFixed(3);
      this.form.projectAddress = (city.address || "") + (city.poi_desc || "");
    },
    getMapInfo() {
      this.$refs.map.showDialog("获取项目地理信息");
    },
    //进度管理
    prjProcessMgr(row) {
      this.$refs.prjSchDlg.showDialog(row);
    },
    /** 查询项目管理列表 */
    getList() {
      this.loading = true;
      listSurProject(this.queryParams).then((response) => {
        this.surProjectList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        deptId: null,
        projectName: null,
        projectCode: null,
        paretProjectName: null,
        paretProjectCode: null,
        simpleName: null,
        projectType: null,
        projiectLevel: null,
        projectRegional: null,
        projectAddress: null,
        projectNature: null,
        licenceNumber: null,
        projectApproval: null,
        projectPerson: null,
        projectPhone: null,
        longitude: null,
        latitude: null,
        projectTimeLimit: null,
        totalInvestment: null,
        floorArea: null,
        totalOutputValue: null,
        plannedCompletionTime: null,
        scheduledStartTime: null,
        actualOperatingTime: null,
        actualCompletionTime: null,
        contractAmount: null,
        paidAmount: null,
        onAccountAmount: null,
        projectSchedule: null,
        projectSummarize: null,
        isDel: null,
        projectStatus: null,
        servicePersonnel: null,
        supervisorPersonnel: null,
        generalContractor: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: 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;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加项目管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getSurProject(id).then((response) => {
        this.form = response.data;
        this.open = true;
        if (!this.form.projectAddress) {
          this.$refs.map.getCity(this.form, this.mapSuccess);
        }
        this.title = "修改项目管理";
      });
    },
    // 更多操作触发
    handleCommand(command, row) {
      switch (command) {
        case "handleProjectUserinfo":
          this.handleProjectUserinfo(row);
          break;
        case "handleDelete":
          this.handleDelete(row);
          break;
        case "handleDesign":
          this.$refs.designDrawer.show(row);
          break;
        case "handleAssess":
          this.$refs.assessDrawer.show(row);
          break;
        case "handleBuildNode":
          this.$refs.nodeDrawer.show(row);
          break;
        case "handleWorkTrain":
          this.$refs.workTrainDrawer.show(row);
          break;
        case "handleEmergencyDrill":
          this.$refs.emergencyDrillDrawer.show(row);
          break;
        case "handleProjectSpecial":
          this.$refs.projectSpecial.show(row);
          break;
        case "handleProjectInsurance":
          this.$refs.insurance.show(row);
          break;
        case "handleProjectChecking":
          this.$refs.projectChecking.show(row);
          break;
        case "handleProjectFunVerify":
          this.$refs.projectFunVerify.show(row);
          break;
        case "handleProjectMeasure":
          this.$refs.projectMeasure.show(row);
          break;
        case "handleProjectMaterialSeal":
          this.$refs.materialSeal.show(row);
          break;
        case "handleVideoConfig":
          this.$refs.videoConfig.show(row);
          break;
        case "handleCostOutput":
          this.$refs.costOutput.show(row);
          break;
        case "handleCheckDetection":
          this.$refs.checkDetection.show(row);
          break;
        case "handleStandard":
          this.$refs.standard.show(row);
          break;
        case "handleAttendanceData":
          this.$refs.attendanceData.show(row);
          break;
        case "handleAiBoxVideoConfig":
          this.$refs.aiBoxVideoConfigDrawer.show(row);
          break;
        case "handlePrjPhotography":
          this.$refs.prjPhotographyDrawer.show(row);
          break;
        case "handleCommittee":
          this.$refs.committeeDrawer.show(row);
          break;
        default:
          break;
      }
    },
    //项目人员
    handleProjectUserinfo(row) {
      this.formData.projectId = row.id;
      this.formData.projectName = row.projectName;
      this.projectUserInfoDrawerVisible = true;
    },
    getDeptIdDisabled() {
      if (this.form && this.form.id) {
        return true;
      } else {
        return false;
      }
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id) {
            updateSurProject(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSurProject(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除项目管理编号为"' + ids + '"的数据项？')
        .then(function () {
          return delSurProject(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "project/surProject/export",
        {
          ...this.queryParams,
        },
        `surProject_${new Date().getTime()}.xlsx`
      );
    },
    //项目形象进度滑块控制
    setVisibleStatus(row, val) {
      this.$confirm(`是否确认修改形象进度为${val == "0" ? "显示" : "隐藏"}？`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          let param = {
            id: row.id,
            progressVisible: val,
          };
          updateSurProjectProgressVisible(param).then((response) => {
            this.$modal.msgSuccess("修改成功");
            this.getList();
          });
        })
        .catch(() => {
          // 取消时恢复原始开关状态
          if (val == "0") {
            row.progressVisible = "1";
          } else {
            row.progressVisible = "0";
          }
        });
    },
    //项目排序控制
    setProjectSort(row, val) {
      let param = {
        id: row.id,
        projectSort: val,
      };
      updateSurProjectSort(param).then((response) => {
        this.$modal.msgSuccess("修改成功");
        this.getList();
      });
    },
    handleProjectSpecial(row) {
      this.formData.projectId = row.id;
      this.formData.projectName = row.projectName;
      this.projectSpecialDrawerVisible = true;
    },
  },
};
</script>
<style lang="scss">
.prj-suprj-edit-dialog {
  .el-dialog__body {
    padding-bottom: 0px;

    .fi-longitude {
      .el-form-item__content {
        display: flex;
      }
    }
  }
}
</style>
