extend-action-timeline.tsx 8.3 KB
Newer Older
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
/* eslint-disable no-param-reassign */
import { defineComponent, PropType, watch, Ref, ref } from 'vue';
import { useNamespace } from '@ibiz-template/vue-util';
import dayjs from 'dayjs';
import { clone } from 'ramda';
import '@ibiz-template/theme/style/components/common/extend-action-timeline/extend-action-timeline.scss';

/**
 * 办理人员名称显示去重
 *
 * @param tag 需要去重的名称标识
 * @param dataS 需要去重数据集
 */
const acceptingOfficerNoDup = (tag: string, dataS: IData[]) => {
  const tempData: IData[] = [];
  if (dataS?.length > 0 && tag) {
    dataS.forEach((data: IData) => {
      tempData.push(data[tag]);
    });
  }
  const noDup = [...new Set(tempData)];
  return noDup;
};

export const ExtendActionTimeLine = defineComponent({
  name: 'ExtendActionTimeLine',
  props: {
    data: {
      type: Object as PropType<IData>,
    },
  },
  setup(props) {
    const ns = useNamespace('extend-action-timeline');

    const UIData: Ref<IData[]> = ref([]);

    const sortData = (a: IData, b: IData) => {
      return Date.parse(b.time) - Date.parse(a.time);
    };

41 42 43 44 45 46 47 48
    /**
     * 处理数据
     *
     * @author fangZhiHao
     * @date 2023-01-12 11:01:07
     * @param {IData[]} handleTasks
     * @return {*}
     */
49
    const handleVal = (handleTasks: IData[], isChild: boolean = false) => {
50 51 52 53 54 55 56 57
      const commentsData: IData[] = [];
      let tasks = clone(handleTasks);
      if (tasks.length > 0) {
        tasks = tasks.reverse();
        tasks.forEach((task: IData) => {
          if (task.usertasks) {
            // 有子流程没有comments  递归处理
            const copyTasks = clone(task.usertasks);
58 59
            Object.assign(task, { tasks: handleVal(copyTasks, true) });
            task.isShow = true;
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
          }
          if (task.identitylinks.length === 0 && task.comments.length === 0) {
            Object.assign(task, { taskName: task.userTaskName });
            commentsData.push(task);
          }
          if (task.identitylinks.length > 0) {
            const authorNames = acceptingOfficerNoDup(
              'displayname',
              task.identitylinks,
            );
            commentsData.push({
              authorName: authorNames.join('、'),
              taskName: task.userTaskName,
              isLink: true,
            });
          }
          if (task.comments.length > 0) {
            task.comments.forEach((comment: IData) => {
              Object.assign(comment, { taskName: task.userTaskName });
            });
            task.comments.sort(sortData);
81 82 83 84 85 86
            task.comments.forEach((comment: IData) => {
              if (isChild && comment.type === '启动流程') {
                return;
              }
              commentsData.push(comment);
            });
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
          }
        });
        return commentsData;
      }
    };

    /**
     * 去重重复名称
     *
     * @author fangZhiHao
     * @date 2023-01-13 15:01:47
     * @param {Array<string>} data
     * @return {*}
     */
    const noDup = (data: Array<string>) => {
      const map = new Map();
      for (let i = 0; i < data.length; i++) {
        if (!map.has(data[i])) {
          map.set(data[i], true);
        }
      }
      return map;
    };

    /**
     * 处理子流程中待办名
     *
     * @author fangZhiHao
     * @date 2023-01-13 11:01:09
     * @param {IData[]} handleTask
     */
    const handlelinkName = (handleTask: IData[]) => {
      handleTask.forEach((item: IData) => {
        const linkName = [];
        if (item.tasks) {
          handlelinkName(item.tasks);
        }
        if (item.tasks) {
          for (let i = 0; i < item.tasks.length; i++) {
            if (item.tasks[i].isLink) {
              const arr =
                item.tasks[i].authorName.indexOf('、') !== -1
                  ? item.tasks[i].authorName.split('、')
                  : item.tasks[i].authorName;
              if (typeof arr === 'string') {
                linkName.push(arr);
              } else {
                linkName.push(...arr);
              }
            }
            if (item.tasks[i].linkName) {
              const arr =
                item.tasks[i].linkName.indexOf('、') !== -1
                  ? item.tasks[i].linkName.split('、')
                  : item.tasks[i].linkName;
              if (typeof arr === 'string') {
                linkName.push(arr);
              } else {
                linkName.push(...arr);
              }
            }
          }
        }
        const noDupName = [...noDup(linkName).keys()];
        item.linkName = noDupName.join('、');
      });
    };

155 156 157 158 159
    watch(
      () => props.data,
      (newVal, oldVal) => {
        if (newVal !== oldVal && newVal) {
          const copyData = clone(newVal);
160 161 162 163 164 165 166
          const tasks = copyData.usertasks;
          if (tasks) {
            const handleTask = handleVal(tasks);
            if (handleTask) {
              handlelinkName(handleTask);
              UIData.value = handleTask;
            }
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
          }
        }
      },
      { immediate: true },
    );

    /**
     * 时间转换
     *
     *  @memberof ExtendActionTimeline
     */
    const formatDate = (date: string, format: string) => {
      return dayjs(date).format(format);
    };

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
    /**
     * 子流程展示隐藏
     *
     * @author fangZhiHao
     * @date 2023-01-12 11:01:34
     * @param {IData} userTask
     */
    const changeExpand = (userTask: IData) => {
      userTask.isShow = !userTask.isShow;
    };

    /**
     *  绘制组件
     *
     * @author fangZhiHao
     * @date 2023-01-12 11:01:07
     * @param {IData[]} data
     * @return {*}
     */
    const renderTimeline = (data: IData[]) => {
      return data.map((task: IData) => {
        return (
          <div
            class={[
              ns.b('task'),
              ns.is('wrong', task.type && task.type.includes('驳回')),
              ns.is('link', task.isLink),
              ns.is('linkname', task.linkName),
            ]}
          >
            <div class={ns.be('task', 'tail')}></div>
            <div
              class={[ns.be('task', 'head'), ns.is('link-head', task.linkName)]}
            ></div>
            <div class={ns.be('task', 'top')}>
217 218
              <div
                class={[
219 220
                  ns.be('task', 'user-task-name'),
                  ns.is('task-link', task.linkName),
221 222
                ]}
              >
223 224 225 226 227
                {task.taskName}
              </div>
              {task.linkName ? (
                <div class={ns.be('task', 'link-name')} title={task.linkName}>
                  {task.linkName}
228
                </div>
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
              ) : null}
              <div
                class={[
                  ns.be('task', 'author-name'),
                  ns.is('has-type', task.type),
                ]}
                title={task.authorName}
              >
                {task.authorName}
              </div>
              {task.type && (
                <div class={ns.be('task', 'type')}>{task.type}</div>
              )}
              {task.time && (
                <div class={ns.be('task', 'last-time')}>
                  {task.time && '处理时间'}
                  <span class={ns.be('task', 'last-time-text')}>
                    {task.time}
                  </span>
248
                </div>
249 250 251 252
              )}
            </div>
            <div class={ns.be('task', 'bottom')}>
              <div class={ns.be('task', 'full-message')}>
253
                {task.fullMessage && task.fullMessage !== 'null' ? (
254 255 256 257
                  `审批意见: ${task.fullMessage}`
                ) : (
                  <div>&nbsp;</div>
                )}
258
              </div>
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
            </div>
            {task.tasks && task.tasks.length >= 1 && (
              <div
                class={ns.be('task', 'trigger')}
                on-click={() => {
                  changeExpand(task);
                }}
              >
                <i-icon type={task.isShow ? 'md-remove' : 'md-add'} />
              </div>
            )}
            {task.tasks && (
              <div class={ns.be('task', 'moreTask')} v-show={task.isShow}>
                {renderTimeline(task.tasks)}
              </div>
            )}
          </div>
        );
      });
    };

    return { ns, formatDate, UIData, renderTimeline };
  },
  render() {
    return (
      <div class={this.ns.b()}>
        {this.UIData && this.renderTimeline(this.UIData)}
286 287 288 289
      </div>
    );
  },
});