UserSelectDefine.vue 8.9 KB

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