workflow-track.vue 12.6 KB
Newer Older
wangcong committed
1 2 3 4
<template>
  <div>
    <div class="workflow-button" :style="{top: styleTop, right: styleRight}" @click="showDrawer = true">
      <div class="icon">
5 6
        <svg width="28px" height="28px" viewBox="0 0 28 28" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
          <use xlink:href="#icon-a-28_BILLEXPAND_C_RBC_xinshenpiguiji"></use>
wangcong committed
7 8 9 10 11 12 13 14 15 16 17 18
        </svg>
      </div>
    </div>
    <Drawer
      :transfer="false"
      title="审批轨迹"
      :closable="true"
      v-model="showDrawer"
      :width="styleDrawerWidth"
      :inner="true"
      :mask="false"
    >
19 20
      <div v-if="!data || data.length == 0">暂无数据</div>
      <div v-if="data && data.length" class="workflow-step-wrapper">
wangcong committed
21 22
        <div
          class="workflow-step"
23
          v-for="step, k in data"
wangcong committed
24 25 26 27 28 29 30 31 32 33 34 35
          :key="k"
        >
          <div class="step-head">
            <div class="step-icon">
              <svg :class="`step-icon ${isCurrentStep(step, k) ? 'waiting-icon' : 'finish-icon'}`" aria-hidden="true">
                <!-- 未到达 -->
                <use v-if="step.state == 1" xlink:href="#icon-a-24_BILLEXPAND_C_RBC_weidaoda"></use>
                <!-- 通过 -->
                <use v-else-if="step.result == 1" xlink:href="#icon-a-24_BILLEXPAND_C_RBC_shenpitongguo"></use>
                <!-- 提交 -->
                <use v-else-if="step.result == -1" xlink:href="#icon-a-24_BILLEXPAND_C_RBC_shenpitijiao"></use>
                <!-- 驳回 -->
36
                <use v-else-if="isRejectStep(step)" xlink:href="#icon-a-24_BILLEXPAND_C_RBC_shenpibohui"></use>
wangcong committed
37 38 39 40
                <!-- 末端节点 -->
                <use v-else-if="step.result == -2" xlink:href="#icon-a-24_BILLEXPAND_C_RBC_moduanjiedian"></use>
              </svg>
            </div>
41
            <div :class="`step-line ${step.state === 2 ? 'finish-line' : 'waiting-line'}`" v-if="k != data.length - 1"></div>
wangcong committed
42 43
          </div>
          <div class="step-main">
44
            <div class="step-main-body">
wangcong committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
              <div :class="`${isCurrentStep(step, k) ? 'text-black' : isRejectStep(step) ? 'text-error' : 'text-grey'}`">
                <div v-if="step.result == -2">
                  <span class="result">审批结束</span>
                </div>
                <div v-else-if="step.state == 2">
                  <span v-if="step.actualOwner" class="participants">{{step.actualOwner}}&nbsp;&nbsp;</span>
                  <span class="result">{{step.result == -1 ? '提交' : step.result == 1 ? '通过' : '驳回'}}</span>
                </div>
                <div v-else>
                  <span v-if="isCurrentStep(step, k)" class="participants">等待</span>
                  <span class="participants">{{step.participants.join('、')}}</span>
                  <span class="result">&nbsp;&nbsp;审批</span>
                </div>
              </div>
              <div v-if="isCurrentStep(step, k) || step.state == 2">{{formatStepTime(step)}}</div>
60 61 62 63
              <div class="comment" v-if="step.comments">
                <div class="label">审批意见:</div>
                <div class="text">{{step.comments}}</div>
              </div>
wangcong committed
64 65 66 67 68 69 70 71 72 73
              <div v-if="step.title" :class="isRejectStep(step) ? 'text-error' : 'text-main'">环节名称: {{step.title}}</div>
            </div>
          </div>
        </div>
      </div>
    </Drawer>
  </div>
</template>

<script>
74
import { APPROVAL_TRACK_TABLE } from '../constant'
wangcong committed
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

export default {
  data() {
    return {
      showDrawer: false,
      data: {
        "procState": 2,
        "startTime": "2021-10-12T07:28:04Z",
        "finishTime": "2021-10-13T02:15:40Z",
        "steps": [],
        "submitter": "ylq"
      },
    }
  },
  props: {
    define: {
      type: Object,
      required: true,
    },
    context: {
      type: Object,
      default: () => { }
    }
  },
  methods:{
    isCurrentStep(step, k) {
      if (k != 0) return false
      return step.result != -2
    },
    isRejectStep(step) {
      return step.result === 3
    },
    formatDate(datetime) {
      const t = new Date(datetime)
      return t.format('yyyy-MM-dd HH:mm:ss')
    },
    /**
     * 根据节点状态返回完成时间或时间差
     * @param {object} step
     * @param {string} step.createTime - 创建时间
     * @param {string | null} step.completeTime - 结束时间
     * @param {number} step.result - 状态
     * @returns {string}
     */
    formatStepTime(step) {
      const currentTimestamp = Date.now()
      if (step.state === 1) {
122
        let ans = ''
wangcong committed
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
        const createTimestamp = (new Date(step.createTime)).getTime()
        let seconds = (currentTimestamp - createTimestamp) / 1000
        const formatList = [
          {
            rate: 60 * 60 * 24,
            label: '天',
          },
          {
            rate: 60 * 60,
            label: '小时',
          },
          {
            rate: 60,
            label: '分钟',
          },
        ]
        // for (const o of formatList) {
        //   const num = Math.floor(seconds / o.rate)
        //   if (num > 0 || o.alwaysShow) {
        //     ans += `${num}${o.label}`
        //     seconds -= num * o.rate
        //   }
        // }
        for (let i = 0; i < formatList.length; ++i) {
          const o = formatList[i]
          const num = Math.floor(seconds / o.rate)
          if (num > 0 || (!ans && i == formatList.length - 1)) {
            ans += `${num}${o.label}`
            seconds -= num * o.rate
          }
        }
154
        ans = '已等待' + ans
wangcong committed
155 156 157 158 159 160 161 162
        return ans
      }
      else {
        return this.formatDate(step.completeTime)
      }
    },
  },
  mounted() {
163 164 165 166 167 168
    const { tableName, subTableSource } = this.define.config
    if (subTableSource) {
      const subTable = this.context.bill.getSubData(tableName)
      if (subTable instanceof Array) {
        this.data = subTable.map((obj) => {
          const operation = obj.getValue(APPROVAL_TRACK_TABLE.OPERATION)
169
          const currNode = obj.getValue(APPROVAL_TRACK_TABLE.CURRENT_NODE)
170 171 172 173
            
          return {
            state: 2,
            result:
174 175 176 177 178 179 180 181 182
              currNode == 99
              ? -2
              : operation == '提交'
              ? -1
              : operation == '同意'
              ? 1
              : operation == '驳回'
              ? 3
              : -2,
183 184 185 186 187 188 189
            actualOwner: obj.getValue(APPROVAL_TRACK_TABLE.CREATOR_FULL_NAME),
            createTime: obj.getValue(APPROVAL_TRACK_TABLE.CREATE_TIME),
            completeTime: obj.getValue(APPROVAL_TRACK_TABLE.CREATE_TIME),
            comments: obj.getValue(APPROVAL_TRACK_TABLE.APPROVAL_COMMENT),
            title: obj.getValue(APPROVAL_TRACK_TABLE.NODE_NAME),
          }
        })
190
        this.data = this.data.reverse()
191 192 193
      }
      return
    }
wangcong committed
194 195 196 197 198 199 200 201 202
    window.GAMS.Util.invokeServer({
      path: 'gms/workflow/task/approved',
      type: 'GET',
      contentType: 'application/json',
      params: {
        bizName: this.context.bill.getBillDefine(),
        bizObjId: this.context.bill.getMasterData().getValue('id'),
      },
    }).then((res) => {
203 204
      const formatTrack = (curTrack) => {
        if (!curTrack) return []
205 206 207 208 209
        curTrack.steps = curTrack.steps.reverse()
        curTrack.steps = curTrack.steps.map((step) => {
          if (step.subTasks && step.subTasks.length) {
            let participants = []
            let actualOwnerList = []
210
            let commentList = []
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
            let resultFlag = 0
            let rejectFlag = false
            for (let task of step.subTasks) {
              if (task.state == 2 && task.result == 3 || task.state == 3) {
                rejectFlag = true
                break
              }
            }

            for (let task of step.subTasks) {
              if (task.participants) {
                participants = participants.concat(task.participants)
              }
              if (task.actualOwner) {
                if (!rejectFlag || task.state == 2 && task.result == 3) {
                  actualOwnerList.push(task.actualOwner)
                }
              }
229 230 231
              if (task.comments) {
                commentList.push(task.comments)
              }
232 233 234 235 236 237 238 239 240 241 242 243
              const curResult = task.result || 0
              resultFlag |= 1 << curResult
            }

            step.result =
              resultFlag & 8
              ? 3
              : resultFlag & 1
              ? 0
              : 1

            rejectFlag && (step.state = 2)
244
            step.comments = commentList.join(';\n')
245 246 247 248 249
            step.participants = participants
            step.actualOwner = actualOwnerList.join('、')
          }
          return step
        })
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
        curTrack.steps.push({
          title: "提交申请",
          state: 2,
          createTime: curTrack.startTime,
          completeTime: curTrack.startTime,
          comments: null,
          result: -1,
          actualOwner: curTrack.submitter,
        })
        // 审批流程结束贴一个结束节点
        if (curTrack.procState === 2) {
          curTrack.steps.unshift({
            state: curTrack.procState,
            createTime: curTrack.finishTime,
            completeTime: curTrack.finishTime,
            result: -2,
          })
        }
        // 否则从当前节点切断,
        else {
          for (let i = 0; i < curTrack.steps.length - 1; ++i) {
            if (curTrack.steps[i].state === 1 && curTrack.steps[i + 1].state === 2) {
              curTrack.steps = curTrack.steps.slice(i)
              break
            }
          }
        }
        return curTrack.steps || []
      }

280 281 282 283 284 285 286 287 288 289
      res = res || []
      let count = 0
      for (let o of res) {
        if (o.procState == 1) {
          ;++count
        }
      }
      if (count > 1) {
        this.$Message.error('工作流数据异常')
      }
290 291 292 293
      this.data = []
      for (let i = res.length - 1; i >= 0; --i) {
        const o = res[i]
        this.data = this.data.concat(formatTrack(o))
wangcong committed
294
      }
295 296 297 298 299
      // 去掉中间的审批结束节点
      for (let i = 1; i < this.data.length; ++i) {
        if (this.data[i].result == -2) {
          this.data.splice(i, 1)
          ;--i
wangcong committed
300 301 302 303 304 305
        }
      }
    })
  },
  computed: {
    styleTop() {
306
      return this.define.layout.top || this.define.config.topDistance || '0px'
wangcong committed
307 308
    },
    styleRight() {
309
      return this.define.layout.right || this.define.config.rightDistance || '0px'
wangcong committed
310 311
    },
    styleDrawerWidth() {
312
      return this.define.layout.drawerWidth || this.define.config.drawerWidth || '400px'
wangcong committed
313 314 315 316 317 318 319 320 321 322 323 324 325
    },
  },
  beforeDestroy() {
  },
}
</script>

<style lang="less" scoped>
@icon-width: 24px;
@main-color: #0DA2E6;
.workflow-button {
  cursor: pointer;
  position: absolute;
326
  z-index: 700;
327 328 329 330 331 332
  padding-top: 4px;
  width: 42px;
  height: 36px;
  background: #005791;
  box-shadow: 0 0 4px 0 rgba(109,109,109,0.50);
  border-radius: 100px 0 0 100px;
wangcong committed
333
  .icon {
334 335 336
    width: 28px;
    height: 28px;
    margin-left: 11px;
wangcong committed
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
  }
  .text {
    margin-top: 2px;
    text-align: center;
    height: 17px;
    font-size: 12px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #FFFFFF;
    line-height: 17px;
    text-shadow: 0px 1px 6px rgba(255, 169, 56, 0.8);
  }
}
.workflow-step-wrapper {
  width: 100%;
  .workflow-step {
    width: 100%;
    position: relative;
    .step-head {
      width: @icon-width;
      position: absolute;
      height: 100%;
      .step-icon {
        width: 100%;
        fill: currentColor;
        height: @icon-width;
      }
      .waiting-icon {
        color: @main-color;
      }
      .finish-icon {
        color: #888;
      }
      .step-line {
        margin-left: @icon-width / 2;
        width: 1px;
        height: calc(100% - @icon-width);
      }
      .finish-line {
        background-color: #C8C8C8;
      }
      .waiting-line {
        background-color: @main-color;
      }
    }
    .step-main {
      width: 100%;
      min-height: calc(@icon-width + 10px);
      padding-left: @icon-width;
      font-size: 12px;
      color: #888888;
      line-height: 17px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
391
      .step-main-body {
wangcong committed
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
        padding-bottom: 30px;
        padding-left: 5px;
        > div {
          margin-bottom: 5px;
        }
        .text-gray {
          color: #888888;
        }
        .text-black {
          color: #222222;
        }
        .text-main {
          color: @main-color;
        }
        .text-error {
          color: #ED664B;
        }
        .participants {
          height: 20px;
          font-size: 14px;
          line-height: 20px;
        }
        .result {
          height: 20px;
          font-size: 14px;
          line-height: 20px;
        }
419 420 421 422 423 424
        .comment {
          display: flex;
          .text {
            white-space: pre-line;
          }
        }
wangcong committed
425 426 427 428 429
      }
    }
  }
}
</style>