<!-- @format -->
<!-- 收文 -->
<template>
  <el-dialog
    ref="swDialog"
    :title="dialogTitle"
    :close-on-click-modal="false"
    @close="colsedialog"
    @opened="openSW"
    :destroy-on-close="true"
    v-model="visible"
    :fullscreen="fullscreen"
    width="85%"
    top="2vh"
    style="min-height: 85vh"
    append-to-body
  >
    <div
      @click="Enlarge"
      style="float: right; position: relative; top: -60px; right: 30px"
    >
      <el-icon><FullScreen /></el-icon>
    </div>
    <div
      @click="Enlarge1"
      style="float: right; position: relative; top: -60px; right: 50px"
    >
      <el-icon><Minus /></el-icon>
    </div>
    <div class="app-container" style="margin-top: -45px">
      <el-row>
        <el-col :span="24">
          <el-tabs type="border-card" class="demo-tabs">
            <el-tab-pane>
              <template #label>
                <span class="custom-tabs-label">
                  <el-icon>
                    <Document />
                  </el-icon>
                  <span>基本信息</span>
                </span>
              </template>
              <el-row :gutter="24">
                <el-col
                  :span="19"
                  style="
                    background-color: #9ca1a7;
                    margin-top: 1vh;
                    padding: 0 5px;
                    margin-left: 10px;
                  "
                >
                  <!--          <PdfViewer
                  ref="pdfViewRef"
                  :key="$route.fullPath"
                  :current-page="pdfPages"
                  :src="pdfUrl"
              ></PdfViewer>-->
                  <iframe
                    style="overflow: scroll; width: 100%; min-height: 77vh"
                    :src="pdfUrl"
                    ref="iframeRef"
                  ></iframe>
                </el-col>
                <el-col style="" :span="4">
                  <el-form
                    ref="receivedFormRef"
                    label-width="88px"
                    style="width: 17.5vw; margin-top: 1vh"
                    :rules="rules"
                    :model="receiverData"
                  >
                    <el-form-item label="来文标题:" prop="title">
                      <el-input
                        :disabled="isEdit"
                        v-model="receiverData.title"
                        placeholder="请输入来文标题"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label="来文单位:" prop="sender">
                      <el-input
                        :disabled="isEdit"
                        v-model="receiverData.sender"
                        placeholder="请输入来文单位"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label="来文日期:" prop="sendTime">
                      <el-date-picker
                        :disabled="isEdit"
                        format="YYYY-MM-DD"
                        value-format="YYYY-MM-DD"
                        v-model="receiverData.sendTime"
                        type="date"
                        placeholder="请输入来文日期"
                        size="defalut"
                        style="width: 19vw"
                      />
                    </el-form-item>
                    <el-form-item label="流水号: " prop="serial">
                      <el-input
                        :disabled="isEdit"
                        v-model="receiverData.serial"
                        placeholder="请输入流水号"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label="文件类型: " prop="receiveType">
                      <!-- <el-input
                          v-model="receiverData.receiveType"
                      ></el-input> -->
                      <el-select
                        :disabled="isEdit"
                        v-model="receiverData.receiveType"
                        placeholder="请选择文件类型"
                        style="width: 350px"
                      >
                        <el-option
                          v-for="dict in sw_open_type"
                          :key="dict.value"
                          :label="dict.label"
                          :value="dict.value"
                          >{{ dict.label }}</el-option
                        >
                      </el-select>
                    </el-form-item>
                    <el-form-item label="文件字号:" prop="documentNum">
                      <el-select
                        :disabled="isEdit"
                        v-model="receiverData.documentNum"
                        placeholder="请选择文件字号"
                        style="width: 350px"
                      >
                        <el-option
                          v-for="dict in receive_type"
                          :key="dict.value"
                          :label="dict.label"
                          :value="dict.value"
                          >{{ dict.label }}</el-option
                        >
                      </el-select>
                    </el-form-item>
                    <el-form-item label="紧急程度:" prop="emergencyDegree">
                      <el-select
                        :disabled="isEdit"
                        style="width: 19vw"
                        v-model="receiverData.emergencyDegree"
                        placeholder="请输入紧急程度"
                      >
                        <el-option
                          v-for="dict of urgent_type"
                          :key="dict.value"
                          :label="dict.label"
                          :value="dict.value"
                        />
                      </el-select>
                    </el-form-item>
                    <el-form-item label="原文链接:">
                      <el-link type="primary">
                        <el-icon class="el-icon--left"> <Document /> </el-icon>
                        {{ receiverData.title }}</el-link
                      >
                      <el-button
                        size="small"
                        plain
                        type="primary"
                        style="float: right; margin-left: 5px"
                        @click="uploadYFile()"
                        >下载</el-button
                      >
                    </el-form-item>
                    <el-form-item label="附件列表:">
                      <el-upload
                        v-if="uploadNot"
                        style="width: 100%"
                        ref="fujianUpload"
                        v-model:file-list="fujianListNew"
                        :action="upload.url"
                        :headers="upload.headers"
                        :on-success="uploadFuJianFiles"
                        @handleRemove="romveFile"
                        multiple
                      >
                        <el-button type="primary">点击上传附件</el-button>
                      </el-upload>
                      <el-link
                        v-for="(item, index) in fujianList"
                        :key="index"
                        type="primary"
                      >
                        <div v-if="item != null">
                          <div
                            style="display: inline-block"
                            @click="openFujianFile(item.url, item.name)"
                          >
                            <el-icon class="el-icon--left">
                              <Document />
                            </el-icon>
                            <span
                              style="
                                display: inline-block;
                                margin-left: 5px;
                                overflow: hidden;
                                white-space: nowrap;
                                text-overflow: ellipsis;
                                width: 9vw;
                                height: 18px;
                                line-height: 18px;
                              "
                            >
                              {{ item.name }}</span
                            >
                          </div>
                          <el-popconfirm
                            v-if="!isEdit"
                            @confirm="confirmEvent(item, index)"
                            @cancel="cancelEvent"
                            title="确认删除该文件吗?"
                          >
                            <template #reference>
                              <span
                                @click="delFile(item, index)"
                                style="
                                  display: inline-block;
                                  margin-top: 5px;
                                  margin-left: 10px;
                                "
                                ><el-icon><Close /></el-icon
                              ></span>
                            </template>
                          </el-popconfirm>
                        </div>
                      </el-link>
                    </el-form-item>
                    <el-form-item v-if="fkFile" label="反馈文件:">
                      <el-link
                        v-for="(item, index) in receiverData.feedbackFileList"
                        :key="index"
                        type="primary"
                        @click="openFujianFile(item.yfile.url)"
                      >
                        <el-icon class="el-icon--left">
                          <Document />
                        </el-icon>
                        {{ item.yfile.name }}
                      </el-link>
                    </el-form-item>
                  </el-form>
                  <el-form
                    v-show="hanldType"
                    label-width="88px"
                    style="width: 17vw; margin-left: 0.8vw"
                  >
                    <el-form-item v-if="nodeShow" label="下一步节点:">
                      <el-select
                        style="width: 19vw"
                        v-model="selNextNode"
                        placeholder="请选择下一步节点"
                      >
                        <el-option
                          v-for="item in NextStepNode"
                          :key="item.NodeID"
                          :label="item.Name"
                          :value="item.NodeID"
                        >
                        </el-option>
                      </el-select>
                    </el-form-item>

                    <div v-show="guidangBt != true">
                      <div v-if="nodeShow">
                        <div v-if="showMessage">
                          <el-form-item v-if="!nodeMsg" label="审核意见:">
                            <el-input
                              style="width: 19vw"
                              type="textarea"
                              :rows="4"
                              placeholder="请输入审核意见"
                              v-model="formData.reviewMsg"
                            />
                          </el-form-item>
                          <el-form-item v-else label="拟办意见:">
                            <el-input
                              @click="openOpinion"
                              type="textarea"
                              :rows="4"
                              placeholder="请输入拟办意见"
                              v-model="formData.reviewMsg"
                            />
                          </el-form-item>
                        </div>
                      </div>

                      <el-form-item v-if="feedback" label="反馈时限:">
                        <div style="font-size: 15px">
                          {{ parseTime(closeTime) }}
                        </div>
                      </el-form-item>
                      <el-form-item v-if="feedback" label="反馈文件:">
                        <el-upload
                          ref="fujianUpload"
                          v-model:file-list="fujianList1"
                          :action="upload.url"
                          :headers="upload.headers"
                          :on-success="uploadFuJianFiles1"
                          multiple
                        >
                          <el-button type="primary">点击上传附件</el-button>
                        </el-upload>
                      </el-form-item>
                      <el-form-item>
                        <template v-if="fileBackFile.length !== 0">
                          <el-link
                            type="primary"
                            v-for="(item, index) in fileBackFile"
                            :key="index"
                            @click="openUrl(item.yfile.url)"
                          >
                            <el-icon>
                              <Document></Document>
                            </el-icon>
                            {{ item.yfile.name }}
                          </el-link>
                        </template>
                      </el-form-item>

                      <div style="text-align: center">
                        <el-button
                          :loading="loadingWebLoad"
                          :disabled="false"
                          @click="sendNext"
                          type="primary"
                          >提交
                        </el-button>
                        <el-button
                          v-if="yijiaoBtn"
                          :disabled="false"
                          @click="sendOtherOne"
                          type="success"
                          >移交
                        </el-button>
                        <el-button
                          v-if="nodeInfo"
                          :disabled="false"
                          @click="sendBack"
                          type="danger"
                          >退回
                        </el-button>
                        <el-button
                          style="display: inline-block"
                          v-if="nodeInfo"
                          @click="notApproved"
                          type="warning"
                          >不予审批
                        </el-button>
                      </div>
                    </div>
                    <!--   归档操作       -->

                    <div v-show="guidangBt">
                      <el-form-item v-if="feedback" label="反馈时限:">
                        <div style="font-size: 15px">
                          {{ parseTime(closeTime) }}
                        </div>
                      </el-form-item>
                      <el-form-item v-if="feedback" label="反馈文件:">
                        <el-upload
                          ref="fujianUpload"
                          v-model:file-list="fujianList1"
                          :action="upload.url"
                          :headers="upload.headers"
                          :on-success="uploadFuJianFiles1"
                          :before-upload="beforeUpload"
                          accept=".pdf,.doc,.docx,.wps,.ppt,.pptx,.xls,.xlsx,.aip,.ceb,cebx,html,ofg,dwg,jpg,tif"
                          multiple
                        >
                          <el-button style="display: inline" type="primary"
                            >点击上传附件</el-button
                          >
                        </el-upload>
                        <!-- <div
                          tip="tip"
                          style="display: inline"
                          class="el-upload__tip"
                        >
                          只能上传以下文件类型：pdf/doc/docx/wps/ppt/pptx/xls/xlsx/aip/ceb/cebx/html/ofg/dwg/jpg/tif
                        </div> -->
                      </el-form-item>
                      <el-form-item>
                        <template v-if="fileBackFile.length !== 0">
                          <el-link
                            type="primary"
                            v-for="(item, index) in fileBackFile"
                            :key="index"
                            @click="openUrl(item.yfile.url)"
                          >
                            <el-icon>
                              <Document></Document>
                            </el-icon>
                            {{ item.yfile.name }}
                          </el-link>
                        </template>
                      </el-form-item>

                      <!-- <el-form-item label="档案编号: ">
                        <el-input placeholder="请输入档案编号" v-model="guidangData.archiveNo"></el-input>
                      </el-form-item> -->
                      <!--
                                  <el-form-item label="档案份数: "  >
                                    <el-input
                                        placeholder="请输入档案编号"
                                        v-model="guidangData.archiveNum"></el-input>
                                  </el-form-item>-->
                      <el-form-item label="档案分类: ">
                        <el-tree-select
                          style="width: 19vw"
                          v-model="guidangData.typeId"
                          :data="typeList"
                          :props="{
                            value: 'archiveTypeId',
                            label: 'name',
                            children: 'children',
                          }"
                          value-key="archiveTypeId"
                          placeholder="请选择档案分类"
                        />
                      </el-form-item>
                      <el-form-item label="打印份数: ">
                        <el-input
                          type="number"
                          placeholder="请输入打印份数"
                          v-model="guidangData.printNum"
                        ></el-input>
                      </el-form-item>
                      <!-- <el-form-item label="密级">
                        <el-select
                          v-model="guidangData.levels"
                          placeholder="请选择密级"
                        >
                          <el-option
                            v-for="dict in archive_levels"
                            :key="dict.value"
                            :label="dict.label"
                            :value="dict.value"
                          ></el-option>
                        </el-select>
                      </el-form-item> -->
                      <el-form-item label=" ">
                        <el-button
                          :disabled="false"
                          @click="sendNext1"
                          type="primary"
                          >归档
                        </el-button>
                      </el-form-item>
                    </div>
                  </el-form>
                </el-col>
              </el-row>
            </el-tab-pane>

            <el-tab-pane>
              <template #label>
                <span class="custom-tabs-label">
                  <el-icon>
                    <Promotion />
                  </el-icon>
                  <span>流转记录</span>
                </span>
              </template>

              <!-- <iframe :src="tuurl" width="100%" height="500px"></iframe> -->
              <div>
                <el-table border :data="liuzhuanData" style="width: 100%">
                  <el-table-column
                    align="center"
                    label="序号"
                    width="120"
                    type="index"
                  >
                  </el-table-column>
                  <el-table-column
                    align="center"
                    prop="NDFromT"
                    label="	节点名称"
                    width="180"
                  >
                  </el-table-column>
                  <el-table-column
                    align="center"
                    width="130"
                    prop="ActionTypeText"
                    label="办理状态"
                  >
                  </el-table-column>
                  <el-table-column
                    align="center"
                    prop="EmpFromT"
                    label="办理人"
                  >
                  </el-table-column>
                  <el-table-column align="center" prop="SDT" label="到达时间">
                  </el-table-column>
                  <el-table-column align="center" prop="RDT" label="处理时间">
                  </el-table-column>
                  <el-table-column
                    align="center"
                    prop="ActionType22"
                    label="审核意见"
                  >
                    <template #default="scope">
                      <div v-if="scope.row.ActionType == 2">
                        退回原因：{{ scope.row.Msg }}
                      </div>
                      <div v-else-if="scope.row.ActionType == 3">
                        移交原因：{{ scope.row.Msg }}
                      </div>
                      <div v-else-if="scope.row.ActionType22 != undefined">
                        <div v-for="item in scope.row.ActionType22" :key="item">
                          <!-- <div></div> -->
                          <div>{{ item.Msg }}</div>
                        </div>
                      </div>
                      <div v-else>{{ scope.row.Msg }}</div>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </el-tab-pane>
            <el-tab-pane label="收文阅办笺">
              <template #label>
                <span class="custom-tabs-label">
                  <el-icon>
                    <SetUp />
                  </el-icon>
                  <span>收文阅办笺</span>
                </span></template
              >
              <div style="text-align: center">
                收文阅办笺
                <el-button
                  type="primary"
                  icon="view"
                  style="margin-left: 5px"
                  @click="openYbj"
                  >预览</el-button
                >
              </div>
            </el-tab-pane>
          </el-tabs>
        </el-col>
      </el-row>
    </div>
    <select-user
      ref="selectRef"
      @ok="handleQuery"
      @yijiao="sendYijiao"
      @closeDialogf="closeSelUser"
    ></select-user>
    <!-- 退回 -->
    <el-dialog title="退回" v-model="dialogBack" width="40%">
      <el-form>
        <el-form-item label-width="200" label="退回节点：">
          <el-select
            v-model="nodeValue"
            placeholder="请选择退回节点信息"
            style="width: 240px"
          >
            <el-option
              v-for="item in nodeData"
              :key="item.No"
              :label="item.Name"
              :value="item.No"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          label-width="200"
          label="退回原因："
          placeholder="请输入退回原因"
        >
          <el-input v-model="returnMsg" style="width: 20vw" type="textarea" />
        </el-form-item>
      </el-form>
      <span
        style="position: relative; left: 28vw"
        slot="footer"
        class="dialog-footer"
      >
        <el-button @click="dialogBack = false">取 消</el-button>
        <el-button type="primary" @click="submitNodeBack">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog style="width: 1000px" title="阅办笺" v-model="ybjState">
      <incoming-message ref="incomRef" :id="receiverData.id"></incoming-message>
    </el-dialog>
  </el-dialog>
  <el-dialog
    v-model="dialogVisibleYiJiao"
    title="请选择移交人员"
    width="40%"
    :before-close="handleClose"
  >
    <div style="padding: 0 20px">
      <el-table
        ref="multipleTable1"
        :data="tableData"
        style="height: 34.4vh"
        :row-key="getRowKeys"
        @selection-change="handleSelectionChange"
        @select="setSelectRows"
        @select-all="selectAll"
      >
        <el-table-column
          :selectable="getSelectable"
          :reserve-selection="true"
          type="selection"
          width="60"
          align="right"
        />
        <el-table-column align="center" prop="name" label="用户姓名" />
      </el-table>
      <el-form style="margin-top: 20px">
        <el-form-item label="移交意见：">
          <el-input
            placeholder="请输入移交意见"
            v-model="yjOpinion"
            style="width: 20vw"
            type="textarea"
          />
        </el-form-item>
      </el-form>
    </div>

    <template #footer>
      <span class="dialog-footer">
        <el-button @click="quxiao">取消</el-button>
        <el-button type="primary" @click="submitUserList"> 确认 </el-button>
      </span>
    </template>
  </el-dialog>
  <!-- 不予审批 -->
  <el-dialog title="不予审批" v-model="dialogApproved" width="30%">
    <el-form>
      <!-- <el-form-item label-width="200" label="退回节点：">
          <el-select
            v-model="nodeValue"
            placeholder="请选择退回节点信息"
            style="width: 240px"
          >
            <el-option
              v-for="item in nodeData"
              :key="item.No"
              :label="item.Name"
              :value="item.No"
            />
          </el-select>
        </el-form-item> -->
      <el-form-item label-width="100" label="原因：">
        <el-input
          placeholder="请输入不予审批原因"
          v-model="formData.reviewMsg"
          style="width: 20vw"
          type="textarea"
        />
      </el-form-item>
    </el-form>
    <span
      style="position: relative; left: 18vw"
      slot="footer"
      class="dialog-footer"
    >
      <el-button @click="cancel()">取 消</el-button>
      <el-button type="primary" @click="submitNotApproved">确 定</el-button>
    </span>
  </el-dialog>
  <!-- 拟办意见 -->
  <el-dialog title="拟办意见" v-model="dialogOpinion" width="900px">
    <el-form style="padding: 10px 25px" model="formDataOpinion">
      <el-form-item label-width="90" label="拟办意见：">
        <el-input
          placeholder="请输入拟办意见"
          v-model="formDataOpinion.reviewMsg"
          style="width: 80vw"
          rows="20"
          type="textarea"
        />
      </el-form-item>
    </el-form>
    <span
      style="position: relative; left: 680px"
      slot="footer"
      class="dialog-footer"
    >
      <el-button type="primary" @click="submitOpinion">确 定</el-button>
      <el-button @click="cancelOpinion()">取 消</el-button>
    </span>
  </el-dialog>
</template>

<script setup name="viewPdfer">
import selectUser from "../../selectUser";
import { getToken } from "@/utils/auth";
import { listType } from "@/api/archive/type";

const { that, proxy } = getCurrentInstance();
import { onMounted, reactive, ref, nextTick } from "vue";
import { saveReceived } from "@/api/office/received";
import { useRoute, useRouter } from "vue-router";
import {
  generNextStepNode,
  generNextStepAllNode,
  judgeNode,
  sendFlowToNext,
  node_ReturnWork,
  receive,
  NodeShift,
  selectDpPersons,
  getWfGenerWorkList,
  delSWFileList,
  getSelfParas,
} from "@/api/liucheng";
import {
  leave,
  getLeave,
  getReturnWorkNode,
  WorkProgressBar,
  NodeReturnWork,
} from "@/api/clocking/leave";
import { ElMessage, ElMessageBox } from "element-plus";
import { getJToken } from "@/utils/auth";
import { saveArchive } from "@/api/archive/archive";
import axios from "axios";
import incomingMessage from "@/views/incomingMessages";
import { Base64 } from "js-base64";
import Cookies from "js-cookie";

const { archive_levels } = proxy.useDict("archive_levels");

const router = useRouter();
const route = useRoute();
const key = computed(() => {
  return route.path + Math.random();
});
const print = ref({
  id: "printContent", //这里的id就是上面我们的打印区域id，实现指哪打哪
  // popTitle: '配置页眉标题', // 打印配置页上方的标题
  // extraHead: '', // 最上方的头部文字，附加在head标签上的额外标签，使用逗号分割
  // preview: false, // 是否启动预览模式，默认是false
  // previewTitle: '预览的标题', // 打印预览的标题
  // previewPrintBtnLabel: '预览结束，开始打印', // 打印预览的标题下方的按钮文本，点击可进入打印
  // zIndex: 20002, // 预览窗口的z-index，默认是20002，最好比默认值更高
  // previewBeforeOpenCallback() { //console.log('正在加载预览窗口！'); }, // 预览窗口打开之前的callback
  // previewOpenCallback() { //console.log('已经加载完预览窗口，预览打开了！') }, // 预览窗口打开时的callback
  // beforeOpenCallback() { //console.log('开始打印之前！') }, // 开始打印之前的callback
  // openCallback() { //console.log('执行打印了！') }, // 调用打印时的callback
  // closeCallback() { //console.log('关闭了打印工具！') }, // 关闭打印的callback(无法区分确认or取消)
  // clickMounted() { //console.log('点击v-print绑定的按钮了！') },
});

const pdfUrl = ref("");
const formDataOpinion = ref({});
const userNames = ref("");
const pdfUurl = ref(null);
const YWUrl = ref(null);
const nodeInfo = ref(true);
const yijiaoBtn = ref(false);
const dialogApproved = ref(false);
const fullscreen = ref(true);
const yjOpinion = ref("");
const showMessage = ref(true);
const dialogVisibleYiJiao = ref(false);
const dialogOpinion = ref(false);
const nodeMsg = ref(false);
const nodeShow = ref(false);
const visible = ref(false);
const isAllowed = ref(true);
const { urgent_type } = proxy.useDict("urgent_type");
const { sw_open_type } = proxy.useDict("sw_open_type");
const nodeValue = ref(null);
const returnMsg = ref(null);
const dialogBack = ref(false);
const feedback = ref(false);
const nodeData = ref([]);
const tableData = ref([]);
const liuzhuanData = ref([]);
const valDate = ref(null);
const closeTime = ref(null);
const loadingWebLoad = ref(false);
let pdfDoc = null;
const pdfPages = ref(0);
const sendDownFile = ref([]);
const fileBackFile = ref([]);
const table = ref([]);
// const incoming = ref("/incomingMessages");
const NextStepNode = ref([]);
const fujianListNew = ref([]);
const fujianList = ref([]);
const fujianList1 = ref([]);
const dialogTitle = ref("收文");
const hanldType = ref(false);
const uploadNot = ref(false);
const isEdit = ref(true);
const guidangBt = ref(false);
const ybjState = ref(false);
const fkFile = ref(false);
const isEndNodeFlg = ref(false);
const selUserNames = ref("");
const tuurl = ref("");
const selNextNode = ref("");
const typeList = ref([]);
const receiverData = ref({});
const downUrl = ref(null);
const pdfUrl2 = ref(null);

//可退回的节点
const reWorkNode = ref({});
function beforeUpload(file) {
  const allowedTypes = [
    "pdf",
    "doc",
    "docx",
    "wps",
    "ppt",
    "pptx",
    "xls",
    "xlsx",
    "aip",
    "ceb",
    "cebx",
    "html",
    "ofg",
    "dwg",
    "jpg",
    "tif",
  ];
  const extension = file.name.split(".").pop(); // 获取文件扩展名
  const isAllowed = allowedTypes.includes(extension);
  if (!isAllowed) {
    this.$message.error(
      "上传文件只能是 PDF、DOC、DOCX、WPS、PPT、PPTX、XLS、XLSX、AIP、CEB、CEBX、HTML、OFD、DWG、JPG、TIF 类型!"
    );
    return false;
  }
  return true;
}
/** 查询归档类型列表 */
function getTypeList() {
  listType({}).then((response) => {
    typeList.value = proxy.handleTree(
      response.data,
      "archiveTypeId",
      "parentId"
    );
  });
}
function confirmEvent(item, index) {
  console.log(item);
  delSWFileList(item.fileId).then((res) => {
    console.log(res);
    proxy.$message({
      type: "success",
      message: "删除成功",
    });
    fujianList.value.splice(index, 1);
    receiverData.value.fujianFileList = fujianList.value;
  });
}
//删除附件
function delFile(item, index) {}
const state = reactive({
  multipleTable1: null,
});
const data = reactive({
  upload: {
    // 设置上传的请求头部
    headers: { Authorization: "Bearer " + getToken() },
    // 上传的地址
    url: import.meta.env.VITE_APP_BASE_API + "/system/file/fileupload",
  },
  formData: {
    reviewMsg: "",
    optionName: null,
    toNodeId: null,
    users: null,
    workid: null,
  },
  receivedParams: {
    title: null, //来文标题
    sender: null, //单位
    sendTime: null, //时间
    serial: null, //流水号
    documentNum: null, //字号
    emergencyDegree: null, //紧急程度
    sendDownFileId: null, //下发文件
    receiveFileId: null, //收文原件
    fujianFileList: [], //附件信息
  },
  guidangData: {
    archiveNo: null,
    workId: null,
    archiveFormNo: null,
    printNum: null,
    levels: null,
    typeId: null,
    name: null,
  },
});
const { formData, upload, receivedParams, rules, guidangData } = toRefs(data);
const receivedFormRef = ref(false);
const flowDatas = ref({});
const emit = defineEmits(["guanbi"]);
function openOpinion() {
  dialogOpinion.value = true;
  formDataOpinion.value.reviewMsg = formData.value.reviewMsg;
}
function cancelOpinion() {
  dialogOpinion.value = false;
}
function submitOpinion() {
  formData.value.reviewMsg = formDataOpinion.value.reviewMsg;
  dialogOpinion.value = false;
  formDataOpinion.value.reviewMsg = "";
}
function openYbj() {
  ybjState.value = true;
}

function quxiao() {
  dialogVisibleYiJiao.value = false;
  proxy.$modal.closeLoading();
}
function closeSelUser() {}

// el-table只能选一个

const setSelectRows = (selection) => {
  if (selection.length > 1) {
    const del_row = selection.shift();
    proxy.$refs.multipleTable1.toggleRowSelection(del_row, false); //设置这一行取消选中
  }
};
function cancel() {
  dialogApproved.value = false;
  proxy.$modal.closeLoading();
}
function notApproved() {
  dialogApproved.value = true;
  formData.value.reviewMsg = "";
  // closePage(0);
}
// 点击表头的全选复选框触发
const selectAll = (selection) => {
  proxy.$modal.msgError("移交人员只能选一个！");
  proxy.$refs.multipleTable1.clearSelection();
  return;
};
function submitNotApproved() {
  proxy.$modal.loading();
  if (formData.value.reviewMsg == "") {
    proxy.$message.error("请输入不予审批原因");
    return;
  }

  formData.value.toNodeId = 306;
  sendFlowToNext(formData.value).then((response) => {
    ElMessage({
      message:
        "已发送到" +
        response.data.VarToNodeName +
        "节点，接收人：" +
        response.data.VarAcceptersName,
      type: "success",
    });
    proxy.$modal.closeLoading();
    ////////关闭文件，释放资源
    dialogApproved.value = false;
    formData.value.reviewMsg = "";
    colsedialog();
  });
}
/** 表单重置 */
function reset() {
  formData.value = {
    reviewMsg: null,
    optionName: null,
    toNodeId: null,
    users: null,
    workid: null,
  };
  NextStepNode.value = [];
  flowDatas.value = [];
  selNextNode.value = "";
  selUserNames.value = "";
  fujianList.value = [];
  fujianList1.value = [];
  sendDownFile.value = [];
}
//移交
function submitUserList() {
  formData.value.users = userNames.value;
  if (formData.value.users == "") {
    proxy.$modal.msgError("请选择要移交的人员");
  } else {
    sendYijiao();
    if (yjOpinion.value != "") {
      dialogVisibleYiJiao.value = false;
    }

    userNames.value = "";
    formData.value.user = [];
    proxy.$refs.multipleTable1.clearSelection();
  }
}
async function submitNodeBack() {
  if (nodeValue.value == null) {
    proxy.$message.error("请选择退回节点信息");
    return;
  }
  if (returnMsg.value == null) {
    proxy.$message.error("请输入退回原因");
    return;
  }
  proxy.$modal.loading("退回中，请稍后...");
  let res = await NodeReturnWork(
    formData.value.workid,
    nodeValue.value,
    returnMsg.value
  );
  proxy.$message.success(res);
  dialogBack.value = false;
  proxy.$emit("closeViewLeave");
  nodeValue.value = null;
  returnMsg.value = null;
  valDate.value = null;
  selNextNode.value = null;
  proxy.$modal.closeLoading();
  colsedialog();
}

function sendBack() {
  dialogBack.value = true;
  // closePage(0);
  returnWorkNode();
}
function Enlarge() {
  fullscreen.value = true;
}
function Enlarge1() {
  fullscreen.value = false;
}

//获取退回界定啊
async function returnWorkNode() {
  let nData = await getReturnWorkNode(getJToken(), formData.value.workid);
  nodeData.value = nData;
}
// // 多选框选中数据  常用联系人
const handleSelectionChange = (selection) => {
  // userNames.value = selection[0].no;
  userNames.value = selection.map((item) => item.no).join(",");
};
const dcolse = (done) => {
  pdfPages.value = 0;
  pdfUrl.value = "";
  sendDownFile.value = [];
  fujianList.value = [];
  fujianList1.value = [];
  receivedFormRef.value = false;
  loadingWebLoad.value = false;
  emit("guanbi");
  done();
};
const colsedialog = () => {
  pdfPages.value = 0;
  pdfUrl.value = "";
  sendDownFile.value = [];
  fujianList.value = [];
  fujianList1.value = [];
  receivedFormRef.value = false;
  visible.value = false;
  loadingWebLoad.value = false;
  reset();
  emit("guanbi");
};
function getLiuzhuanData() {
  getWfGenerWorkList(getJToken(), formData.value.workid).then((res) => {
    liuzhuanData.value = res.trackList;
  });
}
function printPDF() {
  window.print(pdfUrl.value);
}
/** 查询参数列表 */
function showdetal2(recdata, flowData, type, isdel) {
  console.log("recdata", recdata);
  fileBackFile.value = [];
  showMessage.value = true;
  guidangBt.value = false;
  nodeShow.value = true;
  if (flowData.FK_Node == "301") {
    nodeShow.value = false;
  }
  if (flowData.FK_Node == "304") {
    showMessage.value = false;
  }
  if (flowData.FK_Node == "308") {
    yijiaoBtn.value = true;
  }
  if (recdata.feedbackFileList !== undefined) {
    fileBackFile.value = recdata.feedbackFileList;
    // for (let i = 0; i < recdata.feedbackFileList.length; i++) {
    //   receiverData.value.feedbackFileList.push({
    //     fileId: recdata.feedbackFileList[i].yfile.fileId,
    //     userName: recdata.feedbackFileList[i].yfile.createBy,
    //   });
    // }
  }
  feedback.value = false;
  if (recdata.isFeedback == "1") {
    feedback.value = true;
    closeTime.value = recdata.closeTime;
  }
  nodeInfo.value = true;
  nodeMsg.value = false;
  if (
    flowData.FK_Node == "304" ||
    flowData.FK_Node == "306" ||
    flowData.FK_Node == "308" ||
    flowData.FK_Node == "301"
  ) {
    nodeInfo.value = false;
  }
  if (flowData.FK_Node == "302") {
    nodeMsg.value = true;
  }
  visible.value = true;
  if (recdata.sendFile != null) {
    var url = recdata.sendFile.url;
    YWUrl.value = url;
    var b64Encoded = Base64.encode(url);
    pdfUrl.value =
      import.meta.env.VITE_APP_KKFILE2 +
      encodeURIComponent(b64Encoded) +
      "&officePreviewType=pdf";
  }

  for (let i in recdata.fujianFileList) {
    fujianList.value.push(recdata.fujianFileList[i].yfile);
  }
  // receiverData.value.feedbackFileList
  receiverData.value = recdata;
  fkFile.value = false;
  if (receiverData.value.feedbackFileList.length > 0) {
    fkFile.value = true;
  }
  hanldType.value = type;
  formData.value.workid = flowData.WorkID;
  formData.value.optionName = flowData.NodeName;
  flowDatas.value = flowData;
  dialogTitle.value = flowData.NodeName;
  // 是否可编辑原信息
  console.log("isdel", isdel);

  getSelfParas(flowData.WorkID).then((res) => {
    console.log("是否可编辑原信息", res);
    if (res.data.SelfParas == "isEdit") {
      isEdit.value = false;
    }
    uploadNot.value = true;
    if (isdel == "no") {
      isEdit.value = true;
      uploadNot.value = false;
    }
  });

  getLiuzhuanData();

  nextTick(() => {
    if (pdfUrl.value != null && pdfUrl.value != "") {
      // proxy.$refs["pdfViewRef"].loadFile(pdfUrl.value);
    }
  });
  tuurl.value =
    Cookies.get("jFontIp") +
    "/WF/Port.htm?DoWhat=OneWork2&WorkID=" +
    flowData.WorkID +
    "&FK_Flow=" +
    flowData.FK_Flow +
    "&Token=" +
    getJToken();
  //判断当前节点是不是最后一个.
  judgeNode(flowDatas.value.FK_Node, getJToken()).then((nres) => {
    isEndNodeFlg.value = false;
    if (nres.msg == "Y") {
      NextStepNode.value.push({ NodeID: 0, Name: "结束" });
      isEndNodeFlg.value = true;
      selNextNode.value = NextStepNode.value[0].NodeID;
    } else {
      //获取下个节点.
      generNextStepAllNode(
        flowDatas.value.FK_Flow,
        flowDatas.value.WorkID,
        "",
        getJToken()
      ).then((res) => {
        NextStepNode.value = res;
        selNextNode.value = NextStepNode.value[0].NodeID;
        if (flowData.FK_Node == "304") {
          selNextNode.value = NextStepNode.value[0].NodeID;
        }
      });
    }
  });

  if (
    formData.value.optionName == "归档打印" ||
    formData.value.optionName == "赋文号归档"
  ) {
    getTypeList();
    formData.value.reviewMsg = "归档";
    guidangBt.value = true;
  }
}

async function sendYijiao() {
  //保存数据
  if (yjOpinion.value == "") {
    ElMessage({
      message: "请输入移交意见",
      type: "warning",
    });
  } else {
    proxy.$modal.loading("移交中，请稍后...");
    await receive(receiverData.value).then((response) => {
      NodeShift(
        flowDatas.value.WorkID,
        formData.value.users,
        yjOpinion.value
      ).then(() => {
        ElMessage({
          message: response.msg,
          type: "success",
        });
        proxy.$modal.closeLoading();
        colsedialog();
      });
    });
    proxy.$modal.closeLoading();
    yjOpinion.value = "";
  }
}

/** 选择用户后进行下一步 */
function handleQuery(selUsers, str) {
  formData.value.users = selUsers;
  if (selUsers != undefined && selUsers != "") {
    //0：移交   其他：发送到下一步
    if (str == "0") {
      sendYijiao();
    } else {
      onSubmit();
    }
  }
}

function openFujianFile(url) {
  window.open(url, "_blank");
}
function openUrl(url) {
  window.open(url, "_blank");
}
async function uploadYFile() {
  const name = receiverData.value.title;
  const files = await proxy.$download.downloadUrlFile(YWUrl.value, name);
  proxy.$download.saveAs(
    new Blob([files], { type: "text/plain;charset=UTF-8" }),
    name + ".pdf"
  );
}
const openSW = () => {};

/** 打开授权用户表弹窗 */
function openSelectUser(str) {
  flowDatas.value.toNodeId = selNextNode.value;
  proxy.$refs["selectRef"].show1(flowDatas.value, str);
}

//点击提交
const onSubmit = async () => {
  loadingWebLoad.value = true;
  //反馈文件
  proxy.$modal.loading("提交中，请稍后...");

  receiverData.value.feedbackFileList = [];
  for (let i = 0; i < fileBackFile.value.length; i++) {
    if (fileBackFile.value[i].yfile.length !== 0) {
      receiverData.value.feedbackFileList.push({
        fileId: fileBackFile.value[i].fileId,
        userName: fileBackFile.value[i].yfile.createBy,
      });
    }
  }
  for (let i = 0; i < fujianList1.value.length; i++) {
    receiverData.value.feedbackFileList.push({
      fileId: fujianList1.value[i].response.data.fileId,
      userName: fujianList1.value[i].response.data.createBy,
    });
  }
  if (guidangBt.value) {
    guidangData.value.archiveFormNo = flowDatas.value.FK_Flow;
    guidangData.value.workId = flowDatas.value.WorkID;
    let { archiveRes } = await saveArchive(guidangData.value);
  }
  // 如果市最后一个节点则执行 完成
  if (isEndNodeFlg.value) {
    //todo 调用修改接口 修改
    await receive(receiverData.value).then((response) => {});
    generNextStepAllNode(
      flowDatas.value.FK_Flow,
      flowDatas.value.WorkID,
      "",
      getJToken()
    ).then((res) => {
      ElMessage({
        message: "当前工作已结束",
        type: "success",
      });
      colsedialog();
      proxy.$modal.closeLoading();
    });
  } else {
    //todo 调用修改接口 修改
    await receive(receiverData.value).then((response) => {});
    // receiverData.value.feedbackFileList = [];
    sendFlowToNext(formData.value).then((response) => {
      if (response.code == 200) {
        if (
          response.data.VarAcceptersName != "" &&
          response.data.VarAcceptersName != "结束"
        ) {
          ElMessage({
            message:
              "已发送到" +
              response.data.VarToNodeName +
              "节点，接收人：" +
              response.data.VarAcceptersName,
            type: "success",
          });
          proxy.$modal.closeLoading();
        } else if (response.data.VarAcceptersName == "结束") {
          ElMessage({
            message: response.data.Message,
            type: "success",
          });
          proxy.$modal.closeLoading();
        } else {
          ElMessage({
            message: response.data.Message.replaceAll("@", ""),
            type: "success",
          });
        }
        colsedialog();
        proxy.$modal.closeLoading();
        loadingWebLoad.value = false;
      } else {
        loadingWebLoad.value = false;
        colsedialog();
        proxy.$modal.closeLoading();
      }
      loadingWebLoad.value = false;
      proxy.$modal.closeLoading();
    });
  }
};

function openRetrunWork() {}

//退回
const returnWork = () => {
  let reData = {
    workid: flowDatas.value.WorkID,
    returnToNodeID: "",
    returnMsg: "",
    token: getJToken(),
  };
  node_ReturnWork().then((reData) => {
    ElMessage({
      message: "退回成功",
      type: "success",
    });
    colsedialog();
  });
};
const sendOtherOne = () => {
  // openSelectUser("0");
  dialogVisibleYiJiao.value = true;
  selectDpPersons().then((res) => {
    tableData.value = res.Emps;
  });
};
const getRowKeys = (row) => {
  return row.no;
};
//点击发送到下一步
const sendNext = () => {
  if (fujianListNew.value.length != 0) {
    for (let i = 0; i < fujianListNew.value.length; i++) {
      receiverData.value.fujianFileList.push({
        fileId: fujianListNew.value[i].response.data.fileId,
      });
    }
  }
  if (nodeShow.value) {
    if (showMessage.value == true) {
      if (formData.value.reviewMsg == "" || formData.value.reviewMsg == null) {
        ElMessageBox.alert("请填写审核意见", "提示", {
          confirmButtonText: "确定",
          type: "warning",
        });
        return;
      }
    }
  }

  formData.value.toNodeId = selNextNode.value;
  let DeliveryWay = "";
  //查看当前是选择的那个节点
  NextStepNode.value.forEach((item, index) => {
    if (item.NodeID == selNextNode.value) {
      DeliveryWay = item.DeliveryWay;
    }
  });
  // return;
  //判断当前节点是哪一个节点
  //DeliveryWay 3:绑定人员计算
  if (DeliveryWay == "3") {
    onSubmit();
  }
  //4:由发送人选择发送
  else if (DeliveryWay == "4" || DeliveryWay == "1" || DeliveryWay == "9") {
    openSelectUser("1");
    return;
  } else {
    onSubmit();
  }
};
//点击发送到下一步
const sendNext1 = () => {
  // ElMessageBox.confirm("请确认是否已经完成反馈文件上传?", "系统提示", {
  //   confirmButtonText: "是",
  //   cancelButtonText: "否",
  //   type: "warning",
  // })
  //   .then(() => {
  if (showMessage.value == true) {
    if (formData.value.reviewMsg == "" || formData.value.reviewMsg == null) {
      ElMessageBox.alert("请填写审核意见", "提示", {
        confirmButtonText: "确定",
        type: "warning",
      });
    }
  }

  if (feedback.value == true) {
    if (fileBackFile.value.length == 0 && fujianList1.value.length == 0) {
      proxy.$modal.msgError("请上传反馈文件");
      return;
    }
  }

  if (guidangData.value.typeId == null) {
    proxy.$modal.msgError("请选择归档分类");
    return;
  }
  if (guidangData.value.printNum == null) {
    proxy.$modal.msgError("请输入打印份数");
    return;
  }
  formData.value.toNodeId = selNextNode.value;
  let DeliveryWay = "";
  //查看当前是选择的那个节点
  NextStepNode.value.forEach((item, index) => {
    if (item.NodeID == selNextNode.value) {
      DeliveryWay = item.DeliveryWay;
    }
  });
  // return;
  //判断当前节点是哪一个节点
  //DeliveryWay 3:绑定人员计算
  proxy.$modal.loading("归档中，请稍后...");
  if (DeliveryWay == "3") {
    onSubmit();
  }
  //4:由发送人选择发送
  else if (DeliveryWay == "4" || DeliveryWay == "1" || DeliveryWay == "9") {
    openSelectUser("1");
    return;
  } else {
    onSubmit();
  }
  // })
  // .catch(() => {
  //   // ElMessage({
  //   //   type: "info",
  //   //   message: "Delete canceled",
  //   // });
  // });
};

defineExpose({
  showdetal2,
});
</script>
<style>
.el-dialog:not(.is-fullscreen) {
  margin-top: 2vh !important;
}
.app-container {
  padding: 20px 20px 0 20px;
}
</style>
