group-chat.tsx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 class1 from '../images/ic_group_list_mussic_team_stu.png';
  5. import class2 from '../images/ic_group_list_vip.png';
  6. import class3 from '../images/icon_repertoire_play.png';
  7. import class4 from '../images/icon_training.png';
  8. import class5 from '../images/icon-edu.png';
  9. import MSearch from '@/components/m-search';
  10. import activeButtonIcon from '@/common/images/icon-check-active.png';
  11. import inactiveButtonIcon from '@/common/images/icon-check.png';
  12. import request from '@/helpers/request';
  13. import MEmpty from '@/components/m-empty';
  14. export default defineComponent({
  15. name: 'group-chat',
  16. props: {
  17. height: {
  18. type: [Number],
  19. default: 0
  20. },
  21. bottomHeight: {
  22. type: [String, Number],
  23. default: 0
  24. },
  25. headerHeight: {
  26. type: [Number],
  27. default: 0
  28. },
  29. selectItem: {
  30. type: Array,
  31. default: () => []
  32. }
  33. },
  34. emits: ['update:selectItem'],
  35. setup(props, { emit }) {
  36. const checkboxRefs = ref([] as any);
  37. const forms = reactive({
  38. keyword: '',
  39. height: props.height,
  40. list: [],
  41. check: [] as any,
  42. dataShow: true
  43. });
  44. const formatterImage = (type: string) => {
  45. if (type === 'TRAINING') {
  46. return class4;
  47. } else if (type === 'REPERTOIRE_PLAY') {
  48. return class3;
  49. } else if (type === 'VIP' || type === 'COMM') {
  50. return class2;
  51. } else if (type === 'SCHOOL') {
  52. return class5;
  53. } else {
  54. return class1;
  55. }
  56. };
  57. const onToggle = (index: number) => {
  58. //
  59. checkboxRefs.value[index].toggle();
  60. const list: any = [];
  61. forms.list.forEach((item: any) => {
  62. if (forms.check.includes(item.id)) {
  63. list.push({
  64. id: item.id,
  65. value: item.name,
  66. text: item.tags,
  67. avatar: item.img || formatterImage(item.type)
  68. });
  69. }
  70. });
  71. emit('update:selectItem', list);
  72. };
  73. watch(
  74. () => props.height,
  75. () => {
  76. forms.height = props.height;
  77. // console.log(forms.height);
  78. }
  79. );
  80. watch(
  81. () => props.selectItem,
  82. () => {
  83. initSelectItem();
  84. },
  85. { deep: true }
  86. );
  87. const initSelectItem = () => {
  88. const selectItem = props.selectItem || [];
  89. const temp: any = [];
  90. selectItem.forEach((item: any) => {
  91. temp.push(item.id);
  92. });
  93. forms.check = temp;
  94. };
  95. const getList = async () => {
  96. try {
  97. const { data } = await request.post(
  98. '/api-web/imGroup/schoolQueryGroupList',
  99. {
  100. data: {
  101. keyword: forms.keyword
  102. }
  103. }
  104. );
  105. forms.list = data || [];
  106. } catch {
  107. //
  108. } finally {
  109. forms.dataShow = forms.list.length > 0 ? true : false;
  110. }
  111. };
  112. onMounted(() => {
  113. getList();
  114. });
  115. return () => (
  116. <div
  117. style={{
  118. 'min-height': `calc(100vh - ${props.headerHeight}px - ${forms.height}px - ${props.bottomHeight}px )`
  119. }}>
  120. <Sticky
  121. position="top"
  122. offsetTop={props.headerHeight + forms.height}
  123. style={{ width: '100%' }}>
  124. <MSearch
  125. placeholder="请输入群聊名称"
  126. onSearch={async (val: string) => {
  127. forms.keyword = val;
  128. forms.dataShow = true;
  129. await getList();
  130. }}
  131. />
  132. </Sticky>
  133. <CheckboxGroup v-model={forms.check}>
  134. {forms.dataShow ? (
  135. forms.list.map((item: any, index: number) => (
  136. <Cell
  137. center
  138. onClick={() => onToggle(index)}
  139. class={styles.popupCell}>
  140. {{
  141. icon: () => (
  142. <Image
  143. src={item.img || formatterImage(item.type)}
  144. class={styles.imgLogo}
  145. fit="cover"
  146. />
  147. ),
  148. title: () => (
  149. <div class={styles.infos}>
  150. <div class={styles.infoTitle}>{item.name}</div>
  151. <div class={styles.infoContent}>{item.tags}</div>
  152. </div>
  153. ),
  154. 'right-icon': () => (
  155. <Checkbox
  156. name={item.id}
  157. ref={e => (checkboxRefs.value[index] = e)}
  158. onClick={(e: MouseEvent) => {
  159. e.preventDefault();
  160. e.stopPropagation();
  161. onToggle(index);
  162. }}
  163. v-slots={{
  164. icon: (props: any) => (
  165. <Icon
  166. class={styles.boxStyle}
  167. name={
  168. props.checked
  169. ? activeButtonIcon
  170. : inactiveButtonIcon
  171. }
  172. />
  173. )
  174. }}
  175. />
  176. )
  177. }}
  178. </Cell>
  179. ))
  180. ) : (
  181. <MEmpty
  182. style={{
  183. minHeight: `calc(100vh - ${props.headerHeight}px - ${forms.height}px - ${props.bottomHeight}px - 100px)`
  184. }}
  185. description="暂无数据"
  186. />
  187. )}
  188. </CheckboxGroup>
  189. </div>
  190. );
  191. }
  192. });