approval-user-control.vue 12.1 KB
Newer Older
wangcong committed
1 2 3 4 5
<template>
  <div>
    <div class="suggestion-wrapper">
      <div class="label">{{this.define.title}}</div>
      <div class="input-wrapper">
6
        <Input v-model="value" type="textarea" :placeholder="define.config.placeholder" :maxlength="240" />
wangcong committed
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
        <div class="suggestion-button-wrapper">
          <ConfirmPopover
            v-for="suggestion in suggestionOption"
            :key="suggestion.code"
            v-model="suggestion.visible"
            @cancle="suggestion.visible = false"
            @confirm="() => {handleDelete([suggestion]); suggestion.visible = false}"
          >
            <div
              class="suggestion-button"
              :style="{ background: `${themeColor}15`, border: `1px solid ${themeColor}29`}"
              v-show="suggestion.id"
              @click="handleSelectSuggestion(suggestion)"
              @mouseover="currentHoverSuggestion = suggestion"
              @mouseout="currentHoverSuggestion = null"
            >
              <div class="text" :style="{ color: themeColor }">{{suggestion.spyj}}</div>
              <div
                @click.stop="$set(suggestion, 'visible', true)"
                v-show="suggestion === currentHoverSuggestion"
                class="delete-icon"
              >
                <Icon type="md-close-circle" />
              </div>
            </div>
          </ConfirmPopover>
        </div>
        <!-- <div>
          <Button size="small" @click="suggestionOptionModal = true">edit</Button>
          <Button size="small" @click="handleAdd">add</Button>
        </div> -->
      </div>
    </div>
    <el-dialog
      v-if="suggestionOptionModal"
      title="常用意见列表"
      :visible.sync="suggestionOptionModal"
      width="60%"
      :modal="false"
      custom-class="suggestion-option-modal"
    >
      <div slot="title" class="header">
        编辑常用意见
      </div>
      <div class="suggestion-modal-toolbar">
        <div v-if="suggestionOption.length > 0">{{suggestionOption.length}}条审批意见</div>
        <div class="button-wrapper">
          <Button style="margin-right: 5px;" size="small" @click="addNewRow">添加意见</Button>
          <Poptip
            confirm
            :transfer="true"
            title="是否删除选中项?"
            @on-ok="handleBatchDelete"
          >
            <Button size="small">批量删除</Button>
          </Poptip>
        </div>
      </div>
      <Table
        ref="suggestionTable"
        size="small"
        :columns="suggestionTableColumns"
        border
        :max-height="400"
        :data="suggestionOption"
        @on-selection-change="handleSelectionChange"
      >
        <template slot-scope="{ row }" slot="spyj">
          <div
            v-show="currentEditSuggestion.code != row.code"
            @click="handleClickRow(row)"
          >
            {{row.spyj}}
          </div>
          <Input
            v-model="currentEditSuggestion.spyj"
            v-show="currentEditSuggestion.code === row.code"
            :ref="'input-' + row.code"
            @on-blur="handleInputBlur(row)"
            type="textarea"
87
            :maxlength="240"
wangcong committed
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
          />
        </template>
        <template slot-scope="{ row, index }" slot="action">
          <Button
            :class="index < 1 ? '' : 'suggestion-edit-button'"
            :disabled="index < 1"
            size="small"
            type="text"
            @click="setOrder(row, -1)"
          >
            上移
          </Button>
          <Button
            :class="index >= suggestionOption.length - 1 ? '' : 'suggestion-edit-button'"
            :disabled="index >= suggestionOption.length - 1"
            size="small"
            type="text"
            @click="setOrder(row, 1)"
          >
            下移
          </Button>
          <Poptip
            confirm
            :transfer="true"
            title="确定要删除本条意见吗?"
            @on-ok="handleDelete([row])"
            popper-class="suggestion-edit-table-popper"
          >
            <Button class="suggestion-edit-button" size="small" type="text">删除</Button>
          </Poptip>
        </template>
      </Table>
    </el-dialog>
  </div>
</template>

<script>
const TABLE_NAME = "MD_SPYJ"
import ConfirmPopover from './confirm-popover'
export default {
  name: 'ApprovalUserControl',
  components: {
    ConfirmPopover,
  },
  props: {
    define: {
      type: Object,
      required: true,
    },
    context: {
      type: Object,
      default: () => { }
    }
  },
  data() {
    return {
      value: '',
      suggestionOptionModal: false,
      reviewParam:{},
      taskId: null,
      currentEditSuggestion: {},
      suggestionOption: [],
      suggestionTableColumns: [
        {
          type: 'selection',
          width: 50,
          align: 'center',
        },
        {
          title: '序号',
          width: 60,
          align: 'center',
          key: 'index',
        },
        {
          title: '审批意见',
          slot: 'spyj',
        },
        {
          title: '操作',
          slot: 'action',
          // align: 'center',
          maxWidth: 160,
        }
      ],
      selectedSuggestion: [],
      themeColor: this.define?.config?.fontColor || '#5369D8',
      currentHoverSuggestion: null,
176
      currentTagId: null,
wangcong committed
177 178 179 180 181 182 183 184 185
    }
  },
  watch: {
    value(newV) {
      this.reviewParam['suggestions'] = newV;
      this.context.bill.setGlobalParam('reviewParam',this.reviewParam);
    }
  },
  mounted() {
186 187
    this.reviewParam['taskId'] = GMS.workflowTaskId
    this.taskId = GMS.workflowTaskId;
wangcong committed
188 189 190
    // this.reviewParam['billid'] = this.$route.query.id;
    this.context.bill.setGlobalParam('reviewParam',this.reviewParam);
    this.value = this.context.bill.getGlobalParam('reviewParam').suggestions
191
    this.currentTagId = window.nros.context.getCurrTag()
wangcong committed
192 193 194 195 196 197 198 199 200 201 202 203 204
    window.GMS.vbus.$on('approval-user-control-edit', this.openEditModal)
    window.GMS.vbus.$on('approval-user-control-add', this.handleAdd)
    this.getSuggestionOptions()
  },
  beforeUnmount() {
    window.GMS.vbus.$off('approval-user-control-edit')
    window.GMS.vbus.$off('approval-user-control-add')
  },
  methods: {
    showDeletePopover(suggestion) {
      this.$set(suggestion, 'visible', true)
    },
    openEditModal() {
205
      if (this.currentTagId && this.currentTagId != window.nros.context.getCurrTag()) return
wangcong committed
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
      this.suggestionOptionModal = true
    },
    genCode() {
      return `${Date.now()}${Math.random().toString(36).slice(-8)}`
    },
    /**
     * @param {object} row
     * @param {1 | -1} direction - 1下移,-1上移
     */
    async setOrder(row, direction) {
      // index 是从1开始的,,,,
      if (
        row.index + direction > this.suggestionOption.length
        || row.index + direction <= 0
      ) return
      const neighborRow = this.suggestionOption[row.index + direction - 1]
      await window.GAMS.Util.invokeServer({
        path: 'bpm/bill/action/updateOrder',
        type: 'POST',
        contentType: 'application/json',
        data: JSON.stringify([row, neighborRow].map((o) => {
          const ans = {...o}
          delete ans.index
          return ans
        })),
      })
      await this.getSuggestionOptions()
    },
    addNewRow() {
      this.currentEditSuggestion = {
        code: this.genCode(),
      }
      this.suggestionOption.push(this.currentEditSuggestion)
      this.$nextTick(() => {
        this.focusInput(this.currentEditSuggestion.code)
      })
    },
    focusInput(code) {
      this.$refs[`input-${code}`] && this.$refs[`input-${code}`].focus()
    },
    handleInputBlur(row) {
      this.saveSuggestion()
    },
    handleClickRow(row) {
      this.currentEditSuggestion = row
      this.$nextTick(() => {
        this.focusInput(row.code)
      })
    },
    handleBatchDelete() {
      this.handleDelete(this.selectedSuggestion)
      this.selectedSuggestion = []
    },
    handleSelectionChange(selection) {
      this.selectedSuggestion = [...selection]
    },
    handleSelectSuggestion(s) {
      this.value = s.spyj
    },
    handleAdd() {
266 267
      if (this.currentTagId && this.currentTagId != window.nros.context.getCurrTag()) return

wangcong committed
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
      this.currentEditSuggestion = {
        code: this.genCode(),
        spyj: this.value,
      }
      this.saveSuggestion()
    },
    async add() {
      this.currentEditSuggestion = {
        name: "",
        parentcode: "-",
        parentcode_show: {name: "-", title: "-"},
        shortname: "",
        stopflag: 0,
        tableName: TABLE_NAME,
        ...this.currentEditSuggestion,
      }
      await window.GAMS.Util.invokeServer({
        path: 'bpm/bill/action/add',
        type: 'POST',
        contentType: 'application/json',
        data: JSON.stringify(this.currentEditSuggestion),
      })
    },
    async saveSuggestion() {
      if (this.currentEditSuggestion.id) {
        await this.update()
      }
295
      else if (this.currentEditSuggestion.spyj && this.currentEditSuggestion.spyj.trim()) {
wangcong committed
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
        await this.add()
      }
      this.currentEditSuggestion = {}
      this.getSuggestionOptions()
    },
    async update() {
      delete this.currentEditSuggestion.showTitleMap
      this.currentEditSuggestion.ver = Date.now()
      await window.GAMS.Util.invokeServer({
        path: 'baseData/data/update',
        type: 'POST',
        contentType: 'application/json',
        data: JSON.stringify(this.currentEditSuggestion),
      })
    },
    async handleDelete(s) {
      const params = {
        dataList: s,
        tableName: TABLE_NAME,
      }
      await window.GAMS.Util.invokeServer({
        path: 'baseData/data/batch/remove',
        type: 'POST',
        contentType: 'application/json',
        data: JSON.stringify(params),
      })
      this.getSuggestionOptions()
    },
    async getSuggestionOptions() {
      const res = await window.GAMS.Util.invokeServer({
        path: 'bpm/bill/action/list',
        type: 'POST',
        contentType: 'application/json',
        data: JSON.stringify({
          "tableName": TABLE_NAME,
          "pagination": false,
          "searchKey": "",
          "queryDataStructure": "ALL_WITH_REF",
          "stopflag": -1,
          "authType": "NONE"
        }),
      })
      this.suggestionOption = (res && res.rows || []).map((o, index) => ({
        ...o,
        index: index + 1,
        tableName: TABLE_NAME,
      }))
    }
  },
}
</script>

<style lang="less">
.suggestion-wrapper {
  display: flex;
  .label {
    width: 90px;
    text-align: right;
  }
  .input-wrapper {
    flex: 1;
    padding-left: 15px;
    .suggestion-button-wrapper {
      display: flex;
      flex-wrap: wrap;
      padding-top: 12px;
      max-height: 84px;
      overflow: hidden;
      .suggestion-button {
        cursor: pointer;
        height: 28px;
        padding: 0px 11px;
        margin: 0px 8px 8px 0px;
        border-radius: 3px;
        position: relative;
        .delete-icon {
          width: 12px;
          height: 12px;
          font-size: 10px;
          color: red;
          position: absolute;
          top: -10px;
          right: -6px;
        }
        .text {
          height: 28px;
          max-width: 140px;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
          font-size: 14px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          line-height: 28px;
        }
      }
    }
  }
}
.suggestion-edit-table-popper[style] {
  z-index: 3000 !important;
}
.suggestion-option-modal {
  .header {
    text-align: left;
    height: 22px;
    font-size: 16px;
    font-weight: 500;
    color: #0F0F0F;
    line-height: 22px;
  }
  .el-dialog__header {
    border-bottom: 1px solid #e5e5e5;
  }
  .el-dialog__body {
    overflow-y: scroll;
    padding-top: 20px;
    .suggestion-modal-toolbar {
      padding-bottom: 4px;
      display: flex;
      justify-content: space-between;
      .button-wrapper {
        flex: 1;
        display: flex;
        justify-content: flex-end;
      }
    }
    .ivu-table-header thead tr th {
      padding: 5px 0px;
    }
    .ivu-table-small td {
      padding: 5px 0px;
    }
    .ivu-table-cell {
      padding: 0 10px;
    }
    .suggestion-edit-button {
      color: #5369D8;
    }
    
  }
}
</style>