<template>
  <div
    style="
      background-color: #f4f7fc;
      height: 78vh;
      overflow: auto;
      padding: 20px;
    "
  >
    <el-row>
      <el-col :span="4"><div class="grid-content ep-bg-purple" /></el-col>
      <el-col :span="16">
        <el-tabs type="border-card" class="demo-tabs">
          <el-tab-pane>
            <template #label>
              <span class="custom-tabs-label">
                <el-icon><Document /></el-icon>
                <span style="margin-left: 5px">基本信息</span>
              </span>
            </template>
            <div
              v-loading="loading"
              class="grid-content ep-bg-purple-light"
              style="
                background-color: white;
                height: 68vh;
                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; margin-top: 10px; height: 700px">
                <el-form
                  ref="ruleFormRef"
                  :model="form1"
                  :rules="formRules"
                  label-width="265px"
                >
                  <!-- <div style="display: flex"> -->
                  <el-form-item prop="name" label="姓名：">
                    <el-input
                      disabled
                      v-model="form1.name"
                      style="width: 12vw"
                    />
                  </el-form-item>

                  <el-form-item prop="leaveTpye" label="请（休）假类别：">
                    <el-select
                      :disabled="showTable != undefined && !sendBackNode"
                      v-model="form1.leaveTpye"
                      clearable
                      placeholder="请选择请 (休) 假类别"
                      style="width: 12vw"
                    >
                      <el-option
                        v-for="dict in leave_type"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value"
                      />
                    </el-select>
                  </el-form-item>
                  <el-form-item prop="leaveTime" label="请（休）假起止日期：">
                    <el-col :span="24">
                      <el-date-picker
                        :disabled="showTable != undefined && !sendBackNode"
                        style="width: 20vw"
                        v-model="form1.leaveTime"
                        type="daterange"
                        value-format="YYYY-MM-DD"
                        range-separator="至"
                        start-placeholder="请选择起始日期"
                        end-placeholder="请选择截止日期"
                        @change="changeDate(form1.leaveTime)"
                      />
                    </el-col>
                  </el-form-item>
                  <el-form-item prop="leaveNumber" label="请（休）假天数：">
                    <!-- :disabled="showTable !== undefined" -->
                    <el-input
                      disabled
                      v-model="form1.leaveNumber"
                      style="width: 12vw; margin-right: 10px"
                    />天
                  </el-form-item>
                  <el-form-item prop="leaveReason" label="请（休）假事由：">
                    <el-col :span="23">
                      <el-input
                        :disabled="showTable != undefined && !sendBackNode"
                        style="width: 20vw"
                        v-model="form1.leaveReason"
                        type="textarea"
                      />
                    </el-col>
                  </el-form-item>
                  <el-form-item
                    prop=""
                    v-if="nodeInfo !== null"
                    label="退回原因："
                  >
                    <el-col :span="23">
                      <el-input
                        :disabled="showTable !== undefined"
                        style="width: 20vw"
                        v-model="nodeInfo"
                        type="textarea"
                      />
                    </el-col>
                  </el-form-item>
                  <div v-if="initTrue">
                    <div v-if="leaveTrue !== true">
                      <div v-if="leaveClear == true">
                        <!-- <el-form-item
                        v-if="showTable !== undefined"
                        label="下一步节点："
                      >
                        <el-select
                          v-model="selNextNode"
                          placeholder="请选择下一步节点"
                        >
                          <el-option
                            v-for="item in options"
                            :key="item.NodeID"
                            :label="item.Name"
                            :value="item.NodeID"
                        /></el-select>
                      </el-form-item> -->
                        <el-form-item label="销假日期：">
                          <el-date-picker
                            :disabled="showNodeXj"
                            v-model="valDate"
                            type="date"
                            placeholder="请选择销假日期"
                            value-format="YYYY-MM-DD"
                            :size="size"
                          />
                        </el-form-item>
                      </div>
                      <div v-else>
                        <el-form-item
                          v-if="showNode !== true"
                          label="下一步节点："
                        >
                          <el-select
                            v-model="selNextNode"
                            placeholder="请选择下一步节点"
                          >
                            <el-option
                              v-for="item in options"
                              :key="item.NodeID"
                              :label="item.Name"
                              :value="item.NodeID"
                          /></el-select>
                        </el-form-item>
                        <el-form-item
                          v-if="
                            (showTable && !sendBackNode) || showNode !== true
                          "
                          label="审核意见："
                        >
                          <el-col :span="23">
                            <el-input
                              v-model="reviewMsg"
                              style="width: 20vw"
                              type="textarea"
                            />
                          </el-col>
                        </el-form-item>
                        <!-- <el-form-item
                          v-if="showNode !== true"
                          label="审核意见："
                        >
                          <el-col :span="23">
                            <el-input
                              v-model="reviewMsg"
                              style="width: 20vw"
                              type="textarea"
                            />
                          </el-col>
                        </el-form-item> -->
                      </div>
                      <div v-if="showSubmit == true" style="text-align: center">
                        <div
                          v-if="showTable !== undefined"
                          style="text-align: center"
                        >
                          <el-form-item>
                            <el-button
                              v-if="showNode !== true"
                              style="margin-top: 4vh"
                              type="primary"
                              @click="sendNext('Y')"
                              >提交</el-button
                            >
                            <el-button
                              v-if="showNode == true"
                              style="margin-top: 4vh"
                              type="primary"
                              @click="sendNext('Y')"
                              >同意</el-button
                            >

                            <el-button
                              v-if="sendBackNode"
                              style="margin-top: 4vh"
                              type="danger"
                              @click="sendBack"
                              >退回</el-button
                            >
                            <el-button
                              v-if="showNode == true"
                              style="margin-top: 4vh"
                              type="danger"
                              @click="sendNext('N')"
                              >拒绝</el-button
                            >
                          </el-form-item>
                        </div>
                        <div v-else style="text-align: center">
                          <el-form-item style="margin-left: 4vw">
                            <el-button
                              style="padding: 0 35px; margin-top: 14vh"
                              type="primary"
                              @click="onSubmit"
                              >提交</el-button
                            >
                          </el-form-item>
                        </div>
                      </div>

                      <div v-else>
                        <el-button
                          v-if="showNode !== true"
                          style="margin-top: 4vh"
                          type="primary"
                          @click="sendNext('Y')"
                          >确认</el-button
                        >
                      </div>
                    </div>
                  </div>
                  <div style="text-align: center" v-else>
                    <el-button @click="submitClose" type="primary"
                      >确认</el-button
                    >
                  </div>
                </el-form>

                <!-- <el-table
              :data="tableData"
              v-if="showTable !== undefined"
              style="width: 100%"
            >
              <el-table-column
                type="index"
                align="center"
                label="序号"
                width="80"
              />
              <el-table-column
                prop="NodeName"
                align="center"
                label="处理步骤"
              />
              <el-table-column prop="EmpName" align="center" label="处理人" />
              <el-table-column
                prop="DeptName"
                align="center"
                label="处理部门"
              />
              <el-table-column prop="" align="center" label="到达日期">
                <template #default="scope">
                  {{ parseTime(scope.row.RDT, "{y}-{m}-{d} ") }}
                </template>
              </el-table-column>
              <el-table-column prop="" align="center" label="处理日期" />
            </el-table> -->
                <div style="text-align: center" v-if="closeDialog == true">
                  <el-button
                    style="padding: 0 30px; margin: 0px; margin-top: 2vh"
                    type="primary"
                    @click="closeLeaveDialog"
                    >关闭</el-button
                  >
                </div>
              </div>
            </div>
          </el-tab-pane>
          <el-tab-pane>
            <template #label>
              <span class="custom-tabs-label">
                <el-icon><Promotion /></el-icon>
                <span style="margin-left: 5px">流转记录</span>
              </span>
            </template>
            <!-- <iframe
              style="padding-left: 4vw"
              :src="tuurl"
              width="100%"
              height="500px"
            ></iframe> -->
            <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" prop="EmpFromT" label="办理人">
                </el-table-column>
                <el-table-column align="center" prop="SDT" label="到达时间">
                </el-table-column>
                <el-table-column align="center" prop="RDT" label="处理时间">
                </el-table-column>
                <el-table-column
                  align="center"
                  width="80"
                  prop="ActionTypeText"
                  label="办理状态"
                >
                </el-table-column>
                <el-table-column
                  align="center"
                  prop="ActionType22"
                  label="审核意见"
                >
                  <template #default="scope">
                    <div v-if="scope.row.ActionType == 2">
                      退回原因：{{ scope.row.Msg }}
                    </div>
                    <div v-else-if="scope.row.ActionType == 3">
                      移交原因：{{ scope.row.Msg }}
                    </div>
                    <div v-else-if="scope.row.ActionType22 != undefined">
                      <div v-for="item in scope.row.ActionType22" :key="item">
                        <!-- <div></div> -->
                        <div>{{ item.Msg }}</div>
                      </div>
                    </div>
                    <div v-else>{{ scope.row.Msg }}</div>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </el-tab-pane></el-tabs
        >
      </el-col>
      <el-col :span="4"><div class="grid-content ep-bg-purple" /></el-col>
    </el-row>

    <!-- 退回 -->
    <el-dialog title="退回" v-model="dialogBack" width="40%">
      <el-form>
        <el-form-item label-width="200" label="退回节点：">
          <el-select
            v-model="nodeValue"
            placeholder="请选择退回节点信息"
            style="width: 240px"
          >
            <el-option
              v-for="item in nodeData"
              :key="item.No"
              :label="item.Name"
              :value="item.No"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          label-width="200"
          label="退回原因："
          placeholder="请输入退回原因"
        >
          <el-input v-model="returnMsg" style="width: 20vw" type="textarea" />
        </el-form-item>
      </el-form>
      <span
        style="position: relative; left: 28vw"
        slot="footer"
        class="dialog-footer"
      >
        <el-button @click="dialogBack = false">取 消</el-button>
        <el-button type="primary" @click="submitNodeBack">确 定</el-button>
      </span>
    </el-dialog>
    <select-user
      @ok="handleQuery"
      @closeDialogf="closeSelUser"
      ref="selectRef"
    ></select-user>
  </div>
</template>

<script>
import {
  leave,
  getLeave,
  getReturnWorkNode,
  WorkProgressBar,
  NodeReturnWork,
  getMsgByType,
} from "@/api/clocking/leave";
import {
  generNextStepNode1,
  sendFlowToNext,
  sendFlowToNextLeave,
  judgeNode,
  getWfGenerWorkList,
  node_ReturnWork,
} 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 Cookies from "js-cookie";
import { get } from "@vueuse/core";
export default {
  name: "YinetoaLeaveApplication",
  props: [
    "dialogVisible",
    "name",
    "showTable",
    "WorkId",
    "FK_Flow",
    "nodeName",
    "FKNode1",
    "trueLeave",
    "closeDialog",
  ],
  components: { selectUser },
  data() {
    var validator2 = (rule, val, callback) => {
      if (!val) {
        callback(new Error("请输入请假天数"));
      } else {
        const reg = /^([0-9])*$/; //
        if (reg.test(val)) {
          return callback();
        } else {
          callback(new Error("格式错误，仅支持输入纯数字"));
        }
      }
    };

    return {
      sendBackNode: true,
      showNodeXj: false,
      tuurl: "",
      nodeInfo: null,
      initTrue: true,
      showSubmit: true,
      leave_type: useDict("leave_type").leave_type,
      loading: false,
      leaveTrue: false,
      valDate: null,
      nodeValue: null,
      returnMsg: null,
      dialogBack: false,
      reviewMsg: "同意",
      formData: {
        jtoken: null,
        optionName: null,
        toNodeId: null,
        users: null,
        workid: null,
        reviewMsg: null,
      },
      leaveInfo: [
        {
          lable: "事假",
          value: "0",
        },
        {
          lable: "年假",
          value: "1",
        },
        {
          lable: "病假",
          value: "2",
        },
      ],
      flowDatas: {
        FK_Flow: null,
        toNodeId: "",
        WorkID: "",
      },
      flowData: {},
      selNextNode: null,
      tableData: [],
      nodeData: [],
      liuzhuanData: [],
      queryParams: {
        token: null,
        workID: null,
      },
      FK_flow: null,
      FK_node: this.FKNode1,

      leaveClear: false,
      workId: null,
      value2: "",
      showNode: false,
      // name: "",
      input: "",
      form1: {
        leaveTime: null,
      },
      form: {
        status: "1",
      },
      options: [],
      leaveTime: "",
      formRules: {
        name: [{ required: true, trigger: "blur", message: "请输入您的姓名" }],
        leaveNumber: [
          {
            required: true,
            trigger: "blur",
            validator: validator2,
            // message: "请输入请（休）假天数",
          },
        ],
        leaveTpye: [
          {
            required: true,
            message: "请选择请（休）假类别",
            trigger: "change",
          },
        ],
        leaveStartTime: [
          {
            required: true,
            message: "请选择请（休）假起始时间",
            trigger: "change",
          },
        ],
        leaveTime: [
          {
            required: true,
            message: "请选择请（休）假起止时间",
            trigger: "change",
          },
        ],
        leaveEndTime: [
          {
            required: true,
            message: "请选择请（休）假截止时间",
            trigger: "change",
          },
        ],
        leaveReason: [
          {
            required: true,
            message: "请输入请（休）假事由",
            trigger: "change",
          },
        ],
      },
    };
  },

  created() {},
  mounted() {},
  watch: {
    trueLeave: {
      handler(newValue, oldValue) {
        if (newValue) {
          this.leaveTrue = newValue;
        }
      },
      deep: true,
      immediate: true,
    },
    name: {
      handler(newValue, oldValue) {
        if (newValue) {
          this.form1.name = newValue;
        }
      },
      deep: true,
      immediate: true,
    },
    WorkId: {
      handler(newValue, oldValue) {
        if (newValue) {
          this.workId = newValue;
          this.selNextNode = null;
          this.nodeValue = null;
          this.returnMsg = null;
          this.valDate = null;
        }
        this.getLiuzhuanData();
        this.getLeave();
      },
      deep: true,
      immediate: true,
    },
    FK_Flow: {
      handler(newValue, oldValue) {
        if (newValue) {
          this.FK_flow = newValue;
        }
      },
      deep: true,
      immediate: true,
    },
    FKNode1: {
      handler(newValue, oldValue) {
        console.log(newValue, oldValue);
        if (newValue) {
          this.FK_node = newValue;
          this.initTrue = true;
          this.sendBackNode = true;
          this.leaveClear = false;
          if (this.FK_node == "907") {
            this.leaveClear = true;
            this.sendBackNode = false;
            this.showNodeXj = false;
          }
          if (this.FK_node == "908") {
            this.leaveClear = true;
            this.sendBackNode = false;
            this.showNodeXj = true;
          }
          if (this.FK_node == "905") {
            this.sendBackNode = false;
          }
          if (this.FK_node == "904") {
            this.sendBackNode = false;
          }
          if (this.FK_node == "903") {
            this.sendBackNode = false;
          }
          if (this.FK_node == "911") {
            this.sendBackNode = false;
          }
          if (this.FK_node == "912") {
            this.sendBackNode = false;
          }
          if (this.FK_node == "901") {
            this.sendBackNode = false;
            this.getMsgByType1();
          }
          if (this.FK_node == "910") {
            this.initTrue = false;
          }
        }
        console.log("876565656565656565656565");
        this.getLeave();
      },
      deep: true,
      immediate: true,
    },
    nodeName: {
      handler(newValue, oldValue) {
        if (newValue) {
          // this.initTrue = true;
          // this.sendBackNode = true;
          this.NodeName = newValue;
        }
      },
      deep: true,
      immediate: true,
    },
  },

  mounted() {},

  methods: {
    getLiuzhuanData() {
      getWfGenerWorkList(getJToken(), this.workId).then((res) => {
        this.liuzhuanData = res.trackList;
      });
    },
    async getMsgByType1() {
      let { data } = await getMsgByType(this.WorkId, "2");
      this.nodeInfo =
        data[Object.keys(data)[0]][data[Object.keys(data)[0]].length - 1].Msg;
    },
    async judgeNode() {
      let { msg } = await judgeNode(this.FK_node, getJToken());
      if (msg == "Y") {
        this.showSubmit == true;
      } else {
        this.showSubmit == false;
      }
    },
    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.leaveNumber = Math.floor(days) + 1;
    },
    closeLeaveDialog() {
      this.$modal.closeLoading();
      this.$emit("closeViewLeave");
    },

    async submitNodeBack() {
      if (this.nodeValue == null) {
        this.$message.error("请选择退回节点信息");
        return;
      }
      if (this.returnMsg == null) {
        this.$message.error("请输入退回原因");
        return;
      }
      this.$modal.loading("退回中，请稍后...");
      let res = await NodeReturnWork(
        this.workId,
        this.nodeValue,
        this.returnMsg
      );
      this.$message.success(res);
      this.dialogBack = false;
      this.$modal.closeLoading();
      this.$emit("closeViewLeave");
      this.nodeValue = null;
      this.returnMsg = null;
      this.valDate = null;
      this.selNextNode = null;
    },
    submitClose() {
      this.$emit("closeViewLeave");
      this.nextSubmit();
    },
    async getReturnWorkNode() {
      let nodeData = await getReturnWorkNode(getJToken(), this.workId);
      this.nodeData = nodeData;
    },
    sendBack() {
      this.dialogBack = true;
      this.getReturnWorkNode();
      if (this.NodeName == "请假人员") {
        this.leaveClear = false;
      }
    },
    /** 选择用户后进行下一步 */
    handleQuery(selUsers) {
      this.formData.users = selUsers;
      if (selUsers != undefined && selUsers != "") {
        this.nextSubmit();
      }
    },
    //下一步提交
    async nextSubmit() {
      this.$modal.loading("提交中,请稍后...");
      this.formData.jtoken = getJToken();
      this.formData.workid = this.workId;
      this.formData.toNodeId = this.selNextNode;
      if (this.leaveClear == true) {
        this.formData.reviewMsg = "同意";
      } else {
        this.formData.reviewMsg = this.reviewMsg;
      }
      this.formData.xjDate = this.valDate;
      this.formData.optionName = this.nodeName;
      console.log("formData", this.formData);
      let response = await sendFlowToNextLeave(this.formData);

      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.$refs["selectRef"].closeView();
        this.$modal.closeLoading();
        this.$emit("closeViewLeave");
        this.selNextNode = null;
        this.reviewMsg = "";
      }
    },

    //获取下一节点的接收人信息
    sendNext(Yn) {
      if (this.leaveClear == true) {
        if (this.showNode == true) {
          if (this.selNextNode == undefined) {
            this.$modal.msgWarning("请选择下一节点");
            return;
          }
        }

        if (this.valDate == null) {
          this.$modal.msgWarning("请选择销假日期！");
          return;
        }
      } else {
        if (this.showNode !== true) {
          if (this.selNextNode == undefined) {
            this.$modal.msgWarning("请选择下一节点");
            return;
          }
        }
        if (this.reviewMsg == "") {
          this.$modal.msgWarning("请填写审批意见！");
          return;
        }
      }
      if (this.NodeName == "人事处") {
      }
      this.flowData.token = getJToken();
      this.flowData.workid = this.workId.toString();
      this.flowData.flowNo = this.FK_Flow;
      console.log(this.flowData.paras);
      if (this.flowData.paras != "" && this.flowData.paras != undefined) {
        this.flowData.paras = this.flowData.paras + Yn;
      }
      console.log("7869", this.flowData);
      ///////////////////////////!

      generNextStepNode1(
        this.flowData.flowNo,
        this.flowData.workid,
        this.flowData.paras,
        this.flowData.token
      ).then((res) => {
        console.log(res);
        if (res.data.length > 0) {
          res.data.filter((item) => {
            if (item.DeliveryWay == 4) {
              this.openSelectUser();
              if (res.data.length == 1) {
                this.selNextNode = res.data[0].NodeID;
              }
            } else {
              console.log("111111111111111111111111111111");
              if (res.msg == "Y") {
                res.data.push({ NodeID: 0, Name: "结束" });
                console.log("41111111111");
                this.nextSubmit();
              } else if (res.data.length == 1) {
                this.selNextNode = res.data[0].NodeID;
                this.nextSubmit();
              } else {
                this.$modal.msgWarning("流转信息配置错误，请联系管理员");
              }
            }
          });
        } else {
          console.log("111111111111111111111111111111");
          if (res.msg == "Y") {
            res.data.push({ NodeID: 0, Name: "结束" });
            console.log("41111111111");
            this.nextSubmit();
          } else if (res.data.length == 1) {
            this.selNextNode = res.data[0].NodeID;
            this.nextSubmit();
          } else {
            this.$modal.msgWarning("流转信息配置错误，请联系管理员");
          }
        }
      });
      if (!this.showSubmit) {
        this.nextSubmit();
        return;
      }
      // if (this.showNode !== true) {
      // }
      // this.$refs["selectRef"].show1(this.flowDatas);
    },
    openSelectUser() {
      this.flowDatas.WorkID = this.flowData.workid;
      this.flowDatas.FK_Flow = this.FK_Flow;
      this.flowDatas.toNodeId = "904";
      this.$refs["selectRef"].show1(this.flowDatas);
    },
    //获取工作进度
    WorkProgressBar() {
      // this.queryParams.token = getJToken();
      // this.queryParams.workID = this.workId;
      // let { Track } = await WorkProgressBar(getJToken(), this.workId);
      // this.tableData = Track;
      this.tuurl =
        Cookies.get("jFontIp") +
        "/WF/Port.htm?DoWhat=OneWork2&WorkID=" +
        this.WorkId +
        "&FK_Flow=" +
        this.FK_Flow +
        "&Token=" +
        getJToken();
    },
    //获取审批信息
    async getLeave() {
      console.log("111111111111111111111111111111586");
      console.log(this.workId);
      let { data } = await getLeave(this.workId);
      console.log("date", data);
      this.form1.name = data.name;
      this.form1.leaveNumber = data.leaveNumber;
      this.form1.leaveReason = data.leaveReason;
      this.form1.leaveTpye = data.leaveTpye;
      this.form1.leaveTime = [data.leaveStartTime, data.leaveEndTime];
      this.valDate = data.xjDate;
      if (data.params.SelfParas !== "" || data.params.SelfParas !== null) {
        this.showNode = true;
        console.log("583679");
        this.flowData.paras = "@" + data.params.SelfParas + "=";
      } else {
        this.showNode = false;
      }
      //不是审批节点的时候获取下一步节点信息
      if (this.leaveTrue == false && this.leaveClear == true) {
        this.generNextStepAllNode();
      }
      this.judgeNode();

      this.WorkProgressBar();
    },
    async generNextStepAllNode() {
      let res = await generNextStepNode1(
        this.FK_flow,
        this.workId,
        "",
        getJToken()
      );
      console.log("sel", res);
      this.options = res.data;
      if (res.data.length == 0) {
        res.data.push({ NodeID: 0, Name: "结束" });
      }
      if (this.options.length == 1) {
        this.selNextNode = this.options[0].NodeID;
      }
    },
    //基本信息
    getInfo() {
      getInfo().then((res) => {
        this.form1.name = res.user.nickName;
      });
    },
    reset() {
      this.form1 = {
        name: "",
        leaveNumber: null,
        leaveTime: null,
        leaveTpye: null,
        leaveReason: null,
        status: "1",
      };
      this.form1.name = this.form.name;
    },
    onSubmit() {
      this.$modal.loading("提交中...");
      this.$refs["ruleFormRef"].validate((valid) => {
        if (valid) {
          this.form.leaveNumber = Number(this.form1.leaveNumber);
          this.form.name = this.form1.name;
          this.form.leaveReason = this.form1.leaveReason;
          this.form.leaveTpye = Number(this.form1.leaveTpye);
          this.form.leaveStartTime = this.form1.leaveTime[0];

          this.form.leaveEndTime = this.form1.leaveTime[1];

          leave(this.form).then((res) => {
            this.$modal.msgSuccess(
              "已发送到" +
                res.data.VarToNodeName +
                "节点," +
                "处理人:" +
                res.data.VarAcceptersName
            );
            this.$nextTick(() => {
              this.reset();
              this.$refs.ruleFormRef.resetFields();
            });
            this.$modal.closeLoading();
            this.$emit("change1");
          });
        } else {
          this.$modal.closeLoading();
        }
      });
    },
  },
};
</script>

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