FlowChart.vue 13.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
<template>
  <div>
    <van-popup
      v-model="showFlowChart"
      round
      :close-on-click-overlay="false"
      safe-area-inset-bottom
      position="bottom"
      style="max-height: 80%"
    >
      <van-nav-bar
        :title="title"
        left-text="关闭"
        @click-left="showFlowChart = false"
      />
      <div class="btn-group">
        <div v-for="item in btnList" :key="item.id" class="btn-item">
          <span class="icon" :style="{ background: item.bgColor }"></span>
          <span class="label">{{ item.label }}</span>
        </div>
      </div>
      <div class="flow-chart">
        <div
          :style="{
            position: 'relative',
            width: imgWidth + 'px',
            height: imgHeight + 'px',
            background: 'url(' + backGroundImg + ') no-repeat',
          }"
        >
          <template v-for="layout in listLayout">
            <el-popover
              v-if="instId"
              :key="layout.nodeId"
              trigger="hover"
              placement="bottom-start"
            >
              <div v-if="nodeOpinions[layout.nodeId]" class="options">
                <div class="title">任务审批详情</div>
                <!-- 已审批/待审批节点 -->
                <template v-if="hasOpinion(layout)">
                  <table v-for="op in getData(layout)" :key="op.id">
                    <tr>
                      <td class="label">任务名称</td>
                      <td class="value">{{ op.taskName }}</td>
                    </tr>
                    <tr v-show="op.auditor">
                      <td class="label">执行人</td>
                      <td class="value">{{ op.auditorName }}</td>
                    </tr>
                    <tr v-show="!op.auditor">
                      <td class="label">
                        <span>候选人</span>
                        <el-tooltip
                          effect="light"
                          content="有资格审批的用户及用户组"
                          placement="right"
                        >
                          <i class="el-icon-question"></i>
                        </el-tooltip>
                      </td>
                      <td class="value">
                        <span v-for="user in op.qualfieds" :key="user.id">
                          <el-button v-if="!user.users" :disabled="true">
                            <span class="textOverflow" :title="user.name">
                              {{ user.name }}
                            </span>
                          </el-button>
                          <el-tooltip
                            v-if="user.users"
                            effect="light"
                            :content="user.users"
                            placement="top"
                          >
                            <el-button>
                              <span class="textOverflow" :title="user.name">
                                {{ user.name }}
                              </span>
                            </el-button>
                          </el-tooltip>
                        </span>
                      </td>
                    </tr>
                    <tr>
                      <td class="label">开始时间</td>
                      <td class="value">{{ op.createTime }}</td>
                    </tr>
                    <tr>
                      <td class="label">结束时间</td>
                      <td class="value">{{ op.completeTime }}</td>
                    </tr>
                    <tr>
                      <td class="label">审批用时</td>
                      <td class="value">{{ op.durMs | calcDuration }}</td>
                    </tr>
                    <tr>
                      <td class="label">状态</td>
                      <td class="value">{{ op.statusVal }}</td>
                    </tr>
                    <tr>
                      <td class="label">意见</td>
                      <td class="opinion">{{ op.opinion }}</td>
                    </tr>
                  </table>
                </template>

                <!-- 未审批节点 -->
                <template v-else>
                  <div class="sub-title">节点设置详情</div>
                  <table>
                    <tr>
                      <td class="label">状态</td>
                      <td class="value">未产生过任务</td>
                    </tr>
                    <tr>
                      <td class="label">
                        <span>暂定候选人</span>
                        <el-tooltip
                          effect="light"
                          content="暂定的有审批资格的用户及用户组,实际候选人要在产生任务以后才能确定"
                          placement="right"
                        >
                          <i class="el-icon-question"></i>
                        </el-tooltip>
                      </td>
                      <td class="value">
                        <span v-for="user in getData(layout)" :key="user.id">
                          <el-button
                            v-if="!user.users"
                            :disabled="true"
                            style="margin-right: 5px"
                          >
                            <span class="textOverflow" :title="user.name">
                              {{ user.name }}
                            </span>
                          </el-button>
                          <el-tooltip
                            v-else
                            effect="light"
                            :content="user.users"
                            placement="top"
                          >
                            <el-button>
                              <span class="textOverflow" :title="user.name">
                                {{ user.name }}
                              </span>
                            </el-button>
                          </el-tooltip>
                        </span>
                      </td>
                    </tr>
                  </table>
                </template>
              </div>

              <el-button
                v-if="showLayout(layout)"
                slot="reference"
                :style="getStyle(layout)"
              ></el-button>
            </el-popover>
          </template>
        </div>
      </div>
    </van-popup>
  </div>
</template>

<script>
  import flow from '@/api/flow'

  const btnList = [
    { id: 1, label: '待审批', bgColor: '#FF0000' },
    { id: 2, label: '提交', bgColor: '#F89800' },
    { id: 3, label: '重新提交', bgColor: '#FFE76E' },
    { id: 4, label: '同意', bgColor: '#00FF00' },
    { id: 5, label: '挂起', bgColor: '#C33A1F' },
    { id: 6, label: '反对', bgColor: '#0000FF' },
    { id: 7, label: '驳回', bgColor: '#8A0902' },
    { id: 8, label: '驳回到发起人', bgColor: '#FFA500' },
    { id: 9, label: '撤回', bgColor: '#023B62' },
    { id: 10, label: '撤回到发起人', bgColor: '#F23B62' },
    { id: 11, label: '会签通过', bgColor: '#338848' },
    { id: 12, label: '会签不通过', bgColor: '#82B7D7' },
    { id: 13, label: '人工终止', bgColor: '#EEAF97' },
    { id: 14, label: '完成', bgColor: '#4A4A4A' },
  ]
  export default {
    filters: {
      calcDuration(ts) {
        let duration = '',
          st = 1000,
          mt = 60 * st,
          ht = 60 * mt,
          dt = 24 * ht,
          days = Math.floor(ts / dt),
          hours = Math.floor((ts % dt) / ht),
          mins = Math.floor((ts % ht) / mt),
          secs = Math.floor((ts % mt) / st)
        if (days > 0) duration += days + '天'
        if (hours > 0) duration += hours + '小时'
        if (mins > 0) duration += mins + '分钟'
        if (secs > 0) duration += secs + '秒'
        return duration
      },
    },
    props: {
      defId: {
        type: String,
        default: '',
      },
      instId: {
        type: String,
        default: '',
      },
      bpmnInstId: {
        type: String,
        default: '',
      },
      customClass: {
        type: String,
        default: '',
      },
    },
    data() {
      return {
        showFlowChart: false,
        title: '',
        btnList: btnList,
        imgWidth: '',
        imgHeight: '',
        backGroundImg: '',
        listLayout: '',
        nodeOpinions: [],
      }
    },
    methods: {
      showLayout(layout) {
        const taskNames = ['USERTASK', 'SIGNTASK', 'CUSTOMSIGNTASK']
        return taskNames.includes(layout.nodeType)
      },
      hasOpinion(layout) {
        return this.nodeOpinions[layout.nodeId].hasOpinion
      },
      getData(layout) {
        return this.nodeOpinions[layout.nodeId].data
      },
      getStyle(layout) {
        return {
          position: 'absolute',
          top: layout.y + 'px',
          left: layout.x + 'px',
          width: layout.width + 'px',
          height: layout.height + 'px',
          border: 'none',
          background: 'none',
        }
      },
      handleOpen() {
        this.showFlowChart = true

        const data = {
          defId: this.defId,
          instId: this.instId,
          bpmnInstId: this.bpmnInstId,
        }
        flow.instanceFlowImage(data).then((instFlowInfo) => {
          const { defId, instanceId, bpmDefLayout } = instFlowInfo
          let myDefId = ''
          if (['', 'null', 'undefined'].includes(instanceId)) {
            myDefId = defId
          }
          this.title = bpmDefLayout.name
          flow.getBpmImage('', instanceId, myDefId).then((res) => {
            this.imgWidth = bpmDefLayout.width
            this.imgHeight = bpmDefLayout.height

            this.backGroundImg = res

            bpmDefLayout.listLayout.forEach((item) => {
              const style = {
                position: 'absolute',
                left: item.x + 'px',
                top: item.y + 'px',
                width: item.width + 'px',
                height: item.height + 'px',
              }
              item.style = style
            })
            this.listLayout = bpmDefLayout.listLayout

            const tempIds = []
            this.listLayout.forEach((layout) => {
              const { nodeId, nodeType } = layout
              if (['USERTASK', 'SIGNTASK'].includes(nodeType)) {
                tempIds.push(nodeId)
              }
            })

            let nodeIds = tempIds.join(',')
            const data = { instId: this.instId, nodeIds }
            if (this.instId) {
              flow.getNodeOpinions(data).then((options) => {
                if (options) {
                  for (const key in options) {
                    const { data, hasOpinion } = options[key]
                    if (data && hasOpinion) {
                      data.forEach((ele) => {
                        if (ele.qualfieds) {
                          ele.qualfieds = eval('(' + ele.qualfieds + ')')
                        }
                      })
                    }
                  }
                }
                if (nodeIds && tempIds.length == 1) {
                  this.nodeOpinions = {
                    [nodeIds]: options,
                  }
                } else {
                  this.nodeOpinions = options
                }
              })
            }
          })
        })
      },
    },
  }
</script>

<style lang="scss" scoped>
  .btn-group {
    display: flex;
    flex-wrap: wrap;
    font-size: 12px;
    margin: 16px 20px 24px;
    .btn-item {
      display: flex;
      align-items: center;
      // margin: 0 15px 5px 0;
      margin-bottom: 5px;
      width: 25%;
      .icon {
        display: inline-block;
        width: 14px;
        height: 14px;
        margin-right: 4px;

        border-radius: 4px 4px 4px 4px;
      }
      .lable {
        color: #333333;
      }
    }
  }
  .flow-chart {
    font-size: 12px;
    overflow: auto;
    min-height: 500px;
    margin: 0 20px;
    max-height: 550px;
  }
  .title {
    font-size: 14px;
    font-weight: bold;
    margin-bottom: 10px;
  }
  .sub-title {
    font-size: 12px;
  }
  .options {
    max-height: 420px;
    overflow-y: auto;

    ::v-deep table {
      margin-bottom: 10px;
      font-size: 12px;
      border-spacing: 0;
      border-bottom: 1px solid #e7eaec;
      border-left: 1px solid #e7eaec;
      td {
        padding: 8px;
        line-height: 1.42857;
        border-top: 1px solid #e7eaec;
        border-right: 1px solid #e7eaec;
        vertical-align: middle;
      }
      .label {
        width: 80px;
        font-weight: bold;
      }
      .value {
        width: 160px;
        .textOverflow {
          width: 70px;
          display: inline-block;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
      }
      .opinion {
        max-width: 250px;
        min-width: 250px;
        word-wrap: break-word;
      }
    }
  }
  ::v-deep .start-btn__flow-chart {
    width: 60% !important;
    .flow-chart {
      min-height: unset;
    }
  }
  .van-popup {
    ::v-deep {
      .van-nav-bar__left {
        .van-nav-bar__text {
          color: #8c8c8c;
        }
      }
      .van-nav-bar__title {
        font-weight: bold;
      }
      .van-nav-bar__right {
        .van-nav-bar__text {
          color: #409eff;
        }
      }
    }
  }
</style>