index.tsx 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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, 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. })
  26. const modelData = reactive({
  27. orchestra: {} as any,
  28. orchestraStatus: false
  29. })
  30. /** 学生获取我的乐团 */
  31. const getStudentOrchestras = () => {
  32. data.loading = true
  33. request
  34. .post(`${state.platformApi}/orchestra/studentOrchestra`, {
  35. // hideLoading: data.reshLoading
  36. })
  37. .then((res: any) => {
  38. if (Array.isArray(res?.data)) {
  39. data.orchestraList = res.data.map((n: any) => {
  40. return {
  41. ...n,
  42. name: n.name || n.orchestraName || '',
  43. id: n.id || n.orchestraId || ''
  44. }
  45. })
  46. modelData.orchestra = data.orchestraList[0] || {}
  47. }
  48. })
  49. .finally(() => {
  50. setTimeout(() => {
  51. data.loading = false
  52. }, 300)
  53. })
  54. }
  55. const getTeacherOrchestras = async () => {
  56. data.loading = true
  57. request
  58. .post(`${state.platformApi}/orchestra/teacherOrchestra`, {
  59. // hideLoading: data.reshLoading
  60. })
  61. .then((res: any) => {
  62. if (Array.isArray(res?.data)) {
  63. data.orchestraList = res.data.map((n: any) => {
  64. return {
  65. ...n,
  66. name: n.name || n.orchestraName || '',
  67. id: n.id || n.orchestraId || ''
  68. }
  69. })
  70. modelData.orchestra = data.orchestraList[0] || {}
  71. }
  72. })
  73. .finally(() => {
  74. setTimeout(() => {
  75. data.loading = false
  76. }, 300)
  77. })
  78. }
  79. const getData = () => {
  80. if (state.platformType === 'STUDENT') {
  81. getStudentOrchestras()
  82. } else if (state.platformType === 'TEACHER') {
  83. getTeacherOrchestras()
  84. }
  85. }
  86. onMounted(() => {
  87. document.documentElement.style.setProperty('--footer-height', '0px')
  88. getData()
  89. })
  90. return () => (
  91. <div class={[styles.mineOrchestra]}>
  92. <OSticky
  93. onGetHeight={(height: number) => {
  94. document.documentElement.style.setProperty('--header-height', height + 'px')
  95. }}
  96. >
  97. <OHeader title="我的乐团" />
  98. </OSticky>
  99. <OFullRefresh
  100. v-model:modelValue={data.loading}
  101. onRefresh={() => {
  102. data.reshLoading = true
  103. data.orchestraList = []
  104. nextTick(() => {
  105. getData()
  106. })
  107. }}
  108. style="min-height: calc(100vh - var(--van-nav-bar-height) - var(--header-height) - var(--footer-height))"
  109. >
  110. {!data.loading && !!data.orchestraList.length && (
  111. <>
  112. <CellGroup inset>
  113. <Cell
  114. class={styles.select}
  115. center
  116. isLink
  117. onClick={() => (modelData.orchestraStatus = true)}
  118. >
  119. {{
  120. icon: () => <img class={styles.icon} src={iconOrchestra} />,
  121. title: () => <div class="van-ellipsis">{modelData.orchestra.name}</div>
  122. }}
  123. </Cell>
  124. </CellGroup>
  125. <Tabs
  126. v-model:active={tabActive.value}
  127. class={styles.tabs}
  128. lazyRender={true}
  129. background="transparent"
  130. animated
  131. swipeable
  132. lineWidth={16}
  133. lineHeight={4}
  134. >
  135. <Tab name="course" title="我的班级">
  136. <div class={styles.content}>
  137. <MyClass
  138. orchestraName={modelData.orchestra?.name || ''}
  139. list={modelData.orchestra?.classGroupIdList || []}
  140. />
  141. </div>
  142. </Tab>
  143. {/* <Tab name="photo" title="乐团相册">
  144. <div class={styles.content}>
  145. <MyPhoto orchestraId={modelData.orchestra?.id || ''} />
  146. </div>
  147. </Tab> */}
  148. <Tab name="deeds" title="乐团事迹">
  149. <div class={styles.content}>
  150. <OrchestraDeeds orchestraId={modelData.orchestra?.id || ''} />
  151. </div>
  152. </Tab>
  153. </Tabs>
  154. </>
  155. )}
  156. {!data.loading && !data.orchestraList.length && (
  157. <div
  158. class={!data.orchestraList.length && 'emptyRootContainer'}
  159. style={{ minHeight: 'calc(100vh - var(--header-height))' }}
  160. >
  161. <OEmpty btnStatus={false} tips="暂无乐团" />
  162. </div>
  163. )}
  164. </OFullRefresh>
  165. {state.platformType == 'STUDENT' &&
  166. ['REGISTER', 'LEARNING', 'AUTH'].includes(modelData.orchestra?.status) && (
  167. <OSticky
  168. position="bottom"
  169. onGetHeight={(height: any) => {
  170. document.documentElement.style.setProperty('--footer-height', height + 'px')
  171. }}
  172. >
  173. <div class="btnGroup" style="padding-top: 12px">
  174. {(modelData.orchestra?.status === 'REGISTER' ||
  175. modelData.orchestra?.status === 'LEARNING') && (
  176. <Button
  177. type="primary"
  178. round
  179. block
  180. onClick={() => {
  181. router.push({
  182. path: '/apply-withdrawal',
  183. query: {
  184. id: modelData.orchestra?.orchestraId
  185. }
  186. })
  187. }}
  188. >
  189. 申请退团
  190. </Button>
  191. )}
  192. {modelData.orchestra?.status === 'AUTH' && (
  193. <Button type="primary" round block disabled>
  194. 申请退团中
  195. </Button>
  196. )}
  197. </div>
  198. </OSticky>
  199. )}
  200. <Popup
  201. v-model:show={modelData.orchestraStatus}
  202. position="bottom"
  203. round
  204. class={'popupBottomSearch'}
  205. >
  206. <Picker
  207. columns={data.orchestraList}
  208. columnsFieldNames={{ text: 'name', value: 'id' }}
  209. onCancel={() => (modelData.orchestraStatus = false)}
  210. onConfirm={({ selectedValues }: any) => {
  211. const val = selectedValues[0] || ''
  212. modelData.orchestraStatus = false
  213. if (val == modelData.orchestra?.id) {
  214. return
  215. }
  216. const active = data.orchestraList.find((n: any) => n.id == val) || {}
  217. modelData.orchestra = active
  218. }}
  219. />
  220. </Popup>
  221. </div>
  222. )
  223. }
  224. })