FlowMsgSendConfig.vue 18.4 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 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616
<template>
  <div>
    <el-dialog
      width="70%"
      top="8vh"
      title="设置消息模板"
      :visible.sync="dialogVisible"
      :close-on-click-modal="false"
      append-to-body
    >
      <el-form :model="configData" data-vv-scope="msgTemplateForm">
        <el-row v-show="type != 1">
          <el-col>
            <ht-form-item label="发送时机" label-width="120px">
              <ht-radio
                :options="[
                  {key: 'taskCreate', value: '任务创建'},
                  {key: 'taskComplete', value: '任务完成'},
                ]"
                v-model="configData.moment"
              />
            </ht-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <ht-form-item label="消息接收人" label-width="120px">
              <el-button
                size="mini"
                type="primary"
                @click="
                  msgRecieverVisible = true
                  tempReceivers = JSON.parse(
                    JSON.stringify(configData.receivers)
                  )
                "
                >设置</el-button
              >
            </ht-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <ht-form-item label="模板参数" label-width="120px">
              流程变量:
              <el-link
                type="primary"
                v-for="param in templateParams"
                :key="param.key"
                @click="addTemplateParam(param.value)"
                >{{ param.label }}</el-link
              >
              表单变量:<FlowVarSelector
                :defId="defId"
                type="1"
                :includeBpmConstants="false"
                @node-click="addTemplateFormParam"
                size="mini"
              />
              <br />选择模板参数的时候,请注意光标位置(光标位置支持[标题,纯文本])。
            </ht-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <ht-form-item label="标题" label-width="120px">
              <ht-input
                ref="subject"
                v-model="configData.subject"
                type="textarea"
                :cols="100"
                :validate="{required: true}"
                :autosize="{minRows: 1, maxRows: 4}"
                @focus="activeTextarea = 'subject'"
                :maxlength="50"
                :showWordLimit="true"
              />
            </ht-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <ht-form-item label="纯文本" label-width="120px">
              <ht-input
                ref="plain"
                v-model="configData.plain"
                type="textarea"
                :cols="100"
                :autosize="{minRows: 2, maxRows: 8}"
                @focus="activeTextarea = 'plain'"
                :maxlength="200"
                :showWordLimit="true"
              />
              <el-button @click="$refs.eipMsgTemplateDialog.showDialog()"
                >选择模板</el-button
              >
            </ht-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <ht-form-item label="模版体HTML" label-width="120px">
              <htEditor
                v-model="configData.html"
                :config="myConfig"
                :focus="htEditorFocus"
                ref="htEditor"
              ></htEditor>
            </ht-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="confirm">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog
      width="70%"
      top="8vh"
      title="设置消息接收人"
      v-if="msgRecieverVisible"
      :visible.sync="msgRecieverVisible"
      :close-on-click-modal="false"
      append-to-body
    >
      <el-form v-form data-vv-scope="receiverSetForm">
        <el-row class="externalUser-row">
          <el-col>
            <ht-form-item label="当前节点审批人" label-width="200px">
              <el-checkbox v-model="tempReceivers.curAuditor"></el-checkbox>
            </ht-form-item>
            <ht-form-item label="当前节点传阅人" label-width="200px">
              <el-checkbox v-model="tempReceivers.curCopyTo"></el-checkbox>
            </ht-form-item>
            <ht-form-item label="历史节点处理人" label-width="200px">
              <el-select
                size="mini"
                v-model="tempReceivers.hisNode"
                placeholder="请选择"
                clearable
                style="width: 250px"
              >
                <el-option
                  v-for="item in nodeList"
                  :key="item.nodeId"
                  :label="`${item.name}(${item.nodeId})`"
                  :value="item.nodeId"
                >
                </el-option>
              </el-select>
            </ht-form-item>
            <ht-form-item label="发起人" label-width="200px">
              <el-checkbox v-model="tempReceivers.startor"></el-checkbox>
            </ht-form-item>
            <ht-form-item label="变量(用户账号)" label-width="200px">
              <el-input
                style="width: 200px"
                size="mini"
                v-model="tempReceivers.var.name"
                :disabled="true"
              ></el-input>
              <FlowVarSelector
                :defId="defId"
                @node-click="varTreeOnConfirm"
                :removeSub="false"
                size="mini"
              />
              <el-button
                @click="tempReceivers.var = {}"
                icon="el-icon-refresh-right"
                size="mini"
              ></el-button>
            </ht-form-item>
            <ht-form-item label="系统用户" label-width="200px">
              <ht-user-selector-input
                :appendToBody="true"
                v-model="tempReceivers.sysUser.name"
                :config="{
                  id: 'tempReceivers.sysUser.userId',
                  account: 'tempReceivers.sysUser.account',
                }"
              />
            </ht-form-item>
            <ht-form-item label="外部用户" label-width="200px">
              <el-button
                size="mini"
                type="primary"
                @click="tempReceivers.externalUser.push({})"
                >添加</el-button
              >
              <el-table
                size="mini"
                border
                :data="tempReceivers.externalUser"
                style="width: 100%"
              >
                <el-table-column prop="name" label="姓名">
                  <template slot-scope="scope">
                    <ht-input
                      size="mini"
                      v-model="scope.row.name"
                      autocomplete="off"
                    ></ht-input>
                  </template>
                </el-table-column>
                <el-table-column prop="phone" label="手机">
                  <template slot-scope="scope">
                    <div class="flexHen">
                      <ht-input
                        size="mini"
                        v-model="scope.row.mobile"
                        autocomplete="off"
                        :validate="{
                          mobile: !/^\${[\w\.]+}/.test(scope.row.mobile),
                        }"
                      ></ht-input>
                      <FlowVarSelector
                        :defId="defId"
                        @node-click="
                          varTreeOnConfirm(arguments[0], scope.row, 'mobile')
                        "
                        :removeSub="false"
                        size="mini"
                        style="margin-left: 5px"
                      />
                    </div>
                  </template>
                </el-table-column>
                <el-table-column prop="email" label="邮箱">
                  <template slot-scope="scope">
                    <div class="flexHen">
                      <ht-input
                        size="mini"
                        v-model="scope.row.email"
                        autocomplete="off"
                        :validate="{
                          email: !/^\${[\w\.]+}/.test(scope.row.email),
                        }"
                      ></ht-input>
                      <FlowVarSelector
                        :defId="defId"
                        @node-click="
                          varTreeOnConfirm(arguments[0], scope.row, 'email')
                        "
                        :removeSub="false"
                        size="mini"
                        style="margin-left: 5px"
                      />
                    </div>
                  </template>
                </el-table-column>

                <el-table-column label="操作" width="80">
                  <template slot-scope="scope">
                    <el-button
                      @click="tempReceivers.externalUser.remove(scope.row)"
                      type="text"
                      size="small"
                      >删除</el-button
                    >
                  </template>
                </el-table-column>
              </el-table>
            </ht-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="msgRecieverVisible = false">取 消</el-button>
        <el-button type="primary" @click="confirmReceiverSet">确 定</el-button>
      </div>
    </el-dialog>

    <eip-msg-template-dialog
      ref="eipMsgTemplateDialog"
      @onConfirm="templateConfirm"
      append-to-body
    />
  </div>
</template>

<script>
import utils from '@/hotent-ui-util.js'
import {mapState, mapAction} from 'vuex'
const htEditor = () => import('@/components/common/HtEditor.vue')
const EipMsgTemplateDialog = () =>
  import('@/components/dialog/EipMsgTemplateDialog.vue')
const FlowVarSelector = () => import('@/components/flow/FlowVarSelector.vue')

import {Base64} from 'js-base64'
import Debounce from '../vueUeditorWrap/utils/Debounce'

export default {
  props: {
    type: String,
    value: String,
    defId: String,
    nodeId: String,
  },
  components: {
    htEditor,
    EipMsgTemplateDialog,
    FlowVarSelector,
  },
  data() {
    return {
      defaultData: {
        moment: 'taskComplete',
        subject: '',
        plain: '',
        html: '',
        receivers: {externalUser: []},
      },
      configData: {
        moment: 'taskComplete',
        subject: '',
        plain: '',
        html: '',
        receivers: {externalUser: []},
      },
      myConfig: {
        initialFrameHeight: 170,
        UEDITOR_HOME_URL:
          window.location.origin +
          '/' +
          window.location.pathname.split('/')[1] +
          '/static/ueditor/',
        toolbars: [
          [
            // 'source', //源代码
            'undo', //撤销
            'bold', //加粗
            'indent', //首行缩进
            'italic', //斜体
            'underline', //下划线
            'strikethrough', //删除线
            'subscript', //下标
            'fontborder', //字符边框
            'superscript', //上标
            'formatmatch', //格式刷
            'forecolor', //字体颜色
            'justifyleft', //居左对齐
            'justifycenter', //居中对齐
            'justifyright', //居右对齐
            'justifyjustify', //两端对齐
            'fontfamily', //字体
            'fontsize', //字号
            'insertorderedlist', //有序列表
            'insertunorderedlist', //无序列表
            'lineheight', //行间距
            'inserttable', //插入表格
            'link', //超链接
            'simpleupload', //单图上传
            'insertimage', //多图上传
            'attachment', //附件
          ],
        ],
        // 初始容器宽度
        initialFrameWidth: '100%',
        zIndex: 9999,
        enableAutoSave: false,
        readonly: false,
      },
      templateType: [],
      dialogVisible: false,
      templateParams: [
        {
          key: 1,
          value: '${instSubject}',
          label: '流程实例标题',
        },
        {
          key: 2,
          value: '${nodeName}',
          label: '节点名称',
        },
        {
          key: 3,
          value: '${taskSubject}',
          label: '任务标题',
        },
        {
          key: 4,
          value: '${cause}',
          label: '原因',
        },
        {
          key: 5,
          value: '${delegate}',
          label: '委托人',
        },
        {
          key: 6,
          value: '${agent}',
          label: '代理人',
        },
        {
          key: 7,
          value: '${receiver}',
          label: '收信人',
        },
        {
          key: 8,
          value: '${sender}',
          label: '发送人',
        },
      ],
      activeTextarea: '',
      msgRecieverVisible: false,
      tempReceivers: {},
      nodeList: [],
    }
  },
  computed: mapState({
    defConfigData: (state) => state.flow.defConfigData,
    header: (state) => {
      return {
        Authorization: `Bearer ${state.login.currentUser.token}`,
      }
    },
    actionUrl: function () {
      return window.context.portal + '/system/file/v1/upload'
    },
  }),
  watch: {},
  mounted() {},
  methods: {
    htEditorFocus() {
      this.activeTextarea = 'htEditor'
    },
    confirmReceiverSet() {
      this.$validator.validateAll('receiverSetForm').then((r) => {
        if (!r) {
          this.$message.warning('表单校验不通过,请检查表单')
          return
        }
        if (
          !this.tempReceivers.curAuditor &&
          !this.tempReceivers.curCopyTo &&
          !this.tempReceivers.hisNode &&
          !this.tempReceivers.startor &&
          (!this.tempReceivers.externalUser ||
            this.tempReceivers.externalUser.length == 0) &&
          (!this.tempReceivers.var || !this.tempReceivers.var.name) &&
          (!this.tempReceivers.sysUser || !this.tempReceivers.sysUser.userId)
        ) {
          this.$message.warning('请选择消息接收人')
          return
        }
        if (this.tempReceivers.externalUser) {
          let emptyUserIdx = []
          for (
            let index = 0;
            index < this.tempReceivers.externalUser.length;
            index++
          ) {
            const u = this.tempReceivers.externalUser[index]
            if (!u.mobile && !u.email) {
              emptyUserIdx.push(index + 1)
            }
          }
          if (emptyUserIdx.length > 0) {
            this.$message.warning(
              '外部用户第[' +
                emptyUserIdx.join(',') +
                ']行,手机号和邮箱至少填写一个'
            )
            return
          }
        }
        this.configData.receivers = JSON.parse(
          JSON.stringify(this.tempReceivers)
        )
        this.msgRecieverVisible = false
      })
    },
    varTreeOnConfirm(node, subRow, field) {
      let keyStr = node.name
      let source = 'BO'
      if (node.nodeType == 'var') {
        keyStr = node.name
        source = 'flowVar'
      } else {
        keyStr = node.path + '.' + node.name
      }
      let json = {
        source: source,
        name: keyStr,
        executorType: 'user',
        userValType: 'account',
      }
      if (subRow && field) {
        this.$set(subRow, field, '${' + keyStr + '}')
      } else {
        this.tempReceivers['var'] = json
      }
    },
    templateConfirm(data) {
      this.$set(this.configData, 'plain', data)
    },
    addTemplateFormParam(data) {
      this.$refs.htEditor.editorInstance.execCommand(
        'inserthtml',
        data.pathValue
      )
    },
    addTemplateParam(param) {
      if (!this.activeTextarea || this.activeTextarea == 'htEditor') {
        this.$refs.htEditor.editorInstance.execCommand('inserthtml', param)
      } else {
        let textInput =
          this.$refs[this.activeTextarea].$refs.inputEle.$refs.textarea
        let insert = textInput.selectionStart
        this.configData[this.activeTextarea] =
          textInput.value.substr(0, insert) +
          param +
          textInput.value.substr(insert)
      }
    },
    confirm() {
      utils
        .validateForm(this, 'msgTemplateForm')
        .then((r) => {
          if (!this.configData.html && !this.configData.plain) {
            this.$message.error(`纯文本和模板体HTML至少需要填写一个`)
            return
          }
          this.$emit('input', Base64.encode(JSON.stringify(this.configData)))
          this.dialogVisible = false
        })
        .catch((items) => {
          this.$message.error(`请填写标题`)
        })
        .finally(() => {
          this.loading = false
        })
    },
    showDailog() {
      if (!this.value) {
        this.configData = JSON.parse(JSON.stringify(this.defaultData))
      } else {
        this.configData = JSON.parse(Base64.decode(this.value))
      }
      if (this.type == '1') {
        this.configData.moment = 'taskComplete'
      }

      this.nodeList = []
      for (const node of this.defConfigData.nodeSetData.nodes) {
        if (node.nodeId == this.nodeId) {
          this.curNode = node
        } else {
          if (node.type == 'signTask' || node.type == 'userTask') {
            this.nodeList.push(node)
          }
        }
      }
      this.configData.receivers = this.configData.receivers || {}
      this.configData.receivers.externalUser =
        this.configData.receivers.externalUser || []
      this.configData.receivers.var = this.configData.receivers.var || {}
      this.configData.receivers.sysUser =
        this.configData.receivers.sysUser || {}

      this.dialogVisible = true
    },
  },
  created() {
    this.$validator = this.$root.$validator
  },
}
</script>

<style lang="scss" scoped>
.el-link {
  margin: 0 5px;
}

div /deep/ .el-radio-group {
  line-height: 16px;
}
div /deep/.el-form-item--small.el-form-item {
  margin-bottom: 16px;
}
.externalUser-row {
  min-height: 500px;
  max-height: 550px;
  overflow: auto;
}

.externalUser-row /deep/ .el-form-item__error {
  z-index: 1000;
  margin: -1px 0 0 5px;
}

.externalUser-row /deep/ {
  td {
    padding: 0 0;
  }
  .cell {
    margin: 12px 0 0 0;
    & > div {
      margin-bottom: 12px;
    }
  }
}

/deep/ .el-input__count {
  line-height: 20px;
}
.flexHen {
  display: flex;
}
</style>