<template>
  <el-dialog width="80%" title="督办事项" v-model="superVisionDialog">
    <div
      style="
        background-color: #f4f7fc;
        height: 75vh;
        padding: 20px;
        overflow: auto;
      "
    >
      <el-row>
        <el-col :span="3">
          <div class="grid-content ep-bg-purple" />
        </el-col>
        <el-col :span="18">
          <el-tabs
            style="min-height: 600px"
            type="border-card"
            class="demo-tabs"
          >
            <el-tab-pane label="基本信息">
              <template #label>
                <span style="font-size: 15px" class="custom-tabs-label">
                  <span>
                    <el-icon><Document style="padding-top: 2px" /></el-icon
                    >基本信息</span
                  >
                </span>
              </template>
              <div
                class="grid-content ep-bg-purple-light"
                style="
                  background-color: white;
                  width: 100%;
                  border: 1px solid #e4e7ed;
                "
              >
                <div
                  style="
                    height: 60px;
                    line-height: 60px;
                    text-align: center;
                    color: red;
                    font-weight: 700;
                    font-size: 20px;
                    border-bottom: 1px solid #e4e7ed;
                  "
                >
                  督办事项
                </div>
                <div style="padding: 20px">
                  <el-form
                    style="padding: 20px"
                    ref="supervisionRef"
                    :model="form"
                    :rules="rules"
                    label-width="110px"
                  >
                    <el-form-item label="督办事项" prop="title">
                      <el-input
                        :disabled="isEdit"
                        v-model="form.title"
                        placeholder="请输入督办事项"
                      />
                    </el-form-item>
                    <!-- <el-form-item label="信息类别" prop="infoType">
                      <el-input
                        :disabled="isEdit"
                        rows="5"
                        type="textarea"
                        v-model="form.infoType"
                        placeholder="请输入信息类别"
                        :min-height="192"
                      />
                    </el-form-item> -->
                    <el-row type="flex" justify="">
                      <el-col :span="12">
                        <el-form-item label="督办来源" prop="infoSource">
                          <el-select
                            :disabled="isEdit"
                            v-model="form.infoSource"
                            placeholder="请输入督办来源"
                            clearable
                            style="width: 100%"
                          >
                            <el-option
                              v-for="dict in infoSourceData"
                              :key="dict.value"
                              :label="dict.label"
                              :value="dict.value"
                            /> </el-select></el-form-item
                      ></el-col>
                      <el-col :span="12">
                        <el-form-item label="完成时限" prop="doneTime">
                          <el-date-picker
                            :disabled="isEdit"
                            clearable
                            style="width: 100%"
                            v-model="form.doneTime"
                            type="date"
                            value-format="YYYY-MM-DD"
                            placeholder="请选择完成时限"
                          >
                          </el-date-picker>
                          <!-- <el-input
                        :disabled="isEdit"
                        style="margin-top: 20px"
                        rows="3"
                        type="textarea"
                        v-model="form.doneContent"
                        placeholder="**月**日
    ****要求/文件要求/部门确定"
                        :min-height="192"
                      /> -->
                        </el-form-item>
                        <!-- <el-form-item
                          label="处室及负责人"
                          prop="departmentHead"
                        >
                          <el-input
                          :disabled="isEdit"
                            v-model="form.departmentHead"
                            placeholder="请输入处室及负责人"
                          /> </el-form-item
                      > -->
                      </el-col>
                    </el-row>
                    <el-form-item label="督办内容" prop="infoSourceContent">
                      <el-input
                        :disabled="isEdit"
                        rows="3"
                        type="textarea"
                        v-model="form.infoSourceContent"
                        :min-height="192"
                      />
                    </el-form-item>
                    <!-- <el-form-item label="议定事项" prop="itemPostil">
                      <el-input
                        :disabled="isEdit"
                        rows="3"
                        type="textarea"
                        v-model="form.itemPostil"
                        placeholder="请输入议定事项"
                        :min-height="192"
                      />
                    </el-form-item> -->

                    <el-form-item label="责任处室" prop="prersonLiable">
                      <el-input
                        disabled
                        rows="4"
                        style="width: 80%; display: inline-block"
                        type="textarea"
                        v-model="form.prersonLiable"
                        placeholder="请选择责任处室"
                      />
                      <el-button
                        :disabled="isEdit"
                        style="margin-left: 20px"
                        type="primary"
                        @click="handleSelect"
                        >选择</el-button
                      >
                    </el-form-item>
                    <!-- <el-form-item label="完成时限" prop="doneTime">
                      <el-date-picker
                        :disabled="isEdit"
                        clearable
                        v-model="form.doneTime"
                        type="date"
                        value-format="YYYY-MM-DD"
                        placeholder="请选择完成时限"
                      >
                      </el-date-picker>
                      <el-input
                        :disabled="isEdit"
                        style="margin-top: 20px"
                        rows="3"
                        type="textarea"
                        v-model="form.doneContent"
                        placeholder="**月**日
    ****要求/文件要求/部门确定"
                        :min-height="192"
                      />
                    </el-form-item> -->
                    <el-form-item label="各处室进度详情">
                      <!-- <el-descriptions
                        v-if="showDel != 0"
                        class="margin-top"
                        title=" "
                        :column="2"
                        :size="descriptionstype"
                        border
                      >
                        <div
                          v-for="item in form.ywSupervisionItemList"
                          :key="item.id"
                        >
                          <el-descriptions-item min-width="200">
                            <template #label>
                              <div class="cell-item" style="min-width: 200px">
                                {{ item.deptName }}-{{ item.userName }}
                              </div>
                            </template>
                            {{ item.progress }}
                          </el-descriptions-item>
                          <el-descriptions-item min-width="200">
                            修改
                          </el-descriptions-item>
                        </div>
                      </el-descriptions> -->
                      <el-table
                        v-if="showDel != 0"
                        :data="form.ywSupervisionItemList"
                        border
                        style="width: 100%"
                      >
                        <el-table-column
                          width="120"
                          prop="deptName"
                          label="部门"
                        >
                        </el-table-column>
                        <el-table-column
                          width="120"
                          prop="userName"
                          label="姓名"
                        >
                        </el-table-column>
                        <el-table-column prop="progress" label="进展情况">
                        </el-table-column>

                        <el-table-column
                          align="center"
                          fixed="right"
                          label="操作"
                          width="100"
                        >
                          <template #default="scope">
                            <el-button
                              v-if="this.userId == scope.row.userId"
                              @click="editJinDu(scope.row)"
                              icon="edit"
                              type="text"
                              size="small"
                              >修改</el-button
                            >
                          </template>
                        </el-table-column>
                      </el-table>
                      <div v-else>暂无</div>
                    </el-form-item>
                    <el-form-item
                      label="进展情况"
                      prop="progress"
                      v-if="isCsfk"
                    >
                      <el-input
                        rows="12"
                        type="textarea"
                        v-model="formData.progress"
                        placeholder="请输入进展情况"
                      />
                    </el-form-item>
                    <el-form-item
                      label="进度评价"
                      v-if="isEval && liucheng != false"
                    >
                      <el-select
                        v-model="form.progressEva"
                        placeholder="请选择进度评价"
                        clearable
                        style="width: 240px"
                      >
                        <el-option
                          v-for="dict in progress_eva"
                          :key="dict.value"
                          :label="dict.label"
                          :value="dict.value"
                        />
                      </el-select>
                    </el-form-item>
                  </el-form>
                  <!--  下一步提交            -->
                  <div v-if="liucheng">
                    <el-divider></el-divider>
                    <el-form v-show="submitShow" label-width="120px">
                      <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>
                      <div style="width: 100%" v-show="guidangBt != true">
                        <el-form-item v-if="optionsInfo" label="审核意见">
                          <el-col :span="24">
                            <el-input
                              style="width: 16vw"
                              type="textarea"
                              :rows="2"
                              placeholder="请输入审核意见"
                              v-model="formData.reviewMsg"
                            />
                          </el-col>
                        </el-form-item>
                        <div style="text-align: center; width: 100%">
                          <el-button
                            :loading="loadingWebLoad"
                            @click="sendNext"
                            type="primary"
                            >提交
                          </el-button>

                          <el-button
                            v-if="showBack"
                            @click="sendBack"
                            type="danger"
                            >退回
                          </el-button>
                        </div>
                      </div>
                    </el-form>
                    <el-form label-width="120px" v-show="guidangBt">
                      <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>
                      <div style="text-align: center; align-items: center">
                        <el-button
                          :disabled="false"
                          @click="sendNext"
                          type="primary"
                          >归档
                        </el-button>
                      </div>
                    </el-form>
                  </div>
                </div>
              </div>
            </el-tab-pane>
            <el-tab-pane label="流转记录">
              <template #label>
                <span style="font-size: 15px" class="custom-tabs-label">
                  <el-icon><Promotion style="padding-top: 2px" /></el-icon>
                  <span>流转记录</span>
                </span>
              </template>
              <div>
                <el-table border :data="liuzhuanData" style="width: 100%">
                  <el-table-column
                    align="center"
                    label="序号"
                    width="60"
                    type="index"
                  >
                  </el-table-column>
                  <el-table-column
                    align="center"
                    prop="NDFromT"
                    label="节点名称"
                    width="180"
                  >
                  </el-table-column>
                  <el-table-column
                    align="center"
                    width="80"
                    prop="ActionTypeText"
                    label="办理状态"
                  >
                  </el-table-column>
                  <el-table-column
                    align="center"
                    prop="EmpFromT"
                    label="办理人"
                  >
                  </el-table-column>
                  <el-table-column
                    width="160"
                    align="center"
                    prop="SDT"
                    label="到达时间"
                  >
                  </el-table-column>
                  <el-table-column
                    width="160"
                    align="center"
                    prop="RDT"
                    label="处理时间"
                  >
                  </el-table-column>
                  <el-table-column
                    align="center"
                    prop="ActionType22"
                    label="审核意见"
                  >
                    <template #default="scope">
                      <div v-if="scope.row.ActionType22 != undefined">
                        <div v-for="item in scope.row.ActionType22" :key="item">
                          <div>{{ item.Msg }}</div>
                        </div>
                      </div>
                      <div v-else>
                        <div v-if="scope.row.ActionTypeText == '退回'">
                          退回原因：{{ scope.row.Msg }}
                        </div>
                        <div v-if="scope.row.ActionTypeText == '移交'">
                          移交原因：{{ scope.row.Msg }}
                        </div>
                      </div>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
              <!-- <iframe :src="tuurl" width="100%" height="500px"></iframe> -->
            </el-tab-pane>
          </el-tabs>
        </el-col>
        <el-col :span="3">
          <div class="grid-content ep-bg-purple" />
        </el-col>
      </el-row>

      <select-user
        ref="selectRef"
        @ok="handleQuery"
        @closeDialogf="closeSelUser"
      ></select-user>
      <!-- 退回 -->
      <el-dialog title="退回" v-model="dialogBack" width="40%">
        <el-form>
          <el-form-item label-width="12vw" 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="12vw"
            label="退回原因："
            placeholder="请输入退回原因"
          >
            <el-input v-model="returnMsg" style="width: 20vw" type="textarea" />
          </el-form-item>
        </el-form>
        <span
          style="position: relative; left: 26vw"
          slot="footer"
          class="dialog-footer"
        >
          <el-button @click="dialogBack = false">取 消</el-button>
          <el-button type="primary" @click="submitNodeBack">确 定</el-button>
        </span>
      </el-dialog>
      <!-- 进展情况 -->
      <el-dialog
        title="进展情况"
        style="height: 460px"
        v-model="dialogEdit"
        width="60%"
      >
        <el-form style="padding: 0 30px">
          <el-form-item label-width="6vw" label="进展情况：">
            <el-input v-model="progress" :rows="14" type="textarea" />
          </el-form-item>
        </el-form>
        <span style="float: right" slot="footer">
          <el-button @click="dialogEdit = false">取 消</el-button>
          <el-button type="primary" @click="jinDuSub">确 定</el-button>
        </span>
      </el-dialog>
      <el-dialog
        v-model="dialogVisibleSel"
        title="请选择责任处室"
        width="1200px"
        style="height: 850px"
        :before-close="handleClose"
      >
        <el-row :gutter="20">
          <el-col
            style="
              padding: 0;
              width: 250px;
              border: 1px solid #e7eaec;
              border-radius: 5px;
              min-height: 680px;
            "
            :span="4.5"
            :xs="24"
          >
            <div
              style="
                display: flex;
                width: 250px;
                height: 40px;
                line-height: 40px;
                border-bottom: 1px solid #e7eaec;
                margin-bottom: 10px;
              "
            >
              <div
                @click="toggle(0)"
                :class="{ selected: fontIndex === 0 }"
                style="
                  font-size: 17px;
                  margin-left: 15px;
                  padding-left: 10px;
                  height: 40px;
                  width: 110px;
                  border-right: 1px solid #e7eaec;
                  cursor: pointer;
                "
              >
                所属部门
              </div>
            </div>
            <div class="head-container"></div>
            <!-- 部门 -->
            <div class="head-container">
              <el-tree
                :data="deptOptions"
                :props="{ label: 'label', children: 'children' }"
                :expand-on-click-node="false"
                :filter-node-method="filterNode"
                ref="dept"
                node-key="id"
                highlight-current
                default-expand-all
                @node-click="handleNodeClick"
                :current-node-key="currentNodeKey"
                :default-expanded-keys="expandedKeys"
              />
            </div>
          </el-col>
          <!-- 所属部门 -->
          <el-col
            style="margin-left: 40px; margin-top: 5px"
            :span="17"
            :xs="10"
          >
            <el-form
              :model="queryParams"
              ref="queryRef"
              :inline="true"
              label-width="68px"
              style="margin-bottom: 20px"
            >
              <el-form-item label="用户姓名" prop="nickName">
                <el-input
                  v-model="queryParams.nickName"
                  placeholder="请输入用户姓名"
                  clearable
                  style="width: 240px"
                />
              </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-table
              ref="multipleTable1"
              :row-key="getRowKeys"
              :data="userList"
              @selection-change="handleSelectionChange"
            >
              <el-table-column
                :selectable="getSelectable"
                :reserve-selection="true"
                type="selection"
                width="50"
                align="center"
              />
              <el-table-column
                label="用户姓名"
                align="center"
                key="nickName"
                prop="nickName"
                v-if="columns[2].visible"
                :show-overflow-tooltip="true"
              />
              <el-table-column
                :show-overflow-tooltip="true"
                align="center"
                prop="phonenumber"
                label="联系方式"
              ></el-table-column>
              <el-table-column
                label="所属部门"
                align="center"
                key="deptName"
                prop="dept.deptName"
                v-if="columns[3].visible"
                :show-overflow-tooltip="true"
              />
            </el-table>
            <div style="float: right; margin-top: 20px; margin-right: 20px">
              <el-pagination
                v-model:current-page="queryParams.pageNum"
                v-model:page-size="queryParams.pageSize"
                :page-sizes="[10, 20, 30, 50, 100]"
                :small="small"
                :disabled="disabled"
                :background="background"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
              />
            </div>
          </el-col>
        </el-row>

        <template #footer>
          <span class="dialog-footer">
            <el-button @click="this.dialogVisibleSel = false">取消</el-button>
            <el-button type="primary" @click="submitUserList"> 确认 </el-button>
          </span>
        </template>
      </el-dialog>
    </div>
  </el-dialog>
</template>
<script>
import { addCar } from "@/api/car";
import {
  generNextStepNode1,
  node_ReturnWork,
  getReviewMsg,
  getReturnWorkNode,
  getSelfParas,
  getWfGenerWorkList,
} from "@/api/liucheng";
import { ElMessage } from "element-plus";
import selectUser from "@/views/liucheng/selectUser.vue";
import { getJToken } from "@/utils/auth";
import { getInfo } from "@/api/login";
import { useDict } from "@/utils/dict";
import { deptTreeSelect } from "@/api/system/user";
import {
  selSuperVisionByWorkId,
  sendFlowToUsers1,
  updatemyselfDetail,
} from "@/api/offcial/supervision";
import Cookies from "js-cookie";
import { listType } from "@/api/archive/type";
import { saveArchive } from "@/api/archive/archive";
import { updateSupervision } from "../../../../api/offcial/supervision";
import { listUser2, deptTreeSelect2 } from "@/api/system/user";

export default {
  name: "YinetoaLeaveApplication",
  props: [
    "dialogVisible",
    "name",
    "showTable",
    "WorkId",
    "FK_Flow",
    "nodeName",
    "trueLeave",
    "closeDialog",
  ],
  components: { selectUser },
  data() {
    return {
      dialogVisibleSel: false,
      total: 0,
      columns: [
        { key: 0, label: `用户编号`, visible: true },
        { key: 1, label: `用户名称`, visible: true },
        { key: 2, label: `用户昵称`, visible: true },
        { key: 3, label: `部门`, visible: true },
        { key: 4, label: `手机号码`, visible: true },
        { key: 5, label: `状态`, visible: true },
        { key: 6, label: `创建时间`, visible: true },
      ],
      loading: false,
      selection: [],
      deptOptions: [],
      userList: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: undefined,
        phonenumber: undefined,
        status: undefined,
        deptId: undefined,
        nickName: undefined,
      },
      isEval: false,
      iconStyle: {
        large: "8px",
        default: "6px",
        small: "4px",
      },
      LS: {
        color: "#000",
        "text-align": "center",
        "font-weight": "600",
        height: "40px",
        "background-color": "rgba(255, 97, 2, 0.1)",
        "min-width": "110px",
        "word-break": "keep-all",
      },
      descriptionstype: "default",
      isCsfk: false,
      form: { ywSupervisionStartUserList: [] },
      infoSourceData: useDict("info_source").info_source,
      sys_yes_no: useDict("sys_yes_no").sys_yes_no,
      progress_eva: useDict("progress_eva").progress_eva,
      optionsInfo: true,
      rules: {},
      returnMsg: null,
      formData: {
        reviewMsg: "同意",
        optionName: null,
        toNodeId: null,
        users: null,
        workid: null,
        progress: "",
      },
      liuzhuanData: [],
      tripFlowData: {},
      NextStepNode: [],
      guidangData: {
        archiveNo: null,
        workId: null,
        archiveFormNo: null,
        printNum: null,
        levels: null,
        typeId: null,
        name: null,
      },
      nodeValue: null,
      isEdit: true,
      tuurl: "",
      dialogBack: false,
      selNextNode: "",
      superVisionDialog: false,
      submitShow: true,
      guidangBt: false,
      nodeData: [],
      typeList: [],
      showDel: null,
      liucheng: true,
      userId: null,
      dialogEdit: false,
      progress: "",
      id: "",
      nowProgress: "",
      userIdAll: [],
    };
  },

  created() {
    this.getInfo();
  },
  watch: {},

  mounted() {},

  methods: {
    submitUserList() {
      // console.log("selection", this.selection);
      this.form.ywSupervisionStartUserList = [];
      this.form.prersonLiable = "";
      let arr = [];
      for (let i = 0; i < this.selection.length; i++) {
        let obj = {
          userName: this.selection[i].userName,
          userId: this.selection[i].userId,
          nickName: this.selection[i].nickName,
        };
        this.form.ywSupervisionStartUserList.push(obj);
        arr.push(
          this.selection[i].dept.deptName + "--" + this.selection[i].nickName
        );
        console.log("arr", arr);
        this.form.prersonLiable = arr.join(" , ");
      }
      console.log(
        "ywSupervisionStartUserList",
        this.form.ywSupervisionStartUserList
      );
      // let arr = this.selection.map((item) => {
      //   console.log(item);
      //   return item.dept.deptName + "--" + item.nickName;
      // });
      // this.form.prersonLiable = arr.join(" , ");
      console.log("this.form.prersonLiable", this.form.prersonLiable);
      this.dialogVisibleSel = false;
    },
    // // 多选框选中数据  常用联系人
    handleSelectionChange(selection) {
      console.log(selection);
      this.selection = [];
      this.selection = selection;

      this.single = this.selection.length !== 1;
      this.multiple = !this.selection.length;
    },
    // /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryRef");
      this.queryParams.deptId = undefined;
      this.$nextTick(() => {
        this.$refs.deptTreeRef.setCurrentKey(null);
      });
      this.handleQuery();
    },
    // /** 节点单击事件 */
    handleNodeClick(data) {
      this.queryParams.deptId = data.id;
      this.handleQuery();
    },
    getRowKeys(row) {
      return row.userId;
    },
    getSelectable(row) {
      return row.status !== "REJECT";
    },
    //分页
    handleSizeChange(newPage) {
      this.queryParams.pageSize = newPage;
      this.getList();
    },
    handleCurrentChange(val) {
      this.queryParams.pageNum = val;
      this.getList();
    },
    // /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // /** 查询部门下拉树结构 */
    async getDeptTree() {
      await deptTreeSelect2().then((response) => {
        this.deptOptions = response.data;
      });
    },
    async getList() {
      this.loading = true;
      await listUser2(this.addDateRange(this.queryParams, this.dateRange)).then(
        (res) => {
          this.loading = false;
          this.userList = res.rows;
          //console.log("this.userList", this.userList);
          this.total = res.total;
        }
      );
      this.selection = [];
    },
    handleSelect() {
      // this.mailUserIds = [];
      // this.getContactsTree();
      this.queryParams = {
        deptId: undefined,
        pageNum: 1,
        pageSize: 120,
        userName: undefined,
        phonenumber: undefined,
        status: undefined,
        postIds: undefined,
        beginTime: undefined,
        endTime: undefined,
      };
      this.getList();
      this.getDeptTree();

      // 回显
      console.log("回显", this.form.ywSupervisionStartUserList);
      if (this.form.ywSupervisionStartUserList.length > 0) {
        this.$nextTick(() => {
          this.$refs.multipleTable1.clearSelection();
          this.userIdAll = [];
          for (
            let i = 0;
            i < this.form.ywSupervisionStartUserList.length;
            i++
          ) {
            this.userIdAll.push(this.form.ywSupervisionStartUserList[i].userId);
          }
          console.log("this.userIdAll", this.userIdAll);
          setTimeout(() => {
            this.userIdAll.forEach((item) => {
              this.userList.forEach((item1) => {
                if (item == item1.userId) {
                  console.log("item1", item1);
                  this.$refs.multipleTable1.toggleRowSelection(item1, true);
                }
              });
            });
          }, 300);
        });
      }
      this.dialogVisibleSel = true;
    },
    jinDuSub() {
      this.dialogEdit = false;

      updatemyselfDetail({ progress: this.progress, id: this.id }).then(
        (res) => {
          this.$message.success("修改进度评价成功");
          selSuperVisionByWorkId(this.formData.workid).then((res) => {
            console.log("res", res);
            this.form = res.data;
            this.showDel = res.data.ywSupervisionItemList.length;
          });
        }
      );
    },
    getInfo() {
      getInfo().then((res) => {
        console.log(res);
        this.userId = res.user.userId;
      });
    },
    editJinDu(row) {
      this.getInfo();
      console.log("edit", row);
      this.progress = row.progress;

      this.id = row.id;
      this.dialogEdit = true;
    },
    async submitNodeBack() {
      if (this.nodeValue == null) {
        this.$message.error("请选择退回节点信息");
        return;
      }
      if (this.returnMsg == null) {
        this.$message.error("请输入退回原因");
        return;
      }
      this.$modal.loading("退回中，请稍后...");
      let res = await node_ReturnWork({
        workid: this.formData.workid,
        returnToNodeID: this.nodeValue,
        returnMsg: this.returnMsg,
      });
      this.$message.success(res);
      this.dialogBack = false;
      // this.superVisionDialog = false;
      this.$emit("closeViewLeave");
      this.nodeValue = null;
      this.returnMsg = null;
      this.valDate = null;
      this.selNextNode = null;
      this.$modal.closeLoading();
      this.colsedialog();
    },
    getDeptTree() {
      deptTreeSelect().then((response) => {
        this.deptOptions = response.data;
      });
    },
    sumbitSupervise() {
      sendFlowToNext;
    },
    changeDate(val) {
      var d1 = new Date(val[0]);
      var d2 = new Date(val[1]);
      var diff = d2 - d1;
      var days = diff / (1000 * 60 * 60 * 24);
      this.form1.dayNum = Math.floor(days) + 1;
    },

    showDetail1(flowData) {
      console.log("flowData", flowData);
      this.superVisionDialog = true;
      this.showBack = true;
      if (flowData.FK_Node == "1601") {
        this.showBack = false;
      }
      if (flowData.FK_Node == "1605") {
        console.log(flowData.FK_Node);
        this.isCsfk = true;
        this.optionsInfo = false;
      }
      if (flowData.FK_Node == "1606") {
        console.log(flowData.FK_Node);
        this.isEval = true;
      }
      var workid_1 = flowData.workId;
      if (flowData.workId == undefined) {
        workid_1 = flowData.WorkID;
      }
      console.log("workid_1", workid_1);
      getSelfParas(workid_1).then((res) => {
        console.log("是否可编辑原信息", res);
        if (res.data.SelfParas == "isEdit") {
          this.isEdit = false;
        }
      });
      this.tuurl =
        Cookies.get("jFontIp") +
        "/WF/Port.htm?DoWhat=OneWork2&WorkID=" +
        flowData.WorkID +
        "&FK_Flow=" +
        flowData.FK_Flow +
        "&Token=" +
        getJToken();
      this.tripFlowData = flowData;
      this.formData.optionName = flowData.NodeName;
      if (flowData.WorkID == null || flowData.WorkID == undefined) {
        this.formData.workid = flowData.workId;
      } else {
        this.formData.workid = flowData.WorkID;
      }
      getWfGenerWorkList(getJToken(), this.formData.workid).then((res) => {
        this.liuzhuanData = res.trackList;
      });
      selSuperVisionByWorkId(this.formData.workid).then((res) => {
        console.log("res", res);
        this.form = res.data;
        this.showDel = res.data.ywSupervisionItemList.length;
      });
      //获取下个节点
      generNextStepNode1("016", this.formData.workid, "", getJToken()).then(
        (res) => {
          if (res.msg == "Y") {
            this.NextStepNode = [];
            this.NextStepNode.push({ NodeID: 0, Name: "结束" });
          } else {
            this.NextStepNode = res.data;
          }
          this.selNextNode = this.NextStepNode[0].NodeID;
        }
      );
      if (flowData.WorkID != undefined) {
        if (
          this.formData.optionName.indexOf("归档") != -1 ||
          this.formData.optionName.indexOf("存档") != -1
        ) {
          this.getTypeList();
          this.formData.reviewMsg = "存档";
          this.guidangBt = true;
        }
      }
    },
    closeSendNext() {
      this.liucheng = false;
    },
    handleQuery(selUsers) {
      this.formData.users = selUsers;
      if (selUsers != undefined && selUsers != "") {
        this.onSubmit();
      }
    },
    colsedialog() {
      this.$emit("guanbi");

      this.superVisionDialog = false;
    },
    /** 查询归档类型列表 */
    getTypeList() {
      listType({}).then((response) => {
        this.typeList = this.handleTree(
          response.data,
          "archiveTypeId",
          "parentId"
        );
      });
    },
    sendNext() {
      if (this.formData.reviewMsg == "" || this.formData.reviewMsg == null) {
        this.$modal.msgWarning("请填写审核意见");
        return;
      }
      this.formData.toNodeId = this.selNextNode;
      let DeliveryWay = "";
      //查看当前是选择的那个节点
      this.NextStepNode.forEach((item, index) => {
        if (item.NodeID == this.selNextNode) {
          DeliveryWay = item.DeliveryWay;
        }
      });
      //判断当前节点是哪一个节点
      //DeliveryWay 3:绑定人员计算 7:发送给开始节点
      if (DeliveryWay == "3" || DeliveryWay == "7") {
        this.onSubmit();
      }
      //4:由发送人选择发送
      else if (DeliveryWay == "4" || DeliveryWay == "1" || DeliveryWay == "9") {
        this.openSelectUser();
        return;
      } else {
        this.onSubmit();
      }
    },
    sendBack() {
      this.dialogBack = true;
      this.getReturnWorkNode();
    },
    async getReturnWorkNode() {
      console.log(this.formData.workid);
      let nodeData = await getReturnWorkNode({ workid: this.formData.workid });
      this.nodeData = nodeData;
    },
    openSelectUser() {
      this.tripFlowData.toNodeId = this.selNextNode;
      this.$refs["selectRef"].show1(this.tripFlowData);
    },
    async onSubmit() {
      if (this.guidangBt) {
        this.guidangData.archiveFormNo = this.tripFlowData.FK_Flow;
        this.guidangData.workId = this.tripFlowData.WorkID;
        let { upresult } = await updateSupervision(this.form);
        let { archiveRes } = await saveArchive(this.guidangData);
      }
      sendFlowToUsers1(this.formData).then((response) => {
        if (response.code == 200) {
          if (
            response.data.VarAcceptersName != "" &&
            response.data.VarAcceptersName != "结束"
          ) {
            ElMessage({
              message:
                "已发送到" +
                response.data.VarToNodeName +
                "节点，接收人：" +
                response.data.VarAcceptersName,
              type: "success",
            });
          } else if (response.data.VarAcceptersName == "结束") {
            ElMessage({
              message: response.data.Message,
              type: "success",
            });
          } else {
            ElMessage({
              message: response.data.Message.replaceAll("@", ""),
              type: "success",
            });
          }
          this.colsedialog();
        } else {
          this.colsedialog();
        }
      });
    },

    reset() {
      this.form1 = {
        createBy: this.form.createBy,
        phone: this.form.phone,
      };
    },
    SubmitSelect(selUsers) {
      this.form.params["toEmps"] = selUsers;
      if (selUsers != undefined && selUsers != "") {
        console.log(this.form);
        addCar(this.form).then((res) => {
          this.$modal.msgSuccess(
            "已发送到" +
              res.data.VarToNodeName +
              "节点," +
              "处理人:" +
              res.data.VarAcceptersName
          );
          this.$nextTick(() => {
            this.reset();
            this.$refs.ruleFormRef.resetFields();
          });
          this.$emit("change1");
          this.$modal.closeLoading();
        });
      }
    },
  },
};
</script>

<style lang="scss" scoped></style>
