/**version-1.0*/
import {getToken} from "../../utils/auth";
import settingConfig from "@/settings.js";
import {selectDialogMixins} from "../../mixins/selectDialog";

let configUtil = {
  baseUrl: process.env.VUE_APP_BASE_API,
  getToken,
  requireView: (url) => {
    return require("@/views" + url).default;
  },
};

let wfIndexMixin,
  wfStartMixin,
  wfContentMixin,
  wfModifyMixin,
  wfUrgingMixin,
  deleteTaskUserMixin,
  addTaskUserMixin;

function getTarget(t, flag) {
  let target;
  if (t.parentVue) {
    target = t.parentVue;
  } else if (flag === 0) {
    target = t.$parent.$parent;
  } else {
    target = t.$parent.$parent.$parent;
  }
  return target;
}

function oaPublishEvent(that) {
  let _closeWindowOnCheck = that.$attrs._closeWindowOnCheck || that._closeWindowOnCheck;
  if (_closeWindowOnCheck === true || _closeWindowOnCheck === "true") {
    let win = window.opener;
    if (win && domain && domain.call) {
      var event = {type: "topic", name: "successReloadPage"};
      domain.call(win, 'fireEvent', [event]);
    }
  }
}

wfIndexMixin = {
  name: "wfView",
  props: {
    objId: [String, Number],
    wfCode: String,
    serviceId: String,
  },
  data() {
    return {
      wfReloadFlag: false,
      hasWf: false,
      wfStartVisible: false,
      paramData: "",
      showModifyDialog: false,
      showBillEdit: false,
      content: "",
      wfInfo: "",
      currentTask: "",
      taskParam: "",
    };
  },
  computed: {
    current_prefix() {
      return this.serviceId ? "/" + this.serviceId : "";
    },
  },
  created() {
  },
  watch: {
    wfCode(val) {
      this.getWfInfo();
    },
    objId(val) {
      this.getWfInfo();
    },
  },
  async mounted() {
    if (this.objId) {
      let hasWf = false;
      let wfInfo, currentTask, taskParam;
      await this.initWfInfo().then((res) => {
        if (res && res.type == "success") {
          if (res.objx && res.objx.procInstId) {
            hasWf = true;
            wfInfo = res.objx;
          }
        }
      });

      if (hasWf) {
        /* await this.getCurrentTask(wfInfo).then(res1 => {
          if (res1.type == 'success') {
            currentTask = res1.objx;
          }
        }); */
        /* if (wfInfo.taskId) {
          await this.getTaskParams(currentTask).then(res2 => {
            if (res2.type == 'success') {
              taskParam = res2.objx;
            }
          });
        } */
      }
      this.paramData = taskParam;
      this.wfInfo = wfInfo;
      this.currentTask = currentTask;
      this.taskParam = taskParam;

      let flag = true;
      this.$emit("onShow", {
        wfInfo: wfInfo,
        currentTask: currentTask,
        taskParam: taskParam,
        hasWf: hasWf,
        callback: (val) => {
          flag = false;
          if (val !== false && hasWf) {
            this.wfReloadFlag = true;
          }
        },
      });
      if (flag) {
        if (hasWf) {
          this.wfReloadFlag = true;
        }
      }
    }
    this.$on("toDo", (option) => {
      this.$emit(option.methd, option.param);
    });
  },
  methods: {
    getWfInfo() {
      if (this.wfCode && this.objId) {
        this.reload();
      } else {
        this.wfReloadFlag = false;
      }
    },
    openStartWfDialog(code) {
      this.wfStartVisible = true;
    },
    reload() {
      this.wfReloadFlag = false;
      this.$nextTick(() => {
        this.wfReloadFlag = true;
      });
    },
    manualCallback() {
      this.$emit("manualCallback");
    },
    async getCurrentTask(obj) {
      let that = getTarget(this, 0);
      return that.$http({
        url: "/agilebpm/wf_task/getCurrentTask",
        data: {
          procInstId: obj.procInstId,
        },
        method: "post",
        async: false,
        isLoading: true,
        modalStrictly: true,
      });
    },
    async initWfInfo() {
      let that = getTarget(this, 0);
      let id = this.objId;
      let code = this.wfCode;
      return that.$http({
        url: this.current_prefix + "/wf/getWfInfo",
        method: `post`,
        data: {
          objTypeCode: code,
          objId: id,
        },
        isLoading: true,
        modalStrictly: true,
      });
    },
    async getTaskParams(data) {
      let that = getTarget(this, 0);
      return that.$http({
        url: "/agilebpm/wf_task/getTaskParams",
        method: `post`,
        data: {
          taskId: data.taskId,
        },
        isLoading: true,
        modalStrictly: true,
      });
    },
    openWfModifyDialog() {
      let row = this.paramData;
      let url = row.url + ".vue";
      this.showModifyDialog = true;
      this.content = configUtil.requireView(url);
      this.$openEditView("showBillEdit");
    },
    modfyDialogClose() {
      this.showBillEdit = false;
      this.content = null;
    },
  },
};

wfContentMixin = {
  name: "wfContent",
  props: {
    objId: [String, Number],
    wfCode: String,
    serviceId: String,
    _wfInfo: Object,
    _taskParam: Object,
    parentVue: Object,
    wfConfig: Object,
    defaultShowWfContent: Boolean,
  },
  computed: {
    current_prefix() {
      return this.serviceId ? "/" + this.serviceId : "";
    },
    viewTarget() {
      return getTarget(this);
    },
    isHideWf() {
      let that = this.viewTarget;
      let _hideWf = that._hideWf || that.$attrs._hideWf;
      return _hideWf === true || _hideWf === 'true';
    }
  },
  data() {
    let showWfFold =
      settingConfig.showWfFold != null && settingConfig.showWfFold != undefined
        ? settingConfig.showWfFold
        : false;
    if (this.wfConfig.showWfFold != null && this.wfConfig.showWfFold != undefined) {
      showWfFold = this.wfConfig.showWfFold;
    }
    let showWfContent =
      showWfFold &&
      settingConfig.defaultShowWfContent != null &&
      settingConfig.defaultShowWfContent != undefined
        ? settingConfig.defaultShowWfContent
        : true;
    if (
      this.defaultShowWfContent != null &&
      this.defaultShowWfContent != undefined
    ) {
      showWfContent = this.defaultShowWfContent;
    }

    return {
      fileInfos: [],
      showUserDialog: false,
      showContent: true,
      objTypeCode: "",
      // objId: '',
      wfInfo: {},
      // currentTask: {},
      taskParam: {},
      wfImage: "",
      wfStartBtn: false,
      wfManualendBtn: false,
      wfSubmitBtn: false,
      wfRejectBtn: false,
      changeHandlerBtn: false,
      wftaskData: [],
      allWfTaskOpinions: [],
      vxeOption: {},
      rejectNodes: [],
      rejectDialogVisible: false,
      rejectForm: {
        rejectSubmitModel: null,
        nodeId: null,
        opinion: null,
      },
      formLabelWidth: "120px",
      agreeDialogVisible: false,
      agreeForm: {
        opinion: this.$t2('同意', 'components.wf.defaultAgreeOption'),
        nodeId: null,
      },
      changeWfDialogVisible: false,
      changeWfForm: {},
      changeUserRows: [],
      taskStatuses: {
        start: {
          class: "blue",
          value: this.$t2('开始', 'components.wf.startStatus'),
        },
        approve: {
          class: "orgn",
          value: this.$t2('待审批', 'components.wf.approveStatus'),
        },
        submit: {
          class: "green",
          value: this.$t2('同意', 'components.wf.submitStatus'),
        },
        reject: {
          class: "red",
          value: this.$t2('驳回', 'components.wf.rejectStatus'),
        },
        transfer: {
          class: "green",
          value: this.$t2('转办', 'components.wf.transferStatus'),
        },
        addIncreaseSign: {
          class: "green",
          value: this.$t2('加签', 'components.wf.addIncreaseSignStatus'),
        },
        revoke: {
          class: "red",
          value: this.$t2('撤回', 'components.wf.revokeStatus'),
        },
        end: {
          class: "gray",
          value: this.$t2('结束', 'components.wf.endStatus'),
        },
      },
      opinion: "",
      showWfFold: showWfFold,
      showWfContent: showWfContent,

      urgingForm: {},
      urgingDialogVisible: false,
      urgingUserIds: [],
      urgingUsers: [],
      agreeNodes: [],
      showWfManualDialog: false,

      showDeleteTaskUserDialog: false,
      showAddTaskUserDialog: false,
      wfUserParam: {},
      wfUserParamForTransfer: {},//转办
      wfUserParamForAddSign: {},//加签
      wfUserParamForTalk: {},//沟通
      tabIndex: "1",
      linkupOption: {},
      talkForm: {
        receiverName: null,
        content: null,
        attachmentDTOs: [],
        replyId: null
      },
      showTalkUserDialog: false,
      showTalkDialog: false,
      showFlowImg: true,
      operateType: null,
      addIncreaseSignUsers: [],
      addIncreaseSignForm: {
        userNickNames: null,
        opinion: null
      },
      showAddIncreaseSignDialog: false,
      showOpeaImg: true,
      showSetCandidateDialog: false,
      toTalk: false,
      showAllWfOpinon: false,

      revokeDialogVisible: false,
      revokeForm: {opinion: null},
      showWfInfoTab: false,

      showWfMemo:false,
      wfMemoOption: {},
      wfMemoForm: {
        receiverName: null,
        content: null,
        attachmentDTOs: [],
        replyId: null
      },
      showWfMemoDialog: false,
      wfMemoData:[],

      showCandidate: false,
      candidateOption:{},
      candidateDatas:[],
      wfSendTaskId: null,
      showAddOpinionButton: false,

      addOpinionEnabled: false,
      modifyCurrentCandidateEnabled: false,

      //修改脚本
      showWfFlowEleScriptDialog: false
    };
  },
  provide() {
    return {
      getParentVue: () => this.parentVue,
      getWfInfo: () => this.wfInfo,
      getCurrentPrefix: () => this.current_prefix,
      getEditVueTarget: ()=> getTarget(this)
    };
  },
  created() {
    this.wfInfo = this._wfInfo;
    this.showFlowImg = settingConfig.expandWfImage === false ? false : true;
    this.showAllWfOpinon = settingConfig.showAllWfOpinon === true;
  },
  mounted() {
    this.initOperateType();
    this.initForAll();
  },
  methods: {
    openWfFlowEleScriptDialog(){
      this.showWfFlowEleScriptDialog = true
    },
    initWfParam13(){
      //初始化补充意见权限
      let that = getTarget(this);
      return that.$http({
        url: USER_PREFIX + "/wf_diy_attribute/getValue",
        method: `post`,
        data: {attributeKey: "param13"},
        success: (res) => {
          this.addOpinionEnabled = res?.objx === true;
          if(this.addOpinionEnabled){
            this.wfSendTaskId = this.getViewParam('wfSendTaskId');
            this.showAddOpinionButton = !!this.wfSendTaskId;
          }
        },
      });
    },

    initWfParam14(){
      //初始化修改当前候选人权限
      let that = getTarget(this);
      return that.$http({
        url: USER_PREFIX + "/wf_diy_attribute/getValue",
        method: `post`,
        data: {attributeKey: "param14"},
        success: (res) => {
          this.modifyCurrentCandidateEnabled = res?.objx === true;
        },
      });
    },
    getViewParam(key){
      let that = this.viewTarget;
      let value = that[key] || that.$attrs[key];
      return value;
    },
    initCandidate(){
      // 是否显示"节点候选人"选项卡
      let that = getTarget(this);
      that.$http({
        url: USER_PREFIX + "/wf_diy_attribute/getValue",
        method: `post`,
        data: {attributeKey: "param11"},
        isLoading: true,
        success: (res) => {
          this.showCandidate = res?.objx === true;
          if(this.showCandidate){
            this.$nextTick(()=>{
              this.initCandidateTable();
            })
          }
        },
      });
    },
    initCandidateTable(){
      let that = this;
      let tableOption = {
        vue: that,
        tableRef: 'table-candidate',
        tableName: 'wf_candidate-list',
        path: this.current_prefix + '/wf/getAllNodes',
        param: () => {
          return {
            stringOne: this.wfInfo.uuid
          }
        },
        config: {
          height: 350,
          proxyConfig: {
            props: {
              result: "objx", // 配置响应结果列表字段
              total: "objx.length", // 配置响应结果总页数字段
            },
          },
          pagerConfig:{
            autoHidden: true
          }
        },
        columns: [
          {type: 'checkbox', width: 50, resizable: false, fixed: 'left'},
          {title: this.$t2('节点名称', 'components.wf.nodeName'), field: 'nodeName', width: 250, fixed: 'left'},
          {
            field: 'wfTaskCandidates',
            title: this.$t2('候选人', 'components.wf.candidate'),
            width: 450,
            slots: {
              default: ({row, rowIndex}) => {
                return row.wfTaskCandidateDTOs ? row.wfTaskCandidateDTOs.map(item => item.name).join(",") : null;
              },
            },
          },
          {
            width: 47,
            fixed: 'right',
            title: '',
            sortable: false,
          }
        ]
      };
      this.$vxeTableUtil.initVxeTable(tableOption).then(opts => {
        that.candidateOption = opts;
      });
    },
    initOperateType() {
      if (this.operateType) {
        let wfInfo = this.wfInfo;
        if (wfInfo.toSubmit) {
          this.openAgreeDialog('submit');
        } else if (wfInfo.toReject) {
          this.rejectWfTask('reject');
        } else if (wfInfo.toAddIncreaseSign) {
          this.openAddIncreaseSign('addIncreaseSign')
        } else if (wfInfo.toRevoke) {
          this.openRevokeDialog('revoke')
        } else if (wfInfo.toLinkup) {
          this.openTalkDialog(null, null, 'talk');
        } else {
          this.operateType = null;
        }
      }
    },
    initForAll() {
      let that = getTarget(this);
      this.initWf(() => {
        if (this.wfInfo.procInstId) {
          this.initCurrentTask(this.wfInfo.procInstId, () => {
            this.initWftask(this.wfInfo.procInstId);
            this.getAllWfTaskOpinions();
          });
          this.initWfUserParam();
          this.initTabIndex();
          this.initShowTaskInfo();
          //初始化附言
          this.getIsShowWfMemo();
          // 是否显示"节点候选人"选项卡
          this.initCandidate()

          //初始化补充意见权限
          this.initWfParam13();

          //初始化修改当前候选人权限
          this.initWfParam14();

        }
      });
    },
    initTabIndex() {
      let that = getTarget(this);
      that.$http({
        url: USER_PREFIX + "/wf_diy_attribute/getValue",
        method: `post`,
        data: {attributeKey: "param7"},
        isLoading: true,
        success: (res) => {
          let val = res !== null ? res.objx === true : false;
          this.toTalk = val;
          let flag = false;
          if (val) {
            let flag1 = that.$attrs._isNotifyMessage == true || that.$attrs._isNotifyMessage == "true";
            if (flag1) {
              this.tabIndex = "2";
            }
            if (settingConfig.autoOpenWfLinkup) {
              flag = true;
              let flag2 = that.$attrs._wfNotifyType == "wfLinkup";
              let flag3 = flag1 && flag2;
              if (flag3) {
                this.$nextTick(() => {
                  let wfTabPane = this.$refs.wfTabPane;
                  if (!wfTabPane.showContent) {
                    wfTabPane.handleFold();
                  }
                });
              }
            }
          }
          this.initLinkup(flag);
        }
      });

    },
    initWf(done) {
      var data = this.wfInfo;
      if (data && data.procInstId) {
        /** 流程状态：0未启动，1审核中，2已完成，3驳回，4中断 */
        var statuses = {
          1: '<span class="tag">' + this.$t2('审核中', 'components.wf.wfStatus1') + '</span>',
          3: '<span class="tag red">' + this.$t2('已驳回', 'components.wf.wfStatus2') + '</span>',
          2: '<span class="tag green">' + this.$t2('已完成', 'components.wf.wfStatus3') + '</span>',
        };
        var statusStr = "";
        if (data.stat != null) {
          statusStr = statuses[data.stat] || "";
        }
        data.statusStr = statusStr;
        this.wfInfo = data;

        this.wfStartBtn = false;
        if (data.status != 2 && data.starterId) {
          this.wfManualendBtn = true;
        }
        this.wfSubmitBtn = false;
        this.wfRejectBtn = false;

        var url =
          this.current_prefix +
          "/wf/flowImage?procInstId=" +
          data.procInstId +
          "&_r=" +
          Math.random() +
          "&access_token=" +
          configUtil.getToken();
        this.wfImage = configUtil.baseUrl + url;
        done();
      }
    },
    initCurrentTask(procInstId, done) {
      if (this.wfInfo.taskId) {
        this.wfSubmitBtn = true;
        this.wfRejectBtn = true;
        this.changeHandlerBtn = true;
      }
      done();
    },
    initWftask(procInstId) {
      let that = getTarget(this);
      that.$http({
        url: this.current_prefix + "/wf/getWfTaskOpinionMerge",
        data: {
          stringOne: procInstId,
        },
        method: "post",
        async: false,
        isLoading: true,
        modalStrictly: true,
        success: (resultmsg) => {
          var datas = resultmsg.objx || [];
          this.wftaskData = datas;
        },
      });
    },
    getAllWfTaskOpinions() {
      if (!this.showAllWfOpinon) {
        return;
      }
      let that = getTarget(this);
      let wfInfo = this.wfInfo;
      that.$http({
        url: this.current_prefix + "/wf/getAllWfTaskOpinions",
        data: {
          objId: wfInfo.objId,
          objTypeCode: wfInfo.objTypeCode
        },
        method: "post",
        async: false,
        isLoading: true,
        modalStrictly: true,
        success: (resultmsg) => {
          var datas = resultmsg.objx || [];
          this.allWfTaskOpinions = datas;
        },
      });
    },
    openManualDialog(operateType) {
      this.operateType = operateType;
      this.showWfManualDialog = true;
    },
    manualEndWf() {
      this.showWfManualDialog = false;
      let that = getTarget(this);
      var procInstId = this.wfInfo.procInstId;
      var taskId = this.wfInfo.taskId ? this.wfInfo.taskId : "";
      var data = JSON.stringify({
        uuid: this.wfInfo.uuid,
      });
      that.$http({
        url: this.current_prefix + "/wf/interrupt",
        data: data,
        method: "post",
        headers: {
          "Content-Type": "application/json;charset=utf-8",
        },
        isLoading: true,
        success: (resultMsg) => {
          that.$message({
            message: resultMsg.content,
            type: "success",
            duration: 500,
            onClose: (t) => {
              this.reloadContent();
              this.closeWinOnCheck(3);
            },
          });
        },
      });
    },
    async rejectWfTask(operateType) {
      this.handleReminderContent("rejectReminder", async ()=>{
        let that = getTarget(this);
        var procInstId = this.wfInfo.procInstId;
        var taskId = this.wfInfo.taskId;
        var destinations = [];

        await that.$http({
          url: this.current_prefix + "/wf/getPreIncomeNodes",
          data: {
            stringOne: taskId,
          },
          method: "post",
          //contentType: 'application/json;charset=utf-8',
          async: false,
          isLoading: true,
          success: (resultMsg) => {
            destinations = (resultMsg.objx || []).reverse();
          },
        });

        if (destinations == null) {
          return false;
        }
        if (destinations.length == 0) {
          that.$message({
            message: this.$t2('无法驳回，没有目标节点', 'components.wf.rejectWarnMsg1'),
            type: "error",
            duration: 2 * 1000,
          });
          return false;
        }
        this.operateType = operateType;
        let rejectSubmitModel = null;
        if (this.wfInfo.toNextNode === 1) {
          rejectSubmitModel = this.wfInfo.toNextNode
        } else {
          rejectSubmitModel = this.wfInfo.toRejectNode == false ? 2 : null
        }
        this.rejectForm.rejectSubmitModel = rejectSubmitModel;
        this.rejectForm.nodeId = destinations[0].nodeId;
        this.rejectForm.opinion = "";
        this.rejectNodes = destinations;
        this.rejectDialogVisible = true;
      })

    },
    subRejectForm() {
      let that = getTarget(this);
      var procInstId = this.wfInfo.procInstId;
      var taskId = this.wfInfo.taskId;

      if (!this.rejectForm.nodeId) {
        that.$message({
          message: this.$t2('请选择驳回节点', 'components.wf.rejectWarnMsg2'),
          type: "error",
          duration: 2 * 1000,
        });
        return false;
      }

      if (!this.rejectForm.opinion) {
        that.$message({
          message: this.$t2('请输入驳回意见', 'components.wf.rejectWarnMsg3'),
          type: "error",
          duration: 2 * 1000,
        });
        return false;
      }

      var data = JSON.stringify({
        taskId: taskId,
        uuid: this.wfInfo.uuid,
        nodeId: this.rejectForm.nodeId,
        suggestion: this.rejectForm.opinion,
        rejectSubmitModel: this.rejectForm.rejectSubmitModel
      });
      this.rejectDialogVisible = false;
      that.$http({
        url: this.current_prefix + "/wf/reject",
        data: data,
        method: "post",
        headers: {
          "Content-Type": "application/json;charset=utf-8",
        },
        isLoading: true,
        success: (resultMsg) => {
          that.$message({
            message: resultMsg.content,
            type: "success",
            duration: 500,
            onClose: (t) => {
              this.reloadContent();
              this.closeWinOnCheck(2);
            },
          });
        },
      });
    },
    handleReminderContent(scriptType, callback){
      let that = getTarget(this);
      that.$http({
          url: this.current_prefix + "/wf/getReminderContent",
          data: {
            scriptType,
            taskId: this.wfInfo.taskId,
            uuid: this.wfInfo.uuid,
          },
          method: "post",
          isLoading: true,
          errorMsg: false,
          success: (res) => {
            if(res.objx){
              that.$baseConfirm(res.objx).then(() => {
                callback && callback();
              });
            }else{
              callback && callback();
            }
          },
          error: (e) => {
            if(e.response.status === 404){
              callback && callback();
            }else{
              that.$errorMsg({
                content: e.message,
                type: 'error',
              });
            }
          },
      });
    },
    openAgreeDialog(operateType) {
      const done = () => {
        this.handleReminderContent("submitReminder", ()=>{
          this.operateType = operateType;
          let that = getTarget(this);
          this.agreeForm = {
            opinion: this.$t2('同意', 'components.wf.defaultAgreeOption'),
            nodeId: null,
          };
          this.agreeNodes = [];
          that.$http({
            url: this.current_prefix + "/wf/getNextOutgoingNodes",
            data: {
              stringOne: this.wfInfo.taskId,
            },
            method: "post",
            async: false,
            isLoading: true,
            success: (res) => {
              let nodes = res.objx || [];
              /*if (tq == true) {
                nodes.reverse();
              }*/
              if (nodes.length) {
                this.agreeForm.nodeId = nodes[0].nodeId;
              }
              this.agreeNodes = nodes;
              this.agreeDialogVisible = true;
            },
          });
        })
      }
      let wfConfig = this.wfConfig;
      if (wfConfig.onClickAgree) {
        wfConfig.onClickAgree(done)
      } else {
        done();
      }
    },
    subAgreeForm() {
      let wfConfig = this.wfConfig;
      let done = () => {
        this.subAgreeHandle();
      }
      if (wfConfig.onBeforeAgree) {
        wfConfig.onBeforeAgree(done)
      } else {
        done();
      }
    },

    subAgreeHandle() {
      let that = getTarget(this);
      let nodeId = null;
      if (this.agreeNodes.length) {
        if (!this.agreeForm.nodeId) {
          that.$message({
            message: this.$t2('请选择节点', 'components.wf.agreeWarnMsg1'),
            type: "error",
            duration: 2 * 1000,
          });
          return;
        }
        nodeId = this.agreeForm.nodeId;
      }

      var procInstId = this.wfInfo.procInstId;
      var taskId = this.wfInfo.taskId;
      var memo = this.agreeForm.opinion || this.$t2('同意', 'components.wf.defaultAgreeOption');
      var data = JSON.stringify({
        taskId: taskId,
        uuid: this.wfInfo.uuid,
        suggestion: memo,
        nodeId: nodeId,
      });
      this.agreeDialogVisible = false;
      that.$http({
        url: this.current_prefix + "/wf/submit",
        data: data,
        method: "post",
        headers: {
          "Content-Type": "application/json;charset=utf-8",
        },
        isLoading: true,
        success: (resultMsg) => {
          if (resultMsg.objx && resultMsg.objx.code == "999999") {
            this.errorSubmit({
              taskId: taskId,
              uuid: this.wfInfo.uuid,
              suggestion: memo,
              errorMsg: resultMsg.objx.errorMsg
            });
          } else {
            that.$message({
              message: resultMsg.content,
              type: "success",
              duration: 500,
              onClose: (t) => {
                this.reloadContent();
                this.closeWinOnCheck(1);
              },
            });
          }
        },
      });
    },
    errorSubmit(data) {
      let that = getTarget(this);
      that.$http({
        url: this.current_prefix + "/wf/errorSubmit",
        data: data,
        method: "post",
        isLoading: true,
        success: (resultMsg) => {
          that.$message({
            message: resultMsg.content,
            type: "success",
            duration: 500,
            onClose: (t) => {
              this.reloadContent();
              this.closeWinOnCheck(1);
            },
          });
        },
      });
    },
    openChangeWfForm(operateType) {
      this.operateType = operateType;
      this.changeWfDialogVisible = true;
      this.changeUserRows = [];
      this.changeWfForm = {
        userIds: [],
        userNickNames: null,
        opinion: null,
      };
    },
    subChangeWfForm() {
      let that = getTarget(this);
      var procInstId = this.wfInfo.procInstId;
      var taskId = this.wfInfo.taskId;

      var userIds = this.changeWfForm.userIds || [];
      var opinion = this.changeWfForm.opinion || null;

      if (!userIds.length) {
        that.$message({
          message: this.$t2('请选择转办人', 'components.wf.transferWarnMsg1'),
          type: "error",
          duration: 2000,
          onClose: (t) => {
          },
        });
        return false;
      }

      var data = JSON.stringify({
        taskId: taskId,
        uuid: this.wfInfo.uuid,
        transferTo: userIds,
        suggestion: opinion,
      });
      this.changeWfDialogVisible = false;
      that.$http({
        url: this.current_prefix + "/wf/transfer",
        data: data,
        method: "post",
        headers: {
          "Content-Type": "application/json;charset=utf-8",
        },
        isLoading: true,
        success: (resultMsg) => {
          that.$message({
            message: resultMsg.content,
            type: "success",
            duration: 500,
            onClose: (t) => {
              this.reloadContent();
              this.closeWinOnCheck(4);
            },
          });
        },
      });
    },
    userConfirm(rows) {
      if (rows.length > 0) {
        let changeUserRows = this.changeUserRows;
        let ids = changeUserRows.map((changeUserRow) => changeUserRow.id);
        let addRows = rows.filter((row) => !ids.includes(row.id));
        changeUserRows.push(...addRows);

        let row = rows[0];
        this.changeWfForm.userIds = changeUserRows.map(
          (changeUserRow) => changeUserRow.id
        );
        this.changeWfForm.userNickNames = changeUserRows
          .map((changeUserRow) => changeUserRow.nickName)
          .join(",");
      }
    },
    reloadContent() {
      let that = getTarget(this);
      oaPublishEvent(that);
      that.$baseReload();
    },
    closeWinOnCheck(flag) {
      //_closeWindowOnCheck=true, 1提交，2驳回，3中断，4转办时，5沟通 关闭窗口
      let that = getTarget(this);
      let _closeWindowOnCheck = that.$attrs._closeWindowOnCheck || that._closeWindowOnCheck;
      if (_closeWindowOnCheck === true || _closeWindowOnCheck === "true") {
        window.close && window.close();
      }
      let _handleCallback = that.$attrs._handleCallback || that._handleCallback;
      _handleCallback && _handleCallback(flag);
    },
    manualCallback() {
      this.$emit("manualCallback");
    },
    openUrgingDialog(operateType) {
      this.operateType = operateType;
      this.urgingDialogVisible = true;
    },
    openDeleteTaskUserDialog(operateType) {
      this.operateType = operateType;
      this.showDeleteTaskUserDialog = true;
    },
    openAddTaskUserDialog(operateType) {
      this.operateType = operateType;
      this.showAddTaskUserDialog = true;
    },
    openAddIncreaseSign(operateType) {
      this.operateType = operateType;
      this.addIncreaseSignUsers = [];
      this.addIncreaseSignForm = {userNickNames: null};
      this.showAddIncreaseSignDialog = true;
    },
    initWfUserParam(callback) {
      this.initTransferUserParam();//转办
      this.initAddSignUserParam();//加签
      this.initTalkUserParam();//沟通
    },
    //
    initTransferUserParam(callback) {
      //初始化转办用户参数
      let that = getTarget(this);
      return that.$http({
        url: USER_PREFIX + "/wf_diy_attribute/getValue",
        method: `post`,
        data: {attributeKey: "param1"},
        isLoading: true,
        modalStrictly: true,
        success: (res) => {
          this.wfUserParamForTransfer = res.objx || {};
          callback && callback();
        },
      });
    },
    initAddSignUserParam(callback) {
      //初始化加签用户参数
      let that = getTarget(this);
      return that.$http({
        url: USER_PREFIX + "/wf_diy_attribute/getValue",
        method: `post`,
        data: {attributeKey: "param2"},
        isLoading: true,
        modalStrictly: true,
        success: (res) => {
          this.wfUserParamForAddSign = res.objx || {};
          callback && callback();
        },
      });
    },
    initTalkUserParam(callback) {
      //初始化沟通用户参数
      let that = getTarget(this);
      return that.$http({
        url: USER_PREFIX + "/wf_diy_attribute/getValue",
        method: `post`,
        data: {attributeKey: "param3"},
        isLoading: true,
        modalStrictly: true,
        success: (res) => {
          this.wfUserParamForTalk = res.objx || {};
          callback && callback();
        },
      });
    },
    //
    resetLinkup() {
      this.formData = {};
      this.$refs["table-linkup"].commitProxy("reload");
    },
    searchLinkup() {
      this.$refs["table-linkup"].commitProxy("reload");
    },
    initLinkup(flag) {
      let h = this.$createElement;
      let statusMap = {
        0: this.$t2('未完成', 'components.wf.talkStatus0'),
        1: this.$t2('已完成', 'components.wf.talkStatus1'),
        2: this.$t2('已取消', 'components.wf.talkStatus2')
      };
      let tableOption = {
        vue: this,
        tableRef: "table-linkup",
        tableName: "wf_table-linkup",
        path: this.current_prefix + "/wf_linkup/listPage",
        param: () => {
          return {
            uuid: this.wfInfo.uuid,
          };
        },
        config: {
          height: 350
        },
        columns: [
          {type: "checkbox", width: 48, resizable: false, fixed: "left"},
          {
            title: this.$t2('任务名称', 'components.wf.taskName'),
            field: "taskName",
            width: 150,
            fixed: "left",
          },
          {
            title: this.$t2('发送人', 'components.wf.senderName'),
            field: "senderName",
            width: 150,
            slots: {
              default: "sender",
            },
          },
          {
            title: this.$t2('接收人', 'components.wf.receiverName'),
            field: "receiverName",
            width: 150,
            slots: {
              default: "receiver",
            },
          },
          {
            title: this.$t2('沟通内容', 'components.wf.talkContent'),
            field: "content",
            width: 250,
            showOverflow: false,
            slots: {
              default: ({row, rowIndex}) => {
                return row.replyId ? ("[" + this.$t2('回复', 'components.wf.reply') + "]" + row.content) : row.content;
              },
            },
          },
          {
            width: 150,
            title: this.$t2('沟通资料', 'components.wf.talkAttachment'),
            field: "attachmentImage",
            sortable: false,
            slots: {
              default: ({row, rowIndex}) => {
                let option = {
                  title: this.$t2('沟通资料', 'components.wf.talkAttachment'),
                  edit: false,
                  rows: (done) => {
                    done(row.attachmentDTOs);
                  },
                };
                return [
                  h("base-attachment", {
                    props: {
                      option: option,
                      imageLazy: false
                    },
                  }),
                ];
              },
            },
          },

          {
            title: this.$t2('状态', 'components.wf.status'),
            field: "status",
            width: 150,
            slots: {
              default: ({row, rowIndex}) => {
                return statusMap[row.status] || "";
              },
            },
          },
          {
            title: this.$t2('创建时间', 'system.label.createDate'),
            field: "createDate",
            width: 150,
          },
          {
            width: 80,
            fixed: "right",
            title: "",
            sortable: false,
            slots: {
              default: "operate"
            }
          },
        ],
        callback: (rows) => {
          if (rows.length && flag) {
            let row = rows[0];
            if (row.replyToSender) {
              this.$nextTick(() => {
                this.tabIndex = "2";
                this.openTalkDialog(row.sender, row.senderName, 'talk', 1, row.id)
              });
            }
          }
        }
      };
      this.$vxeTableUtil.initVxeTable(tableOption).then((opts) => {
        this.linkupOption = opts;
      });
    },
    cancelTalk(row) {
      let that = getTarget(this);
      that.$baseConfirm(this.$t2('您确定要取消沟通记录吗？', 'components.wf.cancelTalkTip')).then(() => {
        that.$http({
          url: this.current_prefix + "/wf_linkup/cancel",
          data: {id: row.id},
          method: "post",
          loadingTarget: document.body,
          isLoading: true,
          success: (resultMsg) => {
            that.$message({
              message: resultMsg.content,
              type: "success",
              duration: 500,
              onClose: (t) => {
                this.reloadContent();
              },
            });
          },
        });
      });
    },
    openTalkDialog(receiver, receiverName, operateType, flag, replyId) {
      this.operateType = operateType;
      /*this.talkForm.receiver = receiver || null;
      this.talkForm.receiverName = receiverName || null;
      this.talkForm.replyId = replyId || null;
      this.talkForm.content = null;
      this.talkForm.attachmentDTOs = [];*/
      this.initTalkForm(receiver, receiverName, replyId)
      this.showTalkDialog = true;
      if (flag == 1) {
        let opeaBtnDom = this.$refs.opeaBtn;
        opeaBtnDom && opeaBtnDom.scrollIntoView();
      }
    },
    initTalkForm(receiver, receiverName, replyId) {
      this.talkForm.receiver = receiver || null;
      this.talkForm.receiverName = receiverName || null;
      this.talkForm.replyId = replyId || null;
      this.talkForm.content = null;
      this.talkForm.attachmentDTOs = [];
    },
    submitTalkForm() {
      let that = getTarget(this);
      var procInstId = this.wfInfo.procInstId;
      var taskId = this.wfInfo.taskId;

      if (!this.talkForm.receiver) {
        that.$message({
          message: this.$t2('请选择接收人', 'components.wf.talkWarnMsg1'),
          type: "error",
          duration: 2 * 1000,
        });
        return false;
      }
      if (!this.talkForm.content) {
        that.$message({
          message: this.$t2('请输入沟通内容', 'components.wf.talkWarnMsg2'),
          type: "error",
          duration: 2 * 1000,
        });
        return false;
      }

      var data = {
        taskId: taskId,
        uuid: this.wfInfo.uuid,
        receiver: this.talkForm.receiver,
        receiverName: this.talkForm.receiverName,
        replyId: this.talkForm.replyId,
        content: this.talkForm.content,
        attachmentDTOs: this.talkForm.attachmentDTOs,
        notifyType: "wfLinkup",
      };
      this.showTalkDialog = false;
      that.$http({
        url: this.current_prefix + "/wf_linkup/save",
        data: data,
        method: "post",
        isLoading: true,
        success: (resultMsg) => {
          that.$message({
            message: resultMsg.content,
            type: "success",
            duration: 500,
            onClose: (t) => {
              this.reloadContent();
              this.closeWinOnCheck(5);
            },
          });
        },
      });
    },
    openTalkUserDialog() {
      this.showTalkUserDialog = true;
    },
    confirmTalkUserDialog(rows) {
      if (rows.length > 0) {
        let row = rows[0];
        if (this.talkForm.receiver != row.id) {
          this.talkForm.replyId = null;
        }
        this.talkForm.receiver = row.id;
        this.talkForm.receiverName = row.nickName;
      }
    },
    confirmUrging() {
      this.reloadContent();
    },
    confirmDeleteTaskUser() {
      this.reloadContent();
    },
    confirmAddTaskUser(rows) {
      this.addIncreaseSignUsers = rows;
      this.addIncreaseSignForm.userNickNames = rows.map(row => row.nickName).join(',');
      // this.reloadContent();
    },
    submitAddTaskUserForm(flag) {
      let that = getTarget(this);
      let userIds = this.addIncreaseSignUsers.map((checkRow) => checkRow.id);
      if (userIds.length == 0) {
        that.$message({
          message: this.$t2('请选择候选人', 'components.wf.addIncreaseSignWarnMsg1'),
          type: "error",
          duration: 2000,
          onClose: (t) => {
          },
        });
        return false;
      }
      let toDo = () => {
        var data = JSON.stringify({
          uuid: this.wfInfo.uuid,
          taskId: this.wfInfo.taskId,
          userIds: userIds,
          suggestion: this.addIncreaseSignForm.opinion

        });
        this.agreeDialogVisible = false;
        that.$http({
          url: this.current_prefix + "/wf/addIncreaseSign",
          data: data,
          method: "post",
          loadingTarget: document.body,
          headers: {
            "Content-Type": "application/json;charset=utf-8",
          },
          isLoading: true,
          success: (resultMsg) => {
            this.showAddIncreaseSignDialog = false
            that.$message({
              message: resultMsg.content,
              type: "success",
              duration: 500,
              onClose: (t) => {
                this.reloadContent();
              },
            });
          },
        });
      }
      if (flag === 0) {
        toDo();
      } else {
        that.$baseConfirm(this.$t2('您确定要加签吗？', 'components.wf.addIncreaseSignConfirmTip')).then(() => {
          toDo();
        });
      }
    },
    openSetCandidateDialog(operateType) {
      this.operateType = operateType;
      this.showSetCandidateDialog = true;
    },
    closeSetCandidateDialog() {
      this.showSetCandidateDialog = false;
      this.reloadContent();
    },
    openRevokeDialog(operateType) {
      this.operateType = operateType;
      this.revokeForm = {opinion: null}
      this.revokeDialogVisible = true;
    },
    subRevokeForm(flag) {
      //撤回
      let that = getTarget(this);
      let toDo = () => {
        var data = JSON.stringify({
          uuid: this.wfInfo.uuid,
          taskId: this.wfInfo.taskId,
          suggestion: this.revokeForm.opinion,
        });
        this.revokeDialogVisible = false;
        that.$http({
          url: this.current_prefix + "/wf/revoke",
          data: data,
          method: "post",
          loadingTarget: document.body,
          headers: {
            "Content-Type": "application/json;charset=utf-8",
          },
          isLoading: true,
          success: (resultMsg) => {
            that.$message({
              message: resultMsg.content,
              type: "success",
              duration: 500,
              onClose: (t) => {
                this.reloadContent();
              },
            });
          },
        });
      }
      if (flag === 0) {
        toDo();
      } else {
        that.$baseConfirm(this.$t2('您确定要撤回吗？', 'components.wf.revokeConfirmTip')).then(() => {
          toDo();
        });
      }
    },
    initShowTaskInfo(callback) {
      //初始化转办用户参数
      let that = getTarget(this);
      return that.$http({
        url: USER_PREFIX + "/wf_diy_attribute/getValue",
        method: `post`,
        data: {attributeKey: "param9"},
        isLoading: true,
        modalStrictly: true,
        success: (res) => {
          this.showWfInfoTab = res.objx !== 1;
          callback && callback();
        },
      });
    },
    getIsShowWfMemo(){
      let that = getTarget(this);
      that.$http({
        url: USER_PREFIX + "/wf_diy_attribute/getValue",
        method: `post`,
        data: {attributeKey: "param10"},
        isLoading: true,
        success: (res) => {
          this.showWfMemo = res?.objx === true;
          if(this.showWfMemo){
            this.$nextTick(()=>{
              this.initWfMemo();
            })
          }
        },
      });
    },

    initWfMemo() {
      this.wfMemoSearchEvent();
      /* let h = this.$createElement;
      let tableOption = {
        vue: this,
        tableRef: "table-wfMemo",
        tableName: "wf_table-wfMemo",
        path: this.current_prefix + "/wf_memo/listPage",
        param: () => {
          return {
            uuid: this.wfInfo.uuid,
          };
        },
        config: {
          height: 350
        },
        columns: [
          {type: "checkbox", width: 48, resizable: false, fixed: "left"},
          {
            title: this.$t1('操作人'),
            field: "operatorName",
            width: 150,
            fixed: "left",
          },
          {
            title: this.$t1('内容'),
            field: "content",
            width: 250,
            showOverflow: false
          },
          {
            width: 150,
            title: this.$t1('附件'),
            field: "attachmentImage",
            sortable: false,
            slots: {
              default: ({row, rowIndex}) => {
                let option = {
                  title: this.$t1('附件'),
                  edit: false,
                  rows: (done) => {
                    done(row.attachmentDTOs);
                  },
                };
                return [
                  h("base-attachment", {
                    props: {
                      option: option,
                      imageLazy: false
                    },
                  }),
                ];
              },
            },
          },
          {
            title: this.$t2('创建时间', 'system.label.createDate'),
            field: "createDate",
            width: 150,
          },
          {
            width: 80,
            fixed: "right",
            title: "",
            sortable: false
          },
        ]
      };
      this.$vxeTableUtil.initVxeTable(tableOption).then((opts) => {
        this.wfMemoOption = opts;
      }); */
    },
    wfMemoSearchEvent(){
      //  this.$refs['table-wfMemo'].commitProxy('reload');
      let that = getTarget(this);
      that.$http({
        url: this.current_prefix + "/wf_memo/listPage",
        method: `post`,
        data: {
          uuid: this.wfInfo.uuid,
        },
        isLoading: true,
        success: (res) => {
          let rows = res?.objx?.records || [];
          this.wfMemoData = rows;
        },
      });
    },
    openWfMemoDialog(row) {
      if(row){
        this.wfMemoForm = this.$baseLodash.cloneDeep(row);
      }else{
        this.wfMemoForm = {
          uuid: this.wfInfo.uuid,
          content:null,
          attachmentDTOs: []
        }
      }
      this.showWfMemoDialog = true;
    },
    submitWfMemoForm() {
      let that = getTarget(this);

      if (!this.wfMemoForm.content) {
        that.$message({
          message: this.$t1('请输入内容'),
          type: "error",
          duration: 2 * 1000,
        });
        return false;
      }

      this.showWfMemoDialog = false;
      that.$http({
        url: this.current_prefix + "/wf_memo/save",
        data: this.wfMemoForm,
        method: "post",
        isLoading: true,
        success: (resultMsg) => {
          that.$message({
            message: resultMsg.content,
            type: "success"
          });
          this.wfMemoSearchEvent();
        },
      });
    },
  }
};

wfStartMixin = {
  name: "wfStartDialog",
  props: {
    dataId: [String, Number],
    code: [String, Number],
    serviceId: String,
    startParam: Object,
    visible: Boolean,
    parentVue: Object,
    wfName: String,
    formCode: String,
    option: Object
  },
  data() {
    return {
      showDialog: false,
      wfStartForm: {},
      wfDefItems: [],

      startFormData:{},
      wfUserRangeEnabled: false,
      preStartResult:[],
      showSetCandidateDialog2:false
    };
  },
  computed: {
    current_prefix() {
      return this.serviceId ? "/" + this.serviceId : "";
    },
  },
  mounted() {
    this.initWfInfo(this.code);
    // this.showDialog = true;
  },
  methods: {
    preStart(){
      let that = getTarget(this);
      return new Promise(resolve=>{
        return that.$http({
          url: this.current_prefix + "/wf/preStart",
          method: `post`,
          data: this.startFormData,
          success: (res) => {
            resolve(res.objx);
          },
        });
      })
    },
    initWfUserRangeParam(){
      let that = getTarget(this);
      return that.$http({
        url: USER_PREFIX + "/wf_diy_attribute/getValue",
        method: `post`,
        data: {attributeKey: "param12"},
        success: (res) => {
          this.wfUserRangeEnabled = res?.objx === true;
        },
      });
    },
    openSetCandidateDialog(){
      this.showSetCandidateDialog2 = true;
    },
    confirmSetCandidateDialog(rows){
      let formData = {
        ...this.startFormData,
        wfNodeDTOs: rows
      }
      this.startSubmitHanlde(formData);
    },
    async initWfInfo(code) {
      let that = getTarget(this);
      var wfDefItems = null;
      var objId = this.dataId;

      await this.initWfUserRangeParam();
      await that.$http({
        url: this.current_prefix + "/wf_obj_config_item/list",
        data: {
          objTypeCode: code,
          enabled: true,
          objId: objId
        },
        method: "post",
        //contentType: 'application/json;charset=utf-8',
        async: false,
        isLoading: true,
        error: (error) => {
          this.close();
        },
        success: (resultMsg) => {
          wfDefItems = resultMsg.objx || [];
        },
      });

      if (!wfDefItems || wfDefItems.length == 0) {
        that.$baseAlert(this.$t2('无法启动，没有流程单据', 'components.wf.startWarnMsg1'));
        this.close();
        return false;
      }

      (this.wfStartForm = {
        wfCode: code,
      }),
        (this.wfDefItems = wfDefItems);
      this.$set(this.wfStartForm, "modelId", wfDefItems[0].modelId);
      if (wfDefItems.length == 1) {
        if (settingConfig.withoutConfrimByOneWf === true) {
          this.startSubmit();
        } else {
          let wfStartOperateName =
            settingConfig.wfStartOperateName ||
            settingConfig.wfStartButtonName ||
            "启动流程";
          let startTip = "您确定要" + wfStartOperateName + "吗？";
          that
            .$baseConfirm(this.$t2(startTip, 'components.wf.startTip'))
            .then(() => {
              this.startSubmit();
            });
        }
      } else {
        this.showDialog = true;
      }
    },
    startSubmit() {
      var modelId = this.wfStartForm.modelId;
      if (!modelId) {
        that.$baseAlert(this.$t2('请选择流程模版', 'components.wf.startWarnMsg2'));
        return false;
      }
      let option = this.option;
      if (option.onBeforeStartSubmit) {
        option.onBeforeStartSubmit(() => {
          this.subWfStartForm();
        })
      } else {
        this.subWfStartForm();
      }
    },
    async subWfStartForm() {
      let that = getTarget(this);
      var modelId = this.wfStartForm.modelId;
      if (!modelId) {
        that.$baseAlert(this.$t2('请选择流程模版', 'components.wf.startWarnMsg2'));
        return false;
      }

      let option = this.option;

      var objId = this.dataId;

      let startParam = this.startParam || {};
      let formCode = this.formCode || null;

      var data = {
        modelId: modelId,
        objTypeCode: this.code,
        objId: objId,
        formData: startParam,
        formCode: formCode
        // name:this.wfName
      };
      this.startFormData = data;

      if(this.wfUserRangeEnabled){
        this.preStartResult = await this.preStart() || []
        if(this.preStartResult.length){
          this.openSetCandidateDialog()
          return
        }
      }
      this.startSubmitHanlde(this.startFormData);

    },
    startSubmitHanlde(formData){
      this.showDialog = false;
      let that = getTarget(this);
      let option = this.option;
      that.$http({
        url: this.current_prefix + "/wf/start",
        data: formData,
        method: "post",
        /*  headers: {
           "Content-Type": "application/json;charset=utf-8",
         }, */
        isLoading: true,
        callback: (resultMsg) => {
          if (resultMsg.type == "success") {
            that.$message({
              message: resultMsg.content,
              type: "success",
              duration: 500,
              onClose: (t) => {
                if (!option.onStartSuccess) {
                  that.$baseReload();
                } else {
                  option.onStartSuccess();
                }
                if (resultMsg.objx) {
                  that.$baseAlert(resultMsg.objx)
                }
              },
            });
          } else {
            option.onStartFail && option.onStartFail()
          }

        }
      });
    },
    close() {
      this.$emit("update:visible", false);
    },
  },
};

wfModifyMixin = {
  name: "wfModifyMixin",
  props: {
    dataId: [String, Number],
    code: [String, Number],
    visible: Boolean,
    paramData: Object,
    parentVue: Object,
    wfInfo: Object,
    title: String
  },
  data() {
    return {
      showModifyDialog: false,
      showBillEdit: false,
      content: "",
    };
  },
  async mounted() {
    this.openWfModifyDialog(this.code);
  },
  methods: {
    openWfModifyDialog() {
      let row = this.paramData;
      let url = row.url + ".vue";
      this.showModifyDialog = true;
      this.content = configUtil.requireView(url);
      this.$openEditView("showBillEdit");
    },
    modfyDialogClose() {
      this.showBillEdit = false;
      this.content = null;
    },
    refreshEdit() {
      this.showModifyDialog = false;
      this.parentVue.$baseReload()
    }
  },
};

wfUrgingMixin = {
  props: ["visiable", "multi", "rows", "param", "current_prefix", "wfInfo"],
  mixins: [selectDialogMixins],
  created() {
    this.initSetting();
  },
  mounted() {
    this.initTableM1();
  },
  data() {
    return {
      showDialog: true,
      selectMulti: true,
      vxeOption: {},
    };
  },
  methods: {
    initTableM1() {
      var that = this;
      let tableOption = {
        vue: that,
        tableRef: "table-m1",
        tableName: "wf_urgingDialog-m1",
        path: this.current_prefix + "/wf/getTaskCandidates",
        param: () => {
          return {stringOne: this.wfInfo.uuid};
        },
        config: {
          checkboxConfig: {
            checkStrictly: true,
            showHeader: this.selectMulti,
            trigger: "row",
          },
          proxyConfig: {
            props: {
              result: "objx", // 配置响应结果列表字段
              total: "objx.length", // 配置响应结果总页数字段
            },
          },
        },
        columns: [
          {type: "checkbox", width: 50, resizable: false, fixed: "left"},
          {title: this.$t2('催办人', 'components.wf.urgingUser'), field: "name", width: 250, fixed: "left"},
          {title: this.$t2('催办人ID', 'components.wf.urgingUserId'), field: "id", width: 150},
          {
            width: 47,
            fixed: "right",
            title: "",
            sortable: false,
          },
        ],
      };
      this.$vxeTableUtil.initVxeTable(tableOption).then((opts) => {
        that.vxeOption = opts;
      });
    },
    dialogConfirm() {
      this.dialogPrimary();
      this.$emit("confirm");
    },
    subUrgingForm() {
      let that = this;
      let urgingUserIds = this.checkRows.map((checkRow) => checkRow.id);
      if (urgingUserIds.length == 0) {
        that.$message({
          message: this.$t2('请选择催办人', 'components.wf.urgingWarnMsg1'),
          type: "error",
          duration: 2000,
          onClose: (t) => {
          },
        });
        return false;
      }
      that.$baseConfirm(this.$t2('您确定要催办吗？', 'components.wf.urgingConfirmTip')).then(() => {
        var data = JSON.stringify({
          uuid: this.wfInfo.uuid,
          taskId: this.wfInfo.taskId,
          notifyType: "wfUrging",
          userIds: urgingUserIds,
        });
        this.agreeDialogVisible = false;
        that.$http({
          url: this.current_prefix + "/wf/urging",
          data: data,
          method: "post",
          loadingTarget: document.body,
          headers: {
            "Content-Type": "application/json;charset=utf-8",
          },
          isLoading: true,
          success: (resultMsg) => {
            that.$message({
              message: resultMsg.content,
              type: "success",
              duration: 500,
              onClose: (t) => {
                // this.reloadContent();
                this.dialogConfirm();
              },
            });
          },
        });
      });
    },
  },
};

deleteTaskUserMixin = {
  props: ["visiable", "multi", "rows", "param", "current_prefix", "wfInfo"],
  mixins: [selectDialogMixins],
  created() {
    this.initSetting();
  },
  mounted() {
    this.initTableM1();
  },
  data() {
    return {
      showDialog: true,
      selectMulti: true,
      vxeOption: {},
    };
  },
  methods: {
    initTableM1() {
      var that = this;
      let tableOption = {
        vue: that,
        tableRef: "table-m1",
        tableName: "wf_deleteTaskUserDialog-m1",
        path: this.current_prefix + "/wf/getIncreaseSign",
        param: () => {
          return {
            uuid: this.wfInfo.uuid,
            taskId: this.wfInfo.taskId,
          };
        },
        config: {
          checkboxConfig: {
            checkStrictly: true,
            showHeader: this.selectMulti,
            trigger: "row",
          },
          proxyConfig: {
            props: {
              result: "objx", // 配置响应结果列表字段
              total: "objx.length", // 配置响应结果总页数字段
            },
          },
        },
        columns: [
          {type: "checkbox", width: 50, resizable: false, fixed: "left"},
          {title: this.$t2('候选人', 'components.wf.candidate'), field: "name", width: 250, fixed: "left"},
          {title: this.$t2('候选人ID', 'components.wf.candidateId'), field: "id", width: 150},
          {
            width: 47,
            fixed: "right",
            title: "",
            sortable: false,
          },
        ],
      };
      this.$vxeTableUtil.initVxeTable(tableOption).then((opts) => {
        that.vxeOption = opts;
      });
    },
    dialogConfirm() {
      this.dialogPrimary();
      // this.$emit("confirm");
    },
    subForm() {
      let that = this;
      let userIds = this.checkRows.map((checkRow) => checkRow.id);
      if (userIds.length == 0) {
        that.$message({
          message: this.$t2('请选择候选人', 'components.wf.deleteIncreaseSignWarnMsg1'),
          type: "error",
          duration: 2000,
          onClose: (t) => {
          },
        });
        return false;
      }
      that.$baseConfirm(this.$t2('您确定要减签选中的候选人吗？', 'components.wf.deleteIncreaseSignTip')).then(() => {
        var data = JSON.stringify({
          uuid: this.wfInfo.uuid,
          taskId: this.wfInfo.taskId,
          userIds: userIds,
        });
        this.agreeDialogVisible = false;
        that.$http({
          url: this.current_prefix + "/wf/deleteIncreaseSign",
          data: data,
          method: "post",
          loadingTarget: document.body,
          headers: {
            "Content-Type": "application/json;charset=utf-8",
          },
          isLoading: true,
          success: (resultMsg) => {
            that.$message({
              message: resultMsg.content,
              type: "success",
              duration: 500,
              onClose: (t) => {
                this.dialogConfirm();
              },
            });
          },
        });
      });
    },
  },
};

addTaskUserMixin = {
  props: ["visiable", "multi", "rows", "param", "current_prefix", "wfInfo"],
  mixins: [selectDialogMixins],
  data() {
    return {
      showDialog: true,
      selectMulti: true,
      vxeOption: {},
    };
  },
  created() {
    this.initSetting();
  },
  mounted() {
    this.initTableM1();
  },
  methods: {
    dialogConfirm() {
      this.dialogPrimary();
      // this.$emit('confirm');
    },
    subForm() {
      let that = this;
      let userIds = this.checkRows.map((checkRow) => checkRow.id);
      if (userIds.length == 0) {
        that.$message({
          message: this.$t2('请选择候选人', 'components.wf.addIncreaseSignWarnMsg1'),
          type: "error",
          duration: 2000,
          onClose: (t) => {
          },
        });
        return false;
      }
      that.$baseConfirm(this.$t2('您确定要加签选中的候选人吗？', 'components.wf.addIncreaseSignConfirmTip2')).then(() => {
        var data = JSON.stringify({
          uuid: this.wfInfo.uuid,
          taskId: this.wfInfo.taskId,
          userIds: userIds,
        });
        this.agreeDialogVisible = false;
        that.$http({
          url: this.current_prefix + "/wf/addIncreaseSign",
          data: data,
          method: "post",
          loadingTarget: document.body,
          headers: {
            "Content-Type": "application/json;charset=utf-8",
          },
          isLoading: true,
          success: (resultMsg) => {
            that.$message({
              message: resultMsg.content,
              type: "success",
              duration: 500,
              onClose: (t) => {
                this.dialogConfirm();
              },
            });
          },
        });
      });
    },
  },
};

export {
  wfIndexMixin,
  wfStartMixin,
  wfContentMixin,
  wfModifyMixin,
  wfUrgingMixin,
  deleteTaskUserMixin,
  addTaskUserMixin,
};
