index.tsx 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. import OHeader from '@/components/o-header'
  2. import OSticky from '@/components/o-sticky'
  3. import request from '@/helpers/request'
  4. import { state } from '@/state'
  5. import { Button, Cell, CellGroup, Picker, Popup, Sticky, Tab, Tabs } from 'vant'
  6. import { defineComponent, nextTick, onMounted, reactive, ref } from 'vue'
  7. import styles from './index.module.less'
  8. import iconOrchestra from './images/icon-or.png'
  9. import MyClass from './my-class'
  10. import OEmpty from '@/components/o-empty'
  11. import OFullRefresh from '@/components/o-full-refresh'
  12. import OrchestraDeeds from './orchestra-deeds'
  13. import MyPhoto from './my-photo'
  14. import { useRoute, useRouter } from 'vue-router'
  15. export default defineComponent({
  16. name: 'my-orchestra',
  17. setup(props, ctx) {
  18. const route = useRoute()
  19. const router = useRouter()
  20. const tabActive = ref<'course' | 'photo' | 'deeds'>((route.query as any)?.tab || 'course')
  21. const data = reactive({
  22. orchestraList: [] as any[],
  23. loading: true,
  24. reshLoading: false,
  25. dataShow: true
  26. })
  27. const modelData = reactive({
  28. orchestra: {} as any,
  29. orchestraStatus: false
  30. })
  31. /** 学生获取我的乐团 */
  32. const getStudentOrchestras = () => {
  33. data.loading = true
  34. request
  35. .post(`${state.platformApi}/orchestra/studentOrchestra`, {
  36. // hideLoading: data.reshLoading
  37. })
  38. .then((res: any) => {
  39. if (Array.isArray(res?.data)) {
  40. data.orchestraList = res.data.map((n: any) => {
  41. return {
  42. ...n,
  43. name: n.name || n.orchestraName || '',
  44. id: n.id || n.orchestraId || ''
  45. }
  46. })
  47. modelData.orchestra = data.orchestraList[0] || {}
  48. }
  49. })
  50. .finally(() => {
  51. setTimeout(() => {
  52. data.loading = false
  53. data.reshLoading = false
  54. }, 300)
  55. })
  56. }
  57. const getTeacherOrchestras = async () => {
  58. data.loading = true
  59. request
  60. .post(`${state.platformApi}/orchestra/teacherOrchestra`, {
  61. // hideLoading: data.reshLoading
  62. })
  63. .then((res: any) => {
  64. if (Array.isArray(res?.data)) {
  65. data.orchestraList = res.data.map((n: any) => {
  66. return {
  67. ...n,
  68. name: n.name || n.orchestraName || '',
  69. id: n.id || n.orchestraId || ''
  70. }
  71. })
  72. modelData.orchestra = data.orchestraList[0] || {}
  73. }
  74. })
  75. .finally(() => {
  76. setTimeout(() => {
  77. data.loading = false
  78. data.reshLoading = false
  79. }, 300)
  80. })
  81. }
  82. const getData = () => {
  83. if (state.platformType === 'STUDENT') {
  84. getStudentOrchestras()
  85. } else if (state.platformType === 'TEACHER') {
  86. getTeacherOrchestras()
  87. }
  88. }
  89. onMounted(() => {
  90. document.documentElement.style.setProperty('--footer-height', '0px')
  91. getData()
  92. })
  93. return () => (
  94. <div class={[styles.mineOrchestra]}>
  95. <OSticky
  96. onGetHeight={(height: number) => {
  97. document.documentElement.style.setProperty('--header-height', height + 'px')
  98. }}
  99. >
  100. <OHeader title="我的乐团" />
  101. </OSticky>
  102. {!!data.orchestraList.length && (
  103. <CellGroup inset>
  104. <Cell
  105. class={styles.select}
  106. center
  107. isLink
  108. onClick={() => (modelData.orchestraStatus = true)}
  109. >
  110. {{
  111. icon: () => <img class={styles.icon} src={iconOrchestra} />,
  112. title: () => <div class="van-ellipsis">{modelData.orchestra.name}</div>
  113. }}
  114. </Cell>
  115. </CellGroup>
  116. )}
  117. {/* <OFullRefresh
  118. v-model:modelValue={data.loading}
  119. onRefresh={() => {
  120. data.reshLoading = true
  121. data.loading = true
  122. setTimeout(() => {
  123. data.reshLoading = false
  124. data.loading = false
  125. }, 500)
  126. }}
  127. style={`min-height: calc(100vh - var(--van-nav-bar-height) - var(--header-height) - ${
  128. data.orchestraList.length ? '1.2rem' : ''
  129. })`}
  130. > */}
  131. {!!data.orchestraList.length && (
  132. <>
  133. <Tabs
  134. v-model:active={tabActive.value}
  135. class={styles.tabs}
  136. lazyRender={true}
  137. background="transparent"
  138. animated
  139. swipeable
  140. lineWidth={16}
  141. lineHeight={4}
  142. >
  143. <Tab name="course" title="我的班级">
  144. <OFullRefresh
  145. v-model:modelValue={data.reshLoading}
  146. onRefresh={() => {
  147. data.reshLoading = true
  148. getData()
  149. }}
  150. style={`min-height: calc(100vh - var(--van-nav-bar-height) - var(--header-height) - ${
  151. data.orchestraList.length ? '1.2rem' : ''
  152. })`}
  153. >
  154. <div class={styles.content}>
  155. <MyClass
  156. orchestraName={modelData.orchestra?.name || ''}
  157. list={modelData.orchestra?.classGroupIdList || []}
  158. orchestraData={modelData.orchestra}
  159. />
  160. </div>
  161. </OFullRefresh>
  162. </Tab>
  163. {/* <Tab name="photo" title="乐团相册">
  164. <div class={styles.content}>
  165. <MyPhoto orchestraId={modelData.orchestra?.id || ''} />
  166. </div>
  167. </Tab> */}
  168. <Tab name="deeds" title="乐团事迹">
  169. <div class={styles.content}>
  170. <OrchestraDeeds orchestraId={modelData.orchestra?.id || ''} />
  171. </div>
  172. </Tab>
  173. </Tabs>
  174. </>
  175. )}
  176. {!data.loading && !data.orchestraList.length && (
  177. <div
  178. class={!data.orchestraList.length && 'emptyRootContainer'}
  179. style={{ minHeight: 'calc(100vh - var(--header-height))' }}
  180. >
  181. <OEmpty btnStatus={false} tips="暂无乐团" />
  182. </div>
  183. )}
  184. {/* </OFullRefresh> */}
  185. <Popup
  186. v-model:show={modelData.orchestraStatus}
  187. position="bottom"
  188. round
  189. class={'popupBottomSearch'}
  190. >
  191. <Picker
  192. columns={data.orchestraList}
  193. columnsFieldNames={{ text: 'name', value: 'id' }}
  194. onCancel={() => (modelData.orchestraStatus = false)}
  195. onConfirm={({ selectedValues }: any) => {
  196. const val = selectedValues[0] || ''
  197. modelData.orchestraStatus = false
  198. if (val == modelData.orchestra?.id) {
  199. return
  200. }
  201. const active = data.orchestraList.find((n: any) => n.id == val) || {}
  202. modelData.orchestra = active
  203. }}
  204. />
  205. </Popup>
  206. </div>
  207. )
  208. }
  209. })