contacts.tsx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. import { Cell, Checkbox, CheckboxGroup, Icon, Image, Sticky } from 'vant';
  2. import { defineComponent, onMounted, reactive, ref, watch } from 'vue';
  3. import styles from '../index.module.less';
  4. import badge1 from '../images/badge-1.png';
  5. import badge2 from '../images/badge-2.png';
  6. import badge3 from '../images/badge-3.png';
  7. import badge4 from '../images/badge-4.png';
  8. import badge5 from '../images/badge-5.png';
  9. import badge6 from '../images/badge-6.png';
  10. import badge7 from '../images/badge-7.png';
  11. import badge8 from '../images/badge-8.png';
  12. import MSearch from '@/components/m-search';
  13. import activeButtonIcon from '@/common/images/icon-check-active.png';
  14. import inactiveButtonIcon from '@/common/images/icon-check.png';
  15. import iconStudent from '@/common/images/icon-student-default.png';
  16. import iconTeacher from '@/common/images/icon-teacher-default.png';
  17. import request from '@/helpers/request';
  18. import MEmpty from '@/components/m-empty';
  19. export const formatterImage = (type: string) => {
  20. let image: any = badge3;
  21. switch (type) {
  22. case 'SCHOOLMASTER':
  23. image = badge5;
  24. break;
  25. case 'ORCHESTRA_LEADER':
  26. image = badge1;
  27. break;
  28. case 'SCHOOL_LEADER':
  29. image = badge6;
  30. break;
  31. case 'SCHOOL_TEACHER':
  32. image = badge7;
  33. break;
  34. case 'ORCHESTRA_MANAGER':
  35. image = badge4;
  36. break;
  37. case 'ORCHESTRA_TEACHER':
  38. image = badge2;
  39. break;
  40. case 'MAINTENANCE_TECHNICIAN':
  41. image = badge8;
  42. break;
  43. case 'STUDENT':
  44. image = badge3;
  45. break;
  46. }
  47. return image;
  48. };
  49. export default defineComponent({
  50. name: 'contacts-modal',
  51. props: {
  52. height: {
  53. type: [Number],
  54. default: 0
  55. },
  56. bottomHeight: {
  57. type: [String, Number],
  58. default: 0
  59. },
  60. headerHeight: {
  61. type: [Number],
  62. default: 0
  63. },
  64. selectItem: {
  65. type: Array,
  66. default: () => []
  67. }
  68. },
  69. emits: ['update:selectItem'],
  70. setup(props, { emit }) {
  71. const checkboxRefs = ref([] as any);
  72. const forms = reactive({
  73. height: props.height,
  74. list: [],
  75. check: [] as any,
  76. dataShow: true
  77. });
  78. const onToggle = (index: number) => {
  79. //
  80. checkboxRefs.value[index].toggle();
  81. const list: any = [];
  82. forms.list.forEach((item: any) => {
  83. if (forms.check.includes(item.id)) {
  84. list.push({
  85. id: item.id,
  86. value: item.friendNickname,
  87. text: item.memo,
  88. roleType: item.roleType,
  89. avatar:
  90. item.friend.avatar || item.friend.userType === 'TEACHER'
  91. ? iconTeacher
  92. : iconStudent
  93. });
  94. }
  95. });
  96. emit('update:selectItem', list);
  97. };
  98. watch(
  99. () => props.height,
  100. () => {
  101. forms.height = props.height;
  102. }
  103. );
  104. watch(
  105. () => props.selectItem,
  106. () => {
  107. initSelectItem();
  108. },
  109. { deep: true }
  110. );
  111. const initSelectItem = () => {
  112. const selectItem = props.selectItem || [];
  113. const temp: any = [];
  114. selectItem.forEach((item: any) => {
  115. temp.push(item.id);
  116. });
  117. forms.check = temp;
  118. };
  119. const getList = async () => {
  120. try {
  121. const { data } = await request.post(
  122. '/api-web/imGroup/schoolQueryFriendList'
  123. );
  124. forms.list = data || [];
  125. } catch {
  126. //
  127. } finally {
  128. forms.dataShow = forms.list.length > 0 ? true : false;
  129. }
  130. };
  131. onMounted(() => {
  132. getList();
  133. });
  134. return () => (
  135. <div
  136. style={{
  137. 'min-height': `calc(100vh - ${props.headerHeight}px - ${forms.height}px - ${props.bottomHeight}px )`
  138. }}>
  139. <Sticky
  140. position="top"
  141. offsetTop={props.headerHeight + forms.height}
  142. style={{ width: '100%' }}>
  143. <MSearch placeholder="请输入群聊名称" />
  144. </Sticky>
  145. <CheckboxGroup v-model={forms.check}>
  146. {forms.dataShow ? (
  147. forms.list.map((item: any, index: number) => (
  148. <Cell
  149. center
  150. onClick={() => onToggle(index)}
  151. class={styles.popupCell}>
  152. {{
  153. icon: () => (
  154. <Image
  155. src={
  156. item.friend.avatar || item.friend.userType === 'TEACHER'
  157. ? iconTeacher
  158. : iconStudent
  159. }
  160. class={styles.imgLogo}
  161. fit="contain"
  162. />
  163. ),
  164. title: () => (
  165. <div class={styles.infos}>
  166. <div class={styles.infoTitle}>
  167. {item.friendNickname}
  168. <img
  169. src={formatterImage(item.roleType)}
  170. class={[
  171. styles.iconBadge,
  172. item.roleType === 'SCHOOL_LEADER'
  173. ? styles.iconBadge2
  174. : ''
  175. ]}
  176. />
  177. </div>
  178. <div class={styles.infoContent}>{item.memo}</div>
  179. </div>
  180. ),
  181. 'right-icon': () => (
  182. <Checkbox
  183. name={item.id}
  184. ref={e => (checkboxRefs.value[index] = e)}
  185. onClick={(e: MouseEvent) => {
  186. e.stopPropagation();
  187. }}
  188. v-slots={{
  189. icon: (props: any) => (
  190. <Icon
  191. class={styles.boxStyle}
  192. name={
  193. props.checked
  194. ? activeButtonIcon
  195. : inactiveButtonIcon
  196. }
  197. />
  198. )
  199. }}
  200. />
  201. )
  202. }}
  203. </Cell>
  204. ))
  205. ) : (
  206. <MEmpty
  207. style={{
  208. minHeight: `calc(100vh - ${props.headerHeight}px - ${forms.height}px - ${props.bottomHeight}px - 100px)`
  209. }}
  210. description="暂无数据"
  211. />
  212. )}
  213. </CheckboxGroup>
  214. </div>
  215. );
  216. }
  217. });