PushObject.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <el-form :model="ruleForm" ref="ruleFormRef">
  3. <el-form-item
  4. label="推送对象"
  5. prop="recipientType"
  6. :rules="[{ required: true, message: '请选择推送对象' }]"
  7. >
  8. <el-radio-group v-model="ruleForm.recipientType" :disabled="disabled">
  9. <el-radio
  10. v-for="item in recipientTypeName"
  11. :key="item.value"
  12. :value="item.value"
  13. :label="item.label"
  14. />
  15. </el-radio-group>
  16. </el-form-item>
  17. <div class="userGroupList" v-if="ruleForm.recipientType === 2">
  18. <el-form-item
  19. label="选择分组"
  20. prop="userGroupList"
  21. :rules="[{ required: true, message: '请选择分组' }]"
  22. >
  23. <el-select
  24. v-model="ruleForm.userGroupList"
  25. multiple
  26. placeholder="请选择分组"
  27. style="width: 300px"
  28. :disabled="disabled"
  29. >
  30. <el-option
  31. v-for="item in options"
  32. :key="item.userGroupId"
  33. :value="item.userGroupId"
  34. :label="item.name"
  35. />
  36. </el-select>
  37. </el-form-item>
  38. <span
  39. v-if="ruleForm.userGroupList.length > 0"
  40. @click="queryGroupInfo(ruleForm.userGroupList)"
  41. >
  42. 人员详情
  43. </span>
  44. </div>
  45. <div class="customUserList" v-if="ruleForm.recipientType === 3">
  46. <el-form-item
  47. label="选择人员"
  48. prop="customUserList"
  49. :rules="[{ required: true, message: '请选择人员' }]"
  50. >
  51. <el-select
  52. v-model="ruleForm.customUserList"
  53. value-key="id"
  54. multiple
  55. placeholder="请选择人员"
  56. style="width: 300px"
  57. @click="userInfo = true"
  58. :disabled="disabled"
  59. >
  60. <el-option v-for="user in selectedUser" :key="user.id" :label="user.name" :value="user">
  61. </el-option>
  62. </el-select>
  63. </el-form-item>
  64. </div>
  65. </el-form>
  66. <el-dialog
  67. v-model="groupInfo"
  68. title="人员详情"
  69. align-center
  70. :close-on-click-modal="false"
  71. style="height: 583px"
  72. :width="731"
  73. :destroy-on-close="true"
  74. class="groupInfo"
  75. >
  76. <Group :userGroupInfo="userGroupInfo" />
  77. </el-dialog>
  78. <el-dialog
  79. v-model="userInfo"
  80. class="userInfo"
  81. title="添加组内成员"
  82. align-center
  83. :close-on-click-modal="false"
  84. style="height: 583px"
  85. :width="731"
  86. :destroy-on-close="true"
  87. >
  88. <SelectTree @cancel="handleCancle" @submit="handleSubmit" :selectedUser="selectedUser" />
  89. </el-dialog>
  90. </template>
  91. <script setup lang="ts">
  92. import { onMounted, ref, reactive, watch, watchEffect } from 'vue';
  93. import SelectTree from '../persongroup/components/SelectTree.vue';
  94. import Group from './Group.vue';
  95. import { recipientTypeName } from '../constant';
  96. import { ToPushObjectqueryUserGroupList, queryUserGroupDetail } from '../api/index';
  97. import type { FormInstance } from 'element-plus';
  98. import { GroupData } from '../persongroup/type';
  99. const ruleFormRef = ref<FormInstance>();
  100. const groupInfo = ref<boolean>(false);
  101. const userInfo = ref<boolean>(false);
  102. const disabled = ref<boolean>(false);
  103. export interface customUserList {
  104. userId: number;
  105. userLoginName: string;
  106. userNickname: string;
  107. userNumber: string;
  108. }
  109. export interface userGroupVOList {
  110. userGroupId: number;
  111. total: number;
  112. operatorName: string;
  113. operationTime: string;
  114. name: string;
  115. description: string;
  116. }
  117. interface UserList {
  118. id: string;
  119. name: string;
  120. userId: number;
  121. }
  122. const selectedUser = ref<UserList[]>([]);
  123. interface RuleForm {
  124. recipientType?: number;
  125. userGroupList: number[];
  126. customUserList: UserList[];
  127. }
  128. const ruleForm = reactive<RuleForm>({
  129. userGroupList: [],
  130. customUserList: [],
  131. });
  132. const props = defineProps<{
  133. recipientType?: number;
  134. userGroupList?: userGroupVOList[];
  135. customUserList?: customUserList[];
  136. disabled?: boolean;
  137. }>();
  138. interface Options {
  139. userGroupId?: number;
  140. name?: string;
  141. description: string;
  142. total: number;
  143. operatorName: string;
  144. operationTime: string;
  145. }
  146. const options = ref<Options[]>([]);
  147. const userGroupInfo = ref<GroupData[]>();
  148. const queryGroupInfo = (groupList) => {
  149. groupInfo.value = true;
  150. queryUserGroupDetail(groupList).then((res) => {
  151. userGroupInfo.value = res.map((group) => ({
  152. ...group,
  153. isExpand: false,
  154. isHidden: false,
  155. }));
  156. });
  157. };
  158. const submitForm = () => {
  159. return ruleFormRef.value!.validate(() => {});
  160. };
  161. const getChildValue = () => {
  162. return {
  163. recipientType: ruleForm.recipientType,
  164. userGroupList:
  165. ruleForm.recipientType === 3
  166. ? []
  167. : ruleForm.recipientType === 1
  168. ? []
  169. : ruleForm.userGroupList.map((item) => item),
  170. customUserList:
  171. ruleForm.recipientType === 2
  172. ? []
  173. : ruleForm.recipientType === 1
  174. ? []
  175. : ruleForm.customUserList.map((item) => item.userId),
  176. };
  177. };
  178. const handleCancle = () => {
  179. userInfo.value = false;
  180. };
  181. const handleSubmit = (selectedData: UserList[]) => {
  182. selectedUser.value = selectedData;
  183. ruleForm.customUserList = selectedUser.value;
  184. userInfo.value = false;
  185. };
  186. const formatCustomUserList = (customList: customUserList[]): UserList[] => {
  187. return customList.map((item) => ({
  188. id: `u${item.userId}`,
  189. userId: item.userId,
  190. name: `${item.userLoginName}-${item.userNickname}`,
  191. }));
  192. };
  193. defineExpose({
  194. submitForm,
  195. getChildValue,
  196. });
  197. onMounted(() => {
  198. ToPushObjectqueryUserGroupList().then((res) => {
  199. options.value = res.groupVOList;
  200. });
  201. });
  202. watchEffect(() => {
  203. if (props.recipientType) {
  204. ruleForm.recipientType = props.recipientType;
  205. }
  206. if (props.userGroupList) {
  207. ruleForm.userGroupList = props.userGroupList.map((item) => item.userGroupId);
  208. }
  209. if (props.customUserList) {
  210. ruleForm.customUserList = formatCustomUserList(props.customUserList);
  211. selectedUser.value = formatCustomUserList(props.customUserList);
  212. }
  213. if (props.disabled) {
  214. disabled.value = props.disabled;
  215. }
  216. });
  217. watch(
  218. () => ruleForm.customUserList,
  219. (newSelected) => {
  220. selectedUser.value = newSelected;
  221. },
  222. { immediate: true },
  223. );
  224. </script>
  225. <style lang="scss" scoped>
  226. .userGroupList {
  227. margin-left: 12%;
  228. width: 88%;
  229. max-height: 120px;
  230. padding: 12px 17px 12px 12px;
  231. background: #fafafa;
  232. border-radius: 4px;
  233. :deep(.el-form-item) {
  234. margin-bottom: 12px !important;
  235. }
  236. ::v-deep .el-select__selection {
  237. min-height: 25px;
  238. max-height: 60px;
  239. overflow-y: auto;
  240. }
  241. span {
  242. cursor: pointer;
  243. margin-left: 80px;
  244. font-weight: 400;
  245. font-size: 10px;
  246. color: #1777ff;
  247. line-height: 14px;
  248. }
  249. }
  250. .customUserList {
  251. margin-left: 12%;
  252. width: 88%;
  253. max-height: 120px;
  254. padding: 12px 17px 12px 12px;
  255. background: #fafafa;
  256. border-radius: 4px;
  257. :deep(.el-form-item) {
  258. margin-bottom: 12px !important;
  259. }
  260. ::v-deep .el-select__selection {
  261. min-height: 25px;
  262. max-height: 60px;
  263. overflow-y: auto;
  264. }
  265. }
  266. </style>