<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px"
             @submit.native.prevent>
      <el-form-item label="项目名称" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入项目名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="属地辖区" prop="territoriality">
        <el-select v-model="queryParams.territoriality" placeholder="请选择属地辖区" clearable size="small">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="所属开发区" prop="park">
        <el-select v-model="queryParams.park" placeholder="请选择所属开发区">
          <el-option
            v-for="item in deptOptionsPark"
            :key="item.deptId"
            :label="item.deptName"
            :value="item.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="['forest:keyProjects: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="['forest:keyProjects: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="['forest:keyProjects: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="['forest:keyProjects:export']"
        >导出
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="uploadInfo"
          v-hasPermi="['forest:keyProjects:edit']"
        >上传
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="projectsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="70" align="center"/>
      <el-table-column label="属地辖区" align="center" prop="territoriality"/>
      <el-table-column label="所属开发区" align="center" prop="parkLabel" :show-overflow-tooltip="true"/>
      <!--      <el-table-column label="开发区中心点经度" align="center" prop="parkLongitude"/>-->
      <!--      <el-table-column label="开发区中心点纬度" align="center" prop="parkLatitude"/>-->
      <el-table-column label="项目名称" align="center" prop="projectName" width="150" :show-overflow-tooltip="true"/>
      <!--      <el-table-column label="项目环境" align="center" prop="environment">-->
      <!--        <template slot-scope="scope">-->
      <!--          <dict-tag :options="dict.type.centerdata_environment" :value="scope.row.environment"/>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column label="法人单位" align="center" prop="legalUnit"/>-->
      <!--      <el-table-column label="工程目标" align="center" prop="projectTarget"/>-->
      <!--      <el-table-column label="工程属地" align="center" prop="projectLevel">-->
      <!--        <template slot-scope="scope">-->
      <!--          <dict-tag :options="dict.type.centerdata_project_level" :value="scope.row.projectLevel"/>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column label="建设单位" align="center" prop="constructionUnit"/>-->
      <el-table-column label="负责人" align="center" prop="principal"/>
      <el-table-column label="联系电话" align="center" prop="phone"/>
      <el-table-column label="开复工时间" align="center" prop="startTime"/>
      <el-table-column label="计划竣工时间" align="center" prop="endTime"/>
      <!--      <el-table-column label="联系电话" align="center" prop="phone"/>-->
      <!--      <el-table-column label="建设地点" align="center" prop="constructionSite"/>-->
      <!--      <el-table-column label="在建性质" align="center" prop="nature">-->
      <!--        <template slot-scope="scope">-->
      <!--          <dict-tag :options="dict.type.centerdata_zj_nature" :value="scope.row.nature"/>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <el-table-column label="总投资（万元）" align="center" prop="totalInvest" width="120"/>
      <el-table-column label="年度计划投资（万元）" align="center" prop="yearInvest" width="100"/>
      <!--      <el-table-column label="产业类别" align="center" prop="industryType">-->
      <!--        <template slot-scope="scope">-->
      <!--          <dict-tag :options="dict.type.centerdata_industry_type" :value="scope.row.industryType"/>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column label="项目秘书" align="center" prop="secretary"/>-->
      <!--      <el-table-column label="项目秘书职务" align="center" prop="secretaryDuties"/>-->
      <!--      <el-table-column label="项目秘书手机" align="center" prop="secretaryPhone"/>-->
      <!--      <el-table-column label="建筑面积" align="center" prop="constructionArea"/>
            <el-table-column label="所属分类" align="center" prop="cameraSystem">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.camera_system" :value="scope.row.cameraSystem"/>
              </template>
            </el-table-column>-->
      <el-table-column label="所属部门" align="center" prop="deptName"/>
      <el-table-column label="创建人" align="center" prop="createName" :show-overflow-tooltip="true"/>
      <el-table-column label="创建时间" align="center" prop="createTime" :show-overflow-tooltip="true"/>
      <el-table-column label="修改人" align="center" prop="updateName" :show-overflow-tooltip="true"/>
      <el-table-column label="修改时间" align="center" prop="updateTime" :show-overflow-tooltip="true"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-info"
            @click="getScheduleHistory(scope.row)"
            v-hasPermi="['forest:keyProjects:edit']"
          >详情
          </el-button>
          <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)"
                       v-hasPermi="['system:role:edit']">
            <span class="el-dropdown-link">
              <i class="el-icon-d-arrow-right el-icon--right"></i>更多
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="edit" icon="el-icon-edit"
                                v-hasPermi="['forest:keyProjects:edit']">修改
              </el-dropdown-item>
              <el-dropdown-item command="remove" icon="el-icon-delete"
                                v-hasPermi="['forest:keyProjects:remove']">删除
              </el-dropdown-item>
              <!--              <el-dropdown-item command="details" icon="el-icon-info"-->
              <!--                                v-hasPermi="['forest:keyProjects:edit']">详情-->
              <!--              </el-dropdown-item>-->
              <!--              <el-button-->
              <!--                size="mini"-->
              <!--                type="text"-->
              <!--                icon="el-icon-edit"-->
              <!--                @click="handleUpdate(scope.row)"-->
              <!--                v-hasPermi="['forest:keyProjects:edit']"-->
              <!--              >修改-->
              <!--              </el-button>-->
              <!--              <el-button-->
              <!--                size="mini"-->
              <!--                type="text"-->
              <!--                icon="el-icon-delete"-->
              <!--                @click="handleDelete(scope.row)"-->
              <!--                v-hasPermi="['forest:keyProjects:remove']"-->
              <!--              >删除-->
              <!--              </el-button>-->
            </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" :visible.sync="open" width="1000px" class="form-style">
      <el-form ref="form" :model="form" :rules="rules" label-width="160px">
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="项目名称" prop="projectName">
              <el-input v-model="form.projectName" placeholder="请输入项目名称" maxlength="50"/>
            </el-form-item>
            <el-form-item label="经度" prop="longitude" @dblclick.native="showMap">
              <el-input v-model="form.longitude" placeholder="鼠标双击选择经度" maxlength="32"/>
            </el-form-item>
            <el-form-item label="属地辖区" prop="territoriality">
              <el-select v-model="form.territoriality" placeholder="请输入属地辖区" maxlength="32">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <!--<el-form-item label="工程属地" prop="projectLevel">
              <el-select v-model="form.projectLevel" placeholder="请选择工程属地">
                <el-option
                  v-for="dict in dict.type.centerdata_project_level"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="建设单位" prop="constructionUnit">
              <el-input v-model="form.constructionUnit" placeholder="请输入建设单位" maxlength="50"/>
            </el-form-item>-->
            <el-form-item label="负责人" prop="principal">
              <el-input v-model="form.principal" placeholder="请输入负责人" maxlength="20"/>
            </el-form-item>
            <el-form-item label="开发区中心点经度" prop="parkLongitude" @dblclick.native="showMaptwo">
              <el-input v-model="form.parkLongitude" placeholder="鼠标双击选择经度" maxlength="32"/>
            </el-form-item>
            <el-form-item label="开复工时间" prop="startTime">
              <el-date-picker clearable
                              v-model="form.startTime"
                              type="month"
                              value-format="yyyy-MM"
                              placeholder="请选择开复工时间">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="建设地点" prop="constructionSite">
              <el-input v-model="form.constructionSite" placeholder="请输入建设地点" maxlength="255"/>
            </el-form-item>
            <el-form-item label="总投资（万元）" prop="totalInvest">
              <el-input v-model="form.totalInvest" placeholder="请输入总投资" maxlength="32"/>
            </el-form-item>
            <el-form-item label="法人单位" prop="legalUnit">
              <el-input v-model="form.legalUnit" placeholder="请输入法人单位" maxlength="32"/>
            </el-form-item>
            <el-form-item label="项目秘书职务" prop="secretaryDuties">
              <el-input v-model="form.secretaryDuties" placeholder="请输入项目秘书职务" maxlength="32"/>
            </el-form-item>
            <el-form-item label="所属部门" prop="deptId">
              <treeselect v-model="form.deptId" :options="deptOptions" multiple:false :show-count="true"
                          placeholder="请选择部门" @select="hx" :noResultsText="'空'" :noOptionsText="'空'"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目环境" prop="environment">

              <el-select v-model="form.environment" placeholder="请选择项目环境">
                <el-option
                  v-for="dict in dict.type.centerdata_environment"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="纬度" prop="latitude" @dblclick.native="showMap">
              <el-input v-model="form.latitude" placeholder="鼠标双击选择纬度" maxlength="32"/>
            </el-form-item>
            <el-form-item label="所属开发区" prop="park">
              <el-select v-model="form.park" placeholder="请选择所属开发区">
                <el-option
                  v-for="item in deptOptionsPark"
                  :key="item.deptId"
                  :label="item.deptName"
                  :value="item.deptId"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="联系电话" prop="phone">
              <el-input v-model="form.phone" placeholder="请输入联系电话" maxlength="13"/>
            </el-form-item>
            <el-form-item label="开发区中心点纬度" prop="parkLatitude" @dblclick.native="showMaptwo">
              <el-input v-model="form.parkLatitude" placeholder="鼠标双击选择纬度" maxlength="32"/>
            </el-form-item>
            <el-form-item label="计划竣工时间" prop="endTime">
              <el-date-picker clearable
                              v-model="form.endTime"
                              type="month"
                              value-format="yyyy-MM"
                              placeholder="请选择计划竣工时间">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="在建性质" prop="nature">
              <el-select v-model="form.nature" placeholder="请选择在建性质">
                <el-option
                  v-for="dict in dict.type.centerdata_zj_nature"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="年度计划投资（万元）" prop="yearInvest">
              <el-input v-model="form.yearInvest" placeholder="请输入年度计划投资" maxlength="32"/>
            </el-form-item>
            <el-form-item label="项目秘书" prop="secretary">
              <el-input v-model="form.secretary" placeholder="请输入项目秘书" maxlength="32"/>
            </el-form-item>
            <el-form-item label="项目秘书手机" prop="secretaryPhone">
              <el-input v-model="form.secretaryPhone" placeholder="请输入项目秘书手机" maxlength="13"/>
            </el-form-item>
            <el-form-item label="产业类别" prop="industryType">
              <el-select v-model="form.industryType" placeholder="请选择产业类别">
                <el-option
                  v-for="dict in dict.type.centerdata_industry_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <!--<el-form-item label="工程目标" prop="projectTarget">
              <el-input v-model="form.projectTarget" placeholder="请输入工程目标" maxlength="255"/>
            </el-form-item>
            <el-form-item label="建筑面积" prop="constructionArea">
              <el-input v-model="form.constructionArea" placeholder="请输入建筑面积" maxlength="50"/>
            </el-form-item>
            <el-form-item label="所属分类" prop="cameraSystem">
              <el-select v-model="form.cameraSystem" placeholder="请选择所属分类">
                <el-option
                  v-for="dict in dict.type.camera_system"
                  :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="deviceList">
              <el-select v-model="form.deviceList" filterable placeholder="请选择设备" multiple>
                <el-option
                  v-for="dict in cameraList"
                  :key="dict.id"
                  :label="dict.cameraName"
                  :value="dict.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="建设内容" prop="introduction">
              <el-input v-model="form.introduction" type="textarea" placeholder="请输入建设内容" maxlength="500"
                        :autosize="{ minRows: 5, maxRows: 5}"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="封面" prop="photoId">
              <ImageUpload ref="ImageUpload" :limit="1" :fileType="['png', 'jpg', 'jpeg']" :value="form.photoId"
                           @input="getUrl"></ImageUpload>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!--  进度提交  -->
    <el-dialog :title="title" :visible.sync="scheduleUpload" width="800px" class="form-style"><!--:show-close="false"-->
      <el-button style="float: right;z-index: 999; position: relative" type="primary" @click="submitFormToPicture">上
        传
      </el-button>
      <el-form ref="formUpload" :model="form" :rules="rules" label-width="80px">
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="时间" prop="scheduleTime">
              <el-date-picker clearable size="small"
                              :disabled="!scheduleUpload"
                              v-model="form.scheduleTime"
                              type="date"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              placeholder="选择时间">
              </el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item label="备注">
              <el-input v-model="form.scheduleRemark" type="textarea" placeholder="请输入内容" maxlength="500"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="附件" prop="schedulePictures">
          <ImageUpload ref="ImageUpload" :limit="10" :fileType="['jpg', 'png','jpeg']" :value="form.schedulePictures"
                       @input="getUrlToSchedule"></ImageUpload>
        </el-form-item>
      </el-form>
    </el-dialog>

    <el-dialog :title="title" :visible.sync="scheduleHistory" width="900px" class="form-style">
      <!-- 修改内容回显开始 -->
      <!--<el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <ul class="xg_cont">
            <li>
              <el-form-item label="年度计划投资（万元）" prop="yearInvest">
                <el-input v-model="form.yearInvest" placeholder="请输入年度计划投资" maxlength="32" disabled/>
              </el-form-item>
            </li>
            <li>
             &lt;!&ndash; <h4 class="sjxtitle">项目环境</h4>
              <span class="sjx_cont">
                <dict-tag :options="dict.type.centerdata_environment" :value="form.environment"/>
              </span>&ndash;&gt;

              <el-form-item label="项目环境" prop="environment">
                <el-select v-model="form.environment" placeholder="请选择项目环境" disabled>
                  <el-option
                    v-for="dict in dict.type.centerdata_environment"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </li>
            <li>
              <h4 class="sjxtitle">经度</h4>
              <span class="sjx_cont">{{form.longitude}}</span>
            </li>
            <li>
              <h4 class="sjxtitle">纬度</h4>
              <span class="sjx_cont">{{form.latitude}}</span>
            </li>
            <li>
              <h4 class="sjxtitle">属地辖区</h4>
              <span class="sjx_cont">{{form.territoriality}}</span>
            </li>
            <li>
              <h4 class="sjxtitle">所属开发区</h4>
              <span class="sjx_cont">{{form.parkName}}</span>
            </li>
          <li>
            <h4 class="sjxtitle">负责人</h4>
            <span class="sjx_cont">{{form.principal}}</span>
          </li>
          <li>
            <h4 class="sjxtitle">联系电话</h4>
            <span class="sjx_cont">{{form.phone}}</span>
          </li>
            <li>
              <h4 class="sjxtitle">开发区中心点经度</h4>
              <span class="sjx_cont">{{form.parkLongitude}}</span>
            </li>
            <li>
              <h4 class="sjxtitle">开发区中心点纬度</h4>
              <span class="sjx_cont">{{form.parkLatitude}}</span>
            </li>
            <li>
              <h4 class="sjxtitle">开复工时间</h4>
              <span class="sjx_cont">{{form.startTime}}</span>
            </li>
            <li>
              <h4 class="sjxtitle">计划竣工时间</h4>
              <span class="sjx_cont">{{form.endTime}}</span>
            </li>
            <li>
              <h4 class="sjxtitle">建设地点</h4>
              <span class="sjx_cont">{{form.constructionSite}}</span>
            </li>
            <li>
              <h4 class="sjxtitle">在建性质</h4>
              <span class="sjx_cont">
                <dict-tag :options="dict.type.centerdata_zj_nature" :value="form.nature"/>
              </span>
            </li>
            <li>
              <h4 class="sjxtitle">总投资（万元）</h4>
              <span class="sjx_cont">{{form.totalInvest}}</span>
            </li>
            <li>
              <h4 class="sjxtitle">年度计划投资（万元）</h4>
              <span class="sjx_cont">{{form.yearInvest}}</span>
            </li>
            <li>
              <h4 class="sjxtitle">法人单位</h4>
              <span class="sjx_cont">{{form.legalUnit}}</span>
            </li>
            <li>
              <h4 class="sjxtitle">项目秘书</h4>
              <span class="sjx_cont">{{form.secretary}}</span>
            </li>
            <li>
              <h4 class="sjxtitle">项目秘书职务</h4>
              <span class="sjx_cont">{{form.secretaryDuties}}</span>
            </li>
            <li>
              <h4 class="sjxtitle">项目秘书手机</h4>
              <span class="sjx_cont">{{form.secretaryPhone}}</span>
            </li>
            <li>
              <h4 class="sjxtitle">所属部门</h4>
              <span class="sjx_cont">{{form.deptName}}</span>
            </li>
            <li>
              <h4 class="sjxtitle">产业类别</h4>
              <span class="sjx_cont">
                <dict-tag :options="dict.type.centerdata_industry_type" :value="form.industryType"/>
              </span>
            </li>
            <li class="jiansheCont">
              <h4 class="sjxtitle">绑定设备</h4>
              <span class="sjx_cont" >
                <span v-for="(list,index) in form.deviceList">
                  <span v-for="dict in cameraList" v-if="list == dict.id">
                    {{ dict.cameraName }}<span v-if="index!=form.deviceList.length-1" >,</span>
                  </span>
                </span>
              </span>
            </li>
            <li class="jiansheCont">
              <h4 class="sjxtitle">建设内容</h4>
              <span class="sjx_cont js_cont">{{form.introduction}}</span>
            </li>
            <li class="jiansheCont">
              <h4 class="sjxtitle">封面</h4>
              <el-image v-if="form.photoId!=null"
                :src="form.photoId" style="width:150px;height:150px;"
                :preview-src-list="[form.photoId]">
              </el-image>
            </li>

        </ul>
      </el-form>-->

      <el-form ref="form" :model="form" :rules="rules" label-width="160px">
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="项目名称" prop="projectName">
              <el-input v-model="form.projectName" maxlength="50" readonly/>
            </el-form-item>
            <el-form-item label="经度" prop="longitude">
              <el-input v-model="form.longitude" maxlength="32" readonly/>
            </el-form-item>
            <el-form-item label="属地辖区" prop="territoriality">
              <el-input v-model="form.territoriality" maxlength="32" readonly/>
            </el-form-item>
            <el-form-item label="负责人" prop="principal">
              <el-input v-model="form.principal" maxlength="20" readonly/>
            </el-form-item>
            <el-form-item label="开发区中心点经度" prop="parkLongitude" @dblclick.native="showMaptwo">
              <el-input v-model="form.parkLongitude" maxlength="32" readonly/>
            </el-form-item>
            <el-form-item label="开复工时间" prop="startTime">
              <el-input v-model="form.startTime" readonly/>
            </el-form-item>
            <el-form-item label="建设地点" prop="constructionSite">
              <el-input v-model="form.constructionSite" maxlength="255" readonly/>
            </el-form-item>
            <el-form-item label="总投资（万元）" prop="totalInvest">
              <el-input v-model="form.totalInvest" maxlength="32" readonly/>
            </el-form-item>
            <el-form-item label="法人单位" prop="legalUnit">
              <el-input v-model="form.legalUnit" maxlength="32" readonly/>
            </el-form-item>
            <el-form-item label="项目秘书职务" prop="secretaryDuties">
              <el-input v-model="form.secretaryDuties" maxlength="32" readonly/>
            </el-form-item>
            <el-form-item label="所属部门" prop="deptId">
              <el-input v-model="form.deptName" readonly/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目环境" prop="environment">
              <el-select v-model="form.environment" ref="selectRef0" @blur="modelClick()" @click.native="modelClick()"
                         placeholder="">
                <el-option
                  v-for="dict in dict.type.centerdata_environment"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="纬度" prop="latitude" @dblclick.native="showMap">
              <el-input v-model="form.latitude" maxlength="32" readonly/>
            </el-form-item>
            <el-form-item label="所属开发区" prop="park">
              <el-select v-model="form.park" placeholder="" ref="selectRef1" @blur="modelClick()"
                         @click.native="modelClick()">
                <el-option
                  v-for="item in deptOptionsPark"
                  :key="item.deptId"
                  :label="item.deptName"
                  :value="item.deptId"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="联系电话" prop="phone">
              <el-input v-model="form.phone" maxlength="13" readonly/>
            </el-form-item>
            <el-form-item label="开发区中心点纬度" prop="parkLatitude" @dblclick.native="showMaptwo">
              <el-input v-model="form.parkLatitude" maxlength="32" readonly/>
            </el-form-item>
            <el-form-item label="计划竣工时间" prop="endTime">
              <el-input v-model="form.endTime" readonly/>
            </el-form-item>
            <el-form-item label="在建性质" prop="nature">
              <el-select v-model="form.nature" placeholder="" ref="selectRef2" @blur="modelClick()"
                         @click.native="modelClick()">
                <el-option
                  v-for="dict in dict.type.centerdata_zj_nature"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="年度计划投资（万元）" prop="yearInvest">
              <el-input v-model="form.yearInvest" maxlength="32" readonly/>
            </el-form-item>
            <el-form-item label="项目秘书" prop="secretary">
              <el-input v-model="form.secretary" maxlength="32" readonly/>
            </el-form-item>
            <el-form-item label="项目秘书手机" prop="secretaryPhone">
              <el-input v-model="form.secretaryPhone" maxlength="13" readonly/>
            </el-form-item>
            <el-form-item label="产业类别" prop="industryType">
             <el-select v-model="form.industryType" placeholder="" ref="selectRef3" @blur="modelClick()"
                         @click.native="modelClick()">
                <el-option
                  v-for="dict in dict.type.centerdata_industry_type"
                  :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="deviceList">
              <el-select v-model="form.deviceList" multiple placeholder="" ref="selectRef4" @blur="modelClick()"
                         @click.native="modelClick()" style="pointer-events: none;">
                <el-option
                  v-for="dict in cameraList"
                  :key="dict.id"
                  :label="dict.cameraName"
                  :value="dict.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="建设内容" prop="introduction">
              <el-input v-model="form.introduction" type="textarea" maxlength="500"
                        :autosize="{ minRows: 5, maxRows: 5}" readonly/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="封面" prop="photoId">
              <ImageUpload v-if="form.photoId!=null" ref="ImageUpload" :limit="1" :fileType="['png', 'jpg', 'jpeg']"
                           :value="form.photoId"
                           @input="getUrl"></ImageUpload>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <b>{{ this.keyProjectsName }}</b><br><br>
      <div class="block" style="overflow: auto;">
        <el-timeline :reverse="!scheduleHistory">
          <el-timeline-item
            v-for="(activity, index) in activities"
            :key="index"
            :timestamp="activity.scheduleTime" placement="top">
            <div>
              <span>{{ activity.deptName }} -- {{ activity.createName }}</span>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="scheduleDeleteByOne(activity.scheduleId)"
                v-hasPermi="['forest:keyProjects:remove']"
              >删除
              </el-button>
              <br>
              <span v-if="activity.scheduleRemark !== '' && activity.scheduleRemark != null">      (备注:{{
                  activity.scheduleRemark
                }})</span>

            </div>
            <div v-if="activity.schedulePictures !== null">
              <template v-for="(imageUrl, imgIndex) in activity.schedulePictures.split(',')">
                <el-image :src="imageUrl" :key="imgIndex" style="width:8rem; height: 8rem; margin:2px"
                          :preview-src-list="[imageUrl]">
                </el-image>
              </template>
            </div>
          </el-timeline-item>
        </el-timeline>
      </div>

    </el-dialog>

    <ISuperMap ref="ISuperMap" v-if="ISuperMapvisible" @send="send"/>
    <ISuperMap ref="ISuperMaptwo" v-if="ISuperMapvisibletwo" @send="sendtwo"/>
  </div>
</template>

<script>
import {
  addProjects,
  delProjects,
  getProjects, getProjectsSchedule,
  listProjects,
  updateProjects, addProjectsScheduleInfo, getHistoryByTime, deleteSchedule, selectPark
} from "@/api/data/generalbusiness/keyProjects/projects";
import {selectCenterMonitorlList} from "@/api/data/digitalforest/animal/animal";
import deptselector from '@/views/components/deptselector.vue'
import supermap from '@/views/components/supermap.vue'
import {checkLat, checkLon, checkPositiveDecimal4, validPhoneMobile} from "@/api/rules/rules";
import {treeselect} from "@/api/system/dept";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import ISuperMap from "@/views/data/common/ISuperMap";
import TreeDept from "../../../../components/treeDept";


export default {
  name: "Projects",
  dicts: ['project_type', "camera_system", 'centerdata_project_level', 'centerdata_zj_nature', 'centerdata_industry_type', 'centerdata_environment', 'centerdata_park'],
  components: {TreeDept, deptselector, supermap, Treeselect, ISuperMap},
  data() {
    return {
      sign: 1,
      ISuperMapvisible: false,
      ISuperMapvisibletwo: false,
      deptOptions: undefined,
      deptOptionsPark: [],
      disabled: true,
      // 遮罩层
      loading: true,
      loading1: false,
      // 选中数组
      ids: [],
      titleLongitude: '经纬度',
      showLongitude: false,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 重点工程表格数据
      projectsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      scheduleUpload: false,
      scheduleHistory: false,
      keyProjectsId: null,
      keyProjectsName: null,
      scheduleTime: null,
      activities: null,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectName: null,
        projectTarget: null,
        projectType: null,
        projectLevel: null,
        constructionUnit: null,
        principal: null,
        phone: null,
        constructionSite: null,
        constructionArea: null,
        longitude: null,
        photoId: null,
        schedulePictures: null,
        latitude: null,
        cameraSystem: null,
        deptId: null,
        introduction: null,
        parkLongitude: null,
        parkLatitude: null,
        parkLabel:null
      },
      historyQueryParams: {
        startTIme: null,
        endTime: null,
        keyProjectsId: null,
      },
      options: [{
        value: '市本级',
        label: '市本级'
      }, {
        value: '铁东区',
        label: '铁东区'
      }, {
        value: '铁西区',
        label: '铁西区'
      }, {
        value: '梨树县',
        label: '梨树县'
      }, {
        value: '双辽市',
        label: '双辽市'
      }, {
        value: '伊通县',
        label: '伊通县'
      }],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        deptId: [
          {required: true, message: "所属部门不能为空", trigger: "blur"}
        ],
        projectName: [
          {required: true, message: "项目名称不能为空", trigger: "blur"}
        ],
        territoriality: [
          {required: true, message: "属地辖区不能为空", trigger: ["blur", "change"]}
        ],
        principal: [
          {required: true, message: "负责人不能为空", trigger: "blur"}
        ],
        constructionSite: [
          {required: true, message: "建设地点不能为空", trigger: "blur"}
        ],
        nature: [
          {required: true, message: "在建性质不能为空", trigger: "blur"}
        ],
        /*    projectTarget: [
              {required: true, message: "工程目标不能为空", trigger: "blur"}
            ],
            projectLevel: [
              {required: true, message: "工程属地不能为空", trigger: "change"}
            ],*/
        longitude: [
          {required: true, message: "经度不能为空", trigger: ["blur", "change"]},
          {validator: checkLon, trigger: 'blur'}
        ],
        latitude: [
          {required: true, message: "纬度不能为空", trigger: ["blur", "change"]},
          {validator: checkLat, trigger: 'blur'}
        ],
        parkLongitude: [
          {validator: checkLon, trigger: ["blur", "change"]}
        ],
        parkLatitude: [
          {validator: checkLat, trigger: ["blur", "change"]}
        ],
        introduction: [
          {required: true, message: "建设内容不能为空", trigger: "blur"}
        ],
        cameraSystem: [
          {required: true, message: "所属分类不能为空", trigger: "change"}
        ],
        phone: [
          {required: true, message: "联系电话不能为空", trigger: "blur"},
          {validator: validPhoneMobile, trigger: 'blur'}
        ],
        totalInvest: [
          {validator: checkPositiveDecimal4, trigger: 'blur'}
        ],
        yearInvest: [
          {validator: checkPositiveDecimal4, trigger: 'blur'}
        ],
        secretaryPhone: [
          {validator: validPhoneMobile, trigger: 'blur'}
        ],
        scheduleTime: [
          {required: true, message: "时间不能为空", trigger: "blur"}
        ],
        schedulePictures: [
          {required: true, message: "至少上传一张图片", trigger: "blur"}
        ]
      },
      cameraList: [],
      cameraNameList: [],
    };
  },
  created() {
    this.getTreeselect();
    selectCenterMonitorlList(this.queryParams).then(response => {
      this.cameraList = response.data;
    });
  },
  methods: {
    dictFormat(row, column) {
      return this.selectDictLabel(this.dict.type.centerdata_industry_type, row.industryType);
    },
    modelClick() {
      this.$refs.selectRef0.blur();
      this.$refs.selectRef1.blur();
      this.$refs.selectRef2.blur();
      this.$refs.selectRef3.blur();
      this.$refs.selectRef4.blur();
    },
    handleClick() {
      alert('button click');
    },
    // 更多操作触发
    handleCommand(command, row) {
      switch (command) {
        case 'edit':
          this.handleUpdate(row)
          break
        case 'remove':
          this.handleDelete(row)
          break
        // case 'details':
        //   this.getScheduleHistory(row)
        //   break
        default:
          break
      }

    },
    /** 查询部门下拉树结构 */
    getTreeselect() {
      treeselect().then(response => {
        this.deptOptions = response.data
      })
      selectPark({deptType:"sys_dept_type_27"}).then(response => {
        let arr = response.data.map(item => {
          item.deptId = item.deptId + ""
          return item
        })
        this.deptOptionsPark = arr

        this.getList();
      })
    },
    hx(node) {
      this.form.deptId = node.id
      this.form.deptName = node.label
    },
    /** 查询重点工程列表 */
    async getList() {
      this.loading = true;
      await listProjects(this.queryParams).then(response => {
        this.projectsList = response.rows;
    /*    let projectsList1 = []
        this.projectsList.forEach(item1 => {
          this.deptOptionsPark.forEach(item => {
            if (item1.park == item.deptId) {
              item1.park = item.deptName
            }
          })
          projectsList1.push(item1)
        })
        this.projectsList = projectsList1;*/
        this.total = response.total;
        this.loading = false;
      });
    },
    getUrl(url) {
      this.form.photoId = url
    },
    getUrlToSchedule(url) {
      this.form.schedulePictures = url
    },
    setDataDeptId(e) {
      this.form.deptId = e.deptId
      this.form.deptName = e.deptName
    },
    showLatLng: function (lat, lng) {
      this.form.latitude = lat
      this.form.longitude = lng
    },
    showMap() {
      this.ISuperMapvisible = true;
      this.$nextTick(() => {
        this.$refs.ISuperMap.init(this.sign, {
          id: this.form.id,
          longitude: this.form.longitude,
          latitude: this.form.latitude,
          xiantude: this.form.longitude//this.form.longitude换成每个页面对应线或者面对应的字段
        })
      })
    },
    showMaptwo() {
      this.ISuperMapvisibletwo = true;
      this.$nextTick(() => {
        this.$refs.ISuperMaptwo.init(this.sign, {
          id: this.form.id,
          parkLongitude: this.form.longitude,
          parkLatitude: this.form.latitude,
          xiantude: this.form.longitude//this.form.longitude换成每个页面对应线或者面对应的字段
        })
      })
    },
    send(val) {
      if (val === true) {
        this.ISuperMapvisible = false;
        return;
      }
      if (this.sign === 1) {
        this.form.longitude = val.longitude;
        this.form.latitude = val.latitude;
      }
      if (this.sign === 2 || this.sign === 3) this.form.longitude = val.xiantude;//this.form.longitude 换成对应的线或区域的字段
      this.ISuperMapvisible = false
    },
    sendtwo(val) {
      if (val === true) {
        this.ISuperMapvisibletwo = false;
        return;
      }
      if (this.sign === 1) {
        this.form.parkLongitude = val.longitude;
        this.form.parkLatitude = val.latitude;
      }
      if (this.sign === 2 || this.sign === 3) this.form.parkLongitude = val.xiantude;//this.form.parkLongitude 换成对应的线或区域的字段
      this.ISuperMapvisibletwo = false
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    cancelToPicture() {
      this.schedule = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        projectName: null,
        projectTarget: null,
        projectType: null,
        projectLevel: null,
        constructionUnit: null,
        principal: null,
        phone: null,
        photoId: null,
        constructionSite: null,
        constructionArea: null,
        longitude: null,
        latitude: null,
        cameraSystem: null,
        deptId: null,
        introduction: null,
        schedulePictures: null,
        scheduleTime: null,
        keyProjectsId: null,
        activities: null,
        scheduleRemark: null,
        territoriality: null,
        parkLongitude: null,
        totalInvest: null,
        legalUnit: null,
        secretaryDuties: null,
        industryType: null,
        park: null,
        nature: null,
        yearInvest: null,
        secretary: null,
        parkLatitude: null,
        secretaryPhone: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 历史进度记录搜索按钮操作 */
    handleHistoryQuery() {
      this.historyQueryParams.keyProjectsId = this.form.id;
      this.loading1 = true;
      getHistoryByTime(this.historyQueryParams).then(response => {
        this.activities = response.data;
        this.loading1 = false;
      });
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    resetHistoryQuery() {
      this.resetForm("historyForm");
      this.handleHistoryQuery();
    },
    // 多选框选中数据
    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
      getProjects(id).then(response => {
        if (response.data.park !== null){
          response.data.park = response.data.park + ""
        }
        this.form = response.data;
        this.open = true;
        this.title = "修改重点工程";
      });
    },
    /** 上传按钮操作 */
    uploadInfo(row) {
      this.reset();
      const id = row.id || this.ids
      this.form.keyProjectsId = id[0];
      this.title = "进度上传";
      this.scheduleUpload = true;
    },
    /** 历史进度查看 */
    getScheduleHistory(row) {
      this.keyProjectsId = row.id || this.ids
      this.keyProjectsName = row.projectName;
      getProjectsSchedule(this.keyProjectsId).then(res =>{
        this.activities = res.data;
      })
      getProjects(this.keyProjectsId).then(response => {
        let obj = {};
        this.deptOptionsPark.forEach(item => {
          if (item.deptId == response.data.park) {
            obj["parkName"] = item.deptName
          }
        })

        this.form = {...response.data, ...obj};
        this.scheduleHistory = true;
        this.title = "详情";
      })
      this.reset();
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateProjects(this.form).then(() => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addProjects(this.form).then(() => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },

    submitFormToPicture() {
      this.$refs["formUpload"].validate(valid => {
        if (valid) {
          // this.form.keyProjectsId = this.keyProjectsId;
          addProjectsScheduleInfo(this.form).then(() => {
            this.$modal.msgSuccess("新增成功");
            this.scheduleUpload = false;
            this.getList();
          });
          this.reset();
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否删除选中的数据？').then(function () {
        return delProjects(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('sooka-sponest-center-data/projects/export', {
        ...this.queryParams
      }, `重点工程_${new Date().getTime()}.xlsx`)
    },

    /** 删除单条进度信息 */
    scheduleDeleteByOne(scheduleId) {
      this.$modal.confirm('是否删除选中的数据？').then(function () {
        return deleteSchedule(scheduleId);
      }).then(() => {
        this.handleHistoryQuery();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    }
  }
};
</script>
<style>
.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  /* background-color: #f5f7fa; border-bottom: 1px solid #ebeef5; */
}

.dialog-header span {
  font-size: 18px;
  font-weight: bold;
}

h4, ul, li {
  margin: 0;
  padding: 0;
}

.xg_cont {
  padding: 0;
  color: #606266;
  font-size: 14px;
  word-break: break-all;
  overflow: hidden;
}

.xg_cont li {
  list-style: none;
  width: 50%;
  float: left;
  margin: 0 0 10px 0;
}

.xg_cont li.jiansheCont {
  width: 100%;
}

.sjxtitle {
  width: 160px;
  line-height: 36px !important;
  font-weight: 700;
  float: left;
  text-align: right;
  white-space: nowrap;
  font-size: 14px;
  vertical-align: top;
}

.sjx_cont {
  color: #909295;
  line-height: 36px;
  width: 63%;
  display: block;
  margin: 0 0 0 170px;
  vertical-align: top;
}

.js_cont {
  width: 81%;
}
</style>
