index.tsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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, 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. return () => (
  160. <div class={!form.listState.dataShow && 'emptyRootContainer'}>
  161. <OSticky
  162. position="top"
  163. onGetHeight={(height: any) => {
  164. form.listState.height = height
  165. }}
  166. >
  167. <OHeader border={false}>
  168. {{
  169. right: () => (
  170. <Icon
  171. name="plus"
  172. size={19}
  173. onClick={() => {
  174. router.push({
  175. path: 'save-share-image',
  176. query: {
  177. type: 'teacher'
  178. }
  179. })
  180. }}
  181. />
  182. )
  183. }}
  184. </OHeader>
  185. <OSearch
  186. placeholder="请输入伴学指导姓名"
  187. // inputBackground="white"
  188. // background="#f6f8f9"
  189. class="searchGroupInput"
  190. onSearch={(val: any) => {
  191. form.params.keyword = val
  192. onSearch()
  193. }}
  194. />
  195. <div class={'searchGroup'}>
  196. <div
  197. class={['searchItem', form.showPopover && 'searchItem-active']}
  198. onClick={() => (form.showPopover = true)}
  199. >
  200. <span>{form.subjectText}</span>
  201. <i class="arrow"></i>
  202. </div>
  203. <div
  204. class={['searchItem', form.oPopover && 'searchItem-active']}
  205. onClick={() => (form.oPopover = true)}
  206. >
  207. <span>{form.statusText}</span>
  208. <i class="arrow"></i>
  209. </div>
  210. </div>
  211. </OSticky>
  212. {form.listState.dataShow ? (
  213. <OFullRefresh
  214. v-model:modelValue={form.listState.refreshing}
  215. onRefresh={onSearch}
  216. style={{
  217. minHeight: `calc(100vh - ${form.listState.height}px)`
  218. }}
  219. >
  220. <List
  221. // v-model:loading={form.listState.loading}
  222. finished={form.listState.finished}
  223. finishedText=" "
  224. class={[styles.liveList]}
  225. onLoad={getList}
  226. style={{ paddingTop: '12px' }}
  227. immediateCheck={false}
  228. >
  229. {form.list.map((item: any) => (
  230. <CellGroup inset style={{ marginBottom: '12px' }} onClick={() => onDetail(item)}>
  231. <Cell center isLink class={styles.manageCell} clickable={false}>
  232. {{
  233. icon: () => (
  234. <div class={styles.avatarContainer}>
  235. <Image
  236. class={styles.img}
  237. src={item.avatar ? item.avatar : iconTeacher}
  238. fit="cover"
  239. />
  240. {item.delFlag && (
  241. <Tag class={styles.avatarType} round color="#F44541" textColor="#fff">
  242. 解绑
  243. </Tag>
  244. )}
  245. </div>
  246. ),
  247. title: () => (
  248. <div class={styles.teacherContent}>
  249. <div class={styles.content}>
  250. <p class={[styles.name, 'van-ellipsis']}>{item.nickname}</p>
  251. </div>
  252. </div>
  253. ),
  254. value: () => (
  255. <div class={styles.teacherContent}>
  256. <div class={styles.classNum}>
  257. <p class={styles.num}>
  258. {item.completedCourseScheduleNum || 0}/
  259. {item.totalCourseScheduleNum || 0}
  260. </p>
  261. <p class={styles.numText}>课时</p>
  262. </div>
  263. <div
  264. class={styles.message}
  265. onClick={(e: any) => {
  266. e.stopPropagation()
  267. e.preventDefault()
  268. form.showMessage = true
  269. form.selectItem = item
  270. }}
  271. >
  272. <Image class={styles.messageImg} src={iconMessage} />
  273. </div>
  274. </div>
  275. )
  276. }}
  277. </Cell>
  278. <Cell center>
  279. {{
  280. title: () => (
  281. <div class={styles.subjectContainer}>
  282. <span>声部:</span>
  283. <div style={{ display: 'flex', alignItems: 'center', flexWrap: 'wrap' }}>
  284. {item.subjectNames &&
  285. item.subjectNames.length > 0 &&
  286. item.subjectNames.map((subject: any) => (
  287. <Tag
  288. type="primary"
  289. class={styles.tagSubject}
  290. color="#FFE7DA"
  291. textColor="#F67146"
  292. >
  293. {subject}
  294. </Tag>
  295. ))}
  296. </div>
  297. </div>
  298. )
  299. }}
  300. </Cell>
  301. </CellGroup>
  302. ))}
  303. </List>
  304. </OFullRefresh>
  305. ) : (
  306. <OEmpty btnStatus={false} tips="暂无伴学指导" />
  307. )}
  308. <Popup
  309. v-model:show={form.showMessage}
  310. position="bottom"
  311. style={{ background: 'transparent' }}
  312. >
  313. <div class={styles.codeContainer}>
  314. <div class={styles.codeBottom}>
  315. <Icon
  316. name="cross"
  317. size={22}
  318. class={styles.close}
  319. color="#666"
  320. onClick={() => (form.showMessage = false)}
  321. />
  322. <h3 class={styles.title}>
  323. <i></i>联系方式
  324. </h3>
  325. <Grid columnNum={2} border={false}>
  326. <GridItem
  327. onClick={() => {
  328. postMessage({
  329. api: 'joinChatGroup',
  330. content: {
  331. type: 'single', // single 单人 multi 多人
  332. id: form.selectItem.imUserId
  333. }
  334. })
  335. form.showMessage = false
  336. }}
  337. >
  338. {{
  339. icon: () => <Image class={styles.shareImg} src={iconCallMessage} />,
  340. text: () => <div class={styles.shareText}>发送消息</div>
  341. }}
  342. </GridItem>
  343. <GridItem
  344. onClick={() => {
  345. postMessage({
  346. api: 'callPhone',
  347. content: {
  348. phone: form.selectItem.phone
  349. }
  350. })
  351. form.showMessage = false
  352. }}
  353. >
  354. {{
  355. icon: () => <Image class={styles.shareImg} src={iconCallPhone} />,
  356. text: () => <div class={styles.shareText}>拨打电话</div>
  357. }}
  358. </GridItem>
  359. </Grid>
  360. </div>
  361. </div>
  362. </Popup>
  363. <OActionSheet
  364. v-model:show={form.oPopover}
  365. actions={form.action}
  366. onSelect={(val: any) => {
  367. form.action.forEach((child: any) => {
  368. child.selected = false
  369. })
  370. val.selected = true
  371. form.statusText = val.name
  372. form.params.delFlag = val.id === 'ALL' ? null : val.id
  373. form.oPopover = false
  374. onSearch()
  375. }}
  376. />
  377. <Popup v-model:show={form.showPopover} round position="bottom" class={'popupBottomSearch'}>
  378. <Picker
  379. columns={form.subjectList}
  380. onCancel={() => (form.showPopover = false)}
  381. onConfirm={(item: any) => onConfirmSubject(item)}
  382. />
  383. </Popup>
  384. </div>
  385. )
  386. }
  387. })