<!-- @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%"
    style="min-height: 88vh"
    top="2vh"
    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="17"
          style="background-color: #9ca1a7; margin-top: 10px; padding: 20px"
        >
          <iframe
            style="overflow: scroll; width: 100%; height: 100%"
            :src="pdfUrl"
            ref="iframeRef"
          ></iframe>
        </el-col> -->
        <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="17" style="margin-top: 10px; padding: 5px">
                  <!--          <PdfViewer
                  ref="pdfViewRef"
                  :key="$route.fullPath"
                  :current-page="pdfPages"
                  :src="pdfUrl"
              ></PdfViewer>-->
                  <iframe
                    class="bordered-iframe"
                    style="
                      overflow: auto;
                      width: 100%;
                      min-height: 77vh;
                      background-color: #d4d4d7;
                    "
                    :src="pdfUrl"
                    ref="iframeRef"
                  ></iframe>
                  <!-- <iframe :src="pdfUurl" frameborder="0"></iframe> -->
                </el-col>
                <el-col style="" :span="7">
                  <el-form
                    ref="receivedFormRef"
                    label-width="90px"
                    :disabled="isAllowed"
                    style="width: 22vw"
                    :rules="rules"
                    :model="receiverData"
                  >
                    <el-form-item label="紧急程度:" prop="emergencyDegree">
                      <el-select
                        style="width: 22vw"
                        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="来文标题:" prop="title">
                      <el-input
                        v-model="receiverData.title"
                        placeholder="请输入来文标题"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label="来文单位:" prop="sender">
                      <el-input
                        v-model="receiverData.sender"
                        placeholder="请输入来文单位"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label="来文日期:" prop="sendTime">
                      <el-date-picker
                        style="width: 22vw"
                        format="YYYY-MM-DD"
                        value-format="YYYY-MM-DD"
                        v-model="receiverData.sendTime"
                        type="date"
                        placeholder="请输入来文日期"
                        size="defalut"
                      />
                    </el-form-item>
                    <el-form-item label="流水号: " prop="serial">
                      <el-input
                        v-model="receiverData.serial"
                        placeholder="请输入流水号"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label="文件类型: " prop="receiveType">
                      <el-select
                        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-input
                        v-model="receiverData.documentNum"
                        placeholder="请输入文件字号"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label="原文链接:">
                      <el-link @click="uploadYFile()" 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-link
                        v-for="(item, index) in fujianList"
                        :key="index"
                        type="primary"
                        @click="openFujianFile(item.url)"
                      >
                        <el-icon class="el-icon--left">
                          <Document />
                        </el-icon>
                        {{ item.name }}
                      </el-link>
                    </el-form-item>
                    <el-form-item label="完成时限:">
                      <div style="font-size: 15px">
                        {{ closeTime }}
                      </div>
                    </el-form-item>
                  </el-form>
                  <el-form v-show="hanldType" label-width="90px">
                    <el-form-item label="下一步节点:">
                      <el-select
                        style="width: 22vw"
                        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="showMessage">
                        <el-form-item v-if="!nodeMsg" label="审核意见:">
                          <el-input
                            style="width: 22vw"
                            type="textarea"
                            :rows="4"
                            placeholder="请输入审核意见"
                            v-model="formData.reviewMsg"
                          />
                        </el-form-item>
                        <el-form-item v-else label="拟办意见:">
                          <el-input
                            type="textarea"
                            :rows="4"
                            style="width: 22vw"
                            placeholder="请输入拟办意见"
                            v-model="formData.reviewMsg"
                          />
                        </el-form-item>
                      </div>

                      <div
                        style="
                          text-align: center;
                          align-items: center;
                          width: 22vw;
                        "
                        label-width="0"
                        label=""
                      >
                        <el-button
                          :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
                          v-if="nodeInfo"
                          @click="notApproved"
                          type="warning"
                          >不予审批
                        </el-button> -->
                      </div>
                    </div>
                    <!--   归档操作       -->
                    <div v-show="guidangBt || guidangNext">
                      <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> -->

                        <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: 22vw"
                          :disable="guidangNext"
                          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
                          :disable="guidangNext"
                          placeholder="请输入打印份数"
                          v-model="guidangData.printNum"
                        ></el-input>
                      </el-form-item>
                      <el-form-item label="密级：">
                        <el-select
                          :disable="guidangNext"
                          style="width: 22vw"
                          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="责任领导:" prop="hostLeader">
                        <el-input
                          :disable="guidangNext"
                          v-model="guidangData.hostLeader"
                          placeholder="请输入责任领导"
                        ></el-input>
                      </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="110"
                    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.ActionType22 != undefined">
                        <div v-for="item in scope.row.ActionType22" :key="item">
                          <!-- <div></div> -->
                          <div>{{ item.Msg }}</div>
                        </div>
                      </div>
                      <div v-else>
                        <div v-if="scope.row.ActionTypeText == '退回'">
                          退回原因：{{ scope.row.Msg }}
                        </div>
                        <div v-if="scope.row.ActionTypeText == '移交'">
                          移交原因：{{ scope.row.Msg }}
                        </div>
                      </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"
      @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 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
        style="height: 34.4vh"
        ref="multipleTable1"
        :data="tableData"
        :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="dialogVisibleYiJiao = false">取消</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="dialogApproved = false">取 消</el-button>
      <el-button type="primary" @click="submitNotApproved">确 定</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";
import { Base64 } from "js-base64";
const { that, proxy } = getCurrentInstance();
import { onMounted, reactive, ref, nextTick } from "vue";
import { updateReceive } from "@/api/office/received";
import { useRoute, useRouter } from "vue-router";
import {
  generNextStepNode,
  generNextStepAllNode,
  judgeNode,
  receive,
  NodeShift,
  sendFlowToNext,
  node_ReturnWork,
  selectDpPersons,
  getWfGenerWorkList,
} 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 incomingMessage from "@/views/incomingMessages/jijian.vue";

import Cookies from "js-cookie";

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

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 fullscreen = ref(true);
const yjOpinion = ref("");
const nodeInfo = ref(true);
const nodeMsg = ref(false);
const fileBackFile = ref([]);
const nowNode = ref(true);
const visible = ref(false);
const isAllowed = ref(true);
const liuzhuanData = ref([]);
const dialogApproved = ref(false);
const dialogVisibleYiJiao = ref(false);
const { urgent_type } = proxy.useDict("urgent_type");
const yijiaoBtn = ref(false);
const nodeValue = ref(null);
const closeTime = ref(null);
const returnMsg = ref(null);
const dialogBack = ref(false);
const nodeData = ref([]);
const valDate = ref(null);
const tableData = ref([]);
const guidangNext = ref(false);

const showMessage = ref(true);
const loadingWebLoad = ref(false);
let pdfDoc = null;
const pdfPages = ref(0);
const sendDownFile = ref([]);
// const incoming = ref("/incomingMessages");
const NextStepNode = ref([]);
const fujianList = ref([]);
const userNames = ref([]);
const dialogTitle = ref("收文");
const hanldType = ref(false);
const guidangBt = ref(false);
const ybjState = ref(false);
const isEndNodeFlg = ref(false);
const selUserNames = ref("");
const tuurl = ref("");
const selNextNode = ref("");
const typeList = ref([]);
const receiverData = ref({});
//可退回的节点
const reWorkNode = ref({});

/** 查询归档类型列表 */
function getTypeList() {
  listType({}).then((response) => {
    typeList.value = proxy.handleTree(
      response.data,
      "archiveTypeId",
      "parentId"
    );
  });
}

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 openYbj() {
  ybjState.value = true;
}
function notApproved() {
  dialogApproved.value = true;
  formData.value.reviewMsg = "";
}
function closeSelUser() {}
function getLiuzhuanData() {
  getWfGenerWorkList(getJToken(), formData.value.workid).then((res) => {
    liuzhuanData.value = res.trackList;
  });
}
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"
  );
}
/** 表单重置 */
function reset() {
  formData.value = {
    reviewMsg: null,
    optionName: null,
    toNodeId: null,
    users: null,
    workid: null,
  };
  NextStepNode.value = [];
  flowDatas.value = [];
  selNextNode.value = "";
  selUserNames.value = "";
  fujianList.value = [];
  sendDownFile.value = [];
}
function submitNotApproved() {
  proxy.$modal.loading();
  if (formData.value.reviewMsg == "") {
    proxy.$message.error("请输入不予审批原因");
    return;
  }

  formData.value.toNodeId = 1206;
  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();
  });
}
async function submitNodeBack() {
  if (nodeValue.value == null) {
    proxy.$message.error("请选择退回节点信息");
    return;
  }
  if (returnMsg.value == null) {
    proxy.$message.error("请输入退回原因");
    return;
  }
  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;
  colsedialog();
}
const setSelectRows = (selection) => {
  if (selection.length > 1) {
    const del_row = selection.shift();
    proxy.$refs.multipleTable1.toggleRowSelection(del_row, false); //设置这一行取消选中
  }
};
const handleSelectionChange = (selection) => {
  // userNames.value = selection[0].no;
  userNames.value = selection.map((item) => item.no).join(",");
};
//移交
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 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).then(
        () => {
          ElMessage({
            message: response.msg,
            type: "success",
          });
          proxy.$modal.closeLoading();
          colsedialog();
        }
      );
    });
    proxy.$modal.closeLoading();
    yjOpinion.value = "";
  }
}
// 点击表头的全选复选框触发
const selectAll = (selection) => {
  proxy.$modal.msgError("移交人员只能选一个！");
  proxy.$refs.multipleTable1.clearSelection();
  return;
};
function sendBack() {
  dialogBack.value = true;
  returnWorkNode();
}

//获取退回界定啊
async function returnWorkNode() {
  let nData = await getReturnWorkNode(getJToken(), formData.value.workid);
  nodeData.value = nData;
}

const dcolse = (done) => {
  pdfPages.value = 0;
  pdfUrl.value = "";
  sendDownFile.value = [];
  fujianList.value = [];
  receivedFormRef.value = false;
  loadingWebLoad.value = false;
  emit("guanbi");
  done();
};
const colsedialog = () => {
  pdfPages.value = 0;
  pdfUrl.value = "";
  sendDownFile.value = [];
  fujianList.value = [];
  receivedFormRef.value = false;
  visible.value = false;
  loadingWebLoad.value = false;
  reset();
  emit("guanbi");
};
const sendOtherOne = () => {
  // openSelectUser("0");
  dialogVisibleYiJiao.value = true;
  selectDpPersons().then((res) => {
    tableData.value = res.Emps;
  });
};
const getRowKeys = (row) => {
  return row.no;
};
/** 查询参数列表 */
function show(recdata, flowData, type) {
  nodeInfo.value = true;
  showMessage.value = true;
  nodeMsg.value = false;
  fileBackFile.value = [];
  if (flowData.FK_Node == "1204") {
    showMessage.value = false;
  }
  if (
    flowData.FK_Node == "1201" ||
    flowData.FK_Node == "1204" ||
    flowData.FK_Node == "1206" ||
    flowData.FK_Node == "1208"
  ) {
    nodeInfo.value = false;
  }
  if (flowData.FK_Node == "1208") {
    yijiaoBtn.value = true;
  }
  if (flowData.FK_Node == "1204") {
    showMessage.value = true;
  }
  if (flowData.FK_Node == "1202") {
    nodeMsg.value = true;
  }
  if (flowData.FK_Node == "1207") {
    guidangNext.value = true;
  }
  visible.value = true;
  if (recdata.sendFile != null) {
    var url = recdata.sendFile.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);
  }
  closeTime.value = recdata.closeTime;
  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,
    //   });
    // }
  }
  receiverData.value = recdata;
  hanldType.value = type;
  formData.value.workid = flowData.WorkID;
  formData.value.optionName = flowData.NodeName;
  flowDatas.value = flowData;
  console.log("receiverData", receiverData.value);
  getLiuzhuanData();
  dialogTitle.value = flowData.NodeName;
  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) => {
    if (nres.msg == "Y") {
      NextStepNode.value.push({ NodeID: 0, Name: "结束" });
      selNextNode.value = NextStepNode.value[0].NodeID;
      isEndNodeFlg.value = true;
    } else {
      //获取下个节点.
      generNextStepAllNode(
        flowDatas.value.FK_Flow,
        flowDatas.value.WorkID,
        "",
        getJToken()
      ).then((res) => {
        NextStepNode.value = res;
        selNextNode.value = NextStepNode.value[0].NodeID;
      });
    }
  });

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

/** 选择用户后进行下一步 */
function handleQuery(selUsers) {
  formData.value.users = selUsers;
  if (selUsers != undefined && selUsers != "") {
    onSubmit();
  }
}

function openFujianFile(url) {
  window.open(url, "_blank");
}

const openSW = () => {};

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

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

  if (guidangBt.value) {
    guidangData.value.archiveFormNo = flowDatas.value.FK_Flow;
    guidangData.value.workId = flowDatas.value.WorkID;
    let { archiveRes } = await saveArchive(guidangData.value);
    updateReceive({
      id: receiverData.value.id,
      hostLeader: guidangData.value.hostLeader,
    });
  }
  //如果市最后一个节点则执行 完成
  if (isEndNodeFlg.value) {
    generNextStepAllNode(
      flowDatas.value.FK_Flow,
      flowDatas.value.WorkID,
      "",
      getJToken()
    ).then((res) => {
      ElMessage({
        message: "当前工作已结束",
        type: "success",
      });
      proxy.$modal.closeLoading();
      colsedialog();
    });
  } else {
    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",
          });
          proxy.$modal.closeLoading();
        }
        colsedialog();
        proxy.$modal.closeLoading();
        loadingWebLoad.value = false;
      } else {
        proxy.$modal.closeLoading();
        loadingWebLoad.value = false;
        colsedialog();
      }
      proxy.$modal.closeLoading();
      loadingWebLoad.value = false;
    });
  }
};

function openRetrunWork() {}

//退回
const returnWork = () => {
  let reData = {
    workid: flowDatas.value.WorkID,
    returnToNodeID: "",
    returnMsg: "",
    token: getJToken(),
  };
  node_ReturnWork().then((reData) => {
    ElMessage({
      message: "退回成功",
      type: "success",
    });
    colsedialog();
  });
};

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

  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) => {
    //console.log(item);
    if (item.NodeID == selNextNode.value) {
      DeliveryWay = item.DeliveryWay;
    }
  });
  // return;
  // //console.log(selNextNode.value)
  //判断当前节点是哪一个节点
  //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({
  show,
});
</script>
<style>
.el-dialog:not(.is-fullscreen) {
  margin-top: 2vh !important;
}
iframe {
  border: none; /* 移除默认边框 */
}

.bordered-iframe {
  border: 2px solid #898989; /* 设置自定义边框宽度为2px，颜色为红色 */
  box-sizing: border-box; /* 防止内边距和边框改变元素的总宽度和高度 */
}
</style>
