WorkflowSelectUser.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. <template>
  2. <div>
  3. <div class="panel panel-default">
  4. <div class="panel-heading">
  5. {{ $t("lang.workflowSelectUser.approve") }}
  6. </div>
  7. <div class="panel-body">
  8. <div class="row">
  9. <div class="form-horizontal">
  10. <div
  11. v-if="userTaskDtos.length==0 && workFlow.workflowType != 'Auto'"
  12. class="form-group"
  13. >
  14. <label class="col-xs-5 col-sm-4 col-md-3 col-lg-2 control-label img-label">
  15. {{ $t("lang.workflowSelectUser.approveUser") }}
  16. </label>
  17. <div class="col-xs-7 col-sm-8 col-md-9 col-lg-10">
  18. <div
  19. v-for="applyUser in applyUsers"
  20. :key="applyUser.id"
  21. class="img-box"
  22. >
  23. <div>
  24. <span
  25. class="glyphicon glyphicon-trash remove-icon"
  26. @click="removeApplyUser(applyUser)"
  27. />
  28. <AuthImage
  29. :auth-src="getImgSrc(applyUser.imageName)"
  30. class="img-circle"
  31. />
  32. {{ applyUser.name }}
  33. </div>
  34. </div>
  35. <div
  36. class="add-box"
  37. @click="addApplyUser()"
  38. >
  39. <span
  40. class="glyphicon glyphicon-plus add-icon"
  41. aria-hidden="true"
  42. />
  43. </div>
  44. </div>
  45. </div>
  46. <div
  47. v-for="userTaskDto in userTaskDtos"
  48. :key="userTaskDto.id"
  49. class="form-group"
  50. >
  51. <label class="col-xs-5 col-sm-4 col-md-3 col-lg-2 control-label img-label">
  52. {{ userTaskDto.name }}
  53. </label>
  54. <div class="col-xs-7 col-sm-8 col-md-9 col-lg-10">
  55. <div
  56. v-for="applyUser in userTaskDto.assignees"
  57. :key="applyUser.id"
  58. class="img-box"
  59. >
  60. <div>
  61. <span
  62. class="glyphicon glyphicon-trash remove-icon"
  63. @click="removeApplyUser(applyUser,userTaskDto)"
  64. />
  65. <AuthImage
  66. :auth-src="getImgSrc(applyUser.imageName)"
  67. class="img-circle"
  68. />
  69. {{ applyUser.name }}
  70. </div>
  71. </div>
  72. <div
  73. v-if="userTaskDto.multipleInstance || userTaskDto.assignees.length < 1"
  74. class="add-box"
  75. @click="addApplyUser(userTaskDto)"
  76. >
  77. <span
  78. class="glyphicon glyphicon-plus add-icon"
  79. aria-hidden="true"
  80. />
  81. </div>
  82. </div>
  83. </div>
  84. <div
  85. class="form-group"
  86. style="margin-top:20px;"
  87. >
  88. <label class="col-xs-5 col-sm-4 col-md-3 col-lg-2 control-label img-label">
  89. {{ $t("lang.workflowSelectUser.copyUser") }}
  90. </label>
  91. <div class="col-xs-7 col-sm-8 col-md-9 col-lg-10">
  92. <div
  93. v-for="copyUser in copyUsers"
  94. :key="copyUser.id"
  95. class="img-box"
  96. >
  97. <div>
  98. <span
  99. class="glyphicon glyphicon-trash remove-icon"
  100. @click="removeCopyUser(copyUser)"
  101. />
  102. <AuthImage
  103. :auth-src="getImgSrc(copyUser.imageName)"
  104. class="img-circle"
  105. />
  106. {{ copyUser.name }}
  107. </div>
  108. </div>
  109. <div
  110. class="add-box"
  111. @click="addCopyUser"
  112. >
  113. <span
  114. class="glyphicon glyphicon-plus add-icon"
  115. aria-hidden="true"
  116. />
  117. </div>
  118. </div>
  119. </div>
  120. <div
  121. class="form-group"
  122. style="margin-top:20px;"
  123. >
  124. <label class="col-xs-5 col-sm-4 col-md-3 col-lg-2 control-label" />
  125. <div class="col-xs-7 col-sm-8 col-md-9 col-lg-10">
  126. <button
  127. type="button"
  128. class="btn btn-primary"
  129. @click="apply"
  130. >
  131. {{ $t("lang.workflowSelectUser.submit") }}
  132. </button>
  133. </div>
  134. </div>
  135. </div>
  136. </div>
  137. </div>
  138. </div>
  139. <Modal
  140. v-model:show="modal"
  141. :full="true"
  142. @ok="searchDialogOk"
  143. @cancel="searchDialogCancel"
  144. >
  145. <InfoWindow
  146. ref="info"
  147. :info-window-no="infoWindowNo"
  148. :where-clause-source="whereClauseSource"
  149. @data-selected="dataSelected"
  150. />
  151. <template #header>
  152. {{ $t("lang.workflowSelectUser.chooseUser") }}
  153. </template>
  154. </Modal>
  155. <Modal
  156. v-model:show="modal2"
  157. :small="true"
  158. >
  159. <div class="row box">
  160. <div class="col-md-12">
  161. <div class="table-box">
  162. <table class="table table-condensed table-bordered table-user">
  163. <thead>
  164. <tr>
  165. <th>{{ $t("lang.workflowSelectUser.userName") }}</th>
  166. <th>{{ $t("lang.workflowSelectUser.userNo") }}</th>
  167. </tr>
  168. </thead>
  169. <tbody>
  170. <tr
  171. v-for="item in currentUsers"
  172. :key="item.id"
  173. @click="selectCurrentUser(item)"
  174. >
  175. <td>{{ item.name }}</td>
  176. <td>{{ item.no }}</td>
  177. </tr>
  178. </tbody>
  179. </table>
  180. </div>
  181. </div>
  182. </div>
  183. <template #header>
  184. {{ $t("lang.workflowSelectUser.chooseUser") }}
  185. </template>
  186. </Modal>
  187. <Loading v-if="loading" />
  188. </div>
  189. </template>
  190. <script>
  191. import Common from '../common/Common.js';
  192. import AuthImage from '../widget/AuthImage.vue';
  193. export default {
  194. components: {
  195. AuthImage,
  196. },
  197. props: {
  198. // 工作流定义Id
  199. processDefinitionId: {
  200. type: String,
  201. default: null,
  202. },
  203. workFlow: {
  204. type: Object,
  205. default : function(){
  206. return null;
  207. },
  208. },
  209. },
  210. emits: ['apply'],
  211. data: function () {
  212. this.Common = Common;
  213. return {
  214. infoWindowNo: '050408',
  215. className: 'com.leanwo.prodog.base.model.User',
  216. applyUsers: [],
  217. copyUsers: [],
  218. currentUser: '',
  219. whereClauseSource: {
  220. customerDataDimensions:[{
  221. fieldName: 'client.id',
  222. dataDimensionTypeNo: '202201191757',
  223. defaultDataDimensionTypeValueNo: '4',
  224. }],
  225. },
  226. userTaskDtos: [],
  227. selectedUserTaskDto: '',
  228. currentUsers: [],
  229. loading: false,
  230. modal: false,
  231. modal2: false,
  232. };
  233. },
  234. mounted: function () {
  235. var _self = this;
  236. console.log(this.workFlow);
  237. $.ajax({
  238. url: Common.getApiURL('WorkflowResource/listUserTask'),
  239. type: 'post',
  240. dataType: 'json',
  241. beforeSend: function (request) {
  242. Common.addTokenToRequest(request);
  243. },
  244. contentType: 'application/json',
  245. data: _self.processDefinitionId,
  246. success: function (data) {
  247. if (data != undefined) {
  248. _self.userTaskDtos = data;
  249. _self.userTaskDtos.forEach(function (item) {
  250. item.assignees = [];
  251. item.assigneeIds = [];
  252. if ((item.candidateUserIds != undefined && item.candidateUserIds.length > 0) || (item.candidateGroupIds != undefined && item.candidateGroupIds.length > 0)) {
  253. _self.getUserByUserTask(item);
  254. }
  255. });
  256. }
  257. },
  258. error: function (XMLHttpRequest, textStatus, errorThrown) {
  259. Common.processException(XMLHttpRequest, textStatus, errorThrown);
  260. },
  261. });
  262. },
  263. methods: {
  264. // 选择用户后
  265. selectCurrentUser: function (data) {
  266. var _self = this;
  267. _self.modal2 = false;
  268. if (_self.currentUser == 'applyUser') {
  269. for (var i = 0; i < _self.userTaskDtos.length; i++) {
  270. if (_self.userTaskDtos[i] == _self.selectedUserTaskDto) {
  271. if (_self.contains(_self.userTaskDtos[i].assigneeIds, data.id)) {
  272. continue;
  273. }
  274. _self.userTaskDtos[i].assignees.push(data);
  275. _self.userTaskDtos[i].assigneeIds.push(data.id);
  276. }
  277. }
  278. if (!_self.containsId(_self.applyUsers, data)) {
  279. _self.applyUsers.push(data);
  280. }
  281. } else if (_self.currentUser == 'copyUser') {
  282. if (!_self.containsId(_self.copyUsers, data)) {
  283. _self.copyUsers.push(data);
  284. }
  285. }
  286. },
  287. /**
  288. * 审批
  289. * @return {void}
  290. */
  291. apply: function () {
  292. this.$emit('apply');
  293. },
  294. /**
  295. * 初始化数据
  296. * @return {void}
  297. */
  298. initData: function () {
  299. var _self = this;
  300. },
  301. /**
  302. * 选择用户后
  303. * @param {Object} modelData 用户信息
  304. * @return {void}
  305. */
  306. dataSelected: function (modelData) {
  307. var _self = this;
  308. this.modal = false;
  309. var userId = modelData.id;
  310. _self.loading=true;
  311. $.ajax({
  312. url: Common.getApiURL('userResource/getUser'),
  313. type: 'get',
  314. beforeSend: function (request) {
  315. Common.addTokenToRequest(request);
  316. },
  317. data: {
  318. userId: userId,
  319. },
  320. success: function (data) {
  321. _self.loading=false;
  322. if (_self.currentUser == 'applyUser') {
  323. for (var i = 0; i < _self.userTaskDtos.length; i++) {
  324. if (_self.userTaskDtos[i] == _self.selectedUserTaskDto) {
  325. if (_self.contains(_self.userTaskDtos[i].assigneeIds, data.id)) {
  326. continue;
  327. }
  328. _self.userTaskDtos[i].assignees.push(data);
  329. _self.userTaskDtos[i].assigneeIds.push(data.id);
  330. }
  331. }
  332. if (!_self.containsId(_self.applyUsers, data)) {
  333. _self.applyUsers.push(data);
  334. }
  335. } else if (_self.currentUser == 'copyUser') {
  336. if (!_self.containsId(_self.copyUsers, data)) {
  337. _self.copyUsers.push(data);
  338. }
  339. }
  340. _self.className = 'com.leanwo.prodog.base.model.User';
  341. _self.whereClauseSource = {
  342. customerDataDimensions:[{
  343. fieldName: 'client.id',
  344. dataDimensionTypeNo: '202201191757',
  345. defaultDataDimensionTypeValueNo: '4',
  346. }],
  347. };
  348. },
  349. error: function (XMLHttpRequest, textStatus, errorThrown) {
  350. _self.loading=false;
  351. _self.className = 'com.leanwo.prodog.base.model.User';
  352. _self.whereClauseSource = {
  353. customerDataDimensions:[{
  354. fieldName: 'client.id',
  355. dataDimensionTypeNo: '202201191757',
  356. defaultDataDimensionTypeValueNo: '4',
  357. }],
  358. };
  359. Common.processException(XMLHttpRequest, textStatus, errorThrown);
  360. },
  361. });
  362. },
  363. /**
  364. * 获取图片路径
  365. * @param {String} imageName 图片名称
  366. * @return {void}
  367. */
  368. getImgSrc: function (imageName) {
  369. var _self = this;
  370. if (imageName == undefined || imageName == '') {
  371. return '/static/assets/client-base-v4/image/no-image.png';
  372. }
  373. return Common.getImageSrc(_self.className, imageName);
  374. },
  375. /**
  376. * 添加审批人
  377. */
  378. addApplyUser: function (userTaskDto) {
  379. var _self = this;
  380. _self.selectedUserTaskDto = userTaskDto;
  381. _self.currentUser = 'applyUser';
  382. if (userTaskDto != undefined && userTaskDto.users != undefined && userTaskDto.users.length > 0) {
  383. _self.currentUsers = userTaskDto.users;
  384. _self.modal2 = true;
  385. } else {
  386. _self.initData();
  387. _self.modal = true;
  388. }
  389. },
  390. /**
  391. * 添加抄送人
  392. */
  393. addCopyUser: function () {
  394. var _self = this;
  395. _self.currentUser = 'copyUser';
  396. _self.initData();
  397. _self.modal = true;
  398. },
  399. /**
  400. * 移除审批人
  401. * @param {Object} user 用户
  402. * @return {void}
  403. */
  404. removeApplyUser: function (user, userTaskDto) {
  405. var _self = this;
  406. var index = userTaskDto.assignees.indexOf(user);
  407. if (index >= 0) {
  408. userTaskDto.assignees.splice(index, 1);
  409. }
  410. var i = _self.userTaskDtos.indexOf(userTaskDto);
  411. var j = userTaskDto.assigneeIds.indexOf(user.id);
  412. userTaskDto.assigneeIds.splice(j, 1);
  413. var k = _self.applyUsers.indexOf(user);
  414. if (k >= 0) {
  415. _self.applyUsers.splice(k, 1);
  416. }
  417. _self.userTaskDtos[i]=userTaskDto;
  418. },
  419. /**
  420. * 移除抄送人
  421. * @param {Object} user 用户
  422. * @return {void}
  423. */
  424. removeCopyUser: function (user) {
  425. var _self = this;
  426. var index = _self.copyUsers.indexOf(user);
  427. if (index >= 0) {
  428. _self.copyUsers.splice(index, 1);
  429. }
  430. },
  431. /**
  432. * 获取审批人和抄送人 供外部调用
  433. * @return {Object} 用户数据
  434. */
  435. getUserData: function () {
  436. var _self = this;
  437. var applyUsers = [];
  438. var copyUsers = [];
  439. _self.applyUsers.forEach(function (item) {
  440. applyUsers.push(item.id);
  441. });
  442. _self.copyUsers.forEach(function (item) {
  443. copyUsers.push(item.id);
  444. });
  445. var data = {
  446. applyUsers: applyUsers,
  447. copyUsers: copyUsers,
  448. userTaskDtos: _self.userTaskDtos,
  449. };
  450. return data;
  451. },
  452. /**
  453. * 搜索框【确定】按钮点击事件
  454. */
  455. searchDialogOk: function () {
  456. var _self = this;
  457. var selectedModelDatas = _self.$refs.info.getSelectedModelDatas();
  458. if (selectedModelDatas != undefined || selectedModelDatas.length > 0) {
  459. // 选中了数据,更新数据
  460. _self.dataSelected(selectedModelDatas[0]);
  461. }
  462. },
  463. searchDialogCancel: function () {
  464. },
  465. contains: function (arr, item) {
  466. if (arr == undefined || arr.length == 0 || item == undefined) {
  467. return false;
  468. }
  469. for (var i = 0; i < arr.length; i++) {
  470. if (arr[i] == item) {
  471. return true;
  472. }
  473. }
  474. return false;
  475. },
  476. containsId: function (arr, item) {
  477. if (arr == undefined || arr.length == 0 || item == undefined) {
  478. return false;
  479. }
  480. for (var i = 0; i < arr.length; i++) {
  481. if (arr[i].id == item.id) {
  482. return true;
  483. }
  484. }
  485. return false;
  486. },
  487. // 获取用户根据userTask
  488. getUserByUserTask: function (userTaskDto) {
  489. var _self = this;
  490. $.ajax({
  491. type: 'post',
  492. url: Common.getApiURL('userResource/getUserByUserTask'),
  493. dataType: 'json',
  494. contentType: 'application/json',
  495. data: JSON.stringify(userTaskDto),
  496. beforeSend: function (request) {
  497. Common.addTokenToRequest(request);
  498. },
  499. success: function (data) {
  500. if (data && data.length > 0) {
  501. userTaskDto['users']=data;
  502. if (data.length == 1) {
  503. userTaskDto.assignees.push(data[0]);
  504. userTaskDto.assigneeIds.push(data[0].id);
  505. }
  506. }
  507. },
  508. error: function (XMLHttpRequest, textStatus, errorThrown) {
  509. Common.processException(XMLHttpRequest, textStatus, errorThrown);
  510. },
  511. });
  512. },
  513. },
  514. };
  515. </script>
  516. <style scoped>
  517. .img-label {
  518. height: 80px;
  519. line-height: 80px;
  520. padding-top: 0px !important;
  521. }
  522. .img-box {
  523. width: 60px;
  524. height: 80px;
  525. float: left;
  526. text-align: center;
  527. margin-right: 20px;
  528. }
  529. .img-box div img {
  530. width: 60px;
  531. height: 60px;
  532. }
  533. .add-box {
  534. width: 60px;
  535. height: 60px;
  536. float: left;
  537. border-radius: 30px;
  538. border: 1px #999 dashed;
  539. text-align: center;
  540. margin-top: 20px;
  541. }
  542. .add-box:hover {
  543. cursor: pointer;
  544. background-color: #ccc;
  545. }
  546. .add-icon {
  547. width: 60px;
  548. height: 60px;
  549. color: #aaa;
  550. font-size: 40px;
  551. line-height: 60px;
  552. position: relative;
  553. top: -1px;
  554. }
  555. .remove-icon {
  556. color: red;
  557. position: relative;
  558. top: 10px;
  559. right: -30px;
  560. cursor: pointer;
  561. }
  562. .table-box td,
  563. th {
  564. text-align: center;
  565. }
  566. </style>