extend-action-grid.tsx 9.1 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 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
/* 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-grid/extend-action-grid.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;
};

/**
 * 绘制人员
 */
const renderAuthorName = (task: IData) => {
  let authorNames: IData[] = [];
  if (task.comments.length > 0) {
    authorNames = acceptingOfficerNoDup('authorName', task.comments);
  } else {
    authorNames = acceptingOfficerNoDup('displayname', task.identitylinks);
  }
  const disabled = !(authorNames.length > 1);
  const content = authorNames.map(item => item).toString();
  return (
    <i-tooltip
      placement='bottom'
      content={content}
      theme='light'
      disabled={disabled}
    >
      {content}
    </i-tooltip>
  );
};

/**
 * 绘制单位
 */
const renderAuthorOrgName = (task: IData) => {
  let authorOrgNames: IData[] = [];
  if (task.comments.length > 0) {
    authorOrgNames = acceptingOfficerNoDup('authorOrgName', task.comments);
  }
  const disabled = !(authorOrgNames.length > 1);
  const content = authorOrgNames.map(item => item).toString();
  return (
    <i-tooltip
      placement='bottom'
      content={content}
      theme='light'
      disabled={disabled}
    >
      {content}
    </i-tooltip>
  );
};

/**
 * 绘制部门
 */
const renderAuthorDeptName = (task: IData) => {
  let authorDeptNames: IData[] = [];
  if (task.comments.length > 0) {
    authorDeptNames = acceptingOfficerNoDup('authorDeptName', task.comments);
  }
  const disabled = !(authorDeptNames.length > 1);
  const content = authorDeptNames.map(item => item).toString();
  return (
    <i-tooltip
      placement='bottom'
      content={content}
      theme='light'
      disabled={disabled}
    >
      {content}
    </i-tooltip>
  );
};

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

    const UIData: Ref<IData | null> = ref(null);

    watch(
      () => props.data,
      (newVal, oldVal) => {
        if (newVal !== oldVal && newVal) {
          const copyData = clone(newVal);
          if (copyData.usertasks.length > 0) {
            copyData.usertasks.forEach((task: IData) => {
              task.isShow = false;
            });
            copyData.usertasks = copyData.usertasks.reverse();
            UIData.value = copyData;
          }
        }
      },
      { immediate: true },
    );

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

    /**
     * 点击事件
     *
     *  @memberof ExtendActionTimeline
     */
    const changeExpand = (userTask: IData) => {
      userTask.isShow = !userTask.isShow;
    };

    return { ns, formatDate, changeExpand, UIData };
  },
  render() {
    return (
      <div class={this.ns.b()}>
        <div class={this.ns.b('header')}>
          <div class={this.ns.be('header', 'index')}>序号</div>
          <div class={this.ns.be('header', 'user-task-name')}>节点</div>
          <div class={this.ns.be('header', 'author-name')}>办理人员</div>
          <div class={this.ns.be('header', 'author-org-name')}>单位</div>
          <div class={this.ns.be('header', 'author-dept-name')}>部门</div>
          <div class={this.ns.be('header', 'type')}>操作</div>
          <div class={this.ns.be('header', 'last-time')}>完成时间</div>
          <div class={this.ns.be('header', 'full-message')}>审批意见</div>
        </div>
        <div class={this.ns.b('content')}>
          {this.UIData &&
            this.UIData.usertasks.map((task: IData, index: number) => {
              return [
                <div class={this.ns.b('task')}>
                  <div class={this.ns.be('task', 'index')}>
                    <span>{index + 1}</span>
                  </div>
                  <div class={this.ns.be('task', 'user-task-name')}>
                    <i-tooltip
                      placement='bottom'
                      content={task.userTaskName}
                      theme='light'
                    >
                      {task.userTaskName}
                    </i-tooltip>
                  </div>
                  <div class={this.ns.be('task', 'author-name')}>
                    {renderAuthorName(task)}
                  </div>
                  <div class={this.ns.be('task', 'author-org-name')}>
                    {renderAuthorOrgName(task)}
                  </div>
                  <div class={this.ns.be('task', 'author-dept-name')}>
                    {renderAuthorDeptName(task)}
                  </div>
                  <div class={this.ns.be('task', 'type')}>
                    {task.comments[task.comments.length - 1] &&
                      task.comments[task.comments.length - 1].type}
                  </div>
                  <div class={this.ns.be('task', 'last-time')}>
                    {task.comments[task.comments.length - 1] &&
                      this.formatDate(
                        task.comments[task.comments.length - 1].time,
                        'MM月DD日 HH:mm:ss',
                      )}
                  </div>
                  <div class={this.ns.be('task', 'full-message')}>
                    {task.comments[task.comments.length - 1] &&
                      task.comments[task.comments.length - 1].fullMessage}
                  </div>
                  {(task.comments.length > 1 ||
                    task.identitylinks.length > 1) && (
                    <div
                      class={this.ns.be('task', 'arrow')}
                      on-click={() => {
                        this.changeExpand(task);
                      }}
                    >
                      <i-icon type={task.isShow ? 'md-remove' : 'md-add'} />
                    </div>
                  )}
                </div>,
                task.isShow && [
                  task.comments.map((comment: IData) => {
                    return (
                      <div class={this.ns.b('comment')}>
                        <div class={this.ns.be('comment', 'index')}></div>
                        <div
                          class={this.ns.be('comment', 'user-task-name')}
                        ></div>
                        <div class={this.ns.be('comment', 'author-name')}>
                          {comment.authorName}
                        </div>
                        <div class={this.ns.be('comment', 'author-org-name')}>
                          {comment.authorOrgName}
                        </div>
                        <div class={this.ns.be('comment', 'author-dept-name')}>
                          {comment.authorDeptName}
                        </div>
                        <div class={this.ns.be('comment', 'type')}>
                          {comment.type}
                        </div>
                        <div class={this.ns.be('comment', 'last-time')}>
                          {this.formatDate(comment.time, 'MM月DD日 HH:mm:ss')}
                        </div>
                        <div class={this.ns.be('comment', 'full-message')}>
                          {comment.fullMessage}
                        </div>
                      </div>
                    );
                  }),
                  task.identitylinks.length > 0 && (
                    <div class={this.ns.b('identity-link')}>
                      <div class={this.ns.be('identity-link', 'index')}></div>
                      <div
                        class={this.ns.be('identity-link', 'user-task-name')}
                      >
                        <i-tooltip
                          placement='bottom'
                          content='待办理'
                          theme='light'
                        >
                          待办理
                        </i-tooltip>
                      </div>
                      <div class={this.ns.be('identity-link', 'author-name')}>
                        <i-tooltip
                          placement='bottom'
                          content={task.identitylinks
                            .map((item: IData) => item.displayname)
                            .toString()}
                          theme='light'
                        >
                          {task.identitylinks
                            .map((item: IData) => item.displayname)
                            .toString()}
                        </i-tooltip>
                      </div>
                    </div>
                  ),
                ],
              ];
            })}
        </div>
      </div>
    );
  },
});