index.tsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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. enableFlag: true
  88. }
  89. })
  90. // console.log(data, 'data')
  91. const temp = data.rows || []
  92. temp.forEach((row: any) => {
  93. form.subjectList.push({
  94. text: row.subjectName,
  95. value: row.subjectId
  96. })
  97. })
  98. } catch {
  99. //
  100. }
  101. }
  102. const getList = async () => {
  103. try {
  104. const res = await request.post('/api-school/teacher/page', {
  105. data: {
  106. ...form.params,
  107. schoolId: state.user.data.school.id
  108. }
  109. })
  110. form.listState.loading = false
  111. form.listState.refreshing = false
  112. const result = res.data || {}
  113. // 处理重复请求数据
  114. if (form.list.length > 0 && result.current === 1) {
  115. return
  116. }
  117. const rows = result.rows || []
  118. rows.forEach((item: any) => {
  119. item.subjectNames = item.subjectName ? item.subjectName.split(',') : []
  120. })
  121. form.list = form.list.concat(rows)
  122. form.listState.finished = result.current >= result.pages
  123. form.params.page = result.current + 1
  124. form.listState.dataShow = form.list.length > 0
  125. } catch {
  126. form.listState.dataShow = false
  127. form.listState.refreshing = false
  128. form.listState.finished = true
  129. }
  130. }
  131. const onSearch = () => {
  132. form.params.page = 1
  133. form.list = []
  134. form.listState.dataShow = true // 判断是否有数据
  135. form.listState.loading = false
  136. form.listState.finished = false
  137. getList()
  138. }
  139. // 详情
  140. const onDetail = (item: any) => {
  141. router.push({
  142. path: '/companion-teacher-detail',
  143. query: {
  144. id: item.id
  145. }
  146. })
  147. }
  148. // 选择声部
  149. const onConfirmSubject = (item: any) => {
  150. form.subjectText = item.selectedOptions[0].text
  151. form.params.subjectId =
  152. item.selectedOptions[0].value === 'ALL' ? null : item.selectedOptions[0].value
  153. form.showPopover = false
  154. onSearch()
  155. }
  156. onMounted(async () => {
  157. getSubjects()
  158. getList()
  159. // 处理返回上一页的问题
  160. window.history.pushState(null, '', document.URL)
  161. window.addEventListener('popstate', onBack, false)
  162. })
  163. const onBack = () => {
  164. postMessage({ api: 'back' })
  165. }
  166. onUnmounted(() => {
  167. window.removeEventListener('popstate', onBack)
  168. })
  169. return () => (
  170. <div class={!form.listState.dataShow && 'emptyRootContainer'}>
  171. <OSticky
  172. position="top"
  173. onGetHeight={(height: any) => {
  174. form.listState.height = height
  175. }}
  176. >
  177. <OHeader border={false}>
  178. {{
  179. right: () => (
  180. <Icon
  181. name="plus"
  182. size={19}
  183. onClick={() => {
  184. router.push({
  185. path: 'save-share-image',
  186. query: {
  187. type: 'teacher'
  188. }
  189. })
  190. }}
  191. />
  192. )
  193. }}
  194. </OHeader>
  195. <OSearch
  196. placeholder="请输入伴学老师姓名"
  197. // inputBackground="white"
  198. // background="#f6f8f9"
  199. class="searchGroupInput"
  200. onSearch={(val: any) => {
  201. form.params.keyword = val
  202. onSearch()
  203. }}
  204. />
  205. <div class={'searchGroup'}>
  206. <div
  207. class={['searchItem', form.showPopover && 'searchItem-active']}
  208. onClick={() => (form.showPopover = true)}
  209. >
  210. <span>{form.subjectText}</span>
  211. <i class="arrow"></i>
  212. </div>
  213. <div
  214. class={['searchItem', form.oPopover && 'searchItem-active']}
  215. onClick={() => (form.oPopover = true)}
  216. >
  217. <span>{form.statusText}</span>
  218. <i class="arrow"></i>
  219. </div>
  220. </div>
  221. </OSticky>
  222. {form.listState.dataShow ? (
  223. <OFullRefresh
  224. v-model:modelValue={form.listState.refreshing}
  225. onRefresh={onSearch}
  226. style={{
  227. minHeight: `calc(100vh - ${form.listState.height}px)`
  228. }}
  229. >
  230. <List
  231. // v-model:loading={form.listState.loading}
  232. finished={form.listState.finished}
  233. finishedText=" "
  234. class={[styles.liveList]}
  235. onLoad={getList}
  236. style={{ paddingTop: '12px' }}
  237. immediateCheck={false}
  238. >
  239. {form.list.map((item: any) => (
  240. <CellGroup inset style={{ marginBottom: '12px' }} onClick={() => onDetail(item)}>
  241. <Cell center isLink class={styles.manageCell} clickable={false}>
  242. {{
  243. icon: () => (
  244. <div class={styles.avatarContainer}>
  245. <Image
  246. class={styles.img}
  247. src={item.avatar ? item.avatar : iconTeacher}
  248. fit="cover"
  249. />
  250. {item.delFlag && (
  251. <Tag class={styles.avatarType} round color="#F44541" textColor="#fff">
  252. 解绑
  253. </Tag>
  254. )}
  255. </div>
  256. ),
  257. title: () => (
  258. <div class={styles.teacherContent}>
  259. <div class={styles.content}>
  260. <p class={[styles.name, 'van-ellipsis']}>{item.nickname}</p>
  261. </div>
  262. </div>
  263. ),
  264. value: () => (
  265. <div class={styles.teacherContent}>
  266. <div class={styles.classNum}>
  267. <p class={styles.num}>
  268. {item.completedCourseScheduleNum || 0}/
  269. {item.totalCourseScheduleNum || 0}
  270. </p>
  271. <p class={styles.numText}>课时</p>
  272. </div>
  273. <div
  274. class={styles.message}
  275. onClick={(e: any) => {
  276. e.stopPropagation()
  277. e.preventDefault()
  278. form.showMessage = true
  279. form.selectItem = item
  280. }}
  281. >
  282. <Image class={styles.messageImg} src={iconMessage} />
  283. </div>
  284. </div>
  285. )
  286. }}
  287. </Cell>
  288. <Cell center>
  289. {{
  290. title: () => (
  291. <div class={styles.subjectContainer}>
  292. <span>声部:</span>
  293. <div style={{ display: 'flex', alignItems: 'center', flexWrap: 'wrap' }}>
  294. {item.subjectNames &&
  295. item.subjectNames.length > 0 &&
  296. item.subjectNames.map((subject: any) => (
  297. <Tag
  298. type="primary"
  299. class={styles.tagSubject}
  300. color="#FFE7DA"
  301. textColor="#F67146"
  302. >
  303. {subject}
  304. </Tag>
  305. ))}
  306. </div>
  307. </div>
  308. )
  309. }}
  310. </Cell>
  311. </CellGroup>
  312. ))}
  313. </List>
  314. </OFullRefresh>
  315. ) : (
  316. <OEmpty btnStatus={false} tips="暂无伴学老师" />
  317. )}
  318. <Popup
  319. v-model:show={form.showMessage}
  320. position="bottom"
  321. style={{ background: 'transparent' }}
  322. >
  323. <div class={styles.codeContainer}>
  324. <div class={styles.codeBottom}>
  325. <Icon
  326. name="cross"
  327. size={22}
  328. class={styles.close}
  329. color="#666"
  330. onClick={() => (form.showMessage = false)}
  331. />
  332. <h3 class={styles.title}>
  333. <i></i>联系方式
  334. </h3>
  335. <Grid columnNum={2} border={false}>
  336. <GridItem
  337. onClick={() => {
  338. postMessage({
  339. api: 'joinChatGroup',
  340. content: {
  341. type: 'single', // single 单人 multi 多人
  342. id: form.selectItem.imUserId
  343. }
  344. })
  345. form.showMessage = false
  346. }}
  347. >
  348. {{
  349. icon: () => <Image class={styles.shareImg} src={iconCallMessage} />,
  350. text: () => <div class={styles.shareText}>发送消息</div>
  351. }}
  352. </GridItem>
  353. <GridItem
  354. onClick={() => {
  355. postMessage({
  356. api: 'callPhone',
  357. content: {
  358. phone: form.selectItem.phone
  359. }
  360. })
  361. form.showMessage = false
  362. }}
  363. >
  364. {{
  365. icon: () => <Image class={styles.shareImg} src={iconCallPhone} />,
  366. text: () => <div class={styles.shareText}>拨打电话</div>
  367. }}
  368. </GridItem>
  369. </Grid>
  370. </div>
  371. </div>
  372. </Popup>
  373. <OActionSheet
  374. v-model:show={form.oPopover}
  375. actions={form.action}
  376. onSelect={(val: any) => {
  377. form.action.forEach((child: any) => {
  378. child.selected = false
  379. })
  380. val.selected = true
  381. form.statusText = val.name
  382. form.params.delFlag = val.id === 'ALL' ? null : val.id
  383. form.oPopover = false
  384. onSearch()
  385. }}
  386. />
  387. <Popup v-model:show={form.showPopover} round position="bottom" class={'popupBottomSearch'}>
  388. <Picker
  389. columns={form.subjectList}
  390. onCancel={() => (form.showPopover = false)}
  391. onConfirm={(item: any) => onConfirmSubject(item)}
  392. />
  393. </Popup>
  394. </div>
  395. )
  396. }
  397. })