<template>
  <div>
    <div v-if="tableData.length != 0" style="margin-top: 10px">
      <div id="hover">
        <div
          v-for="item in tableData"
          :key="item"
          style="display: flex; padding: 7px 0px 7px 7px; width: 26vw"
        >
          <div style="width: 40px">
            <el-tag type="danger" size="small" v-if="item.WFState == 5"
              >退回
            </el-tag>
            <el-tag size="small" v-else-if="item.WFState == 6">移交</el-tag>
            <el-tag size="small" v-else-if="item.IsRead == '0'">未读</el-tag>
            <el-tag size="small" type="success" v-else class="ml-2"
              >已读</el-tag
            >
          </div>

          <div style="display: inline-block; margin-left: 5px">
            <div
              @click="openPdfViewer(item)"
              id="titleHover"
              style="
                font-size: 15px;
                width: 15vw;
                overflow: hidden;
                white-space: nowrap;
                cursor: pointer;
              "
            >
              <span>
                <span v-if="item.FlowName == '收文-急件'"
                  ><img
                    style="width: 18px; vertical-align: middle"
                    src="@/assets/images/ji.png"
                    alt=""
                /></span>
                <span v-if="item.isZhuBan == 'Y'">
                  <img
                    style="width: 16px; vertical-align: middle"
                    src="@/assets/images/yiban.png"
                    alt=""
                  />
                </span>
                <span style="margin-left: 5px">
                  <!-- 添加左边距以分隔图标和文本 -->
                  {{ item.Title }}
                </span>
              </span>
            </div>
            <div
              style="
                color: #8e959c;
                font-size: 14px;
                margin-top: 12px;
                display: flex;
                justify-content: space-between;
                width: 24vw;
              "
            >
              <div style="width: 80px">
                {{ item.FlowName }}
              </div>
              <div style="width: 130px">
                {{ item.NodeName }}
              </div>
              <div style="width: 150px; margin-top: 2px">
                {{ parseTime(item.SDTOfNode, "{y}-{m}-{d} {h}:{i}") }}
              </div>
            </div>
          </div>
          <div>
            <!-- <div
              style="
                display: flex;
                position: absolute;
                right: 0;
                width: 70px;
                vertical-align: middle;
                height: 20px;
                line-height: 20px;
              "
            >
              <span
                style="
                  font-size: 14px;
                  display: inline-block;
                  /* height: 40px; */
                  width: 58px;
                  /* line-height: 40px; */
                "
                >{{ item.NodeName }}</span
              >
            </div> -->
          </div>
        </div>
      </div>
    </div>
    <div style="margin-top: 5vh" v-else>
      <el-empty :image="emptyImage" />
    </div>
    <el-dialog width="86%" title="信息审核" v-model="approvalDialog">
      <Infoarticle
        :showcolumn="showcolumn"
        :FK_Flow="FK_Flow"
        :nodeName="nodeName"
        @closeViewLeave="closeViewLeave"
        :WorkId1="WorkId1"
        :fldata="fldata"
        :FKNode1="FKNode1"
      ></Infoarticle>
    </el-dialog>

    <sw-view-pdf
      ref="importRef1"
      @guanbi="handleQuery"
      :receiverData1="receiverData1"
    >
    </sw-view-pdf>
    <qtsw-view-pdf
      ref="importRef"
      @guanbi="handleQuery"
      :receiverData="receiverData"
    />
    <el-dialog width="80%" title="请假审批" v-model="leaveDialog">
      <leaveApplication
        ref="child"
        :showTable="showTable"
        :WorkId="WorkId"
        :xiaojia="xiaojia"
        :FK_Flow="FK_Flow"
        :nodeName="nodeName"
        @change="change"
        :FKNode1="FKNode1"
        @closeViewLeave="closeViewLeave"
        :dialogVisible="dialogVisible"
        :before-close="handleClose"
      ></leaveApplication>
    </el-dialog>
    <tripRecord ref="tripRef" @guanbi="handleQuery"> </tripRecord>
    <el-dialog width="85%" :title="titleFw" v-model="ReceivedQiLinDialog">
      <ReceivedQiLin
        ref="QiLinRef"
        :hanldType="hanldType"
        @closeViewLeave="closeViewLeave"
        :ReceivedQiLinData="ReceivedQiLinData"
      ></ReceivedQiLin>
    </el-dialog>
    <el-dialog
      style="min-height: 70vh"
      width="85%"
      title="论文审批"
      v-model="paperApprovalQiLinDialog"
    >
      <paperApprovalQiLin
        ref="paperQiLinRef"
        :hanldType="hanldType"
        @closeViewLeave="closeViewLeave"
        :paperQiLinData="paperQiLinData"
      ></paperApprovalQiLin>
    </el-dialog>
    <outTeacher ref="teacherRef" @guanbi="handleQuery"> </outTeacher>
    <carApproval ref="carRef" @guanbi="handleQuery"></carApproval>
    <workApply ref="workRef" @guanbi="handleQuery"></workApply>
    <Supervise ref="superRef" @guanbi="handleQuery"></Supervise>
    <contSeal ref="contSealRef" @guanbi="handleQuery"></contSeal>

    <sealApplicational ref="sealRef" @guanbi="handleQuery"></sealApplicational>
  </div>
</template>

<script>
import viewPdf from "../../liucheng/todowork/formView/viewPdf.vue";
import outTeacher from "@/views/liucheng/todowork/formView/recordOfOutTeaching.vue";
import Infoarticle from "@/views/liucheng/todowork/Infoarticle.vue";
import leaveApplication from "@/views/liucheng/leaveApplication1.vue";
import tripRecord from "@/views/liucheng/todowork/formView/businessTripRecord.vue";
import Supervise from "@/views/liucheng/todowork/formView/Supervise.vue";
import sealApplicational from "@/views/liucheng/todowork/formView/sealApplicational.vue";

import QtswViewPdf from "@/views/liucheng/todowork/formView/qtswViewPdf";
import SwViewPdf from "@/views/liucheng/todowork/formView/swViewPdf";
import { getHandleList } from "@/api/liucheng/index";
import ReceivedQiLin from "@/views/liucheng/todowork/formView/ReceivedQiLin.vue";
import paperApprovalQiLin from "@/views/liucheng/todowork/formView/paperApprovalQiLin.vue";
import { getReceiveByWorkId } from "@/api/office/received";
import {
  kg_uuid,
  GetUrlbasePath,
  GetUrlbase,
} from "../../official/hookFunction";
import { updateIsRead } from "@/api/liucheng";
import axios from "axios";
import Cookies from "js-cookie";
import { getToken, getJToken } from "@/utils/auth";
import carApproval from "@/views/liucheng/todowork/formView/carApproval.vue";
import workApply from "@/views/liucheng/todowork/formView/workApply.vue";
import contSeal from "@/views/liucheng/todowork/formView/contSeal.vue";
import emptyImage from "@/assets/images/none.png";
export default {
  name: "YinetoaTodoList",
  components: {
    tripRecord,
    outTeacher,
    Infoarticle,
    leaveApplication,
    SwViewPdf,
    QtswViewPdf,
    carApproval,
    workApply,
    Supervise,
    sealApplicational,
    contSeal,
  },
  data() {
    return {
      xiaojia: false,
      emptyImage, // 使用 require 引入图片
      approvalDialog: false,
      showcolumn: false,
      hanldType: true,
      msgs: {},
      comm: true,
      ReceivedQiLinData: null,
      paperQiLinData: null,
      leaveDialog: false,
      titleFw: null,
      ReceivedQiLinDialog: false,
      paperApprovalQiLinDialog: false,
      uuid: "",
      fldata: null,
      WorkId: null,
      WorkId1: null,
      approvalDialog: false,
      showcolumn: false,
      receiverData: undefined,
      receiverData1: undefined,
      queryParams: {
        title: undefined,
      },
      token: "",
      activeName: "first",
      tableData: [],
      currentRow: "",
      guijiDialog: false,
      guiji: "tu",
      tuurl: "",
      xianurl: "",
      biaourl: "",
      myList: [],
      //待办分页
      dbPageSize: 10,
      dbPageNum: 1,
      dbTotal: 0,
      dbLoading: false,
      //在途分页
      ztPageSize: 10,
      ztPageNum: 1,
      ztTotal: 0,
      ztLoading: false,
      //已办分页
      ybPageSize: 10,
      ybPageNum: 1,
      ybTotal: 0,
      ybLoading: false,
      //我发起的列表参数
      myPageSize: 10,
      myPageNum: 1,
      myTotal: 0,
      myLoading: false,
    };
  },
  created() {
    this.token = getJToken();
    this.getList(
      this.token,
      this.dbPageSize,
      this.dbPageNum,
      this.queryParams.title
    );
  },
  mounted() {},

  methods: {
    closeViewLeave() {
      this.leaveDialog = false;
      this.approvalDialog = false;
      this.ReceivedQiLinDialog = false;
      this.paperApprovalQiLinDialog = false;
      this.handleQuery();
      this.WorkId = null;
      this.WorkId1 = null;
      this.ReceivedQiLinData = null;
      this.paperQiLinData = null;
    },
    // 详情
    openPdfViewer(data) {
      if (data.FK_Flow == "012") {
        getReceiveByWorkId(data.WorkID).then((response) => {
          this.receiverData = response.data;
          this.$nextTick(() => {
            this.$refs.importRef.show(this.receiverData, data, true);
          });
        });
      } else if (data.FK_Flow == "003") {
        getReceiveByWorkId(data.WorkID).then((response) => {
          this.receiverData1 = response.data;
          this.$nextTick(() => {
            this.$refs.importRef1.showdetal2(this.receiverData1, data, true);
          });
        });
      } else if (data.FK_Flow == "002") {
        var agent = navigator.userAgent.toLowerCase();
        if (agent.indexOf("windows") > -1) {
          this.handleOpenAppReceived(
            data.WorkID,
            data.NodeName,
            data.FK_Flow,
            data.FK_Node
          );
        } else {
          this.handleOpenAppReceivedQiLin(data);
        }
      } else if (data.FK_Flow == "005") {
        var agent = navigator.userAgent.toLowerCase();
        if (agent.indexOf("windows") > -1) {
          this.handleOpenAppReceived(
            data.WorkID,
            data.NodeName,
            data.FK_Flow,
            data.FK_Node
          );
        } else {
          this.handleOpenAppReceivedQiLin(data);
        }
      } else if (data.FK_Flow == "006") {
        this.$refs.tripRef.showDetail1(data);
      } else if (data.FK_Flow == "007") {
        this.$refs.teacherRef.showDetail1(data);
      } else if (data.FK_Flow == "008") {
        var agent = navigator.userAgent.toLowerCase();
        if (agent.indexOf("windows") > -1) {
          this.handleOpenAppReceived1(
            data.WorkID,
            data.NodeName,
            data.FK_Flow,
            data.FK_Node
          );
        } else {
          this.handleOpenAppPaperQiLin1(data);
        }
      } else if (data.FK_Flow == "021") {
        this.leaveDialog = true;
        this.showTable = true;
        this.xiaojia = false;
        this.WorkId = data.WorkID;
        this.FKNode1 = data.FK_Node;
        this.FK_Flow = data.FK_Flow;
        this.nodeName = data.NodeName;
      } else if (data.FK_Flow == "010") {
        this.approvalDialog = true;
        this.WorkId1 = data.WorkID;
        this.showcolumn = true;
        this.FKNode1 = data.FK_Node;
        this.FK_Flow = data.FK_Flow;
        this.fldata = data;
        this.nodeName = data.NodeName;
      } else if (data.FK_Flow == "015") {
        this.$refs.carRef.showDetail1(data);
      } else if (data.FK_Flow == "020") {
        this.$refs.workRef.showDetail1(data);
      } else if (data.FK_Flow == "016") {
        this.$refs.superRef.showDetail1(data);
      } else if (data.FK_Flow == "017") {
        this.$refs.sealRef.showDetail1(data);
      } else if (data.FK_Flow == "018") {
        this.$refs.contSealRef.showDetail1(data);
      }
      // 修改为已读
      if (data.IsRead == "0") {
        updateIsRead(data.WorkID, this.token, data.FK_Node).then(
          (response) => {}
        );
      }
    },

    //长监听
    getMsg() {
      this.msgs = true;
      let strUrl = "http://127.0.0.1:9588/LongListen?id=" + this.uuid;
      axios({
        method: "get",
        url: strUrl,
        jsonp: "hookback",
        dataType: "jsonp",
        responseType: "jsonp",
      })
        .then((res) => {
          var jsonobj = eval(res.data);
          if (jsonobj.ret != "none") {
            var jsonobj2 = eval(jsonobj.ret);
            this.msgs = JSON.parse(
              decodeURIComponent(JSON.stringify(jsonobj2))
            );
            if (this.msgs.content == "true") {
              this.handleQuery();
            }
          } else {
            this.getMsg();
          }
        })
        .catch((error) => {
          this.getMsg();
        });
    },
    //打开收文弹窗浏览器
    handleOpenAppReceived1(workId, NodeName, FK_Flow, FK_Node) {
      this.$modal.loading("正在打开视图，请稍候...");
      let webUrl =
        GetUrlbase() +
        "/todopaperApproval?FK_Flow=" +
        FK_Flow +
        "&FK_Node=" +
        FK_Node +
        "&hanldType=true&workId=" +
        workId +
        "&NodeName=" +
        encodeURIComponent(NodeName) +
        "&fkNode=";
      var uuid = kg_uuid(16, 32);
      var targetuuid = kg_uuid(16, 32);
      let urlString =
        "http://127.0.0.1:9588/StartApp?" +
        "&id=" +
        uuid +
        "&title=" +
        "发表学术论文审批登记" +
        "&targetid=" +
        targetuuid +
        "&showMode=1" +
        "&cookie=Admin-Token=" +
        getToken() +
        ";J-Token=" +
        getJToken() +
        ";jFontIp=" +
        encodeURIComponent(Cookies.get("jFontIp")) +
        "&weburl=" +
        encodeURIComponent(webUrl);
      fetch(urlString, {
        method: "get",
      }).then((res) => {
        this.$modal.closeLoading();
      });
    },
    //长监听
    getMsg() {
      this.msgs = true;
      let strUrl = "http://127.0.0.1:9588/LongListen?id=" + this.uuid;
      axios({
        method: "get",
        url: strUrl,
        jsonp: "hookback",
        dataType: "jsonp",
        responseType: "jsonp",
      })
        .then((res) => {
          var jsonobj = eval(res.data);
          if (jsonobj.ret != "none") {
            var jsonobj2 = eval(jsonobj.ret);
            this.msgs = JSON.parse(
              decodeURIComponent(JSON.stringify(jsonobj2))
            );
            if (this.msgs.content == "true") {
              this.handleQuery();
            }
          } else {
            this.getMsg();
            this.$emit("pf");
          }
        })
        .catch((error) => {
          this.getMsg();
          this.$emit("pf");
        });
    },
    //麒麟
    handleOpenAppReceivedQiLin(data) {
      this.ReceivedQiLinDialog = true;
      if (data.FK_Flow == "002") {
        this.titleFw = "发文";
      } else if (data.FK_Flow == "005") {
        this.titleFw = "其他处室发文";
      }
      this.ReceivedQiLinData = data;
      this.$nextTick(() => {
        this.$refs.QiLinRef.OnReady();
      });
    },
    //麒麟（论文）
    handleOpenAppPaperQiLin1(data) {
      this.paperApprovalQiLinDialog = true;
      this.paperQiLinData = data;
      this.$nextTick(() => {
        this.$refs.paperQiLinRef.OnReady();
      });
    },
    //打开收文弹窗浏览器
    handleOpenAppReceived(workId, NodeName, FK_Flow, FK_Node) {
      this.$modal.loading("正在打开视图，请稍候...");
      let webUrl =
        GetUrlbase() +
        "/todoReceived?FK_Flow=" +
        FK_Flow +
        "&FK_Node=" +
        FK_Node +
        "&hanldType=true&workId=" +
        workId +
        "&NodeName=" +
        encodeURIComponent(NodeName) +
        "&fkNode=";
      // var uuid = kg_uuid(16, 32);
      this.uuid = kg_uuid(16, 32);
      var targetuuid = kg_uuid(16, 32);
      let urlString =
        "http://127.0.0.1:9588/StartApp?" +
        "&id=" +
        this.uuid +
        "&title=" +
        "发文" +
        "&targetid=" +
        targetuuid +
        "&showMode=1" +
        "&cookie=Admin-Token=" +
        getToken() +
        ";J-Token=" +
        getJToken() +
        ";jFontIp=" +
        encodeURIComponent(Cookies.get("jFontIp")) +
        "&weburl=" +
        encodeURIComponent(webUrl);
      fetch(urlString, {
        method: "get",
      }).then((res) => {
        this.getMsg();
        this.$modal.closeLoading();
        this.$emit("pf");
      });
      this.$modal.closeLoading();
      this.$emit("pf");
    },
    handleQuery() {
      this.getList(
        this.token,
        this.dbPageSize,
        this.dbPageNum,
        this.queryParams.title
      );
    },
    //获取列表
    getList(v, s, n, t) {
      getHandleList(v, s, n, t).then((res) => {
        this.dbTotal = res.total;
        this.tableData = res.list.slice(0, 5);
      });
    },
  },
};
</script>

<style lang="scss" scoped>
#titleHover :hover {
  color: #409eff !important;
  text-decoration: underline !important;
}

#hover :hover {
  background-color: aliceblue;
}

// #button :hover {
//   // background-color: #e6a23c;
//   background-color: #409eff !important;
//   color: white;
// }
// #button1 :hover {
//   // background-color: #e6a23c;
//   background-color: #909399 !important;
//   color: white;
// }
// #button2 :hover {
//   // background-color: #e6a23c;
//   background-color: #f56c6c !important;
//   color: white;
// }
</style>
