<template>
  <div
    :class="{ 'es-flow-narrow': shrink }"
    :style="styles"
    v-if="!shrinkAbled"
  >
    <Reset
      :type="newTypeCode"
      :appId="resetAppId"
      :hideMessage="hideMessage"
      :flowLabelConfig="flowLabelConfig"
      :flowParams="param"
      v-if="newTypeCode == 'reset' || newTypeCode == 'continuation'"
    />
    <div v-else>
      <div class="es-flow-top" style="height: 245px">
        <div class="es-flow-title">
          <span v-show="!shrink"
            >当前节点：{{ isFlow ? '拟稿' : NodeName }}</span
          >
        </div>
        <div class="es-opinion" v-show="!shrink">
          <span class="es-eidt-title" :style="`${!isFlow ? 'color:red' : ''}`"
            >填写意见</span
          >
          <span
            v-show="!isFlow && newTypeCode != 'fenyue'"
            class="es-opinion-file"
            @click="showFileList = true"
            ><i class="es-icon-fujian"></i>意见附件<span
              class="es-file-num"
              v-show="fileNum > 0"
              >({{ fileNum }})</span
            ></span
          >
        </div>
        <CommonOpinions
          class="es-common-opinions"
          v-show="!shrink"
          :rows="3"
          ref="commonOpinions"
          @change="(val) => (value = val)"
          :opinion="value"
          :isBanInputOpinion="isBanInputOpinion"
          :nodeFixedOpinionSelectList="nodeFixedOpinionSelectList"
        />
      </div>
      <div
        v-show="
          (!endFlow || nodeInfos.length > 1) &&
          newTypeCode != 'fenyue' &&
          !shrink
        "
        class="es-info"
      >
        <el-form
          ref="nextNode"
          :model="isFlow ? nodeInfo : nextNode"
          class="demo-dynamic"
          label-width="120px"
        >
          <el-form-item
            v-if="isFlow && nodeInfo.option.length > 0"
            prop="nextNode"
            label="选择流程"
            :rules="[
              { required: true, message: `请选择流程`, trigger: 'blur' }
            ]"
          >
            <el-input
              placeholder="请输入内容"
              class="input-with-select select-process"
              :class="{ 'hide-flow-char': isStartFlowChartView != 'true' }"
            >
              <el-select
                slot="prepend"
                v-model="nodeInfo.nextNode"
                style="width: calc(100% + 40px)"
                :placeholder="`请选择流程`"
                @change="handleChange"
              >
                <el-option
                  v-for="items in nodeInfo.option"
                  :key="items.id"
                  :label="items.name"
                  :value="items.processDefId"
                ></el-option>
              </el-select>
              <el-button
                slot="append"
                v-show="isStartFlowChartView == 'true'"
                icon="el-icon-picture"
                @click="
                  () => {
                    showFlowChart = true;
                  }
                "
              ></el-button>
            </el-input>
          </el-form-item>
          <div v-else>
            <!-- 加签开始 -->
            <el-form-item
              prop="isAddSign"
              v-if="isCanAddSign"
              label="是否加签"
              :rules="[
                { required: true, message: `请选择是否加签`, trigger: 'blur' }
              ]"
            >
              <el-radio-group v-model="nextNode.isAddSign">
                <el-radio label="1">是</el-radio>
                <el-radio label="2">否</el-radio>
              </el-radio-group>
            </el-form-item>
            <div v-show="nextNode.isAddSign === '1'">
              <el-form-item
                prop="addSignUserId"
                label="增加本环节办理人"
                :rules="[
                  { required: false, message: `请选择办理人`, trigger: 'blur' }
                ]"
              >
                <SelectUser
                  :nextUser="nextNode.addSignUserId"
                  :multiple="true"
                  :showTooltip="showTooltip"
                  title="增加办理人"
                  @change="changeSelectUser($event, 'addSignUserId', true)"
                />
              </el-form-item>
              <el-form-item
                prop="addSignMode"
                v-if="isCanPreAddSign"
                label="加签模式"
                :rules="[{ required: true, trigger: 'blur' }]"
              >
                <el-radio-group v-model="nextNode.addSignMode">
                  <el-radio label="preAddSign">前置加签</el-radio>
                  <el-radio label="postAddSign">后置加签</el-radio>
                </el-radio-group>
              </el-form-item>
            </div>
            <!-- 加签结束 -->
            <!-- 减签开始 -->
            <el-form-item
              v-if="isCanRemoveSign"
              prop="isRemoveSign"
              label="是否减签"
              :rules="[
                { required: true, message: `请选择是否加签`, trigger: 'blur' }
              ]"
            >
              <el-radio-group v-model="nextNode.isRemoveSign">
                <el-radio label="1">是</el-radio>
                <el-radio label="2">否</el-radio>
              </el-radio-group>
            </el-form-item>
            <div v-show="nextNode.isRemoveSign === '1'">
              <el-form-item
                prop="removeSignUserId"
                label="删除本环节办理人"
                :rules="[
                  { required: false, message: `请选择办理人`, trigger: 'blur' }
                ]"
              >
                <el-checkbox-group v-model="nextNode.removeSignUserId">
                  <el-checkbox
                    v-for="item of removeUsers"
                    :key="item.userId"
                    :label="item.userId"
                    >{{ item.username }}</el-checkbox
                  >
                </el-checkbox-group>
              </el-form-item>
            </div>
            <!-- 减签结束 -->
            <div
              v-if="
                nextNode.isAddSign != '1' &&
                nextNode.isRemoveSign != '1' &&
                isSpecial
              "
            >
              <el-form-item
                prop="nextOperate"
                label="下步操作"
                v-if="isChooseNextNode == 1"
                :rules="[
                  { required: true, message: `请选择下步操作`, trigger: 'blur' }
                ]"
              >
                <el-select
                  v-model="nextNode.nextOperate"
                  :placeholder="`请选择下步操作`"
                  :disabled="operationList && operationList.length == 1"
                  @change="selecNext($event, true)"
                >
                  <el-option
                    v-for="items in operationList"
                    :key="items.key"
                    :label="items.value"
                    :value="items.key"
                  ></el-option>
                </el-select>
              </el-form-item>
              <div>
                <el-form-item
                  v-if="!isReject && nodeInfos.length != 0 && isShowNode"
                  prop="nextNodeId"
                  label="下步节点"
                  :rules="[
                    {
                      required: true,
                      message: `请选择下步节点`,
                      trigger: 'blur'
                    }
                  ]"
                >
                  <el-select
                    v-if="nextNodeCheckType == 'select'"
                    v-model="nextNode.nextNodeId"
                    :placeholder="`请选择下步节点`"
                    :disabled="nodeInfos && nodeInfos.length == 1"
                    @change="selecNext($event, false)"
                  >
                    <el-option
                      v-for="items in nodeInfos"
                      :key="items.id"
                      :label="items.nodeName"
                      :value="items.nodeId"
                    ></el-option>
                  </el-select>
                  <es-radio-group
                    v-else-if="nextNodeCheckType == 'radio'"
                    v-model="nextNode.nextNodeId"
                    :data="nodeInfos"
                    @change="selecNext(nextNode.nextNodeId, false)"
                    value-key="nodeId"
                    label-key="nodeName"
                  ></es-radio-group>
                </el-form-item>
                <el-form-item
                  v-if="countersignaturetypeCode != 0"
                  prop="handleMode"
                  label="处理方式"
                >
                  <el-input
                    v-model="handleMode"
                    placeholder="请输入内容"
                    disabled
                  />
                </el-form-item>
                <el-form-item
                  v-if="isNextUser"
                  :prop="isShowNextUser ? 'nextUserId' : 'nextOrgId'"
                  :label="
                    isShowNextUser
                      ? `${flowLabelConfig.nextUser || '下步办理人'}`
                      : '办理对象'
                  "
                >
                  <SelectUser
                    :nextUser="
                      isShowNextUser ? nextNode.nextUserId : nextNode.nextOrgId
                    "
                    :radioList="radioList"
                    :multiple="multiple"
                    :showTooltip="showTooltip"
                    :isCustomUser="!isShowNextUser ? 1 : isCustomUser"
                    :isCurrentNodeForbiddenChangeCandidate="
                      isCurrentNodeForbiddenChangeCandidate
                    "
                    :options="options"
                    :mix="multiple"
                    :presetEdit="presetEdit"
                    :selectUserList="selectUserList"
                    @change="
                      changeSelectUser(
                        $event,
                        isShowNextUser ? 'nextUserId' : 'nextOrgId',
                        true
                      )
                    "
                    :types="nextUserTypes"
                    :params="isShowNextUser ? params : {}"
                    :tabs="nextUserTabs"
                  />
                </el-form-item>
                <el-form-item
                  v-if="isHideCurrentOrg"
                  prop="nextCurrentOrgObj"
                  :label="currentOrgName ? currentOrgName : '本单位'"
                >
                  <SelectUser
                    :nextUser="nextCurrentOrgObjSelect"
                    multiple
                    mix
                    :showTooltip="showTooltip"
                    :disableds="currentOrgDisabledObjId"
                    @change="disposeAppUnit($event, 'nextCurrentOrgObjSelect')"
                    :types="['department', 'employee']"
                    :params="{
                      filid: userModel.orgId,
                      roleid: selectorParams.roleid,
                      only_filid: true
                    }"
                  />
                </el-form-item>
                <el-form-item
                  v-if="isHideOtherOrg"
                  prop="nextOtherOrgObj"
                  :label="otherOrgName ? otherOrgName : '外单位'"
                >
                  <SelectUser
                    :nextUser="nextOtherOrgObjSelect"
                    multiple
                    mix
                    :where="{ filid: 'all', roleid: selectorParams.roleid }"
                    :showTooltip="showTooltip"
                    :disableds="otherOrgDisabledObjId"
                    @change="disposeAppUnit($event, 'nextOtherOrgObjSelect')"
                    :types="['enterprise']"
                    :params="otherParams"
                  />
                </el-form-item>
                <el-form-item
                  v-if="isMainSubProcess && isNodeShowProcess"
                  prop="mainSubId"
                  label="主办"
                >
                  <el-select
                    v-model="nextNode.mainSubId"
                    :placeholder="`请选择主办`"
                  >
                    <el-option
                      v-for="items in subProcessColumns"
                      :key="items.id"
                      :label="items.name"
                      :value="items.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
                <TimeLimit
                  v-if="nodeType !== 0 && isLimitedTimeHandling === 1"
                  :newsList="newsList"
                  @change="(val) => (nextNode = { ...nextNode, ...val })"
                />
                <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"
                    :options="presetOptions"
                    :showTooltip="showTooltip"
                    :radioList="presetReadUserId"
                    :presetEdit="1"
                    title="分阅用户"
                    :mix="true"
                    :types="types"
                    @change="changeSelectReadUser($event, 'presetReadUserId')"
                    :tabs="tabs"
                  />
                </el-form-item>
                <el-form-item
                  v-if="isHandleExplain == 1"
                  prop="handleExplain"
                  label="办理说明"
                >
                  <el-input
                    placeholder="请输入办理说明"
                    v-model="nextNode.handleExplain"
                  />
                </el-form-item>
              </div>
            </div>
          </div>
          <CustomPreset
            v-if="isCustomPreset"
            ref="customPreset"
            @changeCustom="
              (data) => {
                presetList = data;
              }
            "
            @changeActiveNames="(val) => (activeNames = val)"
            @loadingEnd="customLoading('end')"
            @loadingStart="customLoading('start')"
            :nextNode="nextNode.nextNodeId"
            :customPresetHintMessage="customPresetHintMessage"
            :id="businessIds"
            :processDefinitionId="nodeInfo.nextNode"
          />
          <Preset
            v-if="isPreset"
            @changePreset="
              (data) => {
                presetUserJson = data;
              }
            "
            @loadingEnd="customLoading('end')"
            @loadingStart="customLoading('start')"
            :nodeId="nextNode.nextNodeId"
            :businessId="businessIds"
            :customPresetHintMessage="customPresetHintMessage"
            :processDefinitionId="nodeInfo.nextNode"
            :presetTaskNodeMap="presetTaskNodeMap"
            :presetTaskNodeKeyStr="presetTaskNodeKeyStr"
          />
        </el-form>
        <div
          v-if="!isFlow && isSpecial && !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-show="showNews" style="transition: 1s">
            <el-checkbox-group v-model="nextNode.notificationType">
              <el-checkbox
                v-for="item of newsList"
                :key="item.cciValue"
                :label="item.cciValue"
                :disabled="
                  readOnlyNotificationType
                    ? readOnlyNotificationType.indexOf(item.cciValue) != -1
                    : false
                "
              >
                {{ item.shortName }}
              </el-checkbox>
            </el-checkbox-group>
            <!-- <div
            v-show="showNews"
            style="
              border: 1px solid #ccc;
              padding: 5px;
              border-radius: 5px;
              font-size: 13px;
            "
          >
            {{ nextNode.notificationMsg }}
          </div> -->
            <es-input
              style="
                border-color: #ccc;
                padding: 5px;
                border-radius: 5px;
                font-size: 13px;
              "
              v-show="showNews"
              type="textarea"
              v-model="nextNode.notificationMsg"
              :readonly="notificationMessageReadOnly"
            />
          </div>
        </div>
      </div>
      <div
        class="es-flow-buttons"
        v-if="newTypeCode != 'fenyue' && !shrink"
        style="margin-top: 10px"
      >
        <div v-if="isSubmitButtonShowAgreeAndDisagree == 1">
          <el-button
            class="es-button-agree"
            type="primary"
            @click="subProcess('同意。')"
            >同意</el-button
          >
          <el-button class="es-button-agree" @click="subProcess('不同意。')"
            >不同意</el-button
          >
          <el-button class="es-button-agree-save" @click="saveInfo()"
            >暂存</el-button
          >
        </div>
        <div
          class="es-user-defined"
          v-if="
            (nodeInfos.length > 0 ||
              nodeInfo.option.length > 0 ||
              operationList.length > 0) &&
            btnList.length <= 2
          "
        >
          <el-button
            v-show="isSubmitButtonShowAgreeAndDisagree != 1"
            v-for="item of hideBtn ? btnList.slice(0, 1) : btnList"
            :key="item.name"
            :type="item.type"
            :style="btnStyle"
            @click="item.event === 'sub' ? subProcess() : saveInfo(false, item)"
          >
            {{ item.text }}
          </el-button>

          <div
            v-if="
              btnList.length > 1 ||
              (!isFlow && (rejectObj.fun || pointsReadingObj.fun || moreList))
            "
            placement="top"
            :class="{ 'em-flow-more-btn': !hideBtn }"
            trigger="click"
          >
            <div v-if="!isFlow && !hideBtn" class="es-footer-btn">
              <el-button
                v-if="rejectObj.fun"
                @click="rejectBtn"
                style="margin-right: 10px"
                type="danger"
              >
                {{ rejectObj.value }}
              </el-button>
              <el-button
                v-if="pointsReadingObj.fun"
                class="es-flow-btn"
                @click="taskReadBtn"
                >分阅</el-button
              >
              <el-button
                class="es-flow-btn"
                v-for="item of moreList"
                :key="item.key"
                @click="goView(item)"
              >
                {{ item.value }}
              </el-button>
            </div>
            <el-button-group
              slot="reference"
              style="margin: 0px 10px"
              v-if="hideBtn"
            >
              <el-button
                v-show="isSubmitButtonShowAgreeAndDisagree != 1"
                v-for="item of btnList.slice(1)"
                :key="item.name"
                :type="item.type"
                :style="btnStyle"
                @click.stop="
                  item.event === 'sub' ? subProcess() : saveInfo(false, item)
                "
              >
                {{ item.text }}
              </el-button>
              <el-dropdown
                v-if="
                  !isFlow &&
                  (rejectObj.fun || pointsReadingObj.fun || moreList.length > 0)
                "
                trigger="click"
                placement="top"
                style="border-left: 1px solid #d9d9d9"
              >
                <el-button>...</el-button>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item v-for="item of moreList" :key="item.key">
                    <div class="es-flow-btn" @click="goView(item)">
                      {{ item.value }}
                    </div>
                  </el-dropdown-item>
                  <el-dropdown-item v-if="pointsReadingObj.fun">
                    <div class="es-flow-btn" @click="taskReadBtn">分阅</div>
                  </el-dropdown-item>
                  <el-dropdown-item v-if="rejectObj.fun">
                    <div style="color: red" @click="rejectBtn">
                      {{ rejectObj.value }}
                    </div>
                  </el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </el-button-group>
          </div>
        </div>
      </div>
      <div v-else-if="!shrink" class="es-fenyue-buttons">
        <el-button
          type="primary"
          size="medium"
          style="width: 100%; margin: 10px 0px"
          @click="taskRead()"
        >
          阅结
        </el-button>
        <el-button
          class="es-flow-btn"
          v-if="isCanFenyue == '1'"
          size="medium"
          style="margin-left: 0px"
          @click="taskReadBtn"
          >分阅</el-button
        >
      </div>
      <!-- 弹窗内容 -->
      <es-dialog
        v-if="handleVisible"
        append-to-body
        height="auto"
        class="flow-dialog"
        ref="handleVisible"
        :title="title"
        :close-on-click-modal="false"
        :visible.sync="handleVisible"
        :closeParent="closeParent"
      >
        <ProcessForm
          :id="businessIds"
          :is-free-start-flow="useScene === 'multiInsMidwayWithSubmitScene'"
          :copy-history="pendedHistoryHandle"
          :process-definition-id="nodeInfo.nextNode"
          :opinion="value"
          :hideMessage="hideMessage"
          :flowLabelConfig="flowLabelConfig"
          :taskParams="taskParams"
          @cancel="closeProcess($event, 'handleVisible', closeParent)"
        />
      </es-dialog>
      <es-dialog
        append-to-body
        :close-on-click-modal="false"
        title="流程图查看"
        :visible.sync="showFlowChart"
        v-if="showFlowChart"
      >
        <!-- <FlowChart :nodeId="nodeInfo.nextNode" v-if="showFlowChart" /> -->
        <img
          style="width: 100%"
          :src="`${charUrl}/bpm/service/diagram/getpng.png?processDefinitionId=${nodeInfo.nextNode}`"
          alt="加载失败"
        />
      </es-dialog>
      <es-dialog
        v-if="showReject"
        append-to-body
        class="flow-dialog"
        height="400px"
        title="驳回"
        ref="showReject"
        :close-on-click-modal="false"
        :visible.sync="showReject"
      >
        <ProcessReject
          :pending-id="pendingId"
          :option="value"
          :hideMessage="hideMessage"
          :flowLabelConfig="flowLabelConfig"
          :show-reject="showReject"
          :news-info="nextNode.notificationMsg"
          @cancel="closeProcess(true, 'showReject')"
        />
      </es-dialog>
      <es-dialog
        v-if="showTaskRead"
        append-to-body
        class="flow-dialog"
        height="400px"
        ref="showTaskRead"
        :close-on-click-modal="false"
        :title="taskReadType === 'transfer' ? '转办' : '分阅'"
        :visible.sync="showTaskRead"
      >
        <StartTaskRead
          :pending-id="pendingId"
          :opinion="value"
          :type="taskReadType"
          :hideMessage="hideMessage"
          :flowLabelConfig="flowLabelConfig"
          :taskExamine="taskExamineInfo"
          :news-info="nextNode.notificationMsg"
          @cancel="closeProcess($event, 'showTaskRead')"
        />
      </es-dialog>
      <es-dialog
        v-if="showFileList"
        append-to-body
        title="意见附件"
        class="flow-dialog"
        :close-on-click-modal="false"
        :visible.sync="showFileList"
      >
        <FileList
          :ownId="pendingId"
          :code="attachedCode"
          @changeFileNum="(val) => (fileNum = val)"
        />
      </es-dialog>
      <es-dialog
        v-if="showSendMsg"
        append-to-body
        height="auto"
        title="发送消息"
        class="flow-dialog"
        ref="showSendMsg"
        :close-on-click-modal="false"
        :visible.sync="showSendMsg"
      >
        <SendMsg
          @cancel="closeProcess($event, 'showSendMsg')"
          :pendingId="pendingId"
          :hideMessage="hideMessage"
          :flowLabelConfig="flowLabelConfig"
          :newsList="newsList"
        />
      </es-dialog>
      <es-dialog
        v-if="showTaskUnionExamine"
        append-to-body
        height="auto"
        class="flow-dialog"
        ref="showTaskUnionExamine"
        :close-on-click-modal="false"
        :title="flowTitle"
        :visible.sync="showTaskUnionExamine"
      >
        <TaskUnionExamine
          @cancel="closeProcess($event, 'showTaskUnionExamine')"
          :pendingId="pendingId"
          :hideMessage="hideMessage"
          :flowLabelConfig="flowLabelConfig"
          :defaultOpinion="nodeDefaultSubmitOpinion"
          :type="flowType"
          :multiple="flowMultiple"
          :disabled="flowDisabled"
        />
      </es-dialog>
      <es-dialog
        v-if="showFreeStartFlow"
        append-to-body
        height="auto"
        class="flow-dialog"
        ref="showFreeStartFlow"
        :close-on-click-modal="false"
        :title="flowTitle"
        :visible.sync="showFreeStartFlow"
      >
        <es-flow
          v-if="showFreeStartFlow"
          isStartFlow
          :hideMessage="hideMessage"
          :flowLabelConfig="flowLabelConfig"
          :businessId="freeStartFlowParams.businessId"
          :flowTypeCode="freeStartFlowParams.flowTypeCode"
          :defaultProcessKey="freeStartFlowParams.defaultProcessKey"
        ></es-flow>
        <!-- @success="handleSuccess"
    @save="handleSave" -->
      </es-dialog>
    </div>
  </div>
</template>

<script>
import CommonOpinions from './component/CommonOpinions.vue';
import ProcessForm from './processForm.vue';
import CustomPreset from './component/CustomPreset.vue';
import Preset from './component/Preset.vue';
import FileList from './component/FileList.vue';
import SendMsg from './component/SendMsg.vue';
import TimeLimit from './component/TimeLimit.vue';
import ProcessReject from './processReject.vue';
import StartTaskRead from './startTaskRead.vue';
import Reset from './reset.vue';
import TaskUnionExamine from './component/taskUnionExamine.vue';
import SelectUser from './selectUser.vue';
import {
  findSysCodes,
  getHandleInfoHtml,
  getNodeInfo,
  tempSave,
  getProcessDefList,
  pendedhistoryList,
  endFlowHtml,
  taskReadHtml,
  findCodeValues,
  toStartTaskReadIndex,
  loginUserInfo,
  getAdjunctFileInfos,
  rejectAndEnd,
  getFreeStartFlowParams,
  isCanStartSubFlow,
  taskHandleHtml
} from 'eoss-ui/src/config/api';
import util from 'eoss-ui/src/utils/util';
export default {
  name: 'EsFreeStartFlow',
  componentName: 'EsFreeStartFlow',
  components: {
    [ProcessForm.name]: ProcessForm,
    [ProcessReject.name]: ProcessReject,
    [StartTaskRead.name]: StartTaskRead,
    [CustomPreset.name]: CustomPreset,
    [CommonOpinions.name]: CommonOpinions,
    [FileList.name]: FileList,
    [TimeLimit.name]: TimeLimit,
    [SendMsg.name]: SendMsg,
    [SelectUser.name]: SelectUser,
    [TaskUnionExamine.name]: TaskUnionExamine,
    Preset,
    Reset
  },
  props: {
    isStartFlow: { type: Boolean, default: false },
    showTooltip: { type: Boolean, default: true },
    startFlowBusinessId: { type: String, default: '' },
    pendingId: { type: String, default: '' },
    useScene: { type: String, default: '' },
    pendedHistoryHandle: { type: String, default: '' },
    nodeName: { type: String, default: '' },
    typeCode: { type: String, default: '' },
    flowTypeCode: { type: String, default: '' },
    defaultProcessKey: { type: String, default: '' },
    hideBtn: { type: Boolean, default: false },
    btnList: {
      type: Array,
      default: () => [
        { text: '提交', event: 'sub', type: 'primary' },
        { text: '暂存', event: 'save' }
      ]
    },
    subFun: {
      type: Function,
      default: (callBack) => {
        callBack();
      }
    },
    beforeSubmit: Function,
    title: { type: String, default: '事务表单办理' },
    closeParent: Boolean,
    param: {
      type: Object,
      default: () => {}
    },
    width: {
      type: String
    },
    resetAppId: { type: String },
    userSelectRange: {
      type: String
    },
    selectorParams: {
      type: Object,
      default: () => {
        return {};
      }
    },
    defaultProcessShowStrategy: { type: String, default: '' },
    taskParams: {
      type: Object,
      default: () => {}
    },
    isEndMessage: { type: Boolean, default: false },
    flowLabelConfig: {
      type: Object,
      default: () => {
        return {};
      }
    }
  },
  data() {
    return {
      styles: {},
      userModel: {},
      showFreeStartFlow: false, //自由发起流程弹窗
      freeStartFlowParam: {}, //自由发起流程参数
      otherOrgDisabledObjId: [],
      currentOrgDisabledObjId: [],
      nextNodeCheckType: 'select',
      readOnlyNotificationType: '',
      notificationMessageReadOnly: false,
      isCanPreAddSign: false,
      isStartFlowChartView: undefined,
      nextOtherOrgObjSelect: [],
      subProcessColumns: [],
      nextCurrentOrgObjSelect: [],
      otherParams: {
        filid: 'all',
        roleid: '',
        nofilid: sessionStorage.getItem('orgId')
      },
      loading: null, // 加载中
      newTypeCode: '',
      NodeName: '', // 当前节点值
      radioList: [],
      taskReadOpinionRequired: undefined,
      value: '',
      nodeFixedOpinionSelectList: [],
      customPresetHintMessage: '', //流程预设标题
      flowType: '',
      flowDisabled: false,
      activeNames: '',
      isEndUserTask: true,
      isForceDisplayDefaultOptionForPrefix: false,
      selectUserList: [],
      selectNextCurrentOrgObjList: [],
      flowMultiple: true,
      isCustomUser: 0,
      shrink: false,
      shrinkAbled: false,
      taskExamineInfo: {},
      presetUserJson: [],
      presetList: [],
      fileNum: 0, //附件数量
      showFileList: false, //意见附件弹窗
      attachedCode: '', //附件code码
      isCustomPreset: false,
      isBanInputOpinion: 0, //是否可以填写意见 0是 1否
      isPreset: false,
      businessIds: '',
      presetTaskNodeKeyStr: '',
      presetTaskNodeMap: {},
      flowTitle: '',
      endFlowInfo: {},
      isCanFenyue: '0',
      appId: '',
      multiple: false, //是否多选(true/false)
      readMultiple: true, //分阅用户是否多选(true/false)
      selectReadUserList: [], //选中分阅用户
      mixPresetList: [], //自动分阅混选
      selectPresetUserList: [], //自动分阅选中用户
      presetOptions: [], //自动分阅
      isLimitedTimeHandling: 0, //是否支持发起子流程限时办理
      nodeType: 0, //节点类型, (普通节点0,承办节点1,会签节点2,阅办节点3)
      userOptions: [], //分阅用户
      mixReadList: [], //分阅混选
      mixCurrentOrg: [], //本单位混选
      isTaskread: 0, //是否展示分阅用户
      showSendMsg: false, //是否展示核稿通知页面
      canPresetRead: false, //是否展示自动分阅
      isHideCurrentOrg: false, //是否隐藏本单位(承办)
      isHideOtherOrg: false, //是否隐藏外单位(承办)
      isMainSubProcess: false, // 判断是否子-主流程
      isNodeShowProcess: false, //是否展示主办
      isNextUser: false,
      isShowNode: false,
      nextNodeList: [],
      removeUsers: [],
      options: [],
      params: {
        filid: 'all', //选择范围(my:本单位/ "" or all:全部)
        selectmix: 'true1',
        deptid: '' //指定部门(my:本部门)
      },
      showReject: false, // 是否展示驳回按钮
      showTaskRead: false, // 是否展示分阅按钮
      taskReadType: '', //分阅类型
      isChooseNextNode: 1, //是否展示下步操作
      isHandleExplain: 0, //是否展示办理说明
      handleVisible: false,
      defaultNextNode: '', //默认节点
      showFlowChart: false, // 展示流程图弹窗
      isReject: false, // 是否驳回
      showTaskUnionExamine: false, //展示联合审核弹窗
      charUrl: util.win.location.origin,
      endFlow: false, // 是否结束流程
      isCurrentNodeForbiddenChangeCandidate: 0, //是否禁止选择办理人
      isSubmitButtonShowAgreeAndDisagree: 0, //是否展示同意和不同意按钮
      pointsReadingObj: {
        value: '分阅',
        fun: undefined
      }, // 分阅
      rejectObj: {
        value: '驳回',
        fun: undefined
      },
      isLimitedTimeHandling: false, // 是否支持发起子流程限时办理
      moreList: [], // 更多数组
      newsList: [], // 通知类型
      isSpecial: false,
      taskId: '',
      showNews: false, // 是否展示通知信息
      userInfo: '', // 用户信息
      objType: '',
      nodeDefaultSubmitOpinion: '', // 默认保存意见
      nodeDefaultRejectOpinion: '', // 默认驳回意见
      choiceOrgId: '',
      choiceDeptId: '',
      pOrgId: '',
      // userSelectionType: '',
      isOpinionRequired: 0, // 常用意见是否必填
      nextUserSelectList: [], // 下步选中办理人
      processObj: {}, // 流程信息
      pid: '123',
      isCanRemoveSign: false, // 是否显示减签
      isCanAddSign: false, // 是否显示加签
      AddSignUserList: [], // 加签办理人数组
      RemoveSignUserList: [], // 减签办理人数组
      operationList: [], // 下一步操作
      userList: [], // 下步办理人数组
      handleMode: '',
      countersignaturetypeCode: 0, //是否展示处理方式
      presetEdit: 0,
      isShowNextUser: true, //是否展示下步办理人
      nextUserTypes: ['employee', 'persongroup'], //下步办理人类型配置
      nextUserTabs: {}, //下步办理人权限配置
      presetReadUserId: [],
      nextNode: {
        nextNodeId: '', // 下步节点
        addSignMode: 'postAddSign',
        isAddSign: '', // 是否加签
        isRemoveSign: '', // 是否减签
        nextOperate: '', // 下步操作
        notificationMsg: '', // 通知信息
        addSignUserId: [], // 加签办理人
        removeSignUserId: [], // 减签办理人
        nextUserId: [], // 下步办理人
        nextOrgId: [], //办理对象
        nextCurrentOrgObj: [],
        nextCurrentOrgObjSerialId: [], //本单位用户
        nextOtherOrgObj: [], //外单位
        nextReadUserId: [], //分阅用户
        presetReadUserId: [], //自动分阅
        handleExplain: '', //办理意见
        notificationType: [], // 通知方式
        isLimitedTime: '2', // 是否限时办理
        mainSubId: ''
      },
      nodeInfos: [], // 下步节点选择数组
      nextFlowNode: '',
      currentOrgName: '', //本单位名称
      otherOrgName: '', //外单位名称
      needRetrialAuth: false, //是否二次鉴权
      nodeInfo: {
        nextNode: '',
        nextUser: '',
        option: []
      }
    };
  },
  created() {
    this.getUserInfo();
  },
  destroyed() {
    this.shrink = false;
  },
  mounted() {
    this.businessIds = this.startFlowBusinessId;
    this.nextNode.nextNodeId = this.nextNodeId;
    this.otherParams.roleid = this.selectorParams.roleid;
    this.getNodeType();
    !this.isFlow &&
      (this.newTypeCode = this.typeCode || this.$route.query.typecode);
    if (this.isFlow) {
      this.startFlowBusinessId && this.getProcess();
    } else if (this.newTypeCode == 'fenyue') {
      this.getTaskReadFlow();
    } else if (
      this.newTypeCode != 'reset' &&
      this.newTypeCode != 'continuation'
    ) {
      this.getHedInfo();
    }
  },
  watch: {
    width: {
      immediate: true,
      handler(val) {
        if (val) {
          this.styles = { width: parseInt(val, 10) + 'px' };
        }
      }
    },
    businessId(val) {
      if (val) {
        this.businessIds = val;
        if (this.isFlow) {
          this.getProcess();
        }
      }
    }
  },
  computed: {
    tabs() {
      return {
        employee: {
          param: {
            filid: this.userModel.orgId,
            name: '本单位用户'
          }
        },
        department: { param: { filid: this.userModel.orgId } }
      };
    },
    currentTabs() {
      return {
        department: {
          param: { filid: this.userModel.orgId }
        },
        employee: {
          param: { filid: this.userModel.orgId }
        }
      };
    }, //
    // 是否开始流程
    isFlow() {
      return this.isStartFlow;
    },
    types() {
      if (this.isCdjxjTaskHandle == 'true') {
        return ['employee', 'enterprise', 'department'];
      } else {
        return ['employee', 'enterprise', 'department', 'persongroup'];
      }
    },
    btnStyle() {
      if (this.btnList.length > 1) {
        return {};
      } else {
        return { width: '100%' };
      }
    }
  },
  methods: {
    handleChange(val) {
      this.$parent.$emit('flowChange', val);
    },
    getsubProcessColumns() {
      if (!this.isMainSubProcess || !this.isNodeShowProcess) return [];
      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;
    },
    // 分阅是否多选
    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;
      }
    },
    //获取附件
    getFile(ownId, code) {
      let params = {
        url: getAdjunctFileInfos,
        params: { ownId, code }
      };
      util
        .ajax(params)
        .then((res) => {
          const { rCode, results, msg } = res;
          if (rCode == 0) {
            results && (this.fileNum = results.length);
          } else {
            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: this.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: this.userModel.orgId } }
          };
          this.multiple = true;
        }
        if (val == 7 || val == 9 || val == 11) {
          this.multiple = false;
        }
      }
    },
    setShrink() {
      this.shrink = !this.shrink;
      this.styles = this.shrink
        ? { width: 0 }
        : { width: this.width ? parseInt(this.width, 10) + 'px' : '' };
      this.$emit('shrink', this.shrink);
    },
    customLoading(type) {
      if (type != 'end') {
        this.loading = util.loading(this.$loading, '加载中...');
      } else {
        this.loading.close();
      }
    },
    taskRead() {
      if (this.taskReadOpinionRequired == 'true' && !this.value) {
        if (!this.$refs.commonOpinions.validate()) return;
      }
      this.$confirm('确认提交?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.loading = util.loading(this.$loading, '加载中...');
          const { businessId, appId, processDefinitionId, pendingId } =
            this.taskExamineInfo;
          let params = {
            businessId,
            appId,
            processDefinitionId,
            pendingId,
            opinion: this.value,
            taskAction: 'complete'
          };
          util
            .ajax({
              url: taskReadHtml,
              params: { taskAction: 'complete' },
              headers: {
                Accept: 'application/json,text/plain'
              },
              method: 'post',
              data: params
            })
            .then((res) => {
              const { status, message } = res;
              this.loading.close();
              if (status === 'success') {
                this.$message.success('提交成功');
                this.$emit('success');
              } else {
                this.$message.error(message || '系统错误，请联系管理员！');
                this.$emit('error');
              }
            })
            .catch((err) => {
              this.loading.close();
              if (err.message && err.message !== 'canceled') {
                this.$message.error(err.message);
              }
            });
        })
        .catch(() => {});
    },
    getTaskReadFlow() {
      this.loading = util.loading(this.$loading, '加载中...');
      util
        .ajax({
          url: toStartTaskReadIndex,
          params: { pendingId: this.pendingId }
        })
        .then((res) => {
          const {
            status,
            message,
            data: { isCanFenyue, taskExamine, taskReadOpinionRequired }
          } = res;
          if (status === 'success') {
            this.taskExamineInfo = taskExamine;
            this.taskReadOpinionRequired = taskReadOpinionRequired;
            this.isCanFenyue = isCanFenyue;
            if (this.nodeName) {
              this.NodeName = this.nodeName;
            }
            this.getNodeType();
          } else {
            this.$message.error(message || '系统错误，请联系管理员！');
          }
          this.loading.close();
        })
        .catch((err) => {
          this.loading.close();
          if (err.message && err.message !== 'canceled') {
            this.$message.error(err.message);
          }
        });
    },
    getUserInfo() {
      let mainConfig = util.getStorage('mainConfig');
      if (mainConfig) {
        this.userModel = JSON.parse(mainConfig).userModel;
      } else {
        util
          .ajax({ url: loginUserInfo })
          .then((res) => {
            const { status, data } = res;
            if (status == 'success') {
              this.userModel = data;
            } else {
              let msg = res.msg || '系统错误，请联系管理员！';
              this.$message.error(msg);
            }
          })
          .catch((err) => {
            if (err.message && err.message !== 'canceled') {
              this.$message.error(err.message);
            }
          });
      }
    },
    changeSelectUser(val, type, isNextNode) {
      // const { nextUser,mixList } = val;
      const { nextUser, mixList } = val;
      if (isNextNode) {
        this.nextNode[type] = nextUser;
        if (type == 'nextCurrentOrgObjSerialId') {
          this.mixCurrentOrg = mixList;
        }
      } else {
        this[type] = nextUser;
      }
    },
    getNodeType() {
      util
        .ajax({
          url: findCodeValues,
          params: {
            ccCode: 'notification_type',
            userId: util.getStorage('userId'),
            pendingId: this.pendingId
          }
        })
        .then((res) => {
          const { status, data } = res;
          if (status === 'success') {
            this.newsList = data;
          }
        })
        .catch((err) => {
          if (err.message && err.message !== 'canceled') {
            this.$message.error(err.message);
          }
        });
    },
    /**
     * saveInfo
     * @desc:暂存
     * @author liufan
     * @date 2022年9月9日
     **/
    saveInfo(type, btn) {
      if (this.isFlow) {
        if (!type) {
          if (btn && btn.before) {
            btn
              .before(
                Object.prototype.hasOwnProperty.call(btn, 'code') ? btn.code : 1
              )
              .then((next) => {
                this.$emit('save', this.businessIds);
              })
              .catch((e) => {});
          } else if (this.beforeSubmit != undefined) {
            this.beforeSubmit(
              btn && Object.prototype.hasOwnProperty.call(btn, 'code')
                ? btn.code
                : 1
            )
              .then((next) => {
                this.$emit('save', this.businessIds);
              })
              .catch((e) => {});
          } else {
            this.$emit('save', this.businessIds);
          }
        }
      } else {
        if (btn && btn.before && !type) {
          btn
            .before(
              Object.prototype.hasOwnProperty.call(btn, 'code') ? btn.code : 2
            )
            .then((next) => {
              this.saveFlowInfo();
            })
            .catch((e) => {});
        } else if (this.beforeSubmit == undefined && !type) {
          this.subFun(this.saveFlowInfo);
        } else if (!type && this.beforeSubmit != undefined) {
          this.beforeSubmit(
            btn && Object.prototype.hasOwnProperty.call(btn, 'code')
              ? btn.code
              : 2
          )
            .then((next) => {
              this.saveFlowInfo();
            })
            .catch((e) => {});
        } else {
          this.saveFlowInfo(type);
        }
      }
    },
    saveFlowInfo(isSave) {
      let params = {
        opinion: this.value,
        pendingId: this.pendingId
      };
      this.loading = util.loading(this.$loading, '保存中...');
      util
        .ajax({ url: tempSave, params })
        .then((res) => {
          const { status, message } = res;
          if (!isSave) this.loading.close();
          if (status == 'success') {
            // this.$message.success('暂存成功');
            !isSave && this.$emit('save', this.businessIds);
          } else {
            this.$message.error(message || '系统错误，请联系管理员！');
          }
        })
        .catch((err) => {
          if (!isSave) this.loading.close();
          if (err.message && err.message !== 'canceled') {
            this.$message.error(err.message);
          }
        });
    },
    /**
     * rejectBtn
     * @desc:点击驳回
     * @author liufan
     * @date 2022年5月25日
     **/
    rejectBtn() {
      if (this.value === '') this.value = this.nodeDefaultRejectOpinion;
      if (!this.value) {
        if (!this.$refs.commonOpinions.validate()) return;
      }
      if (this.beforeSubmit != undefined) {
        this.beforeSubmit(0)
          .then((next) => {
            this.showReject = true;
          })
          .catch((e) => {});
      } else {
        this.showReject = true;
      }
    },
    /**
     * taskReadBtn
     * @desc:点击分阅
     * @author liufan
     * @date 2022年5月25日
     **/
    taskReadBtn() {
      // return this.$message.warning('暂未开放！敬请期待');
      if (this.beforeSubmit != undefined) {
        this.beforeSubmit()
          .then((next) => {
            if (this.value === '') this.value = this.nodeDefaultRejectOpinion;
            this.taskReadType = 'create';
            this.showTaskRead = true;
          })
          .catch((e) => {});
      } else {
        if (this.value === '') this.value = this.nodeDefaultRejectOpinion;
        this.taskReadType = 'create';
        this.showTaskRead = true;
      }
    },
    /**
     * getFind
     * @desc:获取通知方式
     * @author liufan
     * @date 2022年5月25日
     **/
    getFind() {
      util
        .ajax({
          url: findSysCodes
        })
        .then((res) => {
          const { status, message } = res;
          if (status === 'success') {
            if (this.hideMessage) return;
            this.nextNode.notificationType = message.split(',');
            let arr = [];
            this.newsList.map((item) => {
              this.nextNode.notificationType.map((x) => {
                if (x == item.cciValue) {
                  arr.push(x);
                }
              });
            });
            this.nextNode.notificationType = arr;
          }
        })
        .catch((err) => {
          if (err.message && err.message !== 'canceled') {
            this.$message.error(err.message);
          }
        });
    },
    getFreeStartParams() {
      const { businessId, processDefinitionId, nodeId } = this.endFlowInfo;
      let param = {
        url: getFreeStartFlowParams,
        params: {
          businessId,
          processDefinitionId,
          nodeId
        }
      };
      util.ajax(param).then((res) => {
        if (res.rCode == 0 || res.status == 'success') {
          this.freeStartFlowParams = res.results;
          this.showFreeStartFlow = true;
        } else {
          this.$message.error(res.message || '系统错误，请联系管理员！');
        }
      });
    },
    /**
     * endFlows
     * @desc:直接办结
     * @author liufan
     * @param {Object} res 直接办结数据
     * @date 2022年5月25日
     **/
    endFlows(res) {
      if (this.beforeSubmit != undefined) {
        this.beforeSubmit()
          .then((next) => {
            this.saveEndFlows(res);
          })
          .catch((e) => {});
      } else {
        this.saveEndFlows(res);
      }
    },
    saveEndFlows(res) {
      this.$confirm('确认' + res.value + '?')
        .then(() => {
          let params = {
            url: endFlowHtml,
            headers: { Accept: 'application/json,text/plain' },
            method: 'post',
            data: {
              ...this.endFlowInfo,
              ...this.nextNode,
              opinion: this.value,
              userId: util.getStorage('userId'),
              nextUserId: this.multiple
                ? this.nextNode.nextUserId.join(',')
                : this.nextNode.nextUserId,
              addSignUserId: this.nextNode.addSignUserId.join(','),
              customPresetUserJson: JSON.stringify(this.presetList),
              presetUserJson: JSON.stringify(this.presetUserJson),
              removeSignUserId: this.nextNode.removeSignUserId.join(','),
              notificationType: this.nextNode.notificationType.join(',')
            }
          };
          this.loading = util.loading(this.$loading, '加载中...');
          util
            .ajax(params)
            .then((res) => {
              const { status, message } = res;
              this.loading.close();
              if (status === 'success') {
                this.$message.success('提交成功');
                this.$emit('success');
              } else {
                this.$message.error(message || '系统错误，请联系管理员！');
                this.$emit('error');
              }
            })
            .catch((err) => {
              this.loading.close();
              if (err.message && err.message !== 'canceled') {
                this.$message.error(err.message);
              }
            });
        })
        .catch((e) => {});
    },
    /**
     * goView
     * @desc:更多流程按钮操作
     * @author liufan
     * @param {Object} res 当前点击操作按钮数据
     * @date 2022年5月25日
     **/
    goView(res) {
      // 驳回并办结：rejectAndEndHtml
      // 获取转办页面：toTaskTransferHtml
      // 转办：taskTransferHtml
      // 获取分阅页面信息：toStartTaskReadHtml
      // 分阅：taskReadHtml
      // 获取驳回页面信息：toTaskRejectHtml（注释有误：appId改为pendingId）
      // 驳回：taskRejectHtml
      // 直接办结：endFlowHtml
      // 自由发起子流程：toFreeStartFlow
      if (res.fun === 'toStartTaskRead()') {
        // 分阅
        this.taskReadBtn();
      } else if (res.fun === 'reject()') {
        // 驳回
        this.rejectBtn();
      } else if (res.fun === 'endFlow()') {
        // 直接办结
        this.endFlows(res);
      } else if (res.fun === 'rejectAndEnd()') {
        // 驳回并办结
        this.rejectAndEnd(res);
      } else if (res.fun === 'toTransfer()') {
        // 转办
        this.toTransfer(res);
      } else if (res.fun === 'toTaskReadAndEnd()') {
        this.toTaskReadAndEnd(res);
      } else if (res.fun === 'toSendMsg()') {
        // 核稿通知
        this.toSendMsg(res);
      } else if (res.fun === 'toStartDraf()') {
        //稿件递送
        this.flowType = 'startDraf';
        this.flowMultiple = false;
        this.flowDisabled = false;
        this.flowTitle = res.value;
        this.toStartDraf(res);
      } else if (res.fun === 'toTakeAdvice()') {
        //征求意见
        this.flowType = 'takeAdvice';
        this.flowMultiple = true;
        this.flowDisabled = false;
        this.flowTitle = res.value;

        this.toTakeAdvice(res);
      } else if (res.fun === 'toUnionExamine()') {
        //联合审核
        this.flowType = 'unionExamine';
        this.flowTitle = res.value;
        this.flowDisabled = false;
        this.flowMultiple = true;
        this.toStartDraf();
      } else if (res.fun === 'toTaskReview()') {
        // 复核
        this.flowType = 'taskReview';
        this.flowDisabled = true;
        this.flowTitle = res.value;
        this.toStartDraf(res);
      } else if (res.fun === 'toUnionSeal()') {
        // 联合用印
        this.flowType = 'unionSeal';
        this.flowDisabled = true;
        this.flowTitle = res.value;
        this.toStartDraf(res);
      } else if (res.fun == 'toTwoOfficesDispatch()') {
        // 报送两办
        this.flowType = 'twoOfficesDispatch';
        this.flowDisabled = true;
        this.flowTitle = res.value;
        this.toStartDraf(res);
      } else if (res.fun == 'toFreeStartFlow()') {
        this.getFreeStartParams();
        // 报送两办
        // this.flowType = 'twoOfficesDispatch';
        // this.flowDisabled = true;
        // this.flowTitle = res.value;
        // this.toStartDraf(res);
      } else {
        this.$message.warning('暂未开放，敬请期待！');
      }
      // isCanStartSubFlow
    },
    /**
     * toTakeAdvice
     * @desc:征求意见
     * @author liufan
     * @date 2022年9月29日
     **/
    toTakeAdvice(res) {
      if (this.beforeSubmit != undefined) {
        this.beforeSubmit()
          .then((next) => {
            this.saveToTakeAdvice(res);
          })
          .catch((e) => {});
      } else {
        this.saveToTakeAdvice(res);
      }
      // return this.$message.warning('暂未开放！敬请期待');
    },
    saveToTakeAdvice(res) {
      let params = {
        url: isCanStartSubFlow,
        data: {
          appId: this.taskExamineInfo.appId,
          inevitableNode: res.inevitableNode
        },
        method: 'post',
        headers: { Accept: 'application/json,text/plain' }
      };
      this.loading = util.loading(this.$loading, '加载中...');
      util
        .ajax(params)
        .then((res) => {
          const { message } = res;
          this.loading.close();
          if (message == 'success') {
            this.showTaskUnionExamine = true;
          } else {
            this.$message.error(message || '系统错误，请联系管理员！');
          }
        })
        .catch((err) => {
          this.loading.close();
          if (err.message && err.message !== 'canceled') {
            this.$message.error(err.message);
          }
        });
    },
    /**
     * toStartDraf
     * @desc: 稿件递送、联合审核、复核
     * @author liufan
     * @date 2022年9月29日
     **/
    toStartDraf(res) {
      if (this.beforeSubmit != undefined) {
        this.beforeSubmit()
          .then((next) => {
            this.showTaskUnionExamine = true;
          })
          .catch((e) => {});
      } else {
        this.showTaskUnionExamine = true;
      }
    },
    /**
     * toSendMsg
     * @desc:核稿通知
     * @author liufan
     * @date 2022年9月29日
     **/
    toSendMsg(res) {
      if (this.beforeSubmit != undefined) {
        this.beforeSubmit()
          .then((next) => {
            this.showSendMsg = true;
          })
          .catch((e) => {});
      } else {
        this.showSendMsg = true;
      }
    },
    /**
     * toTaskReadAndEnd
     * @desc:分阅并办结
     * @author liufan
     * @date 2022年9月29日
     **/
    toTaskReadAndEnd(res) {
      if (this.beforeSubmit != undefined) {
        this.beforeSubmit()
          .then((next) => {
            if (this.value === '') this.value = this.nodeDefaultRejectOpinion;
            this.taskReadType = 'taskReadAndEnd';
            this.showTaskRead = true;
          })
          .catch((e) => {});
      } else {
        if (this.value === '') this.value = this.nodeDefaultRejectOpinion;
        this.taskReadType = 'taskReadAndEnd';
        this.showTaskRead = true;
      }
    },
    /**
     * rejectAndEnd
     * @desc:驳回并办结
     * @author liufan
     * @date 2022年9月29日
     **/
    rejectAndEnd(res) {
      if (this.isOpinionRequired == 1 && (this.value == '' || !this.value)) {
        if (!this.$refs.commonOpinions.validate()) return;
      }
      if (this.beforeSubmit != undefined) {
        this.beforeSubmit()
          .then((next) => {
            this.saveRejectAndEnd(res);
          })
          .catch((e) => {});
      } else {
        this.saveRejectAndEnd(res);
      }
    },
    saveRejectAndEnd(res) {
      this.$confirm('确认' + res.value + '?')
        .then(() => {
          // return this.$message.warning('请填写意见');
          let params = {
            url: rejectAndEnd,
            headers: { Accept: 'application/json,text/plain' },
            method: 'post',
            data: {
              opinion: this.value,
              pendingId: this.pendingId,
              isSinglePage: false
            }
          };
          this.loading = util.loading(this.$loading, '加载中...');
          util
            .ajax(params)
            .then((res) => {
              const { status, message } = res;
              this.loading.close();
              if (status === 'success') {
                this.$message.success('提交成功');
                this.$emit('success');
              } else {
                this.$message.error(message || '系统错误，请联系管理员！');
                this.$emit('error');
              }
            })
            .catch((err) => {
              this.loading.close();
              if (err.message && err.message !== 'canceled') {
                this.$message.error(err.message);
              }
            });
        })
        .catch(() => {
          // on cancel
        });
    },
    /**
     * toTransfer
     * @desc:转办
     * @author liufan
     * @date 2022年9月29日
     **/
    toTransfer(res) {
      if (this.beforeSubmit != undefined) {
        this.beforeSubmit(0)
          .then((next) => {
            this.taskReadType = 'transfer';
            this.showTaskRead = true;
          })
          .catch((e) => {});
      } else {
        this.taskReadType = 'transfer';
        this.showTaskRead = true;
      }
    },
    /**
     * getNodeInfo
     * @desc:获取节点信息
     * @author liufan
     * @date 2022年5月25日
     **/
    getNodeInfo() {
      let params = {
        processDefinitionId: this.nodeInfo.nextNode,
        nextNodeId: this.nextNode.nextNodeId,
        taskId: this.taskId,
        userId: util.getStorage('userId'),
        pendingId: this.pendingId,
        businessId: this.businessIds
      };
      util
        .ajax({ url: getNodeInfo, params })
        .then((res) => {
          const { status, message, data } = res;
          this.loading.close();
          if (status === 'success') {
            data.otherOrgDisabledObjId &&
              (this.otherOrgDisabledObjId =
                data.otherOrgDisabledObjId.split(','));
            data.currentOrgDisabledObjId &&
              (this.currentOrgDisabledObjId =
                data.currentOrgDisabledObjId.split(','));
            if (data != null) {
              if (
                data.nodeExtAttr.userSelectionType == 7 ||
                data.nodeExtAttr.userSelectionType == 8 ||
                data.nodeExtAttr.userSelectionType == 9 ||
                data.nodeExtAttr.userSelectionType == 10 ||
                data.nodeExtAttr.userSelectionType == 11 ||
                data.nodeExtAttr.userSelectionType == 12
              ) {
                this.getIsShowNextUser(
                  data.nodeExtAttr && data.nodeExtAttr.userSelectionType
                );
              } else {
                this.isMultiple(
                  data.nodeExtAttr && data.nodeExtAttr.userSelectionType,
                  this.choiceOrgId,
                  this.choiceDeptId,
                  this.pOrgId
                );
              }
              this.isReadMultiple(
                data.nodeExtAttr && data.nodeExtAttr.userSelectionType
              );
              this.isTaskread = data.nodeExtAttr.isTaskread;
              this.isHandleExplain = data.nodeExtAttr.isHandleExplain;
              this.isLimitedTimeHandling =
                data.nodeExtAttr.isLimitedTimeHandling;
              this.nodeType = data.nodeExtAttr.nodeType;
              //如果当前为承办节点/会签节点,则展示本单位外单位办理人选择
              if (this.nodeType === 1 || this.nodeType === 2) {
                this.isMainSubProcess === true
                  ? (this.isNodeShowProcess = true)
                  : (this.isNodeShowProcess = false);
                this.isMainSubProcess === true
                  ? (this.isMainSubProcess = true)
                  : (this.isMainSubProcess = false);
                this.isNextUser = false;
                this.isHideCurrentOrg =
                  res.data.nodeExtAttr.isHideCurrentOrg == 1 ? false : true; //判断是否隐藏本单位
                this.isHideOtherOrg =
                  res.data.nodeExtAttr.isHideOtherOrg == 1 ? false : true; //判断是否隐藏外单位
              } else {
                this.isHideCurrentOrg = false;
                this.isHideOtherOrg = false;
                this.isNodeShowProcess = false;
                this.isMainSubProcess = false;
                this.isNextUser = this.nextNode.nextOperate != 9;
                // this.isMainSubProcess === true
                //   ? (this.isMainSubProcess = true)
                //   : (this.isMainSubProcess = false);
              }
              this.multiple
                ? (this.nextNode.nextUserId = [])
                : (this.nextNode.nextUserId = '');
              if (
                this.multiple &&
                data.nodeExtAttr.isDefSelectedObj == 1 &&
                data.nextUserList !== undefined
              ) {
                data.nextUserList.map((item) => {
                  if (item.userId && item.username) {
                    this.nextNode.nextUserId.push(item.userId);
                    this.selectUserList.push({
                      showname: item.username,
                      showid: item.userId
                    });
                  }
                });
              }
              data.nextUserList.map((item) => {
                if (item.userId && item.username) {
                  this.options.push({
                    showname: item.username,
                    showid: item.userId
                  });
                }
              });
              if (data.nodeExtAttr.presetEdit != 0) {
                this.radioList = this.options;
              }
              if (
                !this.multiple &&
                data.nextUserList.length > 0 &&
                data.nodeExtAttr.isDefSelectedObj == 1
              ) {
                this.nextNode.nextUserId = data.nextUserList[0].userId;
                this.selectUserList.push({
                  showname: data.nextUserList[0].username,
                  showid: data.nextUserList[0].userId
                });
              }
              this.isLimitedTimeHandling =
                data.nodeExtAttr.isLimitedTimeHandling;
              this.isCustomUser = data.nodeExtAttr.isCustomUser;
              this.presetEdit = data.nodeExtAttr.presetEdit;
              this.countersignaturetypeCode = data.countersignaturetypeCode; //是否展示处理方式
              this.handleMode = data.countersignaturetypeText;
              data.globalNodeType === 'endEvent' ? (this.endFlow = true) : '';
            }
            this.isCustomPreset &&
              this.$refs.customPreset.getPresetFlowInfo(
                this.nextNode.nextNodeId,
                this.nodeInfo.nextNode,
                true
              );
          } else {
            this.$message.error(message || '系统错误，请联系管理员！');
          }
        })
        .catch((err) => {
          this.loading.close();
          if (err.message && err.message !== 'canceled') {
            this.$message.error(err.message);
          }
        });
    },
    /**
     * selecNext
     * @desc:下步节点变化时更新数据
     * @author liufan
     * @param {String} val 当前选中值
     * @date 2022年5月25日
     **/
    selecNext(val, type, isDef) {
      this.loading = util.loading(this.$loading, '加载中...');
      if (this.multiple) {
        this.nextNode.nextUserId = [];
      } else {
        this.nextNode.nextUserId = '';
      }
      this.options = [];
      this.selectUserList = [];
      this.radioList = [];

      if (type) {
        this.isNextUser = false;
        this.isShowNode = false;
        this.isMainSubProcess = false;
        this.isNodeShowProcess = false;
        this.nextNode.nextNodeId = '';
        this.nextNode.isReturnSubmitter = 0;
        this.nextNode.isUndertakeReply = 0;
        this.nextNode.isTakeAdviceReply = 0;
        this.nextNode.isUndertakeEnd = 0;
        this.nextNode.isTakeAdviceEnd = 0;
        this.nextNode.isReadDealReply = 0;
        this.nextNode.isReadDealEnd = 0;
        this.nextNode.isReturnRejectNode = 0;
        this.nextNode.isSerialSubmit = 0;
        this.nodeInfos = [];
        this.operationList.forEach((item) => {
          if (item.key === val) {
            if (!item.taskNodeList) {
              this.nodeInfos = [];
            } else {
              this.nodeInfos = item.taskNodeList;
            }
            return;
          }
        });
        if (this.defaultNextNode) {
          let defaultNode = this.nodeInfos.filter(
            (item) => item.nodeId == this.defaultNextNode
          );
          if (this.nodeInfos.length > 0 && defaultNode.length == 0) {
            this.nextNode.nextNodeId = this.nodeInfos[0].nodeId;
          } else {
            this.nextNode.nextNodeId = this.defaultNextNode;
          }
        } else if (this.nodeInfos.length > 0) {
          this.nextNode.nextNodeId = this.nodeInfos[0].nodeId;
        }
      }

      if (val === 9) {
        this.isReject = true;
      } else {
        this.isReject = false;
      }
      if (this.isSpecial) {
        if (val == -1) {
          this.nextNode.isSerialSubmit = 1;
          this.loading.close();
          return;
        } else if (val == 0) {
          this.isNextUser = true;
          this.isShowNode = true;
        } else if (val == 1) {
          this.isNextUser = true;
          this.isShowNode = true;
        } else if (val == 2) {
          this.nextNode.isReturnSubmitter = 1;
          this.loading.close();
          return;
        } else if (val == 3) {
          this.nextNode.isUndertakeReply = 1;
          this.loading.close();
          return;
        } else if (val == 4) {
          this.nextNode.isTakeAdviceReply = 1;
          this.loading.close();
          return;
        } else if (val == 5) {
          this.nextNode.isUndertakeEnd = 1;
          this.loading.close();
          return;
        } else if (val == 6) {
          this.nextNode.isTakeAdviceEnd = 1;
          this.loading.close();
          return;
        } else if (val == 7) {
          this.nextNode.isReadDealReply = 1;
          this.loading.close();
          return;
        } else if (val == 8) {
          this.nextNode.isReadDealEnd = 1;
          this.loading.close();
          return;
        } else if (val == 9) {
          this.nextNode.isReturnRejectNode = 1;
          this.loading.close();
          return;
        } else {
        }
      }

      if (isDef !== true) this.getNodeInfo();
    },
    /**
     * isMultiple
     * @desc:是否多选
     * @author liufan
     * @date 2022年9月13日
     **/
    isMultiple(val, choiceOrgId, choiceDeptId, pOrgId) {
      if (val == 2 || val == 4 || val == 6 || val == 16) {
        this.multiple = true;
      } else {
        this.multiple = false;
      }
      if (val == 1 || val == 2 || val == 5) {
        this.params.filid = this.userModel.orgId;
        if (choiceOrgId) {
          this.params.filid = choiceOrgId;
        }
      }
      if (val == 5 || val == 6) {
        this.params.filid = this.userModel.orgId;
        this.params.mydeptid = this.userModel.depId;
        if (choiceDeptId) {
          this.params.mydeptid = choiceDeptId;
        }
        if (choiceOrgId) {
          this.params.filid = choiceOrgId;
        }
      }
      if (val == 15 || val == 16) {
        this.params.filid = this.userModel.orgId;
        if (pOrgId) {
          this.params.filid = pOrgId;
        }
      }
    },
    /**
     * getHedInfo
     * @desc:获取审核页面数据
     * @author liufan
     * @date 2022年5月25日
     **/
    getHedInfo() {
      this.loading = util.loading(this.$loading, '加载中...');
      let params = {
        pendingId: this.pendingId,
        userId: util.getStorage('userId')
      };
      util
        .ajax({ url: getHandleInfoHtml, params })
        .then((res) => {
          //pc返回数据

          this.loading.close();
          if (res.status === 'success') {
            const {
              data: {
                nextNodeList,
                taskOperations,
                isCustomPreset,
                presetTaskNodeKeyStr,
                presetTaskNodeMap,
                isPreset,
                choiceOrgId,
                choiceDeptId,
                readOnlyNotificationType,
                notificationMessageReadOnly,
                nextNodeCheckType,
                pOrgId,
                currentOrgName,
                otherOrgName,
                taskExamine,
                nodeInfoMap,
                canRemoveSignUserList,
                defaultNotificationMessage,
                customPresetHintMessage,
                isCanAddSign,
                isCanRemoveSign,
                attachedCode,
                isSpecial,
                canPresetRead,
                isCdjxjTaskHandle,
                taskButtonList,
                isCanPreAddSign
              }
            } = res;
            this.$emit('startTaskRead', res);
            this.$emit('start-task-read', res);
            this.currentOrgName = currentOrgName;
            this.readOnlyNotificationType = readOnlyNotificationType;
            this.isSpecial = isSpecial;
            this.notificationMessageReadOnly =
              notificationMessageReadOnly == 'true';
            this.otherOrgName = otherOrgName;
            this.isCanPreAddSign = isCanPreAddSign;
            this.endFlowInfo.choiceOrgId = choiceOrgId;
            this.endFlowInfo.choiceDeptId = choiceDeptId;
            this.endFlowInfo.pendingId = this.pendingId;
            this.attachedCode = attachedCode;
            this.endFlowInfo.pOrgId = pOrgId;
            this.canPresetRead = canPresetRead;
            this.isCdjxjTaskHandle = isCdjxjTaskHandle;
            nextNodeCheckType && (this.nextNodeCheckType = nextNodeCheckType);
            this.operationList = taskOperations || [];
            this.customPresetHintMessage = customPresetHintMessage;
            if (canPresetRead) {
              let ids =
                nodeInfoMap.nodeExtAttr.presetReadCandinateIds.split(',');
              let names =
                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);
              });
            }
            if (!this.isFlow) this.getFile(this.pendingId, attachedCode);
            if (nextNodeList && nextNodeList.length != 0) {
              this.nextNodeList = nextNodeList;
            }
            if (canRemoveSignUserList && canRemoveSignUserList.length != 0)
              this.removeUsers = canRemoveSignUserList;
            if (taskOperations && taskOperations.length != 0) {
              taskOperations.map((item) => {
                if (item.key === 9) this.isReject = true;
                if (item.isSelected) {
                  this.nodeInfos = [];
                  this.nextNode.nextOperate = item.key;
                  if (item.taskNodeList != null) {
                    this.nodeInfos = item.taskNodeList;
                  }
                }
                if (taskOperations.length == 1) {
                  this.nodeInfos = [];
                  this.nextNode.nextOperate = taskOperations[0].key;
                  if (taskOperations[0].taskNodeList != null) {
                    this.nodeInfos = taskOperations[0].taskNodeList;
                  }
                }
              });
              this.selecNext(this.nextNode.nextOperate, true, true);
            }
            if (nodeInfoMap && JSON.stringify(nodeInfoMap) != '{}') {
              this.needRetrialAuth =
                !!nodeInfoMap.nodeExtAttr.isCurrentNodeSubmitNeedRetrialAuth;
              if (nodeInfoMap.nodeExtAttr.nodeFixedOpinionSelectList) {
                let notice = JSON.parse(
                  nodeInfoMap.nodeExtAttr.nodeFixedOpinionSelectList
                );
                notice.map((x) => {
                  this.nodeFixedOpinionSelectList.push({ content: x });
                });
              }
              this.isCurrentNodeForbiddenChangeCandidate =
                nodeInfoMap.nodeExtAttr.isCurrentNodeForbiddenChangeCandidate;
              this.nodeDefaultSubmitOpinion =
                nodeInfoMap.nodeExtAttr.nodeDefaultSubmitOpinion;
              this.isSubmitButtonShowAgreeAndDisagree =
                nodeInfoMap.nodeExtAttr.isSubmitButtonShowAgreeAndDisagree;
              this.isBanInputOpinion =
                nodeInfoMap.nodeExtAttr.isBanInputOpinion;
              this.nodeDefaultRejectOpinion =
                nodeInfoMap.nodeExtAttr.nodeDefaultRejectOpinion;
              this.isOpinionRequired =
                nodeInfoMap.nodeExtAttr.isOpinionRequired;
              // this.isChooseNextNode = nodeInfoMap.nodeExtAttr.isChooseNextNode;
              this.defaultNextNode = nodeInfoMap.nodeExtAttr.defaultNextNode;
              if (nodeInfoMap.nodeExtAttr.defaultNextNode) {
                let defaultNode = this.nodeInfos.filter(
                  (item) =>
                    item.nodeId == nodeInfoMap.nodeExtAttr.defaultNextNode
                );
                if (this.nodeInfos.length > 0 && defaultNode.length == 0) {
                  this.nextNode.nextNodeId = this.nodeInfos[0].nodeId;
                } else {
                  this.nextNode.nextNodeId =
                    nodeInfoMap.nodeExtAttr.defaultNextNode;
                }
              } else if (this.nodeInfos.length > 0) {
                this.nextNode.nextNodeId = this.nodeInfos[0].nodeId;
              }
              this.isForceDisplayDefaultOptionForPrefix =
                nodeInfoMap.nodeExtAttr.isForceDisplayDefaultOptionForPrefix ==
                1;
              if (nodeInfoMap.nodeExtAttr.submitText) {
                this.btnList.map((x) => {
                  if (x.event === 'sub') {
                    x.text = nodeInfoMap.nodeExtAttr.submitText;
                  }
                });
              }
            }
            this.choiceOrgId = choiceOrgId;
            this.choiceDeptId = choiceDeptId;
            this.pOrgId = pOrgId;
            if (res.data && res.data.isEndUserTask != undefined) {
              this.isEndUserTask = res.data.isEndUserTask;
            }
            if (JSON.stringify(taskExamine) != '{}' && taskExamine) {
              this.nodeInfo.nextNode = taskExamine.processDefinitionId;
              this.NodeName = taskExamine.nodeName;
              this.taskId = taskExamine.taskId;
              this.businessIds = taskExamine.businessId;
              this.appId = taskExamine.appId;
              this.taskExamineInfo = taskExamine;
              this.taskExamineInfo.choiceOrgId = choiceOrgId;
              this.taskExamineInfo.choiceDeptId = choiceDeptId;
              this.endFlowInfo.processType = taskExamine.processType;
              this.endFlowInfo.isReturnSubmitter =
                taskExamine.isReturnSubmitter;
              this.nextNode.isReturnSubmitter = taskExamine.isReturnSubmitter;
              this.nextNode.isUndertakeReply = taskExamine.isUndertakeReply;
              this.nextNode.isTakeAdviceReply = taskExamine.isTakeAdviceReply;
              this.nextNode.isUndertakeEnd = taskExamine.isUndertakeEnd;
              this.nextNode.isTakeAdviceEnd = taskExamine.isTakeAdviceEnd;
              this.nextNode.isReadDealReply = taskExamine.isReadDealReply;
              this.nextNode.isReadDealEnd = taskExamine.isReadDealEnd;
              this.nextNode.isReturnRejectNode = taskExamine.isReturnRejectNode;
              this.nextNode.isSerialSubmit = taskExamine.isSerialSubmit;
              this.endFlowInfo.isSubFlow = taskExamine.isSubFlow;
              this.endFlowInfo.isUndertakeReply = taskExamine.isUndertakeReply;
              this.endFlowInfo.isUndertakeEnd = taskExamine.isUndertakeEnd;
              this.endFlowInfo.isTakeAdviceEnd = taskExamine.isTakeAdviceEnd;
              this.endFlowInfo.isTakeAdviceReply =
                taskExamine.isTakeAdviceReply;
              this.endFlowInfo.isReadDealEnd = taskExamine.isReadDealEnd;
              this.endFlowInfo.isReadDealReply = taskExamine.isReadDealReply;
              this.endFlowInfo.isReturnRejectNode =
                taskExamine.isReturnRejectNode;
              this.endFlowInfo.isSerialSubmit = taskExamine.isSerialSubmit;
              // this.endFlowInfo.isReadDealReply =
              //   taskExamine.isReadDealReplybusinessId;
              this.endFlowInfo.appId = taskExamine.appId;
              this.endFlowInfo.businessId = taskExamine.businessId;
              this.endFlowInfo.processDefinitionId =
                taskExamine.processDefinitionId;
              this.endFlowInfo.nodeId = taskExamine.nodeId;
            }
            if (this.nodeName) {
              this.NodeName = this.nodeName;
            }
            this.isCanAddSign = isCanAddSign;
            this.processObj = res.data;
            if (this.isCanAddSign) {
              this.nextNode.isAddSign = '2';
            }
            this.isCanRemoveSign = isCanRemoveSign;
            if (this.isCanRemoveSign) {
              this.nextNode.isRemoveSign = '2';
            }

            if (!this.isOpinionRequired) {
              this.isOpinionRequired = 0;
            }
            // opinion && (this.value = opinion);
            this.nextNode.notificationMsg = defaultNotificationMessage;
            this.moreList = [];
            if (taskButtonList && taskButtonList.length != 0) {
              taskButtonList.map((item) => {
                if (item.fun === 'reject()') {
                  this.rejectObj = item;
                } else if (item.fun === 'toStartTaskRead()') {
                  this.pointsReadingObj = item;
                } else {
                  this.moreList.push(item);
                }
              });
            }
            this.isMainSubProcess = res.data.isMainSubProcess == 'true';
            this.isCustomPreset = isCustomPreset;
            this.isPreset = isPreset;
            this.presetTaskNodeMap = presetTaskNodeMap;
            this.presetTaskNodeKeyStr = presetTaskNodeKeyStr;
            this.getFind();

            this.getNodeInfo();
          } else {
            if (res.status === 'taskCompleted') {
              this.$emit('shrink', true);
              this.shrinkAbled = true;
              this.$message.warning(res.message || '系统错误，请联系管理员！');
            } else {
              this.$message.error(res.message || '系统错误，请联系管理员！');
            }
          }
        })
        .catch((err) => {
          this.loading.close();
          if (err.message && err.message !== 'canceled') {
            this.$message.error(err.message);
          }
        });
    },
    /**
     * closeProcess
     * @desc:关闭弹窗
     * @author liufan
     * @param {boolean} val 当前是否办理流程
     * @param {String} type 当前点击的弹窗类型
     * @date 2022年5月25日
     **/
    closeProcess(val, type, closeParent) {
      if (closeParent) {
        this.$refs[type].handleClosed();
      } else {
        this[type] = false;
      }
      if (this.useScene != 'multiInsMidwayWithSubmitScene') {
        this.$emit('close');
        return;
      }
      if (
        val == 'taskReadAndEnd' ||
        (val == true && type != 'taskRead') ||
        val == 'transfer'
      ) {
        this.$emit('success');
      }
    },
    /**
     * selectChange
     * @desc:常用语选择
     * @author liufan
     * @param {String} val 选中值
     * @date 2022年5月25日
     **/
    selectChange(val) {
      this.value = val;
    },
    /**
     * upDate
     * @desc:修改常用语
     * @author liufan
     * @param {Object} val 修改值
     * @date 2022年5月25日
     **/
    upDate(val) {
      this.FormData.id = val.id;
      this.addVisible = true;
    },

    /**
     * getProcess
     * @desc:获取选择流程
     * @author liufan
     * @date 2022年5月25日
     **/
    getProcess() {
      let params = {
        businessId: this.startFlowBusinessId,
        flowTypeCode: this.flowTypeCode,
        defaultProcessKey: this.defaultProcessKey,
        // isOnly: true,
        hideTempSave: true,
        onlyShowDefaultProcess:
          this.defaultProcessShowStrategy == 'onlyShowDefaultProcess'
        // onlyFlag: true
      };
      this.loading = util.loading(this.$loading, '加载中...');
      util
        .ajax({ url: getProcessDefList, params })
        .then((res) => {
          const { status, message, data } = res;
          this.loading.close();
          if (status === 'success') {
            this.isStartFlowChartView = data.isStartFlowChartView;
            if (
              !Object.keys(data).length ||
              (data.definitionList && !data.definitionList.length)
            ) {
              this.$message.error('流程不存在或未关联对应流程！');
            } else {
              this.nodeInfo.option = data.definitionList;
              this.nodeInfo.nextNode = data.definitionList.filter(
                (item) => item.processDefKey == this.defaultProcessKey
              );
              if (this.nodeInfo.nextNode.length) {
                this.nodeInfo.nextNode = this.nodeInfo.nextNode[0].processDefId;
              } else {
                if (data.definitionList.length == 1) {
                  this.nodeInfo.nextNode = data.definitionList[0].processDefId;
                } else {
                  this.nodeInfo.nextNode = '';
                }
              }
              if (this.nodeInfo.nextNode) {
                this.handleChange(this.nodeInfo.nextNode);
              }
            }
          } else {
            this.$message.error(message || '系统错误，请联系管理员！');
          }
        })
        .catch((err) => {
          this.loading.close();
          if (err.message && err.message !== 'canceled') {
            this.$message.error(err.message);
          }
        });
    },
    /**
     * getPendedhistoryList
     * @desc:获取流程列表
     * @author liufan
     * @date 2022年5月25日
     **/
    getPendedhistoryList() {
      let params = {
        apprecordId: this.businessIds,
        userId: util.getStorage('userId'),
        type: 2
      };
      util
        .ajax({ url: pendedhistoryList, data: params, method: 'post' })
        .then((res) => {
          const { rCode, msg, results } = res;
          if (!rCode) {
            this.nextNode.nextUserId = [];
            this.showNews = false;
            this.nextNode.notificationType = [];
            this.pendingId = results[results.length - 1].attachId;
            this.getHedInfo();
          } else {
            this.$message.error(msg || '系统错误，请联系管理员！');
          }
        })
        .catch((err) => {
          if (err.message && err.message !== 'canceled') {
            this.$message.error(err.message);
          }
        });
    },
    // 提交流程
    /**
     * subProcess
     * @desc:提交流程
     * @author liufan
     * @param {String} formName 当前form表单ref值
     * @date 2022年5月25日
     **/
    subProcess(val) {
      this.$refs['nextNode'].validate((valid) => {
        if (valid) {
          if (this.isSubmitButtonShowAgreeAndDisagree == 1) {
            this.value = this.value.replace(RegExp('不同意。', 'g'), '');
            this.value = this.value.replace(RegExp('同意。', 'g'), '');
            this.value = val + this.value;
          }
          if (!this.validInfo()) return;
          if (this.beforeSubmit == undefined) {
            this.subFun(this.sendData);
          } else {
            this.beforeSubmit(1)
              .then((next) => {
                this.sendData();
              })
              .catch((e) => {});
          }
        }
      });
    },
    validInfo() {
      if (
        !this.endFlow &&
        this.newTypeCode != 'fenyue' &&
        !this.shrink &&
        this.nextNode.isAddSign != '1' &&
        this.nextNode.isRemoveSign != '1' &&
        this.isSpecial &&
        !this.isReject &&
        this.nodeInfos.length != 0 &&
        this.isNextUser
      ) {
        if (this.isShowNextUser) {
          if (
            this.nextNode.nextUserId == '' ||
            (this.multiple && this.nextNode.nextUserId.length == 0)
          ) {
            this.$message.warning(
              `请选择${this.flowLabelConfig.nextUser || '下步办理人'}`
            );
            return false;
          }
        } else {
          if (
            this.nextNode.nextOrgId == '' ||
            (this.multiple && this.nextNode.nextOrgId.length == 0)
          ) {
            this.$message.warning('请选择办理对象');
            return false;
          }
        }
      }

      if (
        this.nextNode.isAddSign == '1' &&
        this.nextNode.addSignUserId.length == 0
      ) {
        this.$message.warning('请选择加签办理人');
        return false;
      }
      if (
        this.nextNode.isRemoveSign == '1' &&
        this.nextNode.removeSignUserId.length == 0
      ) {
        this.$message.warning('请选择减签办理人');
        return false;
      }
      if (!this.value && this.isOpinionRequired === 1) {
        this.$message.warning('请选择输入审批意见');
        return false;
      }
      if (this.isHideCurrentOrg && !this.nextNode.nextCurrentOrgObjJson) {
        this.$message.warning(`请选择${this.currentOrgName || '本单位'}`);
        return false;
      }
      return true;
    },
    sendData() {
      this.$refs['nextNode'].validate(async (valid) => {
        if (valid) {
          if (this.isFlow) return (this.handleVisible = true);
          let nextUserId = [];
          if (this.multiple) {
            this.nextNode.nextUserId &&
              this.nextNode.nextUserId.map((item) => nextUserId.push(item));
          }
          let addSignUserId = [];
          if (this.isCanAddSign && this.nextNode.isAddSign == '1') {
            this.nextNode.addSignUserId.map((item) => {
              addSignUserId.push(item);
            });
          }
          let removeSignUserId = [];
          if (this.isCanRemoveSign && this.nextNode.isRemoveSign == '1') {
            this.nextNode.removeSignUserId.map((item) => {
              removeSignUserId.push(item);
            });
          }
          let str = '';
          if (this.value) {
            str = this.value.replace(/\s+/g, '');
          }
          if ((!this.value || str === '') && this.nodeDefaultSubmitOpinion) {
            this.value = this.nodeDefaultSubmitOpinion;
          }
          if (!this.isSpecial) {
            delete this.nextNode.nextOperate;
            delete this.nextNode.nextNodeId;
          }
          if (this.nextNode.nextOperate === 9) {
            this.nextNode.isReturnRejectNode = 1;
            this.nextNode.processDefinitionId =
              this.processObj.taskExamine.processDefinitionId;
          }
          if (
            this.nextNode.nextOperate != 0 &&
            this.nextNode.nextOperate != 1
          ) {
            delete this.nextNode.nextNodeId;
          }
          await this.saveInfo('subMit');
          this.loading = util.loading(this.$loading, '加载中...');

          let notificationType = '';
          notificationType = this.nextNode.notificationType.join(',');
          addSignUserId = addSignUserId.join(',');
          removeSignUserId = removeSignUserId.join(',');
          if (!this.isCanPreAddSign || this.nextNode.isAddSign != '1') {
            delete this.nextNode.addSignMode;
          }
          let params = {
            ...this.nextNode,
            pendingId: this.pendingId,
            opinion:
              this.isForceDisplayDefaultOptionForPrefix &&
              !this.value.startsWith(this.nodeDefaultSubmitOpinion)
                ? this.nodeDefaultSubmitOpinion + this.value
                : this.value,
            userId: util.getStorage('userId'),
            nextUserId: this.multiple
              ? nextUserId.join(',')
              : this.nextNode.nextUserId,
            addSignUserId,
            customPresetUserJson: JSON.stringify(this.presetList),
            presetUserJson: JSON.stringify(this.presetUserJson),
            removeSignUserId,
            nextReadUserId: this.readMultiple
              ? this.mixReadList && this.mixReadList.join('|')
              : this.nextNode.nextReadUserId,
            nextOrgId: !this.isShowNextUser
              ? this.multiple
                ? this.mixOrgIdList && this.mixOrgIdList.join('|')
                : this.nextNode.nextOrgId
              : '',
            presetReadUserId:
              this.mixPresetList && this.mixPresetList.length > 0
                ? this.mixPresetList.join('|')
                : this.nextNode.presetReadUserId.join(','),
            notificationType
          };
          if (this.activeNames != '1') delete params.customPresetUserJson;
          if (this.nextNode.isRemoveSign != '1') {
            delete params.removeSignUserId;
          }
          if (this.nextNode.isAddSign != '1') {
            delete params.addSignUserId;
          }
          this.loading = util.loading(this.$loading, '提交中...');
          const {
            isEndUserTask,
            choiceOrgId,
            choiceDeptId,
            pOrgId,
            taskExamineInfo,
            needRetrialAuth
          } = this;
          params.isEndUserTask = isEndUserTask;
          params.choiceOrgId = choiceOrgId;
          params.choiceDeptId = choiceDeptId;
          params.pOrgId = pOrgId;
          params.processType = taskExamineInfo.processType;
          params.businessId = taskExamineInfo.businessId;
          params.appId = taskExamineInfo.appId;
          params.processDefinitionId = taskExamineInfo.processDefinitionId;
          params.isSubFlow = taskExamineInfo.isSubFlow;
          params.nodeId = taskExamineInfo.nodeId;
          params.needRetrialAuth = needRetrialAuth;
          return util
            .ajax({ url: taskHandleHtml, method: 'post', data: params })
            .then((res) => {
              const { status, message } = res;
              this.loading.close();
              if (status === 'success') {
                this.$message.success('提交成功');
                this.$emit('success');
              } else {
                this.$message.error(message || '系统错误，请联系管理员！');
                this.$emit('error');
              }
            })
            .catch((err) => {
              this.loading.close();
              if (err.message && err.message !== 'canceled') {
                this.$message.error(err.message);
              }
            });
        } else {
          // this.loading.close();
          return false;
        }
      });
    },
    // 单位选择完回调
    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?;
      this.nextNode[label + 'SerialId'] = res.nextUser.join(',');
      this.nextNode[label + 'Json'] = JSON.stringify(res.options);
      this.getsubProcessColumns();
    }
  }
};
</script>
