student-item.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. import { defineComponent, reactive, ref, watch } from 'vue'
  2. import styles from './student-item.module.less'
  3. import defaultIcon from '@/school/images/student-icon.png'
  4. import msgIcon from '@/school/images/msg-icon.png'
  5. import sendmsgIcon from '@/school/images/sendmsg-icon.png'
  6. import phoneIcon from '@/school/images/phone-icon.png'
  7. import { postMessage } from '@/helpers/native-message'
  8. import { Icon, ActionSheet, showToast } from 'vant'
  9. import { useRouter } from 'vue-router'
  10. const myForms = ref({}) as any
  11. export default defineComponent({
  12. props: ['item', 'forms'],
  13. name: 'student-item',
  14. setup(props) {
  15. const router = useRouter()
  16. const showContact = ref(false)
  17. const startContact = () => {
  18. showContact.value = true
  19. }
  20. const closeSheet = () => {
  21. showContact.value = false
  22. }
  23. watch(
  24. () => props.forms,
  25. (val) => {
  26. myForms.value = val
  27. },
  28. {
  29. deep: true
  30. }
  31. )
  32. const postMsg = async () => {
  33. try {
  34. await postMessage({
  35. api: 'joinChatGroup',
  36. content: {
  37. type: 'single', // single 单人 multi 多人
  38. id: props.item.imUserId
  39. }
  40. })
  41. closeSheet()
  42. } catch (e) {
  43. showToast('发起聊天失败')
  44. closeSheet()
  45. }
  46. }
  47. const callPhone = async () => {
  48. try {
  49. await postMessage({
  50. api: 'callPhone',
  51. content: {
  52. phone: props.item.phone
  53. }
  54. })
  55. closeSheet()
  56. } catch (e) {
  57. showToast('发起聊天失败')
  58. closeSheet()
  59. }
  60. }
  61. const gotoDetail = () => {
  62. console.log(myForms.value.practiceMonth, myForms.value.practiceMonthName)
  63. router.push({
  64. path: '/exercis-detail',
  65. query: {
  66. id: props.item.id,
  67. practiceMonth: myForms.value.practiceMonth,
  68. practiceMonthName: myForms.value.practiceMonthName
  69. }
  70. })
  71. }
  72. return () => (
  73. <>
  74. <div>
  75. <div class={styles.itemWrap} onClick={gotoDetail}>
  76. <div class={styles.itemTop}>
  77. <div class={styles.itemTopLeft}>
  78. <div class={styles.headIcon}>
  79. <img src={props.item.avatar ? props.item.avatar : defaultIcon} alt="" />
  80. </div>
  81. <p class={styles.name}>{props.item.nickname}</p>
  82. <div class={styles.tag}>{props.item.subjectNames}</div>
  83. </div>
  84. <div class={styles.itemTopRight}>
  85. <div
  86. class={styles.msgIcon}
  87. onClick={(e: any) => {
  88. e.stopPropagation()
  89. e.preventDefault()
  90. startContact()
  91. }}
  92. >
  93. <img src={msgIcon} alt="" />
  94. </div>
  95. </div>
  96. </div>
  97. <div class={styles.itemBottom}>
  98. <div class={styles.itemBottomLeft}>
  99. <p class={styles.msgMain}>
  100. {props.item.practiceDays ? props.item.practiceDays : 0} <span>天</span>
  101. </p>
  102. <p class={styles.msgsub}>练习天数</p>
  103. </div>
  104. <div class={styles.itemBottomRight}>
  105. <p class={styles.msgMain}>
  106. {props.item.practiceTimes ? props.item.practiceTimes : 0}
  107. <span>分钟</span>
  108. </p>
  109. <p class={styles.msgsub}>练习时长</p>
  110. <Icon class={styles.arrow} name="arrow"></Icon>
  111. </div>
  112. </div>
  113. </div>
  114. </div>
  115. <ActionSheet
  116. class="bottomSheet"
  117. v-model:show={showContact.value}
  118. v-slots={{
  119. description: () => (
  120. <div class={styles.bottomTitle}>
  121. <div class={styles.bottomTitleLeft}>
  122. <span></span>
  123. <p>联系方式</p>
  124. </div>
  125. <div
  126. class={styles.bottomTitleRight}
  127. onClick={(e: any) => {
  128. e.stopPropagation()
  129. e.preventDefault()
  130. closeSheet()
  131. }}
  132. >
  133. <Icon class={styles.cross} name="cross"></Icon>
  134. </div>
  135. </div>
  136. )
  137. }}
  138. >
  139. <div class={styles.bottomConent}>
  140. <div
  141. class={styles.bottomConentLeft}
  142. onClick={(e: any) => {
  143. e.stopPropagation()
  144. e.preventDefault()
  145. postMsg()
  146. }}
  147. >
  148. <div class={styles.bottomImgWrap}>
  149. <img src={sendmsgIcon} alt="" />
  150. </div>
  151. <p>发送消息</p>
  152. </div>
  153. <div
  154. class={styles.bottomConentRight}
  155. onClick={(e: any) => {
  156. e.stopPropagation()
  157. e.preventDefault()
  158. callPhone()
  159. }}
  160. >
  161. <div class={styles.bottomImgWrap}>
  162. <img src={phoneIcon} alt="" />
  163. </div>
  164. <p>拨打电话</p>
  165. </div>
  166. </div>
  167. </ActionSheet>
  168. </>
  169. )
  170. }
  171. })