UserSelectDefine.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <template>
  2. <div v-if="userSelectDefine.editable">
  3. <div>{{ userSelectDefine.nodeName }}</div>
  4. <div v-if="optionalRange === 'ALL'">
  5. <p
  6. v-if="check && (userIdsAll == null || userIdsAll.length == 0)"
  7. class="text-danger"
  8. >
  9. 必选字段*
  10. </p>
  11. <v-select
  12. v-model="userIdsAll"
  13. :reduce="(user) => user.id"
  14. :options="userListAll"
  15. label="text"
  16. :multiple="multiSelect"
  17. @search="listInGroupCompanyByCondition"
  18. />
  19. </div>
  20. <div v-else-if="optionalRange === 'USER'">
  21. <p
  22. v-if="check && (userIds == null || userIds.length == 0)"
  23. class="text-danger"
  24. >
  25. 必选字段*
  26. </p>
  27. <v-select
  28. v-model="userIds"
  29. :reduce="(optionalUser) => optionalUser.userId"
  30. :options="optionalUsers"
  31. label="text"
  32. :multiple="multiSelect"
  33. />
  34. </div>
  35. <div v-else>
  36. <p
  37. v-if="
  38. check &&
  39. (userIdsOfUserGroup == null || userIdsOfUserGroup.length == 0)
  40. "
  41. class="text-danger"
  42. >
  43. 必选字段*
  44. </p>
  45. <v-select
  46. v-model="userIdsOfUserGroup"
  47. :reduce="(user) => user.id"
  48. :options="userListOfUserGroup"
  49. label="text"
  50. :multiple="multiSelect"
  51. />
  52. </div>
  53. </div>
  54. </template>
  55. <script>
  56. import Common from '../common/Common.js';
  57. import UserResource from '../api/base/UserResource.js';
  58. import GroupUserResource from '../api/base/GroupUserResource.js';
  59. import vSelect from 'vue-select';
  60. import 'vue-select/dist/vue-select.css';
  61. import { Notify, Uuid } from 'pc-component-v3';
  62. export default {
  63. components: {
  64. vSelect,
  65. },
  66. props: {
  67. userSelectDefine: {
  68. type: Object,
  69. default : function(){
  70. return null;
  71. },
  72. },
  73. },
  74. data: function () {
  75. return {
  76. // multiSelect
  77. multiSelect: true,
  78. // 选择范围: 全公司(ALL)、指定成员(USER)、用户组(USER_GROUP)
  79. optionalRange: 'ALL',
  80. // 可选用户
  81. optionalUsers: [],
  82. // 可选用户组
  83. optionalUserGroups: [],
  84. // 选择的用户Id集合(指定成员)
  85. userIds: [],
  86. // 用户集合(全公司)
  87. userListAll: [],
  88. // 选择的用户Id集合(全公司)
  89. userIdsAll: [],
  90. // 用户集合(指定用户组)
  91. userListOfUserGroup: [],
  92. // 选择的用户Id集合(指定用户组)
  93. userIdsOfUserGroup: [],
  94. check: false, // 数据校验
  95. };
  96. },
  97. mounted: function () {
  98. this.initData();
  99. },
  100. methods: {
  101. /**
  102. * 根据姓名获取用户集合
  103. */
  104. listInGroupCompanyByCondition: function (search, loading) {
  105. let _self = this;
  106. const searchQueryParam = {
  107. range: {
  108. start: 0,
  109. length: 100,
  110. },
  111. conditional: search,
  112. };
  113. loading(true);
  114. //修复审批节点选择人员显示文件编码bug
  115. var selectList;
  116. if (
  117. this.userIdsAll != undefined &&
  118. this.userListAll != undefined &&
  119. this.userListAll.length > 0
  120. ) {
  121. this.userListAll.forEach(function (value, index) {
  122. if (value.id == _self.userIdsAll) {
  123. selectList = value;
  124. }
  125. });
  126. }
  127. UserResource.listInGroupCompanyByCondition(searchQueryParam).then(
  128. successData => {
  129. if (successData != null && successData.resultList != null) {
  130. successData.resultList.forEach(function (user) {
  131. user.text = user.name + '(';
  132. if(user.organizations != null && user.organizations.length > 0){
  133. let isFirst = true;
  134. user.organizations.forEach(item => {
  135. if(isFirst === true){
  136. user.text += item.organizationName;
  137. isFirst = false;
  138. }else{
  139. user.text += (',' + item.organizationName);
  140. }
  141. });
  142. }
  143. user.text += ')';
  144. });
  145. this.userListAll = successData.resultList;
  146. } else {
  147. this.userListAll = [];
  148. }
  149. //修复审批节点选择人员显示文件编码bug
  150. var result = this.userListAll.some(
  151. item => item.id === _self.userIdsAll,
  152. );
  153. if (selectList != undefined && !result) {
  154. this.userListAll.push(selectList);
  155. }
  156. loading(false);
  157. },
  158. errorData => {
  159. Common.processException(errorData);
  160. loading(false);
  161. },
  162. );
  163. },
  164. /**
  165. * 根据用户组Id集合获取该组内所有用户
  166. */
  167. listUserByGroupIds: function () {
  168. if (
  169. this.optionalUserGroups == null ||
  170. this.optionalUserGroups.length == 0
  171. ) {
  172. const title = this.userSelectDefine.nodeName + '审批节点异常';
  173. const content = '未定义用户组。';
  174. Notify.error(title, content, false);
  175. return;
  176. }
  177. const groupIds = [];
  178. this.optionalUserGroups.forEach(optionalUserGroup => {
  179. groupIds.push(optionalUserGroup.groupId);
  180. });
  181. GroupUserResource.listUserByGroupIds(groupIds).then(
  182. successData => {
  183. if (successData != null) {
  184. successData.forEach(function (item) {
  185. item.text = item.name + ',' + item.organizationName;
  186. });
  187. this.userListOfUserGroup = successData;
  188. } else {
  189. const title = this.userSelectDefine.nodeName + '审批节点异常';
  190. const content = '根据用户组查询不到用户。';
  191. this.userListOfUserGroup = [];
  192. Notify.error(title, content, false);
  193. }
  194. },
  195. errorData => {
  196. Common.processException(errorData);
  197. },
  198. );
  199. },
  200. initData: function () {
  201. this.multiSelect = this.userSelectDefine.multiSelect;
  202. this.optionalRange = this.userSelectDefine.optionalRange;
  203. this.optionalUsers = this.userSelectDefine.optionalUsers;
  204. this.optionalUserGroups = this.userSelectDefine.optionalUserGroups;
  205. if (this.optionalRange === 'ALL') {
  206. this.listInGroupCompanyByCondition(null, function (status) {});
  207. } else if (this.optionalRange === 'USER_GROUP') {
  208. this.listUserByGroupIds();
  209. }
  210. },
  211. getData: function () {
  212. this.check = true;
  213. let userSelectDto = {
  214. nodeId: this.userSelectDefine.nodeId,
  215. nodeName: this.userSelectDefine.nodeName,
  216. variableName: this.userSelectDefine.variableName,
  217. };
  218. if (this.userSelectDefine.editable) {
  219. if (this.optionalRange === 'ALL') {
  220. if (this.userIdsAll == null || this.userIdsAll.length == 0) {
  221. const message = this.userSelectDefine.nodeName + '节点未选择用户。';
  222. throw new Error(message);
  223. }
  224. if (Array.isArray(this.userIdsAll)) {
  225. userSelectDto.userIds = this.userIdsAll;
  226. } else {
  227. userSelectDto.userIds = [this.userIdsAll];
  228. }
  229. } else if (this.optionalRange === 'USER_GROUP') {
  230. if (
  231. this.userIdsOfUserGroup == null ||
  232. this.userIdsOfUserGroup.length == 0
  233. ) {
  234. const message = this.userSelectDefine.nodeName + '节点未选择用户。';
  235. throw new Error(message);
  236. }
  237. if (Array.isArray(this.userIdsOfUserGroup)) {
  238. userSelectDto.userIds = this.userIdsOfUserGroup;
  239. } else {
  240. userSelectDto.userIds = [this.userIdsOfUserGroup];
  241. }
  242. } else if (this.optionalRange === 'USER') {
  243. if (this.userIds == null || this.userIds.length == 0) {
  244. const message = this.userSelectDefine.nodeName + '节点未选择用户。';
  245. throw new Error(message);
  246. }
  247. if (Array.isArray(this.userIds)) {
  248. userSelectDto.userIds = this.userIds;
  249. } else {
  250. userSelectDto.userIds = [this.userIds];
  251. }
  252. } else {
  253. const message =
  254. this.userSelectDefine.nodeName +
  255. '节点类型定义异常,不识别的类型' +
  256. this.optionalRange +
  257. '。';
  258. throw new Error(message);
  259. }
  260. }
  261. return userSelectDto;
  262. },
  263. },
  264. };
  265. </script>