cast-item.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import { Cell, Checkbox, CheckboxGroup, Icon, Image } from 'vant';
  2. import {
  3. PropType,
  4. defineComponent,
  5. onMounted,
  6. reactive,
  7. ref,
  8. watch
  9. } from 'vue';
  10. import styles from '../index.module.less';
  11. // import class1 from '../images/1.png';
  12. import activeButtonIcon from '@/common/images/icon-check-active.png';
  13. import inactiveButtonIcon from '@/common/images/icon-check.png';
  14. import iconStudent from '@/common/images/icon-student-default.png';
  15. export default defineComponent({
  16. name: 'group-chat',
  17. props: {
  18. type: {
  19. type: String as PropType<'edit' | 'look'>,
  20. default: 'edit'
  21. },
  22. height: {
  23. type: [Number],
  24. default: 0
  25. },
  26. bottomHeight: {
  27. type: [String, Number],
  28. default: 0
  29. },
  30. headerHeight: {
  31. type: [Number],
  32. default: 0
  33. },
  34. studentList: {
  35. type: Array,
  36. default: () => []
  37. },
  38. selectItem: {
  39. type: Array,
  40. default: () => []
  41. }
  42. },
  43. emits: ['update:selectItem'],
  44. setup(props, { emit }) {
  45. const checkboxRefs = ref([] as any);
  46. const forms = reactive({
  47. height: props.height,
  48. check: [] as any
  49. });
  50. const onToggle = (index: number) => {
  51. if (props.type === 'look') return;
  52. //
  53. checkboxRefs.value[index].toggle();
  54. const list: any = [];
  55. props.studentList.forEach((item: any) => {
  56. if (forms.check.includes(item.studentId)) {
  57. list.push({
  58. studentId: item.studentId,
  59. studentName: item.studentName,
  60. studentAvatar: item.studentAvatar,
  61. subjectId: item.subjectId
  62. });
  63. }
  64. });
  65. emit('update:selectItem', list);
  66. };
  67. watch(
  68. () => props.height,
  69. () => {
  70. forms.height = props.height;
  71. // console.log(forms.height);
  72. }
  73. );
  74. watch(
  75. () => props.selectItem,
  76. () => {
  77. initSelectItem();
  78. },
  79. { deep: true }
  80. );
  81. const initSelectItem = () => {
  82. const selectItem = props.selectItem || [];
  83. const temp: any = [];
  84. // console.log(selectItem, 'selectItem');
  85. selectItem.forEach((item: any) => {
  86. temp.push(item.studentId);
  87. });
  88. forms.check = temp;
  89. };
  90. onMounted(async () => {
  91. initSelectItem();
  92. });
  93. return () => (
  94. <div
  95. style={{
  96. 'min-height': `calc(100vh - ${props.headerHeight}px - ${forms.height}px - ${props.bottomHeight}px )`
  97. }}>
  98. <CheckboxGroup v-model={forms.check}>
  99. {props.studentList.map((item: any, index: number) => (
  100. <Cell
  101. center
  102. onClick={() => onToggle(index)}
  103. class={styles.popupCell}>
  104. {{
  105. icon: () => (
  106. <Image
  107. src={item.studentAvatar || iconStudent}
  108. class={styles.imgLogo}
  109. fit="contain"
  110. />
  111. ),
  112. title: () => (
  113. <div class={styles.infos}>
  114. <div class={styles.infoTitle}>{item.studentName}</div>
  115. <div class={styles.infoContent}>{item.subjectName}</div>
  116. </div>
  117. ),
  118. 'right-icon': () =>
  119. props.type === 'edit' && (
  120. <Checkbox
  121. name={item.studentId}
  122. ref={e => (checkboxRefs.value[index] = e)}
  123. onClick={(e: MouseEvent) => {
  124. e.stopPropagation();
  125. }}
  126. v-slots={{
  127. icon: (props: any) => (
  128. <Icon
  129. class={styles.boxStyle}
  130. name={
  131. props.checked
  132. ? activeButtonIcon
  133. : inactiveButtonIcon
  134. }
  135. />
  136. )
  137. }}
  138. />
  139. )
  140. }}
  141. </Cell>
  142. ))}
  143. </CheckboxGroup>
  144. </div>
  145. );
  146. }
  147. });