<template>
  <div class="app-container handle">
    <el-form :model="queryParams" ref="queryRef" :inline="true">
      <el-form-item label="标题" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入标题"
          clearable
          style="width: 240px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="RefreshRight" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="24">
      <el-col :xs="26" :sm="24">
        <div class="handle-body">
          <el-tabs v-model="activeName">
            <el-tab-pane label="待办事项" name="first">
              <div class="dbrw-body">
                <div class="dbrw-content" v-loading="dbLoading">
                  <el-table
                    ref="singleTable"
                    :data="tableData"
                    style="width: 100%"
                    highlight-current-row
                  >
                    <el-table-column
                      type="index"
                      width="60"
                      label="序号"
                      align="center"
                    >
                    </el-table-column>
                    <el-table-column
                      prop="FlowName"
                      width="180"
                      align="center"
                      label="流程名称"
                    >
                      <template #default="scope">
                        <el-tag
                          type="danger"
                          effect="dark"
                          v-if="scope.row.WFState == 5"
                          >退回
                        </el-tag>
                        <el-tag
                          type="warning"
                          effect="dark"
                          v-if="scope.row.WFState == 6"
                          >移交
                        </el-tag>
                        {{ scope.row.FlowName }}
                      </template>
                    </el-table-column>
                    <el-table-column
                      prop="Title"
                      label="标题"
                      min-width="280"
                      align="center"
                    >
                      <template #default="scope">
                        <el-tooltip
                          class="item"
                          effect="dark"
                          placement="top"
                          :content="scope.row.Title"
                        >
                          <div>{{ scope.row.Title }}</div>
                        </el-tooltip>
                      </template>
                    </el-table-column>
                    <el-table-column
                      prop="StarterName"
                      width="180"
                      align="center"
                      label="发起人"
                    >
                    </el-table-column>
                    <el-table-column
                      prop="NodeName"
                      label="当前节点"
                      width="180"
                      align="center"
                    >
                    </el-table-column>
                    <el-table-column
                      width="100"
                      label="是否已读"
                      align="center"
                    >
                      <template #default="scope">
                        <el-tag type="success" v-if="scope.row.IsRead == 1"
                          >已读</el-tag
                        >
                        <el-tag plain v-else>未读</el-tag>
                      </template>
                    </el-table-column>
                    <!--                    <el-table-column
                        width="200"
                        prop="RDT"
                        label="开始时间"
                        align="center"
                    >
                    </el-table-column>-->
                    <el-table-column
                      prop="ADT"
                      label="到达时间"
                      width="200"
                      align="center"
                    >
                    </el-table-column>
                    <el-table-column
                      width="180"
                      label="操作"
                      fixed="right"
                      align="center"
                    >
                      <template #default="scope">
                        <!--                        <el-button type="primary" plain @click="openTrajectory(scope.row)">轨迹</el-button >-->
                        <el-button
                          type="primary"
                          plain
                          @click="openPdfViewer(scope.row)"
                          >处理</el-button
                        >
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
                <div
                  style="
                    display: flex;
                    justify-content: flex-end;
                    margin-top: 1.25rem;
                  "
                  v-if="dbTotal != 0"
                >
                  <el-pagination
                    background
                    @current-change="changePage1"
                    :current-page.sync="dbPageNum"
                    :page-size="dbPageSize"
                    layout="total, prev, pager, next"
                    :total="dbTotal"
                  >
                  </el-pagination>
                </div>
              </div>
            </el-tab-pane>
          </el-tabs>
        </div>
      </el-col>
    </el-row>
    <!-- 其他处室收文 -->
    <!--    <viewPdf
      ref="importRef"
      @guanbi="handleQuery"
      :receiverData="receiverData"
    /> -->
    <qtsw-view-pdf
      ref="importRef"
      @guanbi="handleQuery"
      :receiverData="receiverData"
    />
    <!-- 收文 -->
    <!--    <viewPdf1
      ref="importRef1"
      @guanbi="handleQuery"
      :receiverData1="receiverData1"
    />-->
    <sw-view-pdf
      ref="importRef1"
      @guanbi="handleQuery"
      :receiverData1="receiverData1"
    >
    </sw-view-pdf>

    <el-dialog title="轨迹" v-model="guijiDialog" width="80%" height="80%">
      <iframe :src="tuurl" width="100%" height="1000px"></iframe>
      <!--      <el-tabs v-model="guiji" type="card" @tab-click="handleClick">-->
      <!--        <el-tab-pane label="轨迹图" name="tu">轨迹图-->
      <!--          <iframe :src="tuurl" width=100% :height=height frameborder="0" id="iframeUpdate"></iframe>-->
      <!--        </el-tab-pane>-->
      <!--        <el-tab-pane label="时间线" name="xian">时间线-->
      <!--          <iframe :src="xianurl" width=100% :height=height frameborder="0" id="iframeUpdate1"></iframe>-->
      <!--        </el-tab-pane>-->
      <!--        <el-tab-pane label="时间表" name="biao">时间表-->
      <!--          <iframe :src="biaourl" width=100% :height=height frameborder="0" id="iframeUpdate2"></iframe>-->
      <!--        </el-tab-pane>-->
      <!--      </el-tabs>-->
    </el-dialog>
    <el-dialog width="80%" title="请假审批" v-model="leaveDialog">
      <leaveApplication
        ref="child"
        :showTable="showTable"
        :WorkId="WorkId"
        :FK_Flow="FK_Flow"
        :nodeName="nodeName"
        @change="change"
        :FKNode1="FKNode1"
        @closeViewLeave="closeViewLeave"
        :dialogVisible="dialogVisible"
        :before-close="handleClose"
      ></leaveApplication>
    </el-dialog>
    <el-dialog
      style="min-height: 90vh"
      width="85%"
      title="信息审核"
      v-model="approvalDialog"
    >
      <Infoarticle
        ref="infoarticleRef"
        :showcolumn="showcolumn"
        :FK_Flow="FK_Flow"
        :nodeName="nodeName"
        @closeViewLeave="closeViewLeave"
        :WorkId1="WorkId1"
        :fldata="fldata"
      ></Infoarticle>
    </el-dialog>

    <el-dialog width="85%" :title="titleFw" v-model="ReceivedQiLinDialog">
      <ReceivedQiLin
        ref="QiLinRef"
        :hanldType="hanldType"
        @closeViewLeave="closeViewLeave"
        :ReceivedQiLinData="ReceivedQiLinData"
      ></ReceivedQiLin>
    </el-dialog>
    <tripRecord
      ref="tripRef"
      @closeViewLeave="closeViewLeave"
      @guanbi="handleQuery"
    >
    </tripRecord>
    <outTeacher ref="teacherRef" @guanbi="handleQuery"> </outTeacher>
    <carApproval ref="carRef" @guanbi="handleQuery"></carApproval>
    <workApply ref="workRef" @guanbi="handleQuery"></workApply>
    <Supervise ref="superRef" @guanbi="handleQuery"></Supervise>
    <sealApplicational ref="sealRef" @guanbi="handleQuery"></sealApplicational>
    <contSeal ref="contSealRef" @guanbi="handleQuery"></contSeal>
    <el-dialog
      style="min-height: 70vh"
      width="85%"
      title="论文审批"
      v-model="paperApprovalQiLinDialog"
    >
      <paperApprovalQiLin
        ref="paperQiLinRef"
        :hanldType="hanldType"
        @closeViewLeave="closeViewLeave"
        :paperQiLinData="paperQiLinData"
      ></paperApprovalQiLin>
    </el-dialog>
  </div>
</template>

<script>
import { getHandleList } from "@/api/liucheng/index";
import leaveApplication from "@/views/liucheng/leaveApplication1.vue";
// import businessTripRecord from "@/views/liucheng/todowork/formView/businessTripRecord.vue";
import tripRecord from "@/views/liucheng/todowork/formView/businessTripRecord.vue";
import outTeacher from "@/views/liucheng/todowork/formView/recordOfOutTeaching.vue";
import Infoarticle from "@/views/liucheng/todowork/Infoarticle.vue";
import carApproval from "@/views/liucheng/todowork/formView/carApproval.vue";
import workApply from "@/views/liucheng/todowork/formView/workApply.vue";
import Supervise from "@/views/liucheng/todowork/formView/Supervise.vue";
import sealApplicational from "@/views/liucheng/todowork/formView/sealApplicational.vue";
import contSeal from "@/views/liucheng/todowork/formView/contSeal.vue";
import received from "@/views/liucheng/todowork/formView/Received.vue";
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 Cookies from "js-cookie";
import { getToken, getJToken } from "@/utils/auth";
import { onMounted } from "vue";
import axios from "axios";
import QtswViewPdf from "@/views/liucheng/todowork/formView/qtswViewPdf";
import SwViewPdf from "@/views/liucheng/todowork/formView/swViewPdf";
export default {
  name: "todowork",
  components: {
    SwViewPdf,
    QtswViewPdf,
    leaveApplication,
    tripRecord,
    outTeacher,
    Infoarticle,
    received,
    ReceivedQiLin,
    paperApprovalQiLin,
    carApproval,
    workApply,
    Supervise,
    sealApplicational,
    contSeal,
  },
  data() {
    return {
      comm: true,
      hanldType: true,
      ReceivedQiLinData: null,
      paperQiLinData: null,
      msgs: {},
      //////信息审核
      approvalDialog: false,
      showcolumn: false,
      ////////////请假
      FK_Flow: null,
      wzflowData: null,
      FKNode1: null,
      uuid: "",
      nodeName: null,
      showTable: true,
      WorkId: null,
      WorkId1: null,
      fldata: null,
      leaveDialog: false,
      ReceivedQiLinDialog: false,
      paperApprovalQiLinDialog: 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,
      tripDialog: 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() {
    // this.getMsg();
  },
  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;
    },

    handleClick(tab, event) {},
    openPdfViewer(data) {
      console.log("data", data);
      // 修改为已读
      if (data.IsRead == "0") {
        updateIsRead(data.WorkID, this.token, data.FK_Node).then(
          (response) => {}
        );
        this.handleQuery();
      }
      //其他收文
      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 == "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 == "006") {
        this.$refs.tripRef.showDetail1(data);
      } else if (data.FK_Flow == "007") {
        this.$refs.teacherRef.showDetail1(data);
      } else if (data.FK_Flow == "009") {
        this.leaveDialog = true;
        this.showTable = true;
        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.FK_Flow = data.FK_Flow;
        this.nodeName = data.NodeName;
        this.fldata = data;
      } 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);
      }
    },
    openTrajectory(data) {
      this.tuurl =
        Cookies.get("jFontIp") +
        "/WF/Port.htm?DoWhat=OneWork2&WorkID=" +
        data.WorkID +
        "&FK_Flow=" +
        data.FK_Flow +
        "&Token=" +
        this.token;
      this.guijiDialog = true;
    },

    //长监听
    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();
        });
    },
    getMsgLW() {
      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.getMsgLW();
          }
        })
        .catch((error) => {
          this.getMsgLW();
        });
    },
    //麒麟
    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=";
      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=3" +
        "&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();
      });
    },

    //打开论文弹窗浏览器
    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=";
      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=3" +
        "&cookie=Admin-Token=" +
        getToken() +
        ";J-Token=" +
        getJToken() +
        ";jFontIp=" +
        encodeURIComponent(Cookies.get("jFontIp")) +
        "&weburl=" +
        encodeURIComponent(webUrl);
      fetch(urlString, {
        method: "get",
      })
        .then((res) => {
          this.$modal.closeLoading();
          this.getMsgLW();
        })
        .catch((res) => {
          this.$modal.msgError("打开失败，请到登录页下载插件后继续");
        });
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryRef");
      this.handleQuery();
    },
    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;
      });
    },
    //选择列表
    ck1(val) {},
    //待办分页
    changePage1(e) {
      this.dbPageNum = e;
      this.dbLoading = true;
      getHandleList(
        this.token,
        this.dbPageSize,
        this.dbPageNum,
        this.queryParams.title
      ).then((res) => {
        this.tableData = res.list;
        setTimeout(() => {
          this.dbLoading = false;
        }, 1800);
      });
    },

    //待办搜索
    change1() {
      this.dbPageNum = 1;
      this.dbLoading = true;
      getHandleList(
        this.token,
        this.dbPageSize,
        this.dbPageNum,
        this.queryParams.title
      ).then((res) => {
        this.dbTotal = res.total;
        this.tableData = res.list;
        setTimeout(() => {
          this.dbLoading = false;
        }, 1800);
      });
    },
  },
};
</script>
