index.tsx 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. closeToast,
  9. Grid,
  10. GridItem,
  11. Icon,
  12. Image,
  13. List,
  14. Popup,
  15. showFailToast,
  16. showLoadingToast,
  17. showSuccessToast,
  18. showToast
  19. } from 'vant'
  20. import { defineComponent, onMounted, reactive } from 'vue'
  21. import styles from './index.module.less'
  22. import iconSaveImage from '@/school/orchestra/images/icon-save-image.png'
  23. import iconWechat from '@/school/orchestra/images/icon-wechat.png'
  24. import iconTeacher from '@common/images/icon_teacher.png'
  25. import { useRouter } from 'vue-router'
  26. import request from '@/helpers/request'
  27. import { state } from '@/state'
  28. import OEmpty from '@/components/o-empty'
  29. import OFullRefresh from '@/components/o-full-refresh'
  30. import { manageTeacherType } from '@/constant'
  31. import html2canvas from 'html2canvas'
  32. import { promisefiyPostMessage, postMessage } from '@/helpers/native-message'
  33. export default defineComponent({
  34. name: 'companion-teacher',
  35. setup() {
  36. const router = useRouter()
  37. const form = reactive({
  38. oPopover: false,
  39. list: [] as any,
  40. listState: {
  41. dataShow: true, // 判断是否有数据
  42. loading: false,
  43. finished: false,
  44. refreshing: false,
  45. height: 0 // 页面头部高度,为了处理下拉刷新用的
  46. },
  47. statusText: '状态',
  48. params: {
  49. keyword: null,
  50. status: null,
  51. page: 1,
  52. rows: 20
  53. },
  54. isClick: false
  55. })
  56. const getList = async () => {
  57. try {
  58. if (form.isClick) return
  59. form.isClick = true
  60. const res = await request.post('/api-school/schoolStaff/page', {
  61. data: {
  62. ...form.params,
  63. schoolId: state.user.data.school.id
  64. }
  65. })
  66. form.listState.loading = false
  67. form.listState.refreshing = false
  68. const result = res.data || {}
  69. // 处理重复请求数据
  70. if (form.list.length > 0 && result.current === 1) {
  71. return
  72. }
  73. form.list = form.list.concat(result.rows || [])
  74. form.listState.finished = result.current >= result.pages
  75. form.params.page = result.current + 1
  76. form.listState.dataShow = form.list.length > 0
  77. form.isClick = false
  78. } catch {
  79. form.listState.dataShow = false
  80. form.listState.finished = true
  81. form.listState.refreshing = false
  82. form.isClick = false
  83. }
  84. }
  85. const onSearch = () => {
  86. form.params.page = 1
  87. form.list = []
  88. form.listState.dataShow = true // 判断是否有数据
  89. form.listState.loading = false
  90. form.listState.finished = false
  91. getList()
  92. }
  93. const onDetail = (item: any) => {
  94. router.push({
  95. path: '/manage-teacher-detail',
  96. query: {
  97. id: item.id
  98. }
  99. })
  100. }
  101. onMounted(async () => {
  102. getList()
  103. })
  104. return () => (
  105. <div class={!form.listState.dataShow && 'emptyRootContainer'}>
  106. <OSticky
  107. position="top"
  108. onGetHeight={(height: any) => {
  109. form.listState.height = height
  110. }}
  111. >
  112. <OHeader border={false}>
  113. {{
  114. right: () => (
  115. <Icon
  116. name="plus"
  117. size={19}
  118. onClick={() => {
  119. router.push({
  120. path: 'save-share-image',
  121. query: {
  122. type: 'manage'
  123. }
  124. })
  125. }}
  126. />
  127. )
  128. }}
  129. </OHeader>
  130. <OSearch
  131. placeholder="请输入管理老师姓名"
  132. inputBackground="white"
  133. background="#f6f8f9"
  134. onSearch={(val: any) => {
  135. console.log(val)
  136. form.params.keyword = val
  137. onSearch()
  138. }}
  139. v-slots={{
  140. left: () => (
  141. <div
  142. class={styles.searchBand}
  143. style={{ marginRight: '13px' }}
  144. onClick={() => (form.oPopover = true)}
  145. >
  146. {form.statusText} <Icon name={form.oPopover ? 'arrow-up' : 'arrow-down'} />
  147. </div>
  148. )
  149. }}
  150. />
  151. </OSticky>
  152. {form.listState.dataShow ? (
  153. <OFullRefresh
  154. v-model:modelValue={form.listState.refreshing}
  155. onRefresh={onSearch}
  156. style={{
  157. minHeight: `calc(100vh - ${form.listState.height}px)`
  158. }}
  159. >
  160. <List
  161. // v-model:loading={form.listState.loading}
  162. finished={form.listState.finished}
  163. finishedText=" "
  164. class={[styles.liveList]}
  165. onLoad={getList}
  166. immediateCheck={false}
  167. >
  168. {form.list.map((item: any) => (
  169. <Cell center isLink class={styles.manageCell} onClick={() => onDetail(item)}>
  170. {{
  171. icon: () => (
  172. <Image class={styles.img} src={item.avatar ? item.avatar : iconTeacher} />
  173. ),
  174. title: () => (
  175. <div class={styles.content}>
  176. <p class={[styles.name, 'van-ellipsis']}>{item.nickname}</p>
  177. <p class={styles.phone}>{item.phone}</p>
  178. </div>
  179. ),
  180. value: () => (
  181. <span class={[styles.status, item.status === 'LOCKED' ? styles.frozen : '']}>
  182. {manageTeacherType[item.status]}
  183. </span>
  184. )
  185. }}
  186. </Cell>
  187. ))}
  188. </List>
  189. </OFullRefresh>
  190. ) : (
  191. <OEmpty btnStatus={false} tips="暂无管理老师" />
  192. )}
  193. {/* <van-action-sheet v-model:show="show" :actions="actions" @select="onSelect" /> */}
  194. <ActionSheet
  195. v-model:show={form.oPopover}
  196. cancelText="取消"
  197. actions={
  198. [
  199. { name: '全部', id: 'ALL' },
  200. // { name: '注销', id: 'CANCEL' },
  201. { name: '冻结', id: 'LOCKED' },
  202. { name: '正常', id: 'ACTIVATION' }
  203. ] as any
  204. }
  205. onSelect={(val: any) => {
  206. form.statusText = val.name
  207. form.params.status = val.id === 'ALL' ? null : val.id
  208. form.oPopover = false
  209. onSearch()
  210. }}
  211. />
  212. </div>
  213. )
  214. }
  215. })