index.tsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. import OHeader from '@/components/o-header'
  2. import OQrcode from '@/components/o-qrcode'
  3. import OSearch from '@/components/o-search'
  4. import OSticky from '@/components/o-sticky'
  5. import {
  6. ActionSheet,
  7. Cell,
  8. CellGroup,
  9. closeToast,
  10. Grid,
  11. GridItem,
  12. Icon,
  13. Image,
  14. List,
  15. Picker,
  16. Popup,
  17. showFailToast,
  18. showLoadingToast,
  19. showSuccessToast,
  20. showToast,
  21. Tag
  22. } from 'vant'
  23. import { defineComponent, onMounted, onUnmounted, reactive } from 'vue'
  24. import styles from './index.module.less'
  25. import iconSaveImage from '@/school/orchestra/images/icon-save-image.png'
  26. import iconWechat from '@/school/orchestra/images/icon-wechat.png'
  27. import iconCallPhone from '@common/images/icon-call-phone.png'
  28. import iconCallMessage from '@common/images/icon-call-message.png'
  29. import iconTeacher from '@common/images/icon_teacher.png'
  30. import iconMessage from '@common/images/icon-message.png'
  31. import { useRouter } from 'vue-router'
  32. import request from '@/helpers/request'
  33. import { state } from '@/state'
  34. import OEmpty from '@/components/o-empty'
  35. import { manageTeacherType } from '@/constant'
  36. import { postMessage, promisefiyPostMessage } from '@/helpers/native-message'
  37. import html2canvas from 'html2canvas'
  38. import { forms } from '../train-planning/create'
  39. import OFullRefresh from '@/components/o-full-refresh'
  40. import { format } from 'path'
  41. import OActionSheet from '@/components/o-action-sheet'
  42. export default defineComponent({
  43. name: 'companion-teacher',
  44. setup() {
  45. const router = useRouter()
  46. const form = reactive({
  47. showMessage: false,
  48. showPopover: false,
  49. oPopover: false,
  50. subjectList: [{ text: '全部声部', value: 'ALL' }] as any,
  51. action: [
  52. {
  53. name: '解绑',
  54. id: true
  55. },
  56. {
  57. name: '绑定',
  58. id: false,
  59. selected: true
  60. }
  61. ],
  62. list: [] as any,
  63. listState: {
  64. dataShow: true, // 判断是否有数据
  65. loading: false,
  66. finished: false,
  67. refreshing: false,
  68. height: 0 // 页面头部高度,为了处理下拉刷新用的
  69. },
  70. subjectText: '全部声部',
  71. statusText: '绑定',
  72. params: {
  73. keyword: null,
  74. delFlag: false,
  75. subjectId: null,
  76. page: 1,
  77. rows: 20
  78. },
  79. selectItem: {} as any
  80. })
  81. const getSubjects = async () => {
  82. try {
  83. const { data } = await request.post('/api-school/subjectBasicConfig/page', {
  84. data: {
  85. page: 1,
  86. rows: 50
  87. }
  88. })
  89. // console.log(data, 'data')
  90. const temp = data.rows || []
  91. temp.forEach((row: any) => {
  92. form.subjectList.push({
  93. text: row.subjectName,
  94. value: row.subjectId
  95. })
  96. })
  97. } catch {
  98. //
  99. }
  100. }
  101. const getList = async () => {
  102. try {
  103. const res = await request.post('/api-school/teacher/page', {
  104. data: {
  105. ...form.params,
  106. schoolId: state.user.data.school.id
  107. }
  108. })
  109. form.listState.loading = false
  110. form.listState.refreshing = false
  111. const result = res.data || {}
  112. // 处理重复请求数据
  113. if (form.list.length > 0 && result.current === 1) {
  114. return
  115. }
  116. const rows = result.rows || []
  117. rows.forEach((item: any) => {
  118. item.subjectNames = item.subjectName ? item.subjectName.split(',') : []
  119. })
  120. form.list = form.list.concat(rows)
  121. form.listState.finished = result.current >= result.pages
  122. form.params.page = result.current + 1
  123. form.listState.dataShow = form.list.length > 0
  124. } catch {
  125. form.listState.dataShow = false
  126. form.listState.refreshing = false
  127. form.listState.finished = true
  128. }
  129. }
  130. const onSearch = () => {
  131. form.params.page = 1
  132. form.list = []
  133. form.listState.dataShow = true // 判断是否有数据
  134. form.listState.loading = false
  135. form.listState.finished = false
  136. getList()
  137. }
  138. // 详情
  139. const onDetail = (item: any) => {
  140. router.push({
  141. path: '/companion-teacher-detail',
  142. query: {
  143. id: item.id
  144. }
  145. })
  146. }
  147. // 选择声部
  148. const onConfirmSubject = (item: any) => {
  149. form.subjectText = item.selectedOptions[0].text
  150. form.params.subjectId =
  151. item.selectedOptions[0].value === 'ALL' ? null : item.selectedOptions[0].value
  152. form.showPopover = false
  153. onSearch()
  154. }
  155. onMounted(async () => {
  156. getSubjects()
  157. getList()
  158. // 处理返回上一页的问题
  159. window.history.pushState(null, '', document.URL)
  160. window.addEventListener('popstate', onBack, false)
  161. })
  162. const onBack = () => {
  163. postMessage({ api: 'back' })
  164. }
  165. onUnmounted(() => {
  166. window.removeEventListener('popstate', onBack)
  167. })
  168. return () => (
  169. <div class={!form.listState.dataShow && 'emptyRootContainer'}>
  170. <OSticky
  171. position="top"
  172. onGetHeight={(height: any) => {
  173. form.listState.height = height
  174. }}
  175. >
  176. <OHeader border={false}>
  177. {{
  178. right: () => (
  179. <Icon
  180. name="plus"
  181. size={19}
  182. onClick={() => {
  183. router.push({
  184. path: 'save-share-image',
  185. query: {
  186. type: 'teacher'
  187. }
  188. })
  189. }}
  190. />
  191. )
  192. }}
  193. </OHeader>
  194. <OSearch
  195. placeholder="请输入伴学指导姓名"
  196. // inputBackground="white"
  197. // background="#f6f8f9"
  198. class="searchGroupInput"
  199. onSearch={(val: any) => {
  200. form.params.keyword = val
  201. onSearch()
  202. }}
  203. />
  204. <div class={'searchGroup'}>
  205. <div
  206. class={['searchItem', form.showPopover && 'searchItem-active']}
  207. onClick={() => (form.showPopover = true)}
  208. >
  209. <span>{form.subjectText}</span>
  210. <i class="arrow"></i>
  211. </div>
  212. <div
  213. class={['searchItem', form.oPopover && 'searchItem-active']}
  214. onClick={() => (form.oPopover = true)}
  215. >
  216. <span>{form.statusText}</span>
  217. <i class="arrow"></i>
  218. </div>
  219. </div>
  220. </OSticky>
  221. {form.listState.dataShow ? (
  222. <OFullRefresh
  223. v-model:modelValue={form.listState.refreshing}
  224. onRefresh={onSearch}
  225. style={{
  226. minHeight: `calc(100vh - ${form.listState.height}px)`
  227. }}
  228. >
  229. <List
  230. // v-model:loading={form.listState.loading}
  231. finished={form.listState.finished}
  232. finishedText=" "
  233. class={[styles.liveList]}
  234. onLoad={getList}
  235. style={{ paddingTop: '12px' }}
  236. immediateCheck={false}
  237. >
  238. {form.list.map((item: any) => (
  239. <CellGroup inset style={{ marginBottom: '12px' }} onClick={() => onDetail(item)}>
  240. <Cell center isLink class={styles.manageCell} clickable={false}>
  241. {{
  242. icon: () => (
  243. <div class={styles.avatarContainer}>
  244. <Image
  245. class={styles.img}
  246. src={item.avatar ? item.avatar : iconTeacher}
  247. fit="cover"
  248. />
  249. {item.delFlag && (
  250. <Tag class={styles.avatarType} round color="#F44541" textColor="#fff">
  251. 解绑
  252. </Tag>
  253. )}
  254. </div>
  255. ),
  256. title: () => (
  257. <div class={styles.teacherContent}>
  258. <div class={styles.content}>
  259. <p class={[styles.name, 'van-ellipsis']}>{item.nickname}</p>
  260. </div>
  261. </div>
  262. ),
  263. value: () => (
  264. <div class={styles.teacherContent}>
  265. <div class={styles.classNum}>
  266. <p class={styles.num}>
  267. {item.completedCourseScheduleNum || 0}/
  268. {item.totalCourseScheduleNum || 0}
  269. </p>
  270. <p class={styles.numText}>课时</p>
  271. </div>
  272. <div
  273. class={styles.message}
  274. onClick={(e: any) => {
  275. e.stopPropagation()
  276. e.preventDefault()
  277. form.showMessage = true
  278. form.selectItem = item
  279. }}
  280. >
  281. <Image class={styles.messageImg} src={iconMessage} />
  282. </div>
  283. </div>
  284. )
  285. }}
  286. </Cell>
  287. <Cell center>
  288. {{
  289. title: () => (
  290. <div class={styles.subjectContainer}>
  291. <span>声部:</span>
  292. <div style={{ display: 'flex', alignItems: 'center', flexWrap: 'wrap' }}>
  293. {item.subjectNames &&
  294. item.subjectNames.length > 0 &&
  295. item.subjectNames.map((subject: any) => (
  296. <Tag
  297. type="primary"
  298. class={styles.tagSubject}
  299. color="#FFE7DA"
  300. textColor="#F67146"
  301. >
  302. {subject}
  303. </Tag>
  304. ))}
  305. </div>
  306. </div>
  307. )
  308. }}
  309. </Cell>
  310. </CellGroup>
  311. ))}
  312. </List>
  313. </OFullRefresh>
  314. ) : (
  315. <OEmpty btnStatus={false} tips="暂无伴学指导" />
  316. )}
  317. <Popup
  318. v-model:show={form.showMessage}
  319. position="bottom"
  320. style={{ background: 'transparent' }}
  321. >
  322. <div class={styles.codeContainer}>
  323. <div class={styles.codeBottom}>
  324. <Icon
  325. name="cross"
  326. size={22}
  327. class={styles.close}
  328. color="#666"
  329. onClick={() => (form.showMessage = false)}
  330. />
  331. <h3 class={styles.title}>
  332. <i></i>联系方式
  333. </h3>
  334. <Grid columnNum={2} border={false}>
  335. <GridItem
  336. onClick={() => {
  337. postMessage({
  338. api: 'joinChatGroup',
  339. content: {
  340. type: 'single', // single 单人 multi 多人
  341. id: form.selectItem.imUserId
  342. }
  343. })
  344. form.showMessage = false
  345. }}
  346. >
  347. {{
  348. icon: () => <Image class={styles.shareImg} src={iconCallMessage} />,
  349. text: () => <div class={styles.shareText}>发送消息</div>
  350. }}
  351. </GridItem>
  352. <GridItem
  353. onClick={() => {
  354. postMessage({
  355. api: 'callPhone',
  356. content: {
  357. phone: form.selectItem.phone
  358. }
  359. })
  360. form.showMessage = false
  361. }}
  362. >
  363. {{
  364. icon: () => <Image class={styles.shareImg} src={iconCallPhone} />,
  365. text: () => <div class={styles.shareText}>拨打电话</div>
  366. }}
  367. </GridItem>
  368. </Grid>
  369. </div>
  370. </div>
  371. </Popup>
  372. <OActionSheet
  373. v-model:show={form.oPopover}
  374. actions={form.action}
  375. onSelect={(val: any) => {
  376. form.action.forEach((child: any) => {
  377. child.selected = false
  378. })
  379. val.selected = true
  380. form.statusText = val.name
  381. form.params.delFlag = val.id === 'ALL' ? null : val.id
  382. form.oPopover = false
  383. onSearch()
  384. }}
  385. />
  386. <Popup v-model:show={form.showPopover} round position="bottom" class={'popupBottomSearch'}>
  387. <Picker
  388. columns={form.subjectList}
  389. onCancel={() => (form.showPopover = false)}
  390. onConfirm={(item: any) => onConfirmSubject(item)}
  391. />
  392. </Popup>
  393. </div>
  394. )
  395. }
  396. })