<template>
  <div class="app-container handle">
    <el-row :gutter="24">
      <el-col :sm="4">
        <!-- <div class="head-container">
          <el-input
            v-model="name"
            placeholder="请输入分类名称"
            clearable
            prefix-icon="Search"
            style="margin-bottom: 20px"
          />
        </div> -->
        <div class="head-container">
          <el-tree
            style="font-size: 15px; margin-top: 20px"
            :data="typeList"
            :props="{ label: 'NAME', value: 'NO' }"
            :expand-on-click-node="false"
            :filter-node-method="filterNode"
            ref="typeTreeRef"
            node-key="NO"
            :highlight-current="true"
            default-expand-all
            @node-click="handleNodeClick"
            :current-node-key="currentNodeKey"
          /></div
      ></el-col>
      <el-col :xs="26" :sm="20">
        <el-form :model="queryParams11" ref="queryRef" :inline="true">
          <el-form-item label="标题" prop="title">
            <el-input
              v-model="queryParams11.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>
        <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="150"
                      align="center"
                      label="流程名称"
                    >
                    </el-table-column>
                    <el-table-column
                      prop="Title"
                      label="标题"
                      min-width="380"
                      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="120"
                      align="center"
                      label="发起人"
                    >
                    </el-table-column>
                    <el-table-column
                      prop="NodeName"
                      label="当前节点"
                      width="160"
                      align="center"
                    >
                    </el-table-column>

                    <el-table-column
                      width="160"
                      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
                        >
                        <el-button
                          type="danger"
                          plain
                          @click="delFile(scope.row)"
                          >删除</el-button
                        >
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
              </div>
            </el-tab-pane>
          </el-tabs>
          <div
            style="
              display: flex;
              justify-content: flex-end;
              margin-top: 1.25rem;
            "
            v-if="total != 0"
          >
            <el-pagination
              background
              @current-change="changePage1"
              :current-page.sync="queryParams11.pageNum"
              :page-size="queryParams11.pageSize"
              layout="total, prev, pager, next"
              :total="total"
            >
            </el-pagination>
          </div>
        </div>
      </el-col>
    </el-row>
    <sw-view-pdf
      ref="importRef1"
      @guanbi="handleQuery"
      :receiverData1="receiverData1"
    >
    </sw-view-pdf>
    <qtsw-view-pdf
      ref="importRef"
      @guanbi="handleQuery"
      :receiverData="receiverData"
    />
    <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"
        :trueLeave="trueLeave"
        :WorkId="WorkId"
        :closeDialog="closeDialog"
        @change="change"
        :FK_Flow="FK_Flow"
        :FKNode1="FKNode1"
        @closeViewLeave="closeViewLeave"
        :dialogVisible="dialogVisible"
        :before-close="handleClose"
      ></leaveApplication>
    </el-dialog>
    <el-dialog width="70%" title="信息审核" v-model="InfoDialog">
      <InfoApply
        ref="child1"
        :WorkId1="WorkId1"
        :closeDialog="closeDialog"
        @change="change"
        @closeViewLeave="closeViewLeave"
        :dialogVisible="dialogVisible"
        :before-close="handleClose"
      ></InfoApply>
    </el-dialog>
    <el-dialog width="85%" :title="titleFw" v-model="ReceivedQiLinDialog">
      <ReceivedQiLin
        ref="QiLinRef"
        :hanldType="hanldType"
        @closeViewLeave="closeViewLeave"
        :ReceivedQiLinData="ReceivedQiLinData"
      ></ReceivedQiLin>
    </el-dialog>
    <el-dialog width="85%" title="论文审批" v-model="paperApprovalQiLinDialog">
      <paperApprovalQiLin
        ref="paperQiLinRef"
        :hanldType="hanldType"
        @closeViewLeave="closeViewLeave"
        :paperQiLinData="paperQiLinData"
      ></paperApprovalQiLin>
    </el-dialog>
    <tripRecord ref="tripRef" @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>
  </div>
</template>

<script>
import QtswViewPdf from "@/views/liucheng/todowork/formView/qtswViewPdf";
import { allFlows, allJoinOneFlows, deleteFlow } from "@/api/archive/type";
import SwViewPdf from "@/views/liucheng/todowork/formView/swViewPdf";
import { getCompletedList } from "@/api/liucheng/index";
import InfoApply from "@/views/liucheng/todowork/InfoApply.vue";
import tripRecord from "@/views/liucheng/todowork/formView/businessTripRecord.vue";
import outTeacher from "@/views/liucheng/todowork/formView/recordOfOutTeaching.vue";
import ReceivedQiLin from "@/views/liucheng/todowork/formView/ReceivedQiLin.vue";
import paperApprovalQiLin from "@/views/liucheng/todowork/formView/paperApprovalQiLin.vue";
import { getReceive } from "@/api/office/received";
import { getToken, getJToken } from "@/utils/auth";
import { getReceiveByWorkId } from "../../api/office/received";
import { updateIsRead } from "@/api/liucheng";
import leaveApplication from "@/views/liucheng/leaveApplication1.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 { kg_uuid, GetUrlbasePath, GetUrlbase } from "../official/hookFunction";
import Cookies from "js-cookie";
export default {
  name: "handle",
  components: {
    SwViewPdf,
    QtswViewPdf,
    tripRecord,
    outTeacher,
    leaveApplication,
    InfoApply,
    ReceivedQiLin,
    paperApprovalQiLin,
    carApproval,
    workApply,
    Supervise,
    sealApplicational,
    contSeal,
  },
  data() {
    return {
      currentNodeKey: "",
      queryParams11: {
        pageNum: 1,
        pageSize: 10,
        title: null,
        fkFlow: "",
      },
      total: 0,
      domain: "",
      typeList: [],
      typeQueryParams: {
        name: null,
        parentId: null,
        sortNum: null,
      },
      FK_Flow: null,
      FKNode1: null,
      InfoDialog: false,
      hanldType: false,
      ReceivedQiLinData: null,
      ReceivedQiLinDialog: false,
      leaveDialog: false,
      closeDialog: true,
      WorkId: null,
      WorkId1: null,
      receiverData: undefined,
      receiverData1: undefined,
      queryParams: {
        title: undefined,
      },
      token: "",
      paperApprovalQiLinDialog: false,
      paperQiLinData: null,
      activeName: "first",
      tableData: [],
      guijiDialog: false,
      tuurl: "",
      currentRow: "",
      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.getTypeList();
    // this.getList(
    //   this.token,
    //   this.dbPageSize,
    //   this.dbPageNum,
    //   this.queryParams.title,
    //   this.queryParams.typeId
    // );
    this.allJoinOneFlows();
  },
  mounted() {},
  methods: {
    delFile(row) {
      console.log(row);
      this.$modal
        .confirm("是否删除文件")
        .then(() => {
          return deleteFlow(row.WorkID);
        })
        .then(() => {
          this.allJoinOneFlows();
          this.$modal.msgSuccess("删除成功");
        });
    },
    async allJoinOneFlows() {
      let { list, total } = await allJoinOneFlows(this.queryParams11);
      this.tableData = list;
      console.log(this.tableData);
      if (this.tableData.length > 0) {
        this.currentNodeKey = this.tableData[0].FK_Flow;
        console.log(this.currentNodeKey);
        this.queryParams11.fkFlow = this.currentNodeKey;
        this.$nextTick(() => {
          this.$refs.typeTreeRef.setCurrentKey(this.currentNodeKey);
        });
      }
      this.total = total;
    },
    /** 节点单击事件 */
    handleNodeClick(data) {
      this.queryParams11.fkFlow = data.NO;
      this.handleQuery();
    },
    /** 查询归档类型列表 */
    getTypeList() {
      this.loading = true;
      allFlows(this.domain).then((response) => {
        this.typeList = this.handleTree(response, "NO");
        this.loading = false;
        this.queryParams11.fkFlow = this.typeList[0].NO;
        this.handleQuery();
      });
    },
    closeViewLeave() {
      this.leaveDialog = false;
      this.InfoDialog = false;
      this.ReceivedQiLinDialog = false;
      this.paperApprovalQiLinDialog = false;
      this.handleQuery();
      this.WorkId = null;
      this.WorkId1 = null;
      this.ReceivedQiLinData = null;
      this.paperQiLinData = null;
    },
    openTrajectory(data) {
      /*      this.tuurl=Cookies.get("jFontIp")+"/WF/WorkOpt/OneWork/OneWork.htm?" +
                  "CurrTab=Truck&FK_Node="+data.FK_Node+"&FID="+data.FID+"&WorkID="+data.WorkID+"&FK_Flow="+data.FK_Flow+
                  "&Info=&s="+Math.random()+"&isFrameCross=0&token="+this.token;*/

      this.tuurl =
        Cookies.get("jFontIp") +
        "/WF/Port.htm?DoWhat=OneWork1&WorkID=" +
        data.WorkID +
        "&FK_Flow=" +
        data.FK_Flow +
        "&Token=" +
        this.token;
      this.guijiDialog = true;
    },
    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, false);
          });
        });
      } else if (data.FK_Flow == "003") {
        getReceiveByWorkId(data.WorkID).then((response) => {
          console.log("55555555555", response);
          this.receiverData1 = response.data;
          this.$nextTick(() => {
            this.$refs.importRef1.showdetal2(this.receiverData1, data, false);
          });
        });
      } 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);
        this.$refs.tripRef.closeSendNext();
      } else if (data.FK_Flow == "021") {
        this.leaveDialog = true;
        this.showTable = true;
        this.WorkId = data.WorkID;
        this.trueLeave = true;
        this.FKNode1 = data.FK_Node;
        this.FK_Flow = data.FK_Flow;
        this.closeDialog = true;
      } else if (data.FK_Flow == "010") {
        this.InfoDialog = true;
        this.WorkId1 = data.WorkID;
        this.FK_Flow = data.FK_Flow;
        this.nodeName = data.NodeName;
        this.closeDialog = true;
      } else if (data.FK_Flow == "007") {
        this.$refs.teacherRef.showDetail1(data);
        this.$refs.teacherRef.closeSendNext();
      } else if (data.FK_Flow == "015") {
        this.$refs.carRef.showDetail1(data);
        this.$refs.carRef.closeSendNext();
      } else if (data.FK_Flow == "020") {
        this.$refs.workRef.showDetail1(data);
        this.$refs.workRef.closeSendNext();
      } else if (data.FK_Flow == "016") {
        this.$refs.superRef.showDetail1(data);
        this.$refs.superRef.closeSendNext();
      } else if (data.FK_Flow == "017") {
        this.$refs.sealRef.showDetail1(data);
        this.$refs.sealRef.closeSendNext();
      } else if (data.FK_Flow == "018") {
        this.$refs.contSealRef.showDetail1(data);
        this.$refs.contSealRef.closeSendNext();
      }
      //修改为已读
      // if(data.IsRead=="0"){
      //   updateIsRead(data.WorkID,this.token,data.FK_Emp,data.FK_Node,data.FK_Flow).then(response=>{
      //
      //   })
      // }
    },
    //麒麟（论文）
    handleOpenAppPaperQiLin1(data) {
      this.paperApprovalQiLinDialog = true;
      this.paperQiLinData = data;
      this.$nextTick(() => {
        this.$refs.paperQiLinRef.OnReady();
      });
    },
    //麒麟(发文)
    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();
      });
    },
    handleOpenAppReceived1(workId, NodeName, FK_Flow, FK_Node) {
      this.$modal.loading("正在打开视图，请稍候...");
      let webUrl =
        GetUrlbase() +
        "/todopaperApproval?FK_Flow=" +
        FK_Flow +
        "&FK_Node=" +
        FK_Node +
        "&hanldType=false&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();
      });
    },
    //打开收文弹窗浏览器
    handleOpenAppReceived(workId, NodeName, FK_Flow, FK_Node) {
      this.$modal.loading("正在打开视图，请稍候...");
      let webUrl =
        GetUrlbase() +
        "/todoReceived?FK_Flow=" +
        FK_Flow +
        "&FK_Node=" +
        FK_Node +
        "&hanldType=false&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();
      });
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryRef");
      this.handleQuery();
    },
    handleQuery() {
      this.allJoinOneFlows();
    },
    //获取列表
    getList(v, s, n, t, a) {
      getCompletedList(v, s, n, t, a).then((res) => {
        this.dbTotal = res.total;
        this.tableData = res.list;
      });
    },
    //选择列表
    ck1(val) {},
    //待办分页
    changePage1(e) {
      this.queryParams11.pageNum = e;

      this.allJoinOneFlows();
    },

    //待办搜索
    change1() {
      this.dbPageNum = 1;
      this.dbLoading = true;
      getCompletedList(
        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>

<style scoped lang="scss">
/* 点击树结构项的选中颜色 */
.el-tree--highlight-current .is-current.el-tree-node > .el-tree-node__content {
  background-color: #99ccff !important;
}
.handle {
  // position: relative;
  // height: 100%;
  .handle-body {
    // margin-top: -7rem;
    background-color: #fff;
    border-radius: 0.625rem;
    padding: 0.625rem;
    box-sizing: border-box;
    position: relative;
    min-height: 100%;
    .backIndex {
      position: absolute;
      right: 0.625rem;
      top: 0.625rem;
      z-index: 9;
    }
    .dbrw-body {
      overflow: auto;
      .dbrw-header {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: space-between;
        .dbrw-search {
          width: 30%;
        }
        .dbrw-time {
          display: flex;
          align-items: center;
        }
        .dbrw-type {
          display: flex;
          align-items: center;
        }
      }
      .dbrw-content {
        margin-top: 0.25rem;
        height: calc(100vh - 19rem);
      }
    }
  }
}
</style>
<style lang="scss" scoped></style>
