<template>
  <div
    v-loading="loading"
    class="es-flow-form"
    element-loading-text="加载中..."
    element-loading-spinner="el-icon-loading"
    element-loading-background="rgba(255, 255,255, 0.8)"
  >
    <el-form
      ref="nextNode"
      :model="nextNode"
      class="demo-dynamic"
      label-width="100px"
      :rules="rules"
      :label-position="labelPosition"
    >
      <div
        :style="`height:${showBtn ? '430px' : 'auto'}; overflow-y:${
          showBtn ? 'auto' : 'hidden'
        } ; margin-bottom: 10px;overflow-x: hidden;`"
      >
        <el-form-item
          v-show="showBtn"
          prop="nodeName"
          label="当前节点"
          :rules="[
            { required: true, message: `请选择下步节点`, trigger: 'blur' }
          ]"
        >
          <el-input v-model="nextNode.nodeName" disabled />
        </el-form-item>
        <el-form-item
          v-if="isSinglePage || copyHistory || formType == 'readTransfer'"
          prop="newOpinion"
          :label="
            copyHistory || formType == 'readTransfer' ? '填写意见' : '意见'
          "
        >
          <CommonOpinions
            class="opinions"
            :opinion="nextNode.newOpinion"
            :rows="copyHistory || formType == 'readTransfer' ? 2 : 5"
            @change="(val) => (nextNode.newOpinion = val)"
          />
        </el-form-item>
        <el-form-item
          prop="nextOperate"
          label="下步操作"
          v-if="isChooseNextNode == 1"
          :rules="[
            { required: true, message: `请选择下步操作`, trigger: 'blur' }
          ]"
        >
          <el-select
            v-if="nextOperateCheckType == 'select'"
            v-model="nextNode.nextOperate"
            :placeholder="`请选择下步操作`"
            @change="selecNext"
          >
            <el-option
              v-for="items in operationList"
              :key="items.key"
              :label="items.value"
              :value="items.key"
            ></el-option>
          </el-select>
          <es-radio-group
            v-else-if="nextOperateCheckType == 'radio'"
            v-model="nextNode.nextOperate"
            :data="operationList"
            @change="selecNext($event, true)"
            value-key="key"
            label-key="value"
          ></es-radio-group>
        </el-form-item>
        <el-form-item
          prop="nextNode"
          label="下步节点"
          :rules="[
            { required: false, message: `请选择下步节点`, trigger: 'blur' }
          ]"
        >
          <el-select
            v-if="nextNodeCheckType == 'select'"
            v-model="nextNode.nextNode"
            :placeholder="`请选择下步节点`"
            @change="changeSel"
          >
            <el-option
              v-for="items in nextNode.nodeInfo"
              :key="items.id"
              :label="items.nodeName"
              :value="items.nodeId"
            ></el-option>
          </el-select>
          <es-radio-group
            v-else-if="nextNodeCheckType == 'radio'"
            v-model="nextNode.nextNode"
            :data="nextNode.nodeInfo"
            @change="changeSel"
            value-key="nodeId"
            label-key="nodeName"
          ></es-radio-group>
        </el-form-item>
        <el-form-item
          v-if="countersignaturetypeCode != 0"
          prop="countersignaturetypeText"
          label="处理方式"
        >
          <el-input
            v-model="nextNode.countersignaturetypeText"
            placeholder="请输入内容"
            disabled
          />
        </el-form-item>
        <!-- <el-form-item
          prop="nextNode"
          label="下步办理人"
          v-if="isShowNextUser"
          :rules="[
            { required: true, message: `请选择下步办理人`, trigger: 'blur' }
          ]"
        >
          <SelectUser
            :nextUser="nextNode.nextUser"
            :radioList="radioList"
            :multiple="multiple"
            :showTooltip="showTooltip"
            :isCustomUser="isCustomUser"
            :options="options"
            :presetEdit="presetEdit"
            :isDefSelectedObj="isDefSelectedObj"
            :selectUserList="selectUserList"
            @change="changeSelectUser"
            :types="nextUserTypes"
            :params="params"
          />
        </el-form-item> -->
        <el-form-item
          v-if="isHideCurrentOrg"
          prop="nextCurrentOrgObj"
          label="本单位"
        >
          <SelectUser
            :nextUser="nextCurrentOrgObjSelect"
            multiple
            mix
            @change="disposeAppUnit($event, 'nextCurrentOrgObjSelect')"
            :showTooltip="showTooltip"
            :selectUserList="nextCurrentOrgselectUserList"
            :types="currentOrgSelectorTabs"
            :params="currentOrgSelectorParams"
          />
        </el-form-item>
        <el-form-item v-if="isHideOtherOrg" label="外单位">
          <SelectUser
            :nextUser="nextOtherOrgObjSelect"
            multiple
            :showTooltip="showTooltip"
            mix
            :where="{ filid: 'other' }"
            @change="disposeAppUnit($event, 'nextOtherOrgObjSelect')"
            :types="['enterprise', 'filgroup']"
            :params="foreignOrgSelectorParams"
          />
        </el-form-item>
        <el-form-item
          v-if="!isHideOtherOrg && !isHideCurrentOrg"
          :prop="isShowNextUser ? 'nextUser' : 'nextOrgId'"
          :label="
            isShowNextUser
              ? `${flowLabelConfig.nextUser || '下步办理人'}`
              : '办理对象'
          "
        >
          <SelectUser
            :nextUser="isShowNextUser ? nextNode.nextUser : nextNode.nextOrgId"
            :radioList="radioList"
            :multiple="multiple"
            :isCustomUser="!isShowNextUser ? 1 : isCustomUser"
            :showTooltip="showTooltip"
            :isCurrentNodeForbiddenChangeCandidate="
              isCurrentNodeForbiddenChangeCandidate
            "
            :options="options"
            :presetEdit="presetEdit"
            :mix="multiple"
            :isDefSelectedObj="isDefSelectedObj"
            :selectUserList="selectUserList"
            @change="
              changeSelectUser(
                $event,
                isShowNextUser ? 'nextUser' : 'nextOrgId'
              )
            "
            :types="
              !isShowNextUser
                ? nextUserTypes
                : isCdjxjTaskHandle != 'true'
                ? ['employee', 'persongroup']
                : ['employee']
            "
            :params="isShowNextUser ? params : {}"
            :tabs="nextUserTabs"
          />
        </el-form-item>
        <el-form-item
          prop="nextReadUserId"
          v-if="isTaskread == 1"
          label="
           分阅用户
          "
        >
          <SelectUser
            :nextUser="nextNode.nextReadUserId"
            :multiple="true"
            :selectUserList="selectReadUserList"
            :showTooltip="showTooltip"
            :options="userOptions"
            title="分阅用户"
            :mix="true"
            :types="types"
            @change="changeSelectReadUser($event, 'nextReadUserId')"
            :tabs="tabs"
          />
        </el-form-item>
        <el-form-item
          prop="presetReadUserId"
          v-if="canPresetRead"
          label="
           自动分阅
          "
        >
          <SelectUser
            :nextUser="nextNode.presetReadUserId"
            :multiple="true"
            :selectUserList="selectPresetUserList"
            :showTooltip="showTooltip"
            :options="presetOptions"
            title="分阅用户"
            :radioList="presetReadUserId"
            :presetEdit="1"
            :mix="true"
            :types="types"
            @change="changeSelectReadUser($event, 'presetReadUserId')"
            :tabs="tabs"
          />
        </el-form-item>
        <el-form-item
          v-if="enableCustomLimitTimeSetting"
          prop="customLimitTime"
          label="限时办理"
          :rules="[
            {
              required: enableCustomLimitTimeSetting,
              message: showCustomLimitTimeText
                ? '请输入限时办理天数'
                : '请选择限时办理天数',
              trigger: 'blur'
            },
            {
              required: enableCustomLimitTimeSetting,
              validator: checkCustomLimitTime,
              trigger: 'blur'
            }
          ]"
        >
          <div style="display: flex">
            <es-select
              v-model="nextNode.customLimitTimeText"
              placeholder="请选择"
              @change="handleChangeTime"
              :style="`flex:${showBtn ? 'unset' : '1'};width: ${
                showBtn ? '20%' : 'unset'
              } !important; display: inline-block;`"
              sysCode="bpm_custom_limit_time"
            ></es-select>
            <el-input
              v-model="nextNode.customLimitTime"
              :style="`flex:${showBtn ? 'unset' : '1'};width: ${
                showBtn ? '20%' : 'unset'
              } !important; display: inline-block;`"
              placeholder="请输入限时办理的天数"
              class="input-with-select custom-limit-time"
              @change="changeCustomLimitTime"
            >
            </el-input>
            <span style="margin-left: 5px">天</span>
          </div>
        </el-form-item>
        <el-form-item
          v-if="isHandleExplain == 1"
          prop="handleExplain"
          label="办理说明"
        >
          <el-input
            placeholder="请输入办理说明"
            v-model="nextNode.handleExplain"
          />
        </el-form-item>
        <el-form-item
          prop="noticeType"
          label="通知方式"
          v-show="showBtn && nextNode.noticeList.length > 0 && !hideMessage"
        >
          <el-checkbox-group v-model="nextNode.noticeType">
            <el-checkbox
              v-for="item of nextNode.noticeList"
              :key="item.cciValue"
              :label="item.cciValue"
              :disabled="
                readOnlyNotificationType
                  ? readOnlyNotificationType.indexOf(item.cciValue) != -1
                  : false
              "
            >
              {{ item.shortName }}
            </el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item
          v-show="nextNode.noticeType.length != 0 && showBtn"
          prop="nextNode"
          label="通知消息"
        >
          <es-input
            style="
              border-color: #ccc;
              padding: 5px;
              border-radius: 5px;
              font-size: 13px;
            "
            type="textarea"
            v-model="nextNode.noticeInfo"
            :readonly="notificationMessageReadOnly"
          />
        </el-form-item>
        <CustomPreset
          v-show="isCustomPreset"
          ref="customPreset"
          @changeCustom="
            (data) => {
              presetList = data;
            }
          "
          :customPresetHintMessage="customPresetHintMessage"
          @changeActiveNames="(val) => (activeNames = val)"
          @loadingEnd="loading = false"
          @loadingStart="loading = true"
          :nextNode="nextNode.nextNode"
          :id="id"
          :processDefinitionId="processDefinitionId"
        />
        <Preset
          v-show="isPreset"
          @changePreset="
            (data) => {
              presetUserJson = data;
            }
          "
          @loadingEnd="loading = false"
          @loadingStart="loading = true"
          :customPresetHintMessage="customPresetHintMessage"
          :nodeId="nextNode.nextNode"
          :businessId="id"
          :processDefinitionId="processDefinitionId"
          :presetTaskNodeMap="presetTaskNodeMap"
          :presetTaskNodeKeyStr="presetTaskNodeKeyStr"
        />
      </div>
      <el-form-item style="margin-bottom: 0px" v-show="showBtn">
        <div style="text-align: right">
          <el-button type="primary" @click="subProcess('nextNode')">
            确认
          </el-button>
          <el-button @click="quit"> 取消 </el-button>
        </div>
      </el-form-item>
    </el-form>
    <div
      v-if="!showBtn && nextNode.noticeList.length > 0 && !hideMessage"
      style="padding: 5px; background: #fff"
    >
      <div class="news" @click="showNews = !showNews">
        <span class="news-item">消息通知</span>
        <span :class="showNews ? 'show' : 'sj'"></span>
      </div>
      <div v-if="showNews" ref="messagebox" style="transition: 1s">
        <el-checkbox-group v-model="nextNode.noticeType">
          <el-checkbox
            v-for="item of nextNode.noticeList"
            :key="item.cciValue"
            :label="item.cciValue"
            :disabled="
              readOnlyNotificationType
                ? readOnlyNotificationType.indexOf(item.cciValue) != -1
                : false
            "
          >
            {{ item.shortName }}
          </el-checkbox>
        </el-checkbox-group>
        <es-input
          style="
            border-color: #ccc;
            padding: 5px;
            border-radius: 5px;
            font-size: 13px;
          "
          autosize
          v-show="showNews"
          type="textarea"
          v-model="nextNode.noticeInfo"
          @change="handleChange"
          :readonly="notificationMessageReadOnly"
        />
      </div>
    </div>
  </div>
</template>

<script>
import {
  toStartFlow,
  getNodeInfo,
  findSysCodes,
  getNotificationMsg,
  findCodeValues,
  loginUserInfo,
  register,
  freeStartFlow,
  freeStartFlowWithSubmitTask,
  startReadTransferHandleFlowWithTaskReadEnd
} from 'eoss-ui/src/config/api';
import util from 'eoss-ui/src/utils/util';
import SelectUser from './selectUser.vue';
import CommonOpinions from './component/CommonOpinions.vue';
import CustomPreset from './component/CustomPreset.vue';
import Preset from './component/Preset.vue';
export default {
  name: 'ProcessForm',

  components: {
    [Option.name]: Option,
    [SelectUser.name]: SelectUser,
    [CustomPreset.name]: CustomPreset,
    [CommonOpinions.name]: CommonOpinions,
    Preset
  },
  props: {
    processDefinitionId: {
      type: String,
      default: ''
    },
    showTooltip: { type: Boolean, default: true },
    copyHistory: {
      type: String,
      default: ''
    },
    simpleTips: {
      type: Boolean,
      default: true
    },
    formType: {
      type: String,
      default: 'freeStart'
    },
    id: {
      type: String,
      default: ''
    },
    pendingId: {
      type: String,
      default: ''
    },
    opinion: {
      type: String,
      default: ''
    },
    isCancelSecondConfirmationType: {
      type: Boolean,
      default: false
    },
    isFreeStartFlow: {
      type: Boolean,
      default: false
    },
    taskParams: {
      type: Object,
      default: () => {}
    },
    taskExamineParam: {
      type: String,
      default: ''
    },
    labelPosition: {
      type: String,
      default: 'right'
    },
    formTitle: {
      type: String,
      default: ''
    },
    showBtn: { type: Boolean, default: true },
    messageType: {
      type: Array,
      default: () => []
    },
    urgencyLevel: {
      type: [Number, String],
      default: ''
    },
    keyCount: {
      type: [Number, String],
      default: 0
    },
    selectorParams: { type: Object, default: () => {} },
    flowLabelConfig: {
      type: Object,
      default: () => {
        return {};
      }
    },
    hideMessage: { type: Boolean, default: false }
  },
  data() {
    return {
      loading: false,
      isCustomUser: 0,
      isCurrentNodeForbiddenChangeCandidate: 0,
      allLoading: null,
      selectUser: false,
      multiple: false,
      readMultiple: true,
      currentOrgSelectorTabs: ['employee', 'persongroup'],
      customPresetHintMessage: '', //流程预设标题
      nextNodeCheckType: 'select',
      nextOperateCheckType: 'select',
      showNews: false, // 是否展示通知信息
      notificationMessageReadOnly: false,
      isChangeMessage: false,
      readOnlyNotificationType: '',
      show: true,
      enableCustomLimitTimeSetting: false,
      radioList: [],
      nextCurrentOrgselectUserList: [],
      showCustomLimitTimeText: false,
      activeNames: '1',
      selectUserList: [],
      defaultNextNode: '',
      presetUserJson: [],
      businessId: '',
      isTaskread: 0, //是否显示分阅用户
      isHandleExplain: 0, //是否展示办理说明
      options: [],
      presetList: [],
      presetReadUserId: [], //自动分阅
      canPresetRead: false, //是否展示自动分阅
      nextUserTypes: ['employee', 'persongroup'],
      isCustomPreset: false, //是否展示预设节点
      isPreset: false, //是否展示预设办理人
      isSinglePage: false,
      presetEdit: 0,
      isDefSelectedObj: 0,
      isChooseNextNode: 0,
      isHideDefaultOperation: 0,
      countersignaturetypeCode: 0,
      presetTaskNodeKeyStr: '', //预设办理人顺序
      presetTaskNodeMap: {}, //预设办理人
      params: {
        filid: 'all', //选择范围(my:本单位/ "" or all:全部)
        selectmix: 'true1',
        deptid: '' //指定部门(my:本部门)
      },
      newOpinion: '',
      operationList: [],
      tabs: {
        employee: {
          param: {
            filid: JSON.parse(util.getStorage('mainConfig')).userModel.orgId,
            name: '本单位用户'
          }
        },
        department: {
          param: {
            filid: JSON.parse(util.getStorage('mainConfig')).userModel.orgId
          }
        }
      },
      userModel: {},
      nextUserTabs: {},
      selectPresetUserList: [],
      presetOptions: [],
      selectReadUserList: [],
      userOptions: [],
      mixReadList: [],
      mixPresetList: [],
      isCdjxjTaskHandle: '',
      isShowNextUser: true,
      oldMessage: '',
      mixOrgIdList: [], //办理对象混选
      subProcessColumns: [],
      nextOtherOrgObjSelect: [],
      nextCurrentOrgObjSelect: [],
      isHideCurrentOrg: false,
      isHideOtherOrg: false,
      currentOrgSelectorParams: {
        filid: JSON.parse(util.getStorage('mainConfig')).userModel.orgId,
        only_filid: true
      },
      foreignOrgSelectorParams: { filid: 'all', nofilid: 1 },
      nextNode: {
        nodeName: '',
        customLimitTime: '',
        customLimitTimeText: '',
        newOpinion: '',
        countersignaturetypeText: '',
        nextNode: '',
        nextReadUserId: [],
        nextOrgId: [],
        noticeType: [],
        nextOperate: '',
        nextUser: [],
        presetReadUserId: [], //自动分阅
        noticeInfo: '',
        nodeInfo: [],
        userInfo: [],
        handleExplain: '',
        noticeList: [],
        msgTypeCount: 0
      }
    };
  },
  watch: {
    messageType: {
      handler(val) {
        if (this.urgencyLevel) {
          this.nextNode.noticeList = val;
          let arr = [];
          this.nextNode.noticeList.map((item) => {
            this.nextNode.noticeType.map((x) => {
              if (x == item.cciValue) {
                arr.push(x);
              }
            });
          });
          this.nextNode.noticeType = arr;
        } else {
          this.msgTypeCount++;
        }
      }
    },
    processDefinitionId(val) {
      Object.assign(this.$data, this.$options.data());
      this.getUserInfo();
      this.getNodeType();
      this.getStartFlow(val);
      if (this.copyHistory) {
        this.nextNode.newOpinion = this.opinion;
      } else if (this.formType != 'readTransfer') {
        this.newOpinion = this.opinion;
      }
      // this.getStartFlow(val);
    },
    opinion(val) {
      this.newOpinion = this.opinion;
    },
    formTitle: {
      handler(val) {
        if (!this.showBtn && !this.isChangeMessage) {
          this.nextNode.noticeInfo = this.oldMessage.replace('{title}', val);
        }
      },
      deep: true,
      immediate: true
    }
  },
  computed: {
    rules() {
      return {
        customLimitTime: [
          {
            required: this.enableCustomLimitTimeSetting,
            message: this.showCustomLimitTimeText
              ? '请输入限时办理天数'
              : '请选择限时办理天数',
            trigger: 'blur'
          },
          {
            required: this.enableCustomLimitTimeSetting,
            validator: this.checkCustomLimitTime,
            trigger: 'blur'
          }
        ]
      };
    },
    types() {
      if (this.isCdjxjTaskHandle == 'true') {
        return ['employee', 'enterprise', 'department'];
      } else {
        return ['employee', 'enterprise', 'department', 'persongroup'];
      }
    }
  },
  created() {
    this.getUserInfo();
  },
  mounted() {
    if (!this.urgencyLevel) {
      this.getNodeType();
    }
    this.getStartFlow(this.processDefinitionId);
    if (this.copyHistory) {
      this.nextNode.newOpinion = this.opinion;
    } else if (this.formType != 'readTransfer') {
      this.newOpinion = this.opinion;
    }
  },
  methods: {
    handleChangeTime(val) {
      this.nextNode.customLimitTime = val;
    },
    limitTimevalidate() {
      let validSate = true;
      this.$refs.nextNode.validate((valid) => {
        if (valid) {
          validSate = true;
        } else {
          validSate = false;
        }
      });
      return validSate;
    },
    checkCustomLimitTime(rule, value, callback) {
      if (!Number(value) || value.indexOf('.') != -1 || Number(value) < 0) {
        callback(new Error('请输入正确的天数'));
        this.nextNode.customLimitTime = '';
      } else {
        callback();
      }
    },
    handleChange() {
      this.isChangeMessage = true;
    },
    changeCustomLimitTime(val) {
      if (!Number(val) || val.indexOf('.') != -1 || Number(val) < 0) {
        this.$message.warning('请输入正确的天数');
        this.nextNode.customLimitTime = '';
      }
    },
    getUserInfo() {
      let mainConfig = util.getStorage('mainConfig');
      if (mainConfig) {
        this.userModel = JSON.parse(mainConfig).userModel;
        this.foreignOrgSelectorParams.nofilid = this.userModel.orgId;
        this.foreignOrgSelectorParams.roleid =
          this.currentOrgSelectorParams.roleid = this.selectorParams.roleid;
      } else {
        util
          .ajax({ url: loginUserInfo })
          .then((res) => {
            const { status, data } = res;
            if (status == 'success') {
              this.userModel = data;
              this.foreignOrgSelectorParams.nofilid = this.userModel.orgId;
              this.foreignOrgSelectorParams.roleid =
                tthis.currentOrgSelectorParams.roleid =
                  this.selectorParams.roleid;
            } else {
              let msg = res.msg || '系统错误，请联系管理员！';
              this.$message.error(msg);
            }
          })
          .catch((err) => {
            if (err.message && err.message !== 'canceled') {
              this.$message.error(err.message);
            }
          });
      }
    },
    getIsShowNextUser(val) {
      if (
        val == 7 ||
        val == 8 ||
        val == 9 ||
        val == 10 ||
        val == 11 ||
        val == 12
      ) {
        this.isShowNextUser = false;
        //设置办理角色
        // $("#orgRoleCode").val(handleRoleId);
        if (val == 7 || val == 8) {
          this.nextUserTypes = ['department'];
          this.nextUserTabs = {
            department: {
              param: {
                filid: JSON.parse(util.getStorage('mainConfig')).userModel.orgId
              }
            }
          };
          this.multiple = true;
        } else if (val == 9 || val == 10) {
          this.nextUserTypes = ['enterprise'];
          this.nextUserTabs = { enterprise: { param: { filid: 'other' } } };
          this.multiple = true;
        } else if (val == 11 || val == 12) {
          this.nextUserTypes = ['department', 'enterprise'];
          this.nextUserTabs = {
            enterprise: { param: { filid: 'other' } },
            department: {
              param: {
                filid: JSON.parse(util.getStorage('mainConfig')).userModel.orgId
              }
            }
          };
          this.multiple = true;
        }
      }
      if (val == 7 || val == 9 || val == 11) {
        this.multiple = false;
      }
    },
    // 分阅是否多选
    isReadMultiple(nextReadUserSelectType) {
      if (nextReadUserSelectType == 1) {
        this.readMultiple = false;
      } else if (nextReadUserSelectType == 2) {
        this.readMultiple = true;
      } else if (nextReadUserSelectType == 3) {
        this.readMultiple = false;
      } else if (nextReadUserSelectType == 4) {
        this.readMultiple = true;
      } else if (nextReadUserSelectType == 5) {
        this.readMultiple = false;
      } else if (nextReadUserSelectType == 6) {
        this.readMultiple = true;
      }
    },
    changeSelectReadUser(val, type) {
      const { nextUser, mixList } = val;
      this.nextNode[type] = nextUser;
      if (type === 'presetReadUserId') {
        this.mixPresetList = mixList;
      } else {
        this.mixReadList = mixList;
      }
    },
    selecNext(val) {
      this.nextNode.nextUser = [];
      this.options = [];
      this.selectUserList = [];
      this.radioList = [];
      if (this.showBtn) {
        this.loading = true;
      } else {
        this.allLoading = util.loading(this.$loading, '加载中...');
      }
      this.nextNode.nodeInfo = this.operationList[val].list;
      if (this.nextNode.nodeInfo.length > 0) {
        let defaultNodeData = this.nextNode.nodeInfo.filter(
          (x) => x.nodeId == this.defaultNextNode
        );
        length;
        this.nextNode.nextNode =
          defaultNodeData.length > 0
            ? this.defaultNextNode
            : this.nextNode.nodeInfo[0].nodeId;
      }
      this.getNodeInfos();
    },
    changeSelectUser(val, type) {
      const { nextUser, options, mixList } = val;
      this.nextNode[type] = nextUser;
      this.mixOrgIdList = mixList;
    },
    getsubProcessColumns() {
      let data = [];
      let obj = { name: '[部门员工]-' };
      if (this.nextCurrentOrgObjSelect.length > 0) {
        this.nextCurrentOrgObjSelect.map((x) => {
          if (x.stype == 'employee') {
            obj.name = !obj.value
              ? obj.name + x.showname
              : obj.name + ',' + x.showname;
            obj.value = obj.value
              ? obj.value + ',' + x.showid
              : 'employee-' + x.showid;
          } else {
            data.push({
              name: '[部门]' + x.showname,
              value: 'department-' + x.showid
            });
          }
        });
      }
      obj.value && data.push(obj);
      if (this.nextOtherOrgObjSelect.length > 0) {
        this.nextOtherOrgObjSelect.map((x) => {
          data.push({
            name: '[企业]' + x.showname,
            value: 'enterprise-' + x.showid
          });
        });
      }
      this.subProcessColumns = data;
      // return data;
    },
    // 单位选择完回调
    disposeAppUnit(res, type) {
      let label = type.substring(0, type.lastIndexOf('Select'));
      this.nextNode[label + 'Name'] = '';
      res.options && (this[type] = res.options);
      let obj = {};
      // if (typeof res.mixList == 'array')
      res.mixList && (this.nextNode[label] = res.mixList.join('|'));
      res.options.map((item) => {
        if (obj[item.stype]) {
          obj[item.stype].push(item.showname);
        } else {
          obj[item.stype] = [item.showname];
        }
      });
      for (let key in obj) {
        if (
          key === 'enterprise' &&
          this.nextNode[label + 'Name'].indexOf('[企业]') == -1
        ) {
          this.nextNode[label + 'Name'] = this.nextNode[label + 'Name']
            ? this.nextNode[label + 'Name'] +
              '|' +
              '[企业]-' +
              obj[key].join(',')
            : '' + '[企业]-' + obj[key].join(',');
        }
        if (
          key === 'department' &&
          this.nextNode[label + 'Name'].indexOf('[部门]') == -1
        ) {
          this.nextNode[label + 'Name'] = this.nextNode[label + 'Name']
            ? this.nextNode[label + 'Name'] +
              '|' +
              '[部门]-' +
              obj[key].join(',')
            : '' + '[部门]-' + obj[key].join(',');
        }
        if (
          key === 'employee' &&
          this.nextNode[label + 'Name'].indexOf('[部门员工]') == -1
        ) {
          this.nextNode[label + 'Name'] = this.nextNode[label + 'Name']
            ? this.nextNode[label + 'Name'] +
              '|' +
              '[部门员工]-' +
              obj[key].join(',')
            : '' + '[部门员工]-' + obj[key].join(',');
        }
      }
      // this.nextNode[label + 'Name'] = obj.enterprise?;
      if (!this.currentNodeIsCircularReadNode) {
        this.nextNode[label + 'SerialId'] = res.nextUser.join(',');
        this.nextNode[label + 'Json'] = JSON.stringify(res.options);
      }
      this.getsubProcessColumns();
    },
    getNodeType() {
      util
        .ajax({
          url: findCodeValues,
          params: {
            ccCode: 'notification_type',
            userId: util.getStorage('userId')
          }
        })
        .then((res) => {
          const { status, data } = res;
          if (status === 'success') {
            this.nextNode.noticeList = data;
          }
        })
        .catch((err) => {
          if (this.showBtn) {
            this.loading = false;
          } else {
            this.allLoading.close();
          }
          if (err.message && err.message !== 'canceled') {
            this.$message.error(err.message);
          }
        });
    },
    //获取通知信息
    getMessage() {
      let params = {
        processDefinitionId: this.processDefinitionId,
        nodeId: this.nextNode.nextNode,
        businessId: this.id
      };
      if (!this.showBtn) {
        params.openMode = 'samepage';
      }
      util
        .ajax({ url: getNotificationMsg, params, methods: 'post' })
        .then((res) => {
          if (res.status === 'success') {
            if (!this.showBtn) {
              this.oldMessage = res.message;
              this.nextNode.noticeInfo = res.message.replace(
                '{title}',
                this.formTitle
              );
            } else {
              this.nextNode.noticeInfo = res.message;
            }
          }
        })
        .catch((err) => {
          if (this.showBtn) {
            this.loading = false;
          } else {
            this.allLoading.close();
          }
          if (err.message && err.message !== 'canceled') {
            this.$message.error(err.message);
          }
        });
    },
    // 提交表单
    subProcess(formName) {
      this.saveProcess(formName);
    },
    saveProcess(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          const {
            nextNode,
            nextUser,
            noticeInfo,
            noticeType,
            handleExplain,
            presetReadUserId,
            nextReadUserId,
            nextOrgId,
            newOpinion,
            customLimitTime,
            nextOtherOrgObj,
            nextCurrentOrgObj
          } = this.nextNode;
          // if (noticeType.length === 0) {
          //   return this.$message.warning('请选择通知方式');
          // }
          if (this.isShowNextUser) {
            if (
              (nextUser == '' || (this.multiple && nextUser.length == 0)) &&
              !this.isHideCurrentOrg &&
              !this.isHideOtherOrg
            ) {
              return this.$message.warning(
                `请选择${this.flowLabelConfig.nextUser || '下步办理人'}`
              );
            }
          } else {
            if (nextOrgId == '' || (this.multiple && nextOrgId.length == 0)) {
              return this.$message.warning('请选择办理对象');
            }
          }
          if (
            (this.isHideOtherOrg || this.isHideCurrentOrg) &&
            !nextCurrentOrgObj &&
            !nextOtherOrgObj
          ) {
            return this.$message.warning('请选择办理对象');
          }
          if (this.isCancelSecondConfirmationType) {
            this.$confirm('确认提交吗?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              if (this.showBtn) {
                this.loading = true;
              } else {
                this.allLoading = util.loading(this.$loading, '加载中...');
              }
              let newNextUser = [];
              if (this.multiple) {
                nextUser && nextUser.map((item) => newNextUser.push(item));
              }
              let newNoticeType = '';
              if (noticeType) {
                newNoticeType = noticeType.join(',');
              }
              let params = {
                processDefinitionId: this.processDefinitionId,
                nextUserId: this.multiple ? newNextUser.join(',') : nextUser,
                nextNodeId: nextNode,
                businessId: this.businessId,
                notificationType: newNoticeType,
                userId: util.getStorage('userId'),
                notificationMsg: noticeInfo,
                customPresetUserJson: JSON.stringify(this.presetList),
                presetUserJson: JSON.stringify(this.presetUserJson),
                nextReadUserId: this.readMultiple
                  ? this.mixReadList && this.mixReadList.join('|')
                  : nextReadUserId,
                nextOrgId: !this.isShowNextUser
                  ? this.multiple
                    ? this.mixOrgIdList && this.mixOrgIdList.join('|')
                    : nextOrgId
                  : '',
                handleExplain: handleExplain,
                presetReadUserId:
                  this.mixPresetList && this.mixPresetList.length > 0
                    ? this.mixPresetList.join('|')
                    : presetReadUserId.join(','),
                opinion: this.newOpinion || newOpinion
              };
              if (this.enableCustomLimitTimeSetting) {
                params.customLimitTime = customLimitTime;
                if (!customLimitTime) {
                  this.$message.warning('请选择或输入限时办理的天数');
                  this.nextNode.customLimitTime = '';
                  return;
                } else if (
                  !Number(customLimitTime) ||
                  customLimitTime.indexOf('.') != -1 ||
                  Number(customLimitTime) < 0
                ) {
                  this.$message.warning('请输入正确的天数');
                  this.nextNode.customLimitTime = '';
                  return;
                }
              }
              if (this.isHideCurrentOrg) {
                params.nextCurrentOrgObj = nextCurrentOrgObj;
              }
              if (this.isHideOtherOrg) {
                params.nextOtherOrgObj = nextOtherOrgObj;
              }
              if (this.activeNames != '1' || !this.isCustomPreset) delete params.customPresetUserJson;
              if (this.isFreeStartFlow || this.formType === 'readTransfer') {
                let newParm = {};
                newParm.copyHistory =
                  this.copyHistory === 'needCopyPendedHistory';
                newParm.startFlowParamJson = params;
                // newParm.startFlowParamJson.businessId = this.id; //this.id
                newParm.startFlowParamJson.taskExamineParam = {
                  startFlowFirstNodeName: this.taskExamineParam
                };
                newParm.startFlowParamJson = JSON.stringify(
                  newParm.startFlowParamJson
                );
                for (let key in this.taskParams) {
                  if (Array.isArray(this.taskParams[key])) {
                    this.taskParams[key] =
                      this.taskParams[key].length > 0
                        ? this.taskParams[key].join(',')
                        : '';
                  }
                }

                newParm.submitTaskParamJson = JSON.stringify(this.taskParams);
                if (this.formType == 'readTransfer') {
                  newParm.readTransferHandleStartFlowParamJson =
                    JSON.stringify(params);
                  newParm.taskReadEndParamJson = JSON.stringify(
                    this.taskParams
                  );
                  delete newParm.copyHistory;
                  delete newParm.startFlowParamJson;
                  delete newParm.submitTaskParamJson;
                }
                params = newParm;
              }
              if (this.copyHistory && !this.isFreeStartFlow) {
                params.pendingId = this.pendingId;
                delete params.businessId;
              }
              util
                .ajax({
                  url: this.isFreeStartFlow
                    ? freeStartFlowWithSubmitTask
                    : this.formType == 'readTransfer'
                    ? startReadTransferHandleFlowWithTaskReadEnd
                    : this.copyHistory
                    ? freeStartFlow
                    : register,
                  method: 'post',
                  data: params
                })
                .then((res) => {
                  const { status, message } = res;
                  if (this.showBtn) {
                    this.loading = false;
                  } else {
                    this.allLoading.close();
                  }
                  if (status === 'success' || res.rCode == 0) {
                    this.quit(true);
                    this.simpleTips && this.$message.success('操作成功');
                  } else {
                    this.$message.error(message || '系统错误，请联系管理员！');
                  }
                })
                .catch((err) => {
                  if (this.showBtn) {
                    this.loading = false;
                  } else {
                    this.allLoading.close();
                  }
                  if (err.message && err.message !== 'canceled') {
                    this.$message.error(err.message);
                  }
                });
            });
            return;
          }
          if (this.showBtn) {
            this.loading = true;
          } else {
            this.allLoading = util.loading(this.$loading, '加载中...');
          }
          let newNextUser = [];
          if (this.multiple) {
            nextUser && nextUser.map((item) => newNextUser.push(item));
          }
          let newNoticeType = '';
          if (noticeType) {
            newNoticeType = noticeType.join(',');
          }
          let params = {
            processDefinitionId: this.processDefinitionId,
            nextUserId: this.multiple ? newNextUser.join(',') : nextUser,
            nextNodeId: nextNode,
            businessId: this.businessId,
            notificationType: newNoticeType,
            userId: util.getStorage('userId'),
            notificationMsg: noticeInfo,
            customPresetUserJson: JSON.stringify(this.presetList),
            presetUserJson: JSON.stringify(this.presetUserJson),
            nextReadUserId: this.readMultiple
              ? this.mixReadList && this.mixReadList.join('|')
              : nextReadUserId,
            nextOrgId: !this.isShowNextUser
              ? this.multiple
                ? this.mixOrgIdList && this.mixOrgIdList.join('|')
                : nextOrgId
              : '',
            handleExplain: handleExplain,
            presetReadUserId:
              this.mixPresetList && this.mixPresetList.length > 0
                ? this.mixPresetList.join('|')
                : presetReadUserId.join(','),
            opinion: this.newOpinion || newOpinion
          };
          if (this.enableCustomLimitTimeSetting) {
            params.customLimitTime = customLimitTime;
            if (!customLimitTime) {
              this.$message.warning('请选择或输入限时办理的天数');
              this.nextNode.customLimitTime = '';
              return;
            } else if (
              !Number(customLimitTime) ||
              customLimitTime.indexOf('.') != -1 ||
              Number(customLimitTime) < 0
            ) {
              this.$message.warning('请输入正确的天数');
              this.nextNode.customLimitTime = '';
              return;
            }
          }
          if (this.isHideCurrentOrg) {
            params.nextCurrentOrgObj = nextCurrentOrgObj;
          }
          if (this.isHideOtherOrg) {
            params.nextOtherOrgObj = nextOtherOrgObj;
          }
          if (this.activeNames != '1' || !this.isCustomPreset) delete params.customPresetUserJson;
          if (this.isFreeStartFlow || this.formType === 'readTransfer') {
            let newParm = {};
            newParm.copyHistory = this.copyHistory === 'needCopyPendedHistory';
            newParm.startFlowParamJson = params;
            // newParm.startFlowParamJson.businessId = this.id; //this.id
            newParm.startFlowParamJson.taskExamineParam = {
              startFlowFirstNodeName: this.taskExamineParam
            };
            newParm.startFlowParamJson = JSON.stringify(
              newParm.startFlowParamJson
            );
            for (let key in this.taskParams) {
              if (Array.isArray(this.taskParams[key])) {
                this.taskParams[key] =
                  this.taskParams[key].length > 0
                    ? this.taskParams[key].join(',')
                    : '';
              }
            }

            newParm.submitTaskParamJson = JSON.stringify(this.taskParams);
            if (this.formType == 'readTransfer') {
              newParm.readTransferHandleStartFlowParamJson =
                JSON.stringify(params);
              newParm.taskReadEndParamJson = JSON.stringify(this.taskParams);
              delete newParm.copyHistory;
              delete newParm.startFlowParamJson;
              delete newParm.submitTaskParamJson;
            }
            params = newParm;
          }
          if (this.copyHistory && !this.isFreeStartFlow) {
            params.pendingId = this.pendingId;
            delete params.businessId;
          }
          util
            .ajax({
              url: this.isFreeStartFlow
                ? freeStartFlowWithSubmitTask
                : this.formType == 'readTransfer'
                ? startReadTransferHandleFlowWithTaskReadEnd
                : this.copyHistory
                ? freeStartFlow
                : register,
              method: 'post',
              data: params
            })
            .then((res) => {
              const { status, message } = res;
              if (this.showBtn) {
                this.loading = false;
              } else {
                this.allLoading.close();
              }
              if (status === 'success' || res.rCode == 0) {
                this.quit(true);
                this.simpleTips && this.$message.success('操作成功');
              } else {
                this.$message.error(message || '系统错误，请联系管理员！');
              }
            })
            .catch((err) => {
              if (this.showBtn) {
                this.loading = false;
              } else {
                this.allLoading.close();
              }
              if (err.message && err.message !== 'canceled') {
                this.$message.error(err.message);
              }
            });
        } else {
          return false;
        }
      });
    },
    getNodeInfos(nodeId, index) {
      let params = {
        processDefinitionId: this.processDefinitionId,
        nextNodeId: nodeId ? nodeId : this.nextNode.nextNode,
        businessId: this.id,
        userId: util.getStorage('userId')
      };
      util
        .ajax({ url: getNodeInfo, params })
        .then((res) => {
          const {
            status,
            message,
            data: {
              nextUserList,
              nodeExtAttr,
              nodeMoreInfo,
              countersignaturetypeText,
              countersignaturetypeCode
            }
          } = res;
          if (this.showBtn) {
            this.loading = false;
          } else {
            this.allLoading.close();
          }
          if (status === 'success') {
             if( this.currentOrgSelectorParams.department && !this.currentOrgSelectorParams.department.roleid && this.selectorParams.roleid && nodeExtAttr.deptRoleCode){
              this.currentOrgSelectorParams.department.roleid = nodeExtAttr.deptRoleCode;
            }
            this.isCurrentNodeForbiddenChangeCandidate =
              nodeExtAttr.isCurrentNodeForbiddenChangeCandidate;
            this.nextNode.userInfo = nextUserList;
            this.countersignaturetypeCode = countersignaturetypeCode;
            this.nextNode.countersignaturetypeText = countersignaturetypeText;
            this.enableCustomLimitTimeSetting =
              nodeExtAttr.enableCustomLimitTimeSetting == 1;
            if (nodeMoreInfo.currentOrgDefaultSelectObjectItems) {
              this.nextCurrentOrgselectUserList = []
              if (
                nodeMoreInfo.currentOrgDefaultSelectObjectItems.deptIds.length >
                0
              ) {
                nodeMoreInfo.currentOrgDefaultSelectObjectItems.deptIds.map(
                  (x, i) => {
                    this.nextCurrentOrgselectUserList.push({
                      showname:
                        nodeMoreInfo.currentOrgDefaultSelectObjectItems
                          .deptNames[i],
                      showid: x,
                      stype: 'department'
                    });
                  }
                );
              }
              if (
                nodeMoreInfo.currentOrgDefaultSelectObjectItems.userIds.length >
                0
              ) {
                nodeMoreInfo.currentOrgDefaultSelectObjectItems.userIds.map(
                  (x, i) => {
                    this.nextCurrentOrgselectUserList.push({
                      showname:
                        nodeMoreInfo.currentOrgDefaultSelectObjectItems
                          .userNames[i],
                      showid: x,
                      stype: 'employee'
                    });
                  }
                );
              }
              if (
                nodeMoreInfo.currentOrgDefaultSelectObjectItems.orgIds.length >
                0
              ) {
                nodeMoreInfo.currentOrgDefaultSelectObjectItems.orgIds.map(
                  (x, i) => {
                    this.nextCurrentOrgselectUserList.push({
                      showname:
                        nodeMoreInfo.currentOrgDefaultSelectObjectItems
                          .orgNames[i],
                      showid: x,
                      stype: 'enterprise'
                    });
                  }
                );
              }
              this.nextNode.nextCurrentOrgObj = nodeMoreInfo.currentOrgDefaultSelectObjects
            }
            if (
              this.enableCustomLimitTimeSetting &&
              nodeMoreInfo.defaultCustomLimitDays
            ) {
              this.nextNode.customLimitTime =
                this.nextNode.customLimitTimeText =
                  nodeMoreInfo.defaultCustomLimitDays + '';
            }
            this.isTaskread = nodeExtAttr.isTaskread;
            this.isHandleExplain = nodeExtAttr.isHandleExplain;
            this.isCustomUser = nodeExtAttr.isCustomUser; //是否展示选人组件按钮
            this.presetEdit = nodeExtAttr.presetEdit; //是否展示备选人
            this.isDefSelectedObj = nodeExtAttr.isDefSelectedObj; //是否默认选中
            if (
              nodeExtAttr.userSelectionType == 7 ||
              nodeExtAttr.userSelectionType == 8 ||
              nodeExtAttr.userSelectionType == 9 ||
              nodeExtAttr.userSelectionType == 10 ||
              nodeExtAttr.userSelectionType == 11 ||
              nodeExtAttr.userSelectionType == 12
            ) {
              this.getIsShowNextUser(
                nodeExtAttr && nodeExtAttr.userSelectionType
              );
            } else {
              const { multiple, params } = this.isMultiple(
                nodeExtAttr.userSelectionType
              );
              this.multiple = multiple;
              this.params = params;
            }
            // this.isReadMultiple(nodeExtAttr.userSelectionType);
            if (nodeExtAttr.nodeType === 1 || nodeExtAttr.nodeType === 2) {
              this.isHideCurrentOrg =
                nodeExtAttr.isHideCurrentOrg == 1 ? false : true; //判断是否隐藏本单位
              this.isHideOtherOrg =
                nodeExtAttr.isHideOtherOrg == 1 ? false : true; //判断是否隐藏外单位
            } else {
              this.isHideCurrentOrg = false;
              this.isHideOtherOrg = false;
            }
            nextUserList.map((item) => {
              if (
                this.multiple &&
                nodeExtAttr.isDefSelectedObj == 1 &&
                nextUserList !== undefined
              ) {
                this.nextNode.nextUser.push(item.userId);
                this.selectUserList.push({
                  showname: item.username,
                  showid: item.userId
                });
              }

              this.options.push({
                showname: item.username,
                showid: item.userId
              });
            });
            if (this.multiple) {
              this.nextNode.nextReadUserId = [];
            } else {
              this.nextNode.nextReadUserId = '';
            }
            if (
              nextUserList.length > 0 &&
              nodeExtAttr.isDefSelectedObj == 1 &&
              !this.multiple
            ) {
              this.nextNode.nextUser = nextUserList[0].userId;
              this.selectUserList.push({
                showname: nextUserList[0].username,
                showid: nextUserList[0].userId
              });
            }
            this.radioList = this.options;
          } else {
            this.$message.error(message || '系统错误，请联系管理员！');
          }
          nodeId && this.$refs.selectUser[index].changeInfo();
        })
        .catch((err) => {
          if (this.showBtn) {
            this.loading = false;
          } else {
            this.allLoading.close();
          }
          if (err.message && err.message !== 'canceled') {
            this.$message.error(err.message);
          }
        });
    },
    changeSel(val) {
      this.nextNode.nextUser = [];
      this.options = [];
      this.selectUserList = [];
      this.radioList = [];
      if (this.showBtn) {
        this.loading = true;
      } else {
        this.allLoading = util.loading(this.$loading, '加载中...');
      }
      this.getNodeInfos();
    },
    // 取消
    quit(val) {
      if (val === true) return this.$emit('cancel', val);
      this.$emit('cancel', false);
    },
    getFind() {
      util
        .ajax({
          url: findSysCodes
        })
        .then((res) => {
          const { status, message } = res;
          if (status === 'success') {
            if (this.hideMessage) return;
            this.nextNode.noticeType = message.split(',');
            let arr = [];
            this.nextNode.noticeList.map((item) => {
              this.nextNode.noticeType.map((x) => {
                if (x == item.cciValue) {
                  arr.push(x);
                }
              });
            });
            this.nextNode.noticeType = arr;
          } else {
            this.$message.error(message || '系统错误，请联系管理员！');
          }
        })
        .catch((err) => {
          if (this.showBtn) {
            this.loading = false;
          } else {
            this.allLoading.close();
          }
          if (err.message && err.message !== 'canceled') {
            this.$message.error(err.message);
          }
        });
    },
    /**
     * isMultiple
     * @desc:是否多选
     * @author liufan
     * @date 2022年9月13日
     **/
    isMultiple(val, choiceOrgId, choiceDeptId, pOrgId) {
      let multiple = false;
      let params = {};
      if (val == 2 || val == 4 || val == 6 || val == 16 || val == 12) {
        multiple = true;
      }
      if (val == 1 || val == 2 || val == 5) {
        params.filid = this.userModel.orgId;
        params.only_filid = true;
        if (choiceOrgId) {
          params.filid = choiceOrgId;
        }
      }
      if (val == 5 || val == 6) {
        params.filid = this.userModel.orgId;
        params.mydeptid = this.userModel.depId;
        if (choiceDeptId) {
          params.mydeptid = choiceDeptId;
        }
        if (choiceOrgId) {
          params.filid = choiceOrgId;
        }
      }
      if (val == 15 || val == 16) {
        params.filid = this.userModel.orgId;
        if (pOrgId) {
          params.filid = pOrgId;
        }
      }
      return { multiple, params };
    },
    getStartFlow(processId) {
      if (!processId) {
        return false;
      }
      if (this.showBtn) {
        this.loading = true;
      } else {
        this.allLoading = util.loading(this.$loading, '加载中...');
      }
      this.businessId = this.id;
      let params = {
        processDefinitionId: processId, // processId || this.processDefinitionId,
        userId: util.getStorage('userId'),
        businessId: this.businessId
      };
      if (!this.shwowBtn) {
        params.taskAction = 'toStartFlowWithoutTempSave';
      }
      // 获取节点
      util
        .ajax({ url: toStartFlow, params })
        .then((res) => {
          //pc接口返回数据处理
          const { status, message, data } = res;
          if (status == 'success') {
            data.nodeInfoMap.nodeExtAttr.submitTipsMsg &&
              this.$confirm(
                data.nodeInfoMap.nodeExtAttr.submitTipsMsg,
                '提示',
                {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消',
                  type: 'warning'
                }
              )
                .then(() => {})
                .catch(() => {
                  this.quit();
                });
            data.nextNodeCheckType &&
              (this.nextNodeCheckType = data.nextNodeCheckType);
            data.nextOperateCheckType &&
              (this.nextOperateCheckType = data.nextOperateCheckType);
            if (data.currentOrgSelectorParams) {
              if (
                data.currentOrgSelectorParams.enableCurrentOrgConfig == 'true'
              ) {
                this.currentOrgSelectorTabs =
                  data.currentOrgSelectorParams.currentOrgType.split(',');
                let currentOrgparams =
                  data.currentOrgSelectorParams.currentOrgRange.split(',');
                this.currentOrgSelectorTabs.map((x, i) => {
                  this.currentOrgSelectorParams[x] = {
                    filid:
                      currentOrgparams[i] == 'my'
                        ? JSON.parse(util.getStorage('mainConfig')).userModel
                            .orgId
                        : currentOrgparams[i],
                    only_filid: true
                  };
                });
              }
            }
            this.customPresetHintMessage = data.customPresetHintMessage;
            this.readOnlyNotificationType = data.readOnlyNotificationType;
            this.notificationMessageReadOnly =
              data.notificationMessageReadOnly == 'true';
            this.nextNode.nodeInfo = data.nextNodeList;
            this.nextNode.nextNode = data.nextNodeList[0].nodeId;
            this.isPreset = data.isPreset;
            this.isHideDefaultOperation =
              data.nodeInfoMap.nodeExtAttr.isHideDefaultOperation;
            this.defaultNextNode = data.nodeInfoMap.nodeExtAttr.defaultNextNode;
            this.isChooseNextNode =
              data.nodeInfoMap.nodeExtAttr.isChooseNextNode;
            this.isCdjxjTaskHandle = data.isCdjxjTaskHandle;
            if (this.isChooseNextNode == 1) {
              this.operationList = [
                // { key: 0, value: '默认', list: [] },
                { key: 1, value: '自定义', list: [] }
              ];
              if (data.nodeInfoMap.nodeExtAttr.isHideDefaultOperation != 1) {
                this.operationList.unshift({
                  key: 0,
                  value: '默认',
                  list: data.nextNodeList
                });
              }
              let arr = [];
              for (let key in data.taskNodeMap) {
                arr.push({ nodeName: data.taskNodeMap[key], nodeId: key });
              }
              // this.operationList[0].list = data.nextNodeList;
              this.operationList[
                data.nodeInfoMap.nodeExtAttr.isHideDefaultOperation != 1 ? 1 : 0
              ].list = arr;
              if (this.isHideDefaultOperation != 1) {
                this.nextNode.nextOperate = 0;
                this.nextNode.nodeInfo = this.operationList[0].list;
                if (this.nextNode.nodeInfo.length > 0) {
                  let defaultNodeData = data.nextNodeList.filter(
                    (x) => x.nodeId == this.defaultNextNode
                  );
                  this.nextNode.nextNode =
                    defaultNodeData.length > 0
                      ? this.defaultNextNode
                      : data.nextNodeList[0].nodeId;
                }
              }
              if (
                data.nodeInfoMap.nodeExtAttr.defaultNextOperate == 1 ||
                data.nodeInfoMap.nodeExtAttr.isHideDefaultOperation == 1
              ) {
                //  this.nextNode.nodeInfo = data.nextNodeList
                this.nextNode.nextOperate = 1;
                this.nextNode.nodeInfo =
                  this.operationList[
                    this.isHideDefaultOperation != 1 ? 1 : 0
                  ].list;

                if (this.nextNode.nodeInfo.length > 0) {
                  let defaultNodeData = this.nextNode.nodeInfo.filter(
                    (x) => x.nodeId == this.defaultNextNode
                  );
                  this.nextNode.nextNode =
                    defaultNodeData.length > 0
                      ? this.defaultNextNode
                      : this.nextNode.nodeInfo[0].nodeId;
                }
              }
            }
            this.isCustomPreset = data.isCustomPreset;
            this.presetTaskNodeKeyStr = data.presetTaskNodeKeyStr;
            this.presetTaskNodeMap = data.presetTaskNodeMap;
            this.isSinglePage = data.taskExamine.isSinglePage;
            this.isSinglePage &&
              (this.nextNode.opinion = data.taskExamine.opinion);
            // this.nextNode.noticeInfo = data.taskExamine.notificationMsg;
            this.nextNode.nodeName = data.taskExamine.nodeName;
            this.canPresetRead = data.canPresetRead;
            if (data.canPresetRead) {
              let ids =
                data.nodeInfoMap.nodeExtAttr.presetReadCandinateIds.split(',');
              let names =
                data.nodeInfoMap.nodeExtAttr.presetReadCandinateNames.split(
                  ','
                );
              ids.map((item, index) => {
                this.presetReadUserId.push({
                  showid: item,
                  showname: names[index]
                });
                this.selectPresetUserList.push({
                  showid: item,
                  showname: names[index]
                });
                this.nextNode.presetReadUserId.push(item);
              });
            }
            this.getNodeInfos();
            // this.getPresetFlowInfo();
            this.isCustomPreset &&
              this.$refs.customPreset.getPresetFlowInfo(this.nextNode.nextNode);
            this.getFind();
            this.getMessage();
          } else {
            this.$message.error(message || '系统错误，请联系管理员！');
          }
        })
        .catch((err) => {
          if (this.showBtn) {
            this.loading = false;
          } else {
            this.allLoading.close();
          }
          if (err.message && err.message !== 'canceled') {
            this.$message.error(err.message);
          }
        });
    }
  }
};
</script>
