music-list.tsx 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. import OEmpty from '@/components/o-empty'
  2. import { postMessage } from '@/helpers/native-message'
  3. import request from '@/helpers/request'
  4. import { browser } from '@/helpers/utils'
  5. import { state } from '@/state'
  6. import { useRect } from '@vant/use'
  7. import OFullRefresh from '@/components/o-full-refresh'
  8. import {
  9. Cell,
  10. CellGroup,
  11. DropdownItem,
  12. DropdownMenu,
  13. Icon,
  14. List,
  15. Popover,
  16. PullRefresh,
  17. Search,
  18. showConfirmDialog,
  19. Sticky
  20. } from 'vant'
  21. import { defineComponent, reactive, ref, onMounted, nextTick, computed } from 'vue'
  22. import { useRoute, useRouter } from 'vue-router'
  23. import { getImage } from './images'
  24. import styles from './index.module.less'
  25. import OSticky from '@/components/o-sticky'
  26. export default defineComponent({
  27. name: 'accompany-music-list',
  28. props: {
  29. musicTree: {
  30. type: Array,
  31. default: () => []
  32. }
  33. },
  34. setup(props, ctx) {
  35. const route = useRoute()
  36. const router = useRouter()
  37. const imgDefault = getImage('icon-music.svg')
  38. const userInfo = ref<any>({})
  39. const data = reactive({
  40. loading: false,
  41. finished: false,
  42. refreshing: false,
  43. musicTree: [] as any,
  44. pagenation: {
  45. page: 1,
  46. rows: 20
  47. },
  48. value1: null,
  49. value2: null,
  50. PopoverOpen: false,
  51. list: [] as any,
  52. keyword: ''
  53. })
  54. const getTree = async () => {
  55. try {
  56. const res: any = await request.get(
  57. state.platformApi + '/musicSheetCategories/queryTree?enable=true'
  58. )
  59. if (Array.isArray(res?.data)) {
  60. data.musicTree = res.data
  61. }
  62. getList()
  63. } catch (error) {
  64. console.log(error)
  65. }
  66. }
  67. /**获取会员购买记录 */
  68. const getUserInfo = async () => {
  69. try {
  70. const res: any = await request.get(`/api-student/student/member`)
  71. userInfo.value = res.data || {}
  72. } catch (error) {}
  73. }
  74. const option1 = computed(() => {
  75. const v1: any = data.musicTree.find((n: any) => n.id == route.query.categorieid)
  76. if (Array.isArray(v1?.musicSheetCategoriesList)) {
  77. const list = v1.musicSheetCategoriesList.map((m: any) => {
  78. if (!data.value1) {
  79. data.value1 = m.id
  80. data.value2 = null
  81. }
  82. return {
  83. text: m.name,
  84. value: m.id
  85. }
  86. })
  87. return list
  88. }
  89. return []
  90. })
  91. const option2 = computed(() => {
  92. const v1: any = data.musicTree.find((n: any) => n.id == route.query.categorieid)
  93. if (Array.isArray(v1?.musicSheetCategoriesList)) {
  94. const v2: any = v1.musicSheetCategoriesList.find((n: any) => n.id == data.value1)
  95. if (Array.isArray(v2?.musicSheetCategoriesList)) {
  96. const list = [{ text: '全部', value: null }].concat(
  97. v2.musicSheetCategoriesList.map((m: any) => {
  98. return {
  99. text: m.name,
  100. value: m.id
  101. }
  102. })
  103. )
  104. return list
  105. }
  106. }
  107. return [{ text: '全部', value: null }]
  108. })
  109. const getList = async () => {
  110. if (data.loading) return
  111. data.loading = true
  112. try {
  113. const res: any = await request.post(state.platformApi + '/musicSheet/page', {
  114. data: {
  115. ...data.pagenation,
  116. keyword: data.keyword,
  117. musicSheetCategoriesId: data.value2 || data.value1
  118. },
  119. hideLoading: true
  120. })
  121. if (Array.isArray(res?.data?.rows)) {
  122. data.list = [].concat(data.list, res.data.rows)
  123. data.pagenation.page += 1
  124. data.finished = res.data.rows.length ? false : true
  125. } else {
  126. data.finished = true
  127. }
  128. } catch (error) {
  129. data.finished = true
  130. }
  131. data.loading = false
  132. data.refreshing = false
  133. }
  134. // 重置搜索
  135. const onSearch = () => {
  136. data.pagenation.page = 1
  137. data.list = []
  138. data.finished = false
  139. data.list = []
  140. getList()
  141. }
  142. //进入云教练
  143. const openView = (item: any) => {
  144. // 学生端验证
  145. if (state.platformType == 'STUDENT') {
  146. //学生有待激活会员
  147. if (!userInfo.value.membershipDays && userInfo.value.purchaseMemberRecord) {
  148. showConfirmDialog({
  149. message: '您的团练宝暂未激活,请激活后使用'
  150. }).then(() => {
  151. router.push({
  152. path: '/memberCenter'
  153. })
  154. })
  155. return
  156. }
  157. //学生没有会员
  158. if (!userInfo.value.vipMember) {
  159. showConfirmDialog({
  160. message: '您暂未开通团练宝,请开通后使用'
  161. }).then(() => {
  162. router.push({
  163. path: '/memberCenter'
  164. })
  165. })
  166. return
  167. }
  168. }
  169. let src = `${location.origin}/orchestra-music-score/?id=${item.id}`
  170. console.log('🚀 ~ 去云教练的src', src)
  171. postMessage({
  172. api: 'openAccompanyWebView',
  173. content: {
  174. url: src,
  175. orientation: 0,
  176. isHideTitle: true,
  177. statusBarTextColor: false,
  178. isOpenLight: true
  179. }
  180. })
  181. }
  182. onMounted(() => {
  183. getUserInfo()
  184. getTree()
  185. })
  186. return () => (
  187. <div class={styles['accompany-music-list']}>
  188. <OSticky
  189. mode="sticky"
  190. class={styles.heade}
  191. onGetHeight={(height: number) => {
  192. document.documentElement.style.setProperty('--header-height', height + 'px')
  193. }}
  194. >
  195. <div>
  196. <DropdownMenu>
  197. <DropdownItem
  198. v-model:modelValue={data.value1}
  199. options={option1.value}
  200. onChange={() => onSearch()}
  201. ></DropdownItem>
  202. <DropdownItem
  203. v-model:modelValue={data.value2}
  204. options={option2.value as any}
  205. onChange={() => onSearch()}
  206. ></DropdownItem>
  207. </DropdownMenu>
  208. <div class={styles.filter}>
  209. <Search
  210. placeholder="请输入搜索关键词"
  211. background="#F8F8F8"
  212. shape="round"
  213. showAction={true}
  214. v-model:modelValue={data.keyword}
  215. >
  216. {{
  217. // label: () => (
  218. // <Popover
  219. // v-model:show={data.PopoverOpen}
  220. // actions={actions}
  221. // placement="bottom-start"
  222. // >
  223. // {{
  224. // reference: () => (
  225. // <div>
  226. // 长笛 <Icon name="arrow" />
  227. // </div>
  228. // )
  229. // }}
  230. // </Popover>
  231. // ),
  232. action: () => (
  233. <div class={styles.searchBtn} onClick={() => onSearch()}>
  234. 搜索
  235. </div>
  236. )
  237. }}
  238. </Search>
  239. </div>
  240. </div>
  241. </OSticky>
  242. <OFullRefresh
  243. v-model:modelValue={data.refreshing}
  244. onRefresh={onSearch}
  245. style="min-height: calc(100vh - var(--header-height))"
  246. >
  247. <List
  248. loading-text=" "
  249. immediateCheck={false}
  250. loading={data.loading}
  251. v-model:finished={data.finished}
  252. finishedText="没有更多了"
  253. onLoad={() => {
  254. getList()
  255. }}
  256. >
  257. <CellGroup inset>
  258. {data.list.map((item: any) => {
  259. return (
  260. <Cell
  261. size="large"
  262. center
  263. title={item.musicSheetName}
  264. isLink
  265. onClick={() => openView(item)}
  266. >
  267. {{
  268. icon: () => (
  269. <Icon style={{ marginRight: '12px' }} size={40} name={imgDefault} />
  270. )
  271. }}
  272. </Cell>
  273. )
  274. })}
  275. </CellGroup>
  276. </List>
  277. {!data.loading && !data.list.length && <OEmpty tips="暂无曲谱" />}
  278. </OFullRefresh>
  279. </div>
  280. )
  281. }
  282. })