<template>
  <div class="app-container">
    <el-form
      v-if="type === '1'"
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="70px"
    >
      <el-form-item label="会议主题" prop="meetingTheme">
        <el-input
          v-model.trim="queryParams.meetingTheme"
          placeholder="请输入会议主题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="会议编号" prop="meetingCode">
        <el-input
          v-model.trim="queryParams.meetingCode"
          placeholder="请输入会议编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="会议类别" prop="meetingType">
        <el-select
          v-model="queryParams.meetingType"
          placeholder="全部"
          clearable
        >
          <el-option
            v-for="dict in dict.type.meeting_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="会议日期" prop="startTime">
        <el-date-picker
          v-model="queryParams.timeVal"
          type="daterange"
          range-separator="至"
          start-placeholder="会议开始日期"
          end-placeholder="会议结束日期"
          value-format="yyyy-MM-dd"
        >
        </el-date-picker>
      </el-form-item>
      <!-- <el-form-item label="开始时间" prop="startTime">
        <el-date-picker
          style="width: 205px"
          clearable
          v-model="queryParams.startTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择会议开始时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="endTime">
        <el-date-picker
          style="width: 205px"
          clearable
          v-model="queryParams.endTime"
          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" v-if="type === '1'">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['invest:meeting:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleSelectData(1)"
          v-hasPermi="['invest:meeting:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="single"
          @click="handleSelectData(2)"
          v-hasPermi="['invest:meeting: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="['invest:meeting:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      ref="dataTable"
      @row-click="clickRow"
      class="tableWrapper"
      v-if="type !== '3'"
      v-loading="loading"
      border
      :data="meetingList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column
        v-if="type === '1'"
        type="selection"
        width="55"
        align="center"
      />

      <el-table-column
        type="index"
        label="序号"
        width="50"
        align="center"
      ></el-table-column>
      <!-- <el-table-column label="主键ID" align="center" prop="id" /> -->
      <el-table-column
        label="会议编号"
        width="120"
        align="center"
        prop="meetingCode"
      >
        <template slot-scope="scope">
          <div :title="scope.row.meetingCode">
            {{ scope.row.meetingCode }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="会议主题"
        width="200"
        align="center"
        prop="meetingTheme"
        title="meetingTheme"
      >
        <template slot-scope="scope">
          <div
            :title="scope.row.meetingTheme"
            class="public-text-blue public-cursor"
            @click.stop="handleDetail(scope.row)"
          >
            {{ scope.row.meetingTheme }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="项目名称"
        align="center"
        width="200"
        prop="tProjectPool.projectName"
      >
        <template slot-scope="scope">
          <div :title="scope.row.tProjectPool.projectName">
            {{ scope.row.tProjectPool.projectName }}
          </div>
        </template>
      </el-table-column>

      <el-table-column
        label="会议类别"
        width="120"
        align="center"
        prop="meetingType"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.meeting_type"
            :value="scope.row.meetingType"
          />
          <!-- :title="scope.row.meetingType" -->
        </template>
      </el-table-column>
      <el-table-column
        label="会议发起人"
        width="120"
        align="center"
        prop="promoter"
      >
        <template slot-scope="scope">
          <div :title="scope.row.promoter">
            {{ scope.row.promoter }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="会议参与人"
        width="300"
        align="center"
        prop="participants"
      >
        <template slot-scope="scope">
          <div :title="scope.row.participants">
            {{ scope.row.participants }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="会议开始时间"
        width="160"
        align="center"
        prop="startTime"
      >
        <template slot-scope="scope">
          <span :title="scope.row.startTime">{{
            parseTime(scope.row.startTime, "{y}-{m}-{d} {h}:{i}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="会议结束时间"
        width="160"
        align="center"
        prop="endTime"
      >
        <template slot-scope="scope">
          <span :title="scope.row.startTime">{{
            parseTime(scope.row.endTime, "{y}-{m}-{d} {h}:{i}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="会议地点" width="150" align="center" prop="place">
        <template slot-scope="scope">
          <div :title="scope.row.place">
            {{ scope.row.place }}
          </div>
        </template>
      </el-table-column>

      <el-table-column
        label="创建人"
        width="120"
        align="center"
        prop="createBy"
      >
        <template slot-scope="scope">
          <div :title="scope.row.createBy">
            {{ scope.row.createBy }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="160"
      >
        <template slot-scope="scope">
          <div :title="scope.row.createTime">
            {{ scope.row.createTime }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        v-if="false"
        fixed="right"
        align="center"
        class-name="small-padding fixed-width"
        width="120"
      >
        <template slot-scope="scope">
          <el-button
            v-if="user.nickName === scope.row.createBy"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['invest:meeting:edit']"
            >修改</el-button
          >
          <!-- <el-button
            v-if="user.nickName !== scope.row.createBy"
            class="custom-blue-color"
            size="mini"
            type="text"
            icon="el-icon-search"
            @click="handleDetail(scope.row)"
            >详情</el-button
          > -->
          <el-button
            v-if="user.nickName === scope.row.createBy"
            class="custom-red-color"
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['invest:meeting:remove']"
            >删除</el-button
          >

          <el-dropdown
            v-if="
              (scope.row.meetingType == 'LX' ||
                scope.row.meetingType == 'TJ') &&
              false
            "
            trigger="click"
            @command="handleCommand($event, scope.row)"
          >
            <!-- class="custom-blue-color"  -->
            <span
              class="el-dropdown-link"
              v-preventReClick
              @click="getButtonItem(scope.row)"
            >
              <el-button size="mini" type="text" icon="el-icon-d-arrow-right"
                >更多</el-button
              >
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item
                v-if="!showLookMark && showMarkBtn"
                command="1"
                icon="el-icon-document-remove"
                @click="handleMark(scope.row, '1', false)"
                >去打分</el-dropdown-item
              >
              <el-dropdown-item
                v-if="showLookMark && showMarkBtn"
                icon="el-icon-search"
                command="2"
                @click="handleMark(scope.row, '1', true)"
                >查看打分表</el-dropdown-item
              >
              <el-dropdown-item
                v-if="isInitiator"
                icon="el-icon-search"
                command="3"
                @click="handleLookMark(scope.row, '2', true)"
                >查看打分汇总表</el-dropdown-item
              >
            </el-dropdown-menu>
          </el-dropdown>
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-document-remove"
            @click="handleMark(scope.row, '1',false)"
            >去打分</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-search"
            @click="handleMark(scope.row, '1',true)"
            >查看打分表</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-search"
            @click="handleLookMark(scope.row, '2',true)"
            >查看打分汇总表</el-button
          > -->
        </template>
      </el-table-column>
    </el-table>

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

    <!-- 添加或修改会议记录对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="1000px"
      append-to-body
    >
      <el-form
        class="special-el-form"
        ref="form"
        :model="form"
        :rules="rules"
        label-width="120px"
      >
        <el-form-item
          label="项目名称"
          prop="projectName"
          class="special-el-form-item public-input-height-2"
          :rules="[
            { required: verifyProjectName, trigger: 'blur', message: '请选择' },
          ]"
        >
          <div
            class="el-input__inner inputSimulation yichu1"
            @click="handleProjectItem"
            :class="{ show_disabled: pageType === '1' }"
            :title="form.projectName"
          >
            {{ form.projectName ? form.projectName : "请选择 " }}
          </div>
          <projectItem
            ref="projectItem"
            @getProjectInfo="getProjectInfo"
          ></projectItem>
        </el-form-item>
        <el-form-item
          label="项目阶段"
          prop="projectStage"
          class="special-el-form-item"
        >
          <el-select v-model="form.projectStage" disabled placeholder="">
            <el-option
              v-for="dict in dict.type.project_stage"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="会议主题" prop="meetingTheme">
          <el-input
            maxlength="100"
            v-model="form.meetingTheme"
            placeholder="请输入会议主题"
          />
        </el-form-item>

        <!-- <el-form-item label="会议编号" prop="meetingCode">
          <el-input v-model="form.meetingCode" placeholder="请输入会议编号" />
        </el-form-item> -->
        <el-form-item label="会议类别" prop="meetingType">
          <el-select
            v-if="showAllType"
            v-model="form.meetingType"
            placeholder="请选择会议类别"
            :disabled="
              meetingTypeDisabled || (pageType === '1' && meetingType != null)
            "
          >
            <el-option
              v-for="dict in meetingTypeList"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
          <el-select
            v-else
            v-model="form.meetingType"
            placeholder="请选择会议类别"
            :disabled="
              meetingTypeDisabled || (pageType === '1' && meetingType != null)
            "
          >
            <el-option
              v-for="dict in meetingTypeList1"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="会议开始时间" prop="startTime">
          <el-date-picker
            v-model="form.startTime"
            type="datetime"
            placeholder="请选择会议开始时间"
            format="yyyy-MM-dd HH:mm"
            value-format="yyyy-MM-dd HH:mm"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="会议结束时间" prop="endTime">
          <el-date-picker
            v-model="form.endTime"
            format="yyyy-MM-dd HH:mm"
            value-format="yyyy-MM-dd HH:mm"
            type="datetime"
            placeholder="请选择会议结束时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="会议地点" prop="place">
          <el-input
            maxlength="100"
            v-model="form.place"
            placeholder="请输入会议地点"
          />
        </el-form-item>
        <el-form-item
          label="会议发起人"
          prop="promoter"
          class="public-input-height"
        >
          <div class="el-input__inner" @click="openSelectDept(1)">
            {{ form.promoter ? form.promoter : "请选择会议发起人" }}
          </div>
          <selecDept
            ref="selecDepts"
            @getDeptUserInfo="getDeptUserInfo"
            :deptId="deptId"
          ></selecDept>
        </el-form-item>
        <el-form-item
          label="会议参与人"
          prop="participants"
          class="special-el-form-item public-input-height-2"
        >
          <div
            class="el-input__inner inputSimulation yichu1"
            @click="handleSelectPeople()"
            :title="form.participants"
          >
            {{ form.participants ? form.participants : "请选择会议参与人" }}
          </div>
        </el-form-item>
        <el-form-item label="附件" prop="file" class="special-el-form-item">
          <fileItem
            ref="fileItems"
            :id="form.id"
            @getFileList="getFileList"
          ></fileItem>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" v-preventReClick
          >确 定</el-button
        >
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!--选择人员-->
    <selecUser
      ref="flowUser"
      :checkType="checkType"
      :selectValues="selectValues"
      :selectNameValues="selectNameValues"
      @handleUserSelect="handleUserSelect"
    ></selecUser>
    <!-- 会议记录详情-->
    <el-dialog
      title="会议详情"
      :visible.sync="openDetail"
      width="1000px"
      append-to-body
    >
      <el-form
        class="special-el-form"
        ref="form"
        :model="form"
        label-width="120px"
      >
        <el-form-item
          label="项目名称"
          prop="projectName"
          class="special-el-form-item"
        >
          <el-input
            type="textarea"
            rows="2"
            v-model="form.projectName"
            disabled
          />
        </el-form-item>
        <el-form-item
          label="项目阶段"
          prop="projectStage"
          class="special-el-form-item"
        >
          <el-select v-model="form.projectStage" disabled>
            <el-option
              v-for="dict in dict.type.project_stage"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="会议主题" prop="meetingTheme">
          <el-input maxlength="100" v-model="form.meetingTheme" disabled />
        </el-form-item>
        <el-form-item label="会议类别" prop="meetingType">
          <el-select v-if="showAllType" v-model="form.meetingType" disabled>
            <el-option
              v-for="dict in meetingTypeList"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
          <el-select v-else v-model="form.meetingType" disabled>
            <el-option
              v-for="dict in meetingTypeList1"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="会议开始时间" prop="startTime">
          <el-date-picker
            v-model="form.startTime"
            type="datetime"
            disabled
            format="yyyy-MM-dd HH:mm"
            value-format="yyyy-MM-dd HH:mm"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="会议结束时间" prop="endTime">
          <el-date-picker
            v-model="form.endTime"
            format="yyyy-MM-dd HH:mm"
            value-format="yyyy-MM-dd HH:mm"
            type="datetime"
            disabled
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="会议地点" prop="place">
          <el-input maxlength="100" v-model="form.place" disabled />
        </el-form-item>
        <el-form-item label="会议发起人" prop="promoter">
          <el-input v-model="form.promoter" disabled />
        </el-form-item>
        <el-form-item
          label="会议参与人"
          prop="participants"
          class="special-el-form-item"
        >
          <el-input
            rows="4"
            type="textarea"
            v-model="form.participants"
            disabled
          />
        </el-form-item>
        <el-form-item label="附件" prop="file" class="special-el-form-item">
          <fileItem
            ref="fileItemsDet"
            :id="form.id"
            @getFileList="getFileList"
          ></fileItem>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="openDetail = false">关 闭</el-button>
      </div>
    </el-dialog>
    <!-- 立项申请弹窗 -->
    <el-dialog
      :title="titleLXApply"
      :visible.sync="openLXApply"
      width="1000px"
      append-to-body
    >
      <el-form
        class="special-el-form"
        ref="formLXApply"
        :model="formLXApply"
        :rules="rulesLXApply"
        label-width="120px"
      >
        <el-form-item
          label="项目名称"
          prop="projectName"
          class="special-el-form-item public-input-height-2"
          :rules="[
            { required: true, trigger: 'blur', message: '请选择' },
          ]"
        >
          <div
            class="el-input__inner inputSimulation"
            @click="handleProjectItem"
            :class="{ show_disabled: pageType === '1' }"
            :title="formLXApply.projectName"
          >
            {{ formLXApply.projectName ? formLXApply.projectName : "请选择 " }}
          </div>
          <projectItemLX
            ref="projectItem"
            @getProjectInfo="getProjectInfo"
          ></projectItemLX>
        </el-form-item>

        <el-form-item
          label="项目概况"
          prop="projectOverview"
          class="special-el-form-item"
        >
          <el-input
            rows="4"
            type="textarea"
            maxlength="200"
            v-model="formLXApply.projectOverview"
            placeholder="请输入项目概况"
          />
        </el-form-item>
        <el-form-item
          label="项目亮点"
          prop="projectSparkle"
          class="special-el-form-item"
        >
          <el-input
            rows="4"
            type="textarea"
            maxlength="200"
            v-model="formLXApply.projectSparkle"
            placeholder="请输入项目亮点"
          />
        </el-form-item>
        <el-form-item
          label="立项资料"
          prop="listFile"
          class="special-el-form-item"
        >
          <fileItem
            ref="fileItemLXApply"
            :id="formLXApply.id"
            @getFileList="getFileListLXApply"
          ></fileItem>
        </el-form-item>
<!--        <el-form-item
          label="通知名单"
          prop="participants"
          class="special-el-form-item public-input-height-2"
        >
          <div
            class="el-input__inner inputSimulation yichu1"
            @click="handleSelectPeople()"
            :title="formLXApply.participants"
          >
            {{ formLXApply.participants ? formLXApply.participants : "请选择" }}
          </div>
        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
<!--        <el-button type="primary" @click="submitFormLXApply" v-preventReClick
          >确 定</el-button
        >-->
        <el-button @click="openLXApply = false">取 消</el-button>
        <el-button type="warning" @click="submitFormLXApply(false)" v-preventReClick>暂 存</el-button>
        <el-button type="primary" @click="submitFormLXApply(true)" v-preventReClick>提 交</el-button>

      </div>
    </el-dialog>
    <!-- 投决申请弹窗 -->
    <el-dialog
      :title="titleTJApply"
      :visible.sync="openTJApply"
      width="1000px"
      append-to-body
    >
      <el-form
        class="special-el-form"
        ref="formTJApply"
        :model="formTJApply"
        :rules="rulesTJApply"
        label-width="120px"
      >
        <el-form-item
          label="项目名称"
          prop="projectName"
          class="special-el-form-item public-input-height-2"
          :rules="[
            { required: true, trigger: 'blur', message: '请选择' },
          ]"
        >
          <div
            class="el-input__inner inputSimulation"
            @click="handleProjectItem"
            :class="{ show_disabled: pageType === '1' }"
            :title="formTJApply.projectName"
          >
            {{ formTJApply.projectName ? formTJApply.projectName : "请选择 " }}
          </div>
          <projectItemTJ
            ref="projectItem"
            @getProjectInfo="getProjectInfo"
          ></projectItemTJ>
        </el-form-item>

        <el-form-item
          label="股权/其他合作商务条款"
          prop="provision"
          class="special-el-form-item"
        >
          <el-input
            rows="4"
            type="textarea"
            maxlength="200"
            v-model="formTJApply.provision"
            placeholder="请输入股权/其他合作商务条款"
          />
        </el-form-item>
        <el-form-item
          label="投决资料"
          prop="listFile"
          class="special-el-form-item"
        >
          <fileItem
            ref="fileItemTJApply"
            :id="formTJApply.id"
            @getFileList="getFileListTJApply"
          ></fileItem>
        </el-form-item>
<!--        <el-form-item
          label="通知名单"
          prop="participants"
          class="special-el-form-item public-input-height-2"
        >
          <div
            class="el-input__inner inputSimulation yichu1"
            @click="handleSelectPeople()"
            :title="formTJApply.participants"
          >
            {{ formTJApply.participants ? formTJApply.participants : "请选择" }}
          </div>
        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="openTJApply = false">取 消</el-button>
        <el-button type="warning" @click="submitFormTJApply(false)" v-preventReClick>暂 存</el-button>
        <el-button type="primary" @click="submitFormTJApply(true)" v-preventReClick>提 交</el-button>
      </div>
    </el-dialog>
    <!-- 终止申请弹窗 -->
    <el-dialog
      :title="titleZZApply"
      :visible.sync="openZZApply"
      width="1000px"
      append-to-body
    >
      <el-form
        class="special-el-form"
        ref="formZZApply"
        :model="formZZApply"
        :rules="rulesZZApply"
        label-width="120px"
      >
       <el-form-item
          label="项目名称"
          prop="projectName"
          class="special-el-form-item public-input-height-2"
          :rules="[
            { required: true, trigger: 'blur', message: '请选择' },
          ]"
        >
          <div
            class="el-input__inner inputSimulation"
            @click="handleProjectItem"
            :class="{ show_disabled: pageType === '1' }"
            :title="formZZApply.projectName"
          >
            {{ formZZApply.projectName ? formZZApply.projectName : "请选择 " }}
          </div>
          <projectItemZZ
            ref="projectItem"
            @getProjectInfo="getProjectInfo"
          ></projectItemZZ>
        </el-form-item>

        <el-form-item
          label="终止原因"
          prop="reason"
          class="special-el-form-item"
        >
          <el-input
            rows="4"
            type="textarea"
            maxlength="200"
            v-model="formZZApply.reason"
            placeholder="请输入终止原因"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="openTJApply = false">取 消</el-button>
        <el-button type="warning" @click="submitFormZZApply(false)" v-preventReClick>暂 存</el-button>
        <el-button type="primary" @click="submitFormZZApply(true)" v-preventReClick>提 交</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listMeeting,
  getMeeting,
  delMeeting,
  addMeeting,
  updateMeeting,
  getCanScoringMeetingId,
  addApproval,
  updateApproval,
  addDecision,
  updateDecision,
} from "@/api/invest/meeting";
import {approvalStart} from "@/api/project/approval/pool";
import {decisionStart} from "@/api/project/decision/pool";
import projectItem from "../invest/components/projectItem";
import projectItemLX from "./approval/projectItem";
import projectItemTJ from "./decision/projectItem";
import projectItemZZ from "./termination/projectItem";
import fileItem from "../invest/components/fileItem";
import selecDept from "../invest/components/selecDept";
import selecUser from "../invest/components/selecUser";
import { mapGetters } from "vuex";

export default {
  props: {
    type: {
      type: String,
      default: "1", //1=显示全部列表  2=显示某项目下的详情列表  3=只展示弹窗
    },
    projectId: {
      type: String,
    },
  },
  dicts: ["meeting_type", "project_stage", "project_group"],
  components: { projectItem,projectItemLX, projectItemTJ,projectItemZZ, selecDept, fileItem, selecUser },
  watch: {
    "form.meetingType": function (newValue, oldValue) {
      // console.log(newValue,"this.form.meetingType", this.form.meetingType);
      if (this.form.meetingType == "LX" || this.form.meetingType == "TJ") {
        this.verifyProjectName = true;
      } else {
        this.verifyProjectName = false;
      }
    },
    open: function (newValue, oldValue) {
      if (newValue === false) {
        this.selectValues = null;
        this.selectNameValues = null;
        this.queryParams.projectPoolId = null;
        this.meetingType = null;
        this.pageType = null;
      }
    },
  },
  data() {
    const validateLogo = (rule, value, callback) => {
      if (this.fileListLXApply.length <= 0) {
        callback(new Error("请上传文件"));
      } else {
        callback();
      }
    };
    const validateLogo1 = (rule, value, callback) => {
      if (this.fileListTJApply.length <= 0) {
        callback(new Error("请上传文件"));
      } else {
        callback();
      }
    };
    return {
      meetingTypeDisabled: false, //会议类别
      showMenu: false,
      // 人员选择器
      checkType: "multiple",
      // 数据回显
      selectValues: null,
      selectNameValues: null,
      userVisible: false,
      pageType: null,
      meetingType: null,
      verifyProjectName: false,
      fileList: [],
      showProjectItem: false,
      deptId: process.env.VUE_APP_DEPTID,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      idsName: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 选中数组
      selectRowList: [],
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 会议记录表格数据
      meetingList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        meetingTheme: null,
        meetingCode: null,
        meetingType: null,
        startTime: null,
        endTime: null,
        timeVal: null,
        orderByColumn: "createTime",
        isAsc: "desc",
      },
      // 表单参数
      form: {
        id: null,
        meetingTheme: null,
        meetingCode: null,
        meetingType: null,
        projectPoolId: null,
        projectName: null,
        projectStage: null,
        projectGroup: "",
        startTime: null,
        endTime: null,
        place: null,
        promoter: null,
        promoterId: null,
        participants: null,
        participantsId: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        projectGroup: "",
      },
      // 表单校验
      rules: {
        meetingTheme: [{ required: true, trigger: "blur", message: "请输入" }],
        meetingType: [{ required: true, trigger: "change", message: "请选择" }],
        // projectGroup: [{ required: true, trigger: "change", message: "请选择" }],
        // projectName: [{ required: true, trigger: "blur", message: "请选择" }],
        startTime: [{ required: true, trigger: "change", message: "请选择" }],
        endTime: [{ required: true, trigger: "blur", message: "请选择" }],
        place: [{ required: true, trigger: "blur", message: "请输入" }],
        promoter: [{ required: true, trigger: "blur", message: "请选择" }],
        participants: [{ required: true, trigger: "blur", message: "请选择" }],
      },
      isInitiator: false, //是否是发起人
      showLookMark: false, //是否查看打分表
      showMarkBtn: false,
      meetingTypeList1: [
        {
          value: "A",
          label: "管理会议",
        },
        {
          value: "X",
          label: "临时会议",
        },
      ],
      meetingTypeList: [
        {
          value: "A",
          label: "管理会议",
        },
        {
          value: "LX",
          label: "项目立项会",
        },
        {
          value: "TJ",
          label: "项目投决会",
        },
        {
          value: "X",
          label: "临时会议",
        },
      ],
      showAllType: false,
      openDetail: false,
      // 立项申请
      titleLXApply: "",
      openLXApply: false,
      formLXApply: {
        id: null,
        projectPoolId: null,
        projectName: null,
        projectOverview: null,
        projectSparkle: null,
        listFile: null,
        participants: null,
        participantsId: null,
        flag:null,
      },
      fileListLXApply: [],
      rulesLXApply: {
        projectOverview: [
          { required: true, trigger: "blur", message: "请输入" },
        ],
        projectSparkle: [
          { required: true, trigger: "blur", message: "请输入" },
        ],
        listFile: [{ required: true, validator: validateLogo }],
      },
      // 投决申请
      titleTJApply: "",
      openTJApply: false,
      formTJApply: {
        id: null,
        projectPoolId: null,
        projectName: null,
        provision: null,
        listFile: null,
        participants: null,
        participantsId: null,
        flag:null,
      },
      fileListTJApply: [],
      rulesTJApply: {
        provision: [{ required: true, trigger: "blur", message: "请输入" }],
        listFile: [{ required: true, validator: validateLogo1 }],
      },
      // 终止申请
      titleZZApply: "",
      openZZApply: false,
      formZZApply: {
        id: null,
        projectPoolId: null,
        projectName: null,
        reason:null,
        participants: null,
        participantsId: null,
        flag:null,
      },
      rulesZZApply: {
        reason: [{ required: true, trigger: "blur", message: "请输入" }],
      },
    };
  },
  computed: {
    ...mapGetters(["user"]),
  },
  created() {
    this.showAllType = this.type === "3";
    // 查询该id下的列表信息
    if (this.$route.query.id) {
      this.queryParams.projectPoolId = this.$route.query.id;
    }
    // 会议类型
    if (this.$route.query.meetingType) {
      this.meetingType = this.$route.query.meetingType;
    }
    // 直接弹出新增
    if (this.$route.query.type === "1") {
      this.pageType = this.$route.query.type;
      this.handleAdd();
    }
    if (this.projectId) {
      this.queryParams.projectPoolId = this.projectId;
    }
    if (this.type !== "3") {
      this.getList();
    }
  },
  methods: {
    handleSelectPeople() {
      // this.userVisible = true;
      this.$refs.flowUser.handleUserVisible(true);
    },
    /*用户选中赋值*/
    // checkUserComplete() {
    //   this.userVisible = false;
    //   this.checkType = "";
    // },
    // 用户选中数据
    handleUserSelect(selection) {
      const that = this;
      if (selection && selection[0]) {
        let form;
        if (this.open) {
          form = this.form;
        } else if (this.openLXApply) {
          form = this.formLXApply;
        } else if (this.openTJApply) {
          form = this.formTJApply;
        }
        if (selection instanceof Array) {
          const userIds = selection.map((item) => item.userId);
          const nickName = selection.map((item) => item.nickName);
          form.participants = nickName.join(",");
          form.participantsId = userIds.join(",");
          this.selectNameValues = nickName.join(",");
          this.selectValues = userIds.join(",");
        } else {
          form.participants = selection.nickName;
          form.participantsId = selection.userId;
          this.selectNameValues = selection.nickName;
          this.selectValues = selection.userId;
        }
        this.$refs.form.clearValidate(["participants"]);
      }
    },
    getButtonItem(row) {
      this.showMarkBtn = false;
      this.isInitiator = false;
      // 是否是发起人
      let isInitiator = row.promoterId == this.user.userId;
      this.isInitiator = isInitiator;
      // 参与人数组
      let participantsIdList = row.participantsId.split(",");
      // console.log("是否是发起人",this.isInitiator)
      // console.log("参与人数组",participantsIdList,"this.user.userId=",this.user.userId,participantsIdList.indexOf(this.user.userId) > -1)
      // 参与人里面包含发起人
      if (participantsIdList.indexOf(this.user.userId) > -1) {
        this.showMarkBtn = true;
      }
      // console.log("this.showMarkBtn=",this.showMarkBtn)
      getCanScoringMeetingId(row.id).then((response) => {
        // 查看打分
        if (response.tProjectScoring) {
          this.showLookMark = true;
          this.$store.commit("SET_TPROJECTSCORING", response.tProjectScoring);
        } else {
          // 去打分
          this.showLookMark = false;
          if (!this.showMarkBtn && !isInitiator) {
            this.$message({
              message: "暂无更多操作权限",
              duration: 1500,
              type: "warning",
            });
          }
        }
      });
    },
    // getCanScoringMeetingId
    handleCommand(command, row) {
      // console.log("handleCommand", command);
      // console.log("row", row);
      let type = "1",
        readonly = true;
      if (command === "1") {
        readonly = false;
      }
      if (command === "3") {
        type = "2";
      }
      this.handleMark(row, type, readonly);
    },
    // 去打分
    handleMark(row, type, readonly) {
      this.$router.push({
        path: "/invest/meeting/mark",
        query: { id: row.id, formType: type, readonly: readonly },
      });
    },
    // 查看打分表
    handleLookMark(row, type) {
      this.$router.push({
        path: "/invest/meeting/mark",
        query: { id: row.id, formType: type },
      });
    },
    // 选择部门人
    openSelectDept(type) {
      if (type == 2) {
        // this.$refs.selecDepts1.show(type);
      } else {
        this.$refs.selecDepts.show(type, this.form.promoterId);
      }
    },
    getDeptUserInfo(info) {
      if (info.length > 0) {
        this.form.promoter = info[0].nickName;
        this.form.promoterId = info[0].userId.toString();
        this.$refs.form.clearValidate(["promoter"]);
      }
    },
    // 多选人
    getDeptMoreUserInfo(info) {
      let peoList = [],
        peoIdList = [];
      for (let i in info) {
        peoList.push(info[i].nickName);
        peoIdList.push(info[i].userId.toString());
      }
      let peopleStr = peoList.join(",");
      let peopleIdStr = peoIdList.join(",");
      this.form.participants = peopleStr;
      this.form.participantsId = peopleIdStr;
      this.$refs.form.clearValidate(["participants"]);
    },
    // 会议申请附件回显
    getFileList(fileList) {
      if (fileList && fileList.length > 0) {
        this.fileList = fileList;
      } else {
        this.fileList = [];
      }
    },
    // 展示立项申请弹窗
    showLXApplyPop(row) {
      this.resetLXApply(row);
      this.fileListLXApply = [];
      this.openLXApply = true;
      this.titleLXApply = "立项申请";
      setTimeout(() => {
        this.$refs.fileItemLXApply.fileList = [];
      }, 200);
    },
    // 展示投决申请弹窗
    showTJApplyPop(row) {
      this.resetTJApply(row);
      this.fileListLXApply = [];
      this.openTJApply = true;
      this.titleTJApply = "投决申请";
      setTimeout(() => {
        this.$refs.fileItemTJApply.fileList = [];
      }, 200);
    },
    // 展示终止申请弹窗
    showZZApplyPop() {
      // this.resetZZApply(row);
      //this.fileListZZApply = [];
      this.openZZApply = true;
      this.titleZZApply = "终止申请";
      /*setTimeout(() => {
        this.$refs.fileItemZZApply.fileList = [];
      }, 200);*/
    },
    // 立项申请附件回显
    getFileListLXApply(fileList) {
      this.fileListLXApply = fileList;
      if (fileList && fileList.length > 0) {
        this.$refs.formLXApply.clearValidate(["listFile"]);
      } else {
        this.fileListLXApply = [];
      }
    },
    // 投决申请附件回显
    getFileListTJApply(fileList) {
      this.fileListTJApply = fileList;
      if (fileList && fileList.length > 0) {
        this.$refs.formTJApply.clearValidate(["listFile"]);
      } else {
        this.fileListTJApply = [];
      }
    },
    // 获取公司信息
    getProjectInfo(info) {
      if (info.length > 0) {
        this.form.projectPoolId = info[0].id;
        this.form.projectName = info[0].projectName;
        this.formLXApply.projectPoolId = info[0].id;
        this.formLXApply.projectName = info[0].projectName;
        this.formTJApply.projectPoolId = info[0].id;
        this.formTJApply.projectName = info[0].projectName;
        this.formZZApply.projectPoolId = info[0].id;
        this.formZZApply.projectName = info[0].projectName;
      }
    },
    //展示人员
    handleProjectItem() {
      this.$refs.projectItem.showProjectItem = true;
      // 2. 调用子组件的刷新方法，重新加载项目列表
      // 确保子组件已加载且存在刷新方法
      if (this.$refs.projectItem && typeof this.$refs.projectItem.refreshProjectList === 'function') {
        this.$refs.projectItem.refreshProjectList();
      }
    },
    /** 查询会议记录列表 */
    getList() {
      this.loading = true;
      if (this.projectId) {
        this.queryParams.projectPoolId = this.projectId;
      }
      listMeeting(this.queryParams).then((response) => {
        this.meetingList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 会议申请表单重置
    reset() {
      this.form = {
        id: null,
        meetingTheme: null,
        meetingCode: null,
        meetingType: null,
        projectPoolId: null,
        projectName: null,
        projectStage: null,
        projectGroup: "",
        startTime: null,
        endTime: null,
        place: null,
        promoter: this.user.nickName,
        promoterId: this.user.userId,
        participants: null,
        participantsId: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        projectGroup: "",
      };
      this.resetForm("form");
    },
    // 立项申请表单重置
    resetLXApply(row) {
      this.formLXApply = {
        id: null,
        projectPoolId: null,
        projectName: null,
        projectOverview: null,
        projectSparkle: null,
        listFile: null,
      };
      this.resetForm("formLXApply");
    },
    // 投决申请表单重置
    resetTJApply(row) {
      this.formTJApply = {
        id: null,
        projectPoolId: null,
        projectName: null,
        projectOverview: null,
        projectSparkle: null,
        listFile: null,
      };
      this.resetForm("formTJApply");
    },
    // 终止申请表单重置
    resetZZApply(row) {
      this.formZZApply = {
        id: null,
        projectPoolId: row.id,
        projectName: row.projectName,
        projectOverview: null,
        projectSparkle: null,
        listFile: null,
      };
      this.resetForm("formZZApply");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      if (this.queryParams.timeVal && this.queryParams.timeVal.length > 0) {
        this.queryParams.startTime = this.queryParams.timeVal[0];
        this.queryParams.endTime = this.queryParams.timeVal[1];
      }
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.timeVal = null;
      this.queryParams.startTime = null;
      this.queryParams.endTime = null;
      this.queryParams.orderByColumn = "createTime";
      this.queryParams.isAsc = "desc";
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.idsName = selection.map((item) => item.meetingTheme);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
      this.selectRowList = selection;
    },
    /** 新增按钮操作 */
    handleAdd(projectId, meetingType) {
      let that = this;
      this.fileList = [];
      this.showAllType = this.type === "3";
      this.meetingTypeDisabled = false;
      this.selectValues = null;
      this.selectNameValues = null;
      this.reset();
      if (meetingType) {
        this.meetingType = meetingType;
        this.meetingTypeDisabled = true;
      }
      if (projectId && typeof projectId === "string") {
        this.pageType = "1";
      }
      // 直接绑定好项目
      if (this.pageType === "1") {
        let projectItemMessage = this.$store.getters.projectItemMessage;
        this.form.projectPoolId = projectItemMessage.id;
        this.form.projectName = projectItemMessage.projectName;
        this.form.projectStage = projectItemMessage.projectStage;
        this.form.projectGroup = projectItemMessage.projectGroup;
        this.form.meetingType = this.meetingType;
      }
      this.open = true;
      this.title = "添加会议";
      setTimeout(() => {
        that.$refs.fileItems.fileList = [];
      }, 200);
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.selectValues = null;
      this.selectNameValues = null;
      this.showAllType = true;
      this.reset();
      const id = row.id || this.ids;
      this.meetingTypeDisabled = true;
      getMeeting(id).then((response) => {
        this.form = response.data;
        this.form.projectName = response.data.tProjectPool.projectName;
        this.form.projectStage = response.data.tProjectPool.projectStage;
        this.form.projectGroup = response.data.tProjectPool.projectGroup;
        this.open = true;
        this.title = "修改会议";
        this.selectValues = response.data.participantsId;
        this.selectNameValues = response.data.participants;
        setTimeout(() => {
          this.$refs.fileItems.fileList = [];
          this.$refs.fileItems.getListFileBusinessId(id);
        }, 300);
      });
    },
    // 详情
    handleDetail(row) {
      this.selectValues = null;
      this.selectNameValues = null;
      this.showAllType = true;
      this.reset();
      const id = row.id || this.ids;
      this.meetingTypeDisabled = true;
      getMeeting(id).then((response) => {
        this.form = response.data;
        this.form.projectName = response.data.tProjectPool.projectName;
        this.form.projectStage = response.data.tProjectPool.projectStage;
        this.form.projectGroup = response.data.tProjectPool.projectGroup;
        this.openDetail = true;
        this.selectValues = response.data.participantsId;
        this.selectNameValues = response.data.participants;
        setTimeout(() => {
          this.$refs.fileItemsDet.fileList = [];
          this.$refs.fileItemsDet.getListFileBusinessId(id);
          this.$refs.fileItemsDet.handleButton();
        }, 300);
      });
    },
    /** 会议-提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (!this.form.projectGroup) {
            this.form.projectGroup = "";
          }
          if (
            new Date(this.form.endTime).getTime() <
            new Date(this.form.startTime).getTime()
          ) {
            this.$confirm("会议结束时间不能小于开始时间,请重新选择!", "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
            })
              .then(() => {})
              .catch(() => {});
            return false;
          }
          this.form.listFile = this.fileList;
          if (this.form.id != null) {
            updateMeeting(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMeeting(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    // 项目申请-提交
    submitFormLXApply(flag) {
      this.$refs["formLXApply"].validate((valid) => {
        if (valid) {
          this.formLXApply.listFile = this.fileListLXApply;
          if (this.formLXApply.id != null) {
            /*updateApproval(this.formLXApply).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.openLXApply = false;
              this.$emit("getList");
            });*/
          } else {
            /*addApproval(this.formLXApply).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.openLXApply = false;
              this.$emit("getList");
            });*/
          }
          this.formLXApply.flag=flag;
          approvalStart(this.formLXApply).then((response) => {
            this.$modal.msgSuccess("新增成功");
            this.openLXApply = false;
            this.$emit("getList");
          });
        }
      });
    },
    // 投决申请-提交
    submitFormTJApply(flag) {
      this.$refs["formTJApply"].validate((valid) => {
        if (valid) {
          this.formTJApply.listFile = this.fileListTJApply;
          /*if (this.formTJApply.id != null) {
            updateDecision(this.formTJApply).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.openTJApply = false;
              this.$emit("getList");
            });
          } else {
            addDecision(this.formTJApply).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.openTJApply = false;
              this.$emit("getList");
            });
          }*/
          this.formTJApply.flag=flag;
          decisionStart(this.formTJApply).then((response) => {
            this.$modal.msgSuccess("新增成功");
            this.openTJApply = false;
            this.$emit("getList");
          });
        }
      });
    },
    // 终止申请-提交
    submitFormZZApply(flag) {
      this.$refs["formZZApply"].validate((valid) => {
        if (valid) {
          this.formZZApply.flag=flag;
          terminationStart(this.formZZApply).then((response) => {
            this.$modal.msgSuccess("新增成功");
            this.openZZApply = false;
            this.$emit("getList");
          });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      const idsName = row.meetingTheme ? row.meetingTheme : this.idsName;
      this.$modal
        .confirm('是否确认删除"' + idsName + '"？')
        .then(function () {
          return delMeeting(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "invest/meeting/export",
        {
          ...this.queryParams,
        },
        `meeting_${new Date().getTime()}.xlsx`
      );
    },

    clickRow(row) {
      this.$refs.dataTable.toggleRowSelection(row);
    },
    handleSelectData(type) {
      // type 1=修改 2=删除
      if (this.selectRowList.length == 1) {
        const row = this.selectRowList[0];
        // 创建人
        if (row.createBy === this.user.nickName) {
          if (type === 1) {
            // 修改
            this.handleUpdate(row);
          } else if (type === 2) {
            // 删除
            this.handleDelete(row);
          }
        } else {
          this.$message({
            message: "无权限",
            duration: 1500,
            type: "error",
          });
        }
      } else {
        this.$message({
          message: "只能选择一条数据",
          duration: 1500,
          type: "warning",
        });
      }
    },
  },
};
</script>
