<!-- @format -->

<template>
  <div class="app-container">
    <el-row>
      <el-col :span="24">
        <!--        <el-button
                      :loading="openFileState"
                      @click="openLocalFile()"
                      type="primary" >打开本地文档
                  </el-button>-->
        <!--        <el-button
                      :loading="openFileState"
                      @click="openLocalFile()"
                      type="primary" >打印预览
                  </el-button>   -->
        <!--        <el-button
                      @click="closePage(0)"
                      type="primary" >隐藏页面
                  </el-button>
                  <el-button
                      @click="closePage(1)"
                      type="primary" >打开
                  </el-button>-->

        <!-- </el-col>
        <el-col :span="6"> -->
        <el-tabs type="border-card" class="demo-tabs">
          <el-tab-pane label="基本信息">
            <template #label>
              <span @click="openjbxx" class="custom-tabs-label">
                <el-icon>
                  <Document />
                </el-icon>
                <span>基本信息</span>
              </span>
            </template>
            <el-row :gutter="24">
              <el-col
                :span="18"
                style="
                  min-height: 86vh;
                  background-color: #9ca1a7;
                  margin-top: 10px;
                  padding: 5px;
                "
              >
                <div style="height: 88vh" id="WebOffice2015"></div>
              </el-col>
              <el-col :span="6">
                <div
                  style="
                    border: 1px solid #9ca1a7;
                    padding: 25px 30px 10px 0px;
                    height: 85.5vh;
                    overflow: auto;
                    border-radius: 5px;
                    margin-top: 10px;
                  "
                >
                  <el-form
                    ref="outMessageFormRef"
                    label-width="90px"
                    style="width: 20vw; margin-left: 15px; margin-top: 15px"
                    :rules="rules"
                    :disabled="isAllowed"
                    :model="ywJournalPublishParams"
                  >
                    <el-form-item label="投稿人处室:" prop="deptName">
                      <el-input
                        disabled
                        v-model="ywJournalPublishParams.deptName"
                        placeholder="请输入投稿人处室"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label="投稿人姓名:" prop="userName">
                      <el-input
                        disabled
                        v-model="ywJournalPublishParams.userName"
                        placeholder=" 请输入投稿人姓名"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label="论文名称:" prop="paperName">
                      <el-input
                        v-model="ywJournalPublishParams.paperName"
                        placeholder="请输入论文名称"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label="期刊级别:" prop="journalLevel">
                      <el-input
                        v-model="ywJournalPublishParams.journalLevel"
                        placeholder="请输入期刊级别"
                      ></el-input>
                    </el-form-item>
                    <el-form-item
                      label="发表期刊的年、卷、期:"
                      prop="journalNumber"
                    >
                      <el-input
                        style="margin: 15px 0"
                        v-model="ywJournalPublishParams.journalNumber"
                        placeholder="请输入发表期刊的年、卷、期"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label="版面费金额:" prop="layoutFees">
                      <el-input
                        v-model="ywJournalPublishParams.layoutFees"
                        placeholder="请输入版面费金额"
                        :formatter="
                          (value) =>
                            `${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
                        "
                        :parser="(value) => value.replace(/\$\s?|(,*)/g, '')"
                        ><template #append>元</template></el-input
                      >
                    </el-form-item>
                    <el-form-item
                      label="报销金额:"
                      prop="eliminateMoney"
                      v-show="!bxFlg"
                    >
                      <el-input
                        v-model="ywJournalPublishParams.eliminateMoney"
                        placeholder="请输入报销金额"
                        :formatter="
                          (value) =>
                            `${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
                        "
                        :parser="(value) => value.replace(/\$\s?|(,*)/g, '')"
                        ><template #append>元</template></el-input
                      >
                    </el-form-item>
                    <el-form-item label="登记日期:" prop="registrationDate">
                      <el-date-picker
                        style="width: 20vw"
                        format="YYYY-MM-DD"
                        value-format="YYYY-MM-DD"
                        v-model="ywJournalPublishParams.registrationDate"
                        type="date"
                        placeholder="请选择登记日期"
                        size="defalut"
                      />
                    </el-form-item>
                    <el-form-item label="附件列表:">
                      <el-link
                        v-for="(item, index) in fujianList"
                        :key="index"
                        type="primary"
                        @click="openFujianFile(item.url, item.name)"
                      >
                        <el-icon class="el-icon--left">
                          <Document />
                        </el-icon>
                        {{ item.name }}
                      </el-link>
                    </el-form-item>
                  </el-form>

                  <el-form
                    v-show="hanldType"
                    label-width="90px"
                    style="width: 300px; margin-left: 25px"
                  >
                    <el-form-item label="下一步节点: ">
                      <el-select
                        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>
                    <el-form-item
                      label="报销金额:"
                      prop="eliminateMoney"
                      v-show="bxFlg"
                    >
                      <el-input
                        v-model="ywJournalPublishParams.eliminateMoney"
                        placeholder="请输入报销金额"
                        :formatter="
                          (value) =>
                            `${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
                        "
                        :parser="(value) => value.replace(/\$\s?|(,*)/g, '')"
                        ><template #append>元</template></el-input
                      >
                    </el-form-item>
                    <!--  发送到下一步操作         -->
                    <div v-show="guidangBt != true">
                      <el-form-item label="审核意见: ">
                        <el-input
                          type="textarea"
                          :rows="2"
                          placeholder="请输入审核意见"
                          v-model="formData.reviewMsg"
                        ></el-input>
                      </el-form-item>
                      <el-form-item label=" ">
                        <el-button
                          :loading="loadingWebLoad"
                          :disabled="false"
                          @click="sendNext"
                          type="primary"
                          >提交
                        </el-button>
                        <el-button
                          v-if="showBack"
                          @click="sendBack"
                          type="danger"
                          >退回
                        </el-button>
                      </el-form-item>
                    </div>
                    <!--   归档操作       -->
                    <div v-show="guidangBt">
                      <!-- <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
                          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
                        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="sendNext"
                          type="primary"
                          >归档
                        </el-button>
                      </el-form-item>
                    </div>
                  </el-form>
                </div>
              </el-col>
            </el-row>
          </el-tab-pane>
          <el-tab-pane label="流转记录">
            <template #label>
              <span @click="openlzjl" 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="200"
                  type="index"
                >
                </el-table-column>
                <el-table-column
                  align="center"
                  prop="NDFromT"
                  label="	节点名称"
                  width="220"
                >
                </el-table-column>
                <el-table-column
                  align="center"
                  width="200"
                  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 @click="opendjb" class="custom-tabs-label">
                <el-icon>
                  <SetUp />
                </el-icon>
                <span>发表学术论文审批登记表</span>
              </span> </template
            ><a @click="openYbj">发表学术论文审批登记表</a>
          </el-tab-pane>
        </el-tabs>
      </el-col>
    </el-row>
    <select-user
      ref="selectRef"
      @ok="handleQuery"
      @closeDialogf="closePage"
    ></select-user>
    <!-- 退回 -->
    <el-dialog
      title="退回"
      v-model="dialogBack"
      width="40%"
      @close="closePage(1)"
    >
      <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="onSubmit">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog
      title="审批登记表"
      v-model="ybjState"
      :before-close="openOfficePage"
    >
      <signPaperApproval
        ref="incomRef"
        :id="ywJournalPublishParams.id"
      ></signPaperApproval>
    </el-dialog>
  </div>
</template>

<script setup>
import selectUser from "../../selectUser";
import { ref, reactive, onMounted, onBeforeUnmount } from "vue";
import Cookies from "js-cookie";
import { detectOS, initOffice } from "@/static/webOffice/KingiWebOffice2015";

import WebOffice2015 from "@/static/webOffice/WebOffice";
import signPaperApproval from "@/views/flows/signPaperApproval";

import {
  getRequest,
  GetUrlbase,
  getUrlParameter,
} from "../../../official/hookFunction";
import {
  generNextStepNode1,
  sendFlowToNext1,
  getWfGenerWorkList,
  CurrNodeInfo,
} from "@/api/liucheng";
import {
  leave,
  getLeave,
  getReturnWorkNode,
  WorkProgressBar,
  NodeReturnWork,
} from "@/api/clocking/leave";
import { getPublishByWorkId, updatePublish } from "@/api/office/publish";
import { uploadFile, base64toBlob } from "@/api/system/oafile";
import { saveArchive } from "@/api/archive/archive";
import { ElMessage, ElMessageBox } from "element-plus";
import { getJToken, getToken } from "@/utils/auth";
import { getInfo } from "@/api/login";
import { listType } from "@/api/archive/type";

const { proxy } = getCurrentInstance();

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

const nodeValue = ref(null);
const returnMsg = ref(null);
const dialogBack = ref(false);
const bxFlg = ref(false);
const nodeData = ref([]);
const valDate = ref(null);
const fujianList = ref([]);
const liuzhuanData = ref([]);
const hanldType = ref(true);
const dangansel = ref(false);
const nType = ref(0);
const mkdir = ref("");
const iWebOfficeDom = ref(null); //获取他的dom
const openFileState = ref(false);
const loadingWebLoad = ref(false);
const isAllowed = ref(true);
const showBack = ref(true);
const outMessageFormRef = ref(false);
const guidangBt = ref(false);
const receivedData = ref(null);
const workId = ref(null);
const ybjState = ref(false);
const NextStepNode = ref([]);
const flowDatas = ref({});
const selNextNode = ref("");
const typeList = ref([]);
const tuurl = ref("");
const msgValue = ref(true);
const szFileName = ref("");
const baseUrl = ref(import.meta.env.VITE_APP_BASE_API);
const urgentDict = ref([]);
const docFile = ref({});
const dialogApproved = ref(false);
const uuid = ref(null);
function openYbj() {
  ybjState.value = true;
}
const data = reactive({
  ywJournalPublishParams: {
    userId: null,
    paperName: "",

    journalLevel: "",
    journalNumber: "",
    layoutFees: "",
    registrationDate: "",
    eliminateTime: "",
    eliminateMoney: "",
    sendFileId: "",
    params: {},
  },
  formData: {
    reviewMsg: "同意",
    optionName: null,
    toNodeId: null,
    users: null,
    workid: null,
  },
  guidangData: {
    archiveNo: null,
    workId: null,
    archiveFormNo: null,
    printNum: null,
    levels: null,
    typeId: null,
    name: null,
  },
});

const { formData, guidangData, ywJournalPublishParams } = toRefs(data);
const webOfficeOBJ = ref({
  UserName: "",
});
const upload = reactive({
  // 设置上传的请求头部
  headers: { Authorization: "Bearer " + getToken() },
  // 上传的地址
  url: import.meta.env.VITE_APP_BASE_API + "/system/file/fileupload",
});
const props = defineProps({
  paperQiLinData: null,
  hanldType: null,
});
let requestParams = getRequest(); //获取当前url地址
let WebOffice;
const onSubmit = (formEl) => {
  closePage(0);
  saveOffice2Web();
};
function openlzjl() {
  let cloState = webOfficeOBJ.value.WebClose();
}
function opendjb() {
  let cloState = webOfficeOBJ.value.WebClose();
}
function openjbxx() {
  proxy.$nextTick(() => {
    WebDownLoadFile();
  });
}
function getLiuzhuanData() {
  getWfGenerWorkList(getJToken(), formData.value.workid).then((res) => {
    liuzhuanData.value = res.trackList;
  });
}
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();
  webOfficeOBJ.value.CloseDocument();
}

function openOfficePage() {
  ybjState.value = false;
}

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

async function reSendFlowToNext() {
  if (dialogBack.value) {
    submitNodeBack();
  } else {
    if (guidangBt.value) {
      guidangData.value.archiveFormNo = flowDatas.value.FK_Flow;
      guidangData.value.workId = workId.value;
      let { archiveRes } = await saveArchive(guidangData.value);
    }
    sendFlowToNext1(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.$emit("closeViewLeave");
        } else if (response.data.VarAcceptersName == "结束") {
          ElMessage({
            message: response.data.Message,
            type: "success",
          });
          proxy.$emit("closeViewLeave");
        } else {
          ElMessage({
            message: response.data.Message.replaceAll("@", ""),
            type: "success",
          });
        }
        proxy.$emit("closeViewLeave");
        proxy.$modal.closeLoading();
      } else {
        proxy.$modal.msgError("发送失败");
        proxy.$emit("closeViewLeave");
      }
    });
  }
}

/** 选择用户后进行下一步 */
function VBAShowRevisions(flg) {
  webOfficeOBJ.value.VBAShowRevisions(flg);
}
/** 查询归档类型列表 */
function getTypeList() {
  listType({}).then((response) => {
    typeList.value = proxy.handleTree(
      response.data,
      "archiveTypeId",
      "parentId"
    );
  });
}
function colsedialog() {
  this.$emit("guanbi");
  fujianList.value = [];
}

function handleQuery(selUsers) {
  formData.value.users = selUsers;
  if (selUsers != undefined && selUsers != "") {
    onSubmit();
  }
}

/** 表单重置 */
function reset() {
  formData.value = {
    reviewMsg: null,
    optionName: null,
    toNodeId: null,
    users: null,
    workid: null,
  };
  fujianList.value = [];
  NextStepNode.value = [];
  flowDatas.value = {};
  selNextNode.value = "";
}
function notApproved() {
  dialogApproved.value = true;
  closePage(0);
}
//点击发送到下一步
const sendNext = () => {
  if (formData.value.reviewMsg == "" || formData.value.reviewMsg == null) {
    closePage(0);
    ElMessageBox.alert("请填写审核意见", "提示", {
      confirmButtonText: "确定",
      type: "warning",
      callback: (action) => {
        closePage(1);
      },
    });
    return;
  }
  if (
    (ywJournalPublishParams.value.eliminateMoney == "" ||
      ywJournalPublishParams.value.eliminateMoney == null) &&
    bxFlg.value
  ) {
    closePage(0);
    ElMessageBox.alert("请填写报销金额", "提示", {
      confirmButtonText: "确定",
      type: "warning",
      callback: (action) => {
        closePage(1);
      },
    });
    return;
  }
  formData.value.toNodeId = selNextNode.value;
  let DeliveryWay = "";
  //查看当前是选择的那个节点
  NextStepNode.value.forEach((item, index) => {
    if (item.NodeID == selNextNode.value) {
      DeliveryWay = item.DeliveryWay;
    }
  });

  //判断当前节点是哪一个节点
  //DeliveryWay 3:绑定人员计算
  if (DeliveryWay == "3") {
    onSubmit();
  }
  //4:由发送人选择发送
  else if (DeliveryWay == "4" || DeliveryWay == "1" || DeliveryWay == "9") {
    openSelectUser();
    return;
  } else {
    onSubmit();
  }
};
async function openFujianFile(url, name) {
  const files = await proxy.$download.downloadUrlFile(url, name);
  proxy.$download.saveAs(
    new Blob([files], { type: "text/plain;charset=UTF-8" }),
    name
  );
  // window.open(url, "_blank");
}
/** 打开授权用户表弹窗 */
function openSelectUser() {
  //   webOfficeOBJ.value.obj.HidePlugin(0);
  flowDatas.value.toNodeId = selNextNode.value;
  proxy.$refs["selectRef"].show1(flowDatas.value);
}

async function saveOffice2Web() {
  proxy.$modal.loading("正在提交中，请稍候...");

  //保存文件到本地
  var FileName = "/tmp/" + Math.round(Math.random() * 100000000) + ".doc";
  webOfficeOBJ.value.saveAs(FileName);
  var httpclient = webOfficeOBJ.value.Http;
  httpclient.SetRequestHeader("Authorization", "Bearer " + getToken());
  httpclient.AddFile("file", FileName);
  let baseurl = window.location.href.split("/")[2];
  if (httpclient.Open(1, "http://" + baseurl + upload.url, false)) {
    if (httpclient.Send()) {
      if (httpclient.Status == 200) {
        // alert(httpclient.ResponseText);
        var res = JSON.parse(httpclient.ResponseText);

        if (res.code == 200) {
          //设置修订痕迹记录用户

          //   webOfficeOBJ.value.VBASetUserName(webOfficeOBJ.value.UserName);
          ywJournalPublishParams.value.sendFileId = res.data.fileId;
          loadingWebLoad.value = true;
          updatePublish(ywJournalPublishParams.value).then((response) => {
            if (response.code == 200) {
              loadingWebLoad.value = false;
              // proxy.$modal.msgSuccess("提交成功");
              reSendFlowToNext();
              webOfficeOBJ.value.CloseDocument();
              proxy.$emit("closeViewLeave");
              proxy.$modal.closeLoading();
            } else {
              proxy.$modal.closeLoading();
              proxy.$modal.msgError("提交失败");
              webOfficeOBJ.value.CloseDocument();
              proxy.$emit("closeViewLeave");
            }
          });
        } else {
          proxy.$modal.closeLoading();
          proxy.$modal.msgError("保存文档到服务器失败");
          webOfficeOBJ.value.CloseDocument();
          proxy.$emit("closeViewLeave");
          return false;
        }
      }
    }
    httpclient.Close();
  }
}

const handlePreview = () => {};
const handleRemove = () => {};

function Load() {
  fujianList.value = [];
  getPublishByWorkId(flowDatas.value.WorkID).then((response) => {
    if (response.code == "200") {
      ywJournalPublishParams.value = response.data;
      var resfiles = response.data.fujianFileList;
      for (let i = 0; i < resfiles.length; i++) {
        fujianList.value.push(resfiles[i]);
      }
      docFile.value = response.data.sendFile;
      WebDownLoadFile();
    }
  });
  showBack.value = true;
  flowDatas.value.FK_Node = formData.value.FK_Node;
  CurrNodeInfo(getToken(), flowDatas.value.FK_Node).then((res) => {
    if (res[0].ReturnRole == 0) {
      showBack.value = false;
    } else {
      showBack.value = true;
    }
  });
  if (flowDatas.value.FK_Node == "803") {
    bxFlg.value = true;
  }
  //chrome浏览器，HookEnabled设置为true，用于控件中和本地excel表格的焦点互相切换

  loadingWebLoad.value = false;
}
//作用：打开远程文件
function WebDownLoadFile() {
  loadingWebLoad.value = false;
  //   if (document.getElementById("WebOfficeId") != null) {
  webOfficeOBJ.value = document.getElementById("WebOffice");
  getInfo().then((res) => {
    webOfficeOBJ.value.UserName = res.user.nickName;
    try {
      var OSType = detectOS();
      if (OSType.indexOf("Win") > -1) {
        return false;
      }

      var strFileType = ".doc";
      //alert(strFileType);

      if (strFileType == ".doc" || strFileType == ".docx") {
        nType.value = 1; //WPS文字编辑软件
        //nType = 14;    //永中Office文字编辑软件
      } else if (strFileType == ".xls" || strFileType == ".xlsx") {
        nType.value = 12; //WPS文字编辑软件

        //nType = 15;    //永中Office文字编辑软件
      } else if (strFileType == ".wps") {
        nType.value = 1;
      } else if (strFileType == ".et") {
        nType.value = 12;
      } else if (strFileType == ".ppt" || strFileType == ".pptx") {
        nType.value = 13; //WPS文字编辑软件

        //nType = 16;    //永中Office文字编辑软件
      } else if (strFileType == ".ofd") {
        nType.value = 3; //数科ofd阅读器
      }

      webOfficeOBJ.value.setPluginType(nType.value); //设置信创中间件加载文字编辑软件
      //alert("weburl");
      //以下属性必须设置，实始化iWebOffice
      webOfficeOBJ.value.FileName = Math.random() * 100000 + "Mytemplate.doc";
      webOfficeOBJ.value.ShowWindow = false; //显示/隐藏进度条
      webOfficeOBJ.value.EditType = "2"; //设置加载文档类型 0 锁定文档，1无痕迹模式，2带痕迹模式
      mkdir.value = "/media/greatwall/D盘/iweboffice/file/";
      var mkd = webOfficeOBJ.value.WebMkDirectory(mkdir.value); //创建临时目录用于控件下载文档到此目录

      if (mkd) {
        webOfficeOBJ.value.WebSetTmpPath(mkdir.value); //设置控件下载文档到本地的临时目录
      }

      webOfficeOBJ.value.MaxFileSize = 4 * 1024; //最大的文档大小控制，默认是8M，现在设置成4M。
      // var ret = webOfficeOBJ.value.CreateFile();
      proxy.$modal.closeLoading();
      var urlFile = ywJournalPublishParams.value.sendFile.url;
      var mResult = webOfficeOBJ.value.WebDownLoadFile(
        urlFile,
        "/tmp/test.doc"
      );
      szFileName.value = "/tmp/test.doc";

      if (mResult) {
        webOfficeOBJ.value.WebOpenLocalFile("/tmp/test.doc");
        //alert("成功");
      } else {
        //alert("失败");
      }
    } catch (e) {
      proxy.$modal.closeLoading();
    }
  });
}
function onCloseBtnClicked() {}

const onCloseBtnClicked1 = () => {};

function closePage(numf) {
  if (numf == undefined) {
    return;
  }
}

//获取所有可退回的节点
const allreturnWork = () => {
  getReturnWorkNode().then((reData) => {
    reWorkNode.value = reData;
  });
};
//退回
const returnWork = () => {
  let reData = {
    workid: flowDatas.value.WorkID,
    returnToNodeID: "",
    returnMsg: "",
    token: getJToken(),
  };
  node_ReturnWork().then((reData) => {
    ElMessage({
      message: "退回成功",
      type: "success",
    });
    colsedialog();
  });
};
function OnReady() {
  //获取iWebOffice2015控件对象，WebOffice.FuncExtModule是iWebOffice2015控件扩展接口对象
  //   WebOffice = document.getElementById("WebOffice2015");
  //   webOfficeOBJ.value = new WebOffice2015();
  //   webOfficeOBJ.value.setObj(WebOffice);

  //修改页面title
  hanldType.value = props.hanldType;
  formData.value = props.paperQiLinData;
  formData.value.workid = formData.value.WorkID;
  flowDatas.value.WorkID = formData.value.WorkID;
  flowDatas.value.FK_Node = formData.value.FK_Node;
  flowDatas.value.FK_Flow = formData.value.FK_Flow;
  formData.value.optionName = formData.value.NodeName;
  getLiuzhuanData();
  if (
    formData.value.optionName == "归档打印" ||
    formData.value.optionName == "赋文号归档" ||
    formData.value.optionName.indexOf("归档打印") != -1
  ) {
    getTypeList();
    formData.value.reviewMsg = "归档";
    guidangBt.value = true;
  }

  //是否展示 发送下一步
  // hanldType.value = getUrlParameter("hanldType") == "true";
  //console.log(hanldType.value)
  //档案查看
  //   dangansel.value = getUrlParameter("dangan") == "true";
  //console.log(formData.value);
  //获取下个节点
  generNextStepNode1(
    flowDatas.value.FK_Flow,
    flowDatas.value.WorkID,
    "",
    getJToken()
  ).then((res) => {
    if (res.msg == "Y") {
      NextStepNode.value.push({ NodeID: 0, Name: "结束" });
    } else {
      NextStepNode.value = res.data;
    }
    selNextNode.value = NextStepNode.value[0].NodeID;
  });
  loadingWebLoad.value = true;
  proxy.$modal.loading("正在打开中...");
  //获取iWebOffice2015控件对象，WebOffice.FuncExtModule是iWebOffice2015控件扩展接口对象
  //加载dom元素，获取 weboffice对象
  initOffice(document);
  setTimeout(function () {
    Load();
  }, 1000); //需要做一个延时，iWebOffice2015才能获取FuncExtModule扩展接口对象
}

onMounted(async () => {
  OnReady();
  window.addEventListener("beforeunload", beforeUnloadListener());
});

onBeforeUnmount(() => {
  window.removeEventListener("beforeunload", beforeUnloadListener());
});

function beforeUnloadListener() {
  // setCloseTabItemAs()
  // alert("111")
}
defineExpose({
  OnReady,
});
</script>

<style lang="scss" scoped>
.iWebOfficeDom {
  height: 950px;
}
::v-deep .el-dialog__body {
  padding: 0px 20px !important;
}
</style>
