Browse Source

添加购买

lex-xin 2 months ago
parent
commit
0fba4366a6

+ 8 - 0
src/router/routes-teacher.ts

@@ -351,6 +351,14 @@ export default [
         }
       },
       {
+        path: '/courseListSearch',
+        name: 'courseListSearch',
+        component: () => import('@/tenant/music/courseListSearch/index'),
+        meta: {
+          title: '搜索'
+        }
+      },
+      {
         path: '/coursewarePlay',
         component: () => import('@/tenant/music/coursewarePlay'),
         meta: {

+ 2 - 1
src/tenant/music/courseList/index.tsx

@@ -421,7 +421,8 @@ export default defineComponent({
                       router.push({
                         path: '/courseListSearch',
                         query: {
-                          id: route.query.id
+                          id: route.query.id,
+                          taId: route.query.taId
                         }
                       })
                     }}>

+ 6 - 24
src/tenant/music/courseListSearch/child-node.tsx

@@ -45,34 +45,13 @@ const ChildNode = defineComponent({
       default: ''
     }
   },
-  emits: ['update:collapse'],
+  emits: ['update:collapse', "handleClick"],
   setup(props, { emit }) {
     const router = useRouter()
+    
     const toDetail = (item: any) => {
       //
-      if (browser().isApp) {
-        postMessage({
-          api: 'openWebView',
-          content: {
-            url: `${location.origin}${location.pathname}#/coursewarePlay?lessonId=${props.id}&source=search&kId=${item.id}&search=${encodeURIComponent(props.search)}`,
-            orientation: 0,
-            isHideTitle: true,
-            statusBarTextColor: false,
-            isOpenLight: true,
-            showLoadingAnim: true
-          }
-        });
-      } else {
-        router.push({
-          path: '/coursewarePlay',
-          query: {
-            lessonId: props.id,
-            kId: item.id,
-            search: props.search,
-            source: 'search'
-          }
-        });
-      }
+      emit('handleClick', item)
     }
 
     const formatName = (name: string) => {
@@ -130,6 +109,9 @@ const ChildNode = defineComponent({
                       onUpdate:collapse={val => {
                         point.collapse = val;
                       }}
+                      onHandleClick={(item) => {
+                        toDetail(item)
+                      }}
                     />
                   )}
                 </>

+ 155 - 17
src/tenant/music/courseListSearch/index.tsx

@@ -8,10 +8,10 @@ import {
 import styles from './index.module.less';
 import request from '@/helpers/request';
 import { state } from '@/state';
-import { useRoute } from 'vue-router';
+import { useRoute, useRouter } from 'vue-router';
 // import OLoading from '@/components/o-loading';
 // import OEmpty from '@/components/o-empty';
-import { Cell, Collapse, CollapseItem } from 'vant';
+import { Cell, Collapse, CollapseItem, Dialog } from 'vant';
 import ChildNode, { getImage } from './child-node';
 import iconMenu from './image/icon-menu.png';
 import TheSticky from '@/components/the-sticky';
@@ -20,34 +20,24 @@ import ColSearch from '@/components/col-search';
 import { Vue3Lottie } from 'vue3-lottie';
 import AstronautJSON from '../music-detail/animate/refresh_anim.json'
 import ColResult from '@/components/col-result';
+import { browser } from '@/helpers/utils';
+import { orderStatus } from '@/views/order-detail/orderStatus';
 // import OSticky from '@/components/o-sticky';
 
 export default defineComponent({
   name: 'course-list-search',
   setup() {
     const route = useRoute();
+    const router = useRouter()
     const data = reactive({
       titleOpacity: 0,
       loading: true,
-      detail: {
-        // id: '',
-        // cover: '',
-        // name: '',
-        // des: '',
-        useStatus: ''
-      },
+      detail: {} as Record<string, any>,
       list: [] as any,
       search: '' as string | undefined,
       parentCollapse: '' as any
       // childrenCollapse: '' as any
     });
-    /** 是否锁定 */
-    const isLock = computed(() => {
-      return data.detail.useStatus === 'LOCK' &&
-        state.platformType === 'STUDENT'
-        ? true
-        : false;
-    });
     const formatDataList = (list: any = []) => {
       const tempList: any = [];
       list.forEach((item: any) => {
@@ -168,8 +158,154 @@ export default defineComponent({
       }
       data.loading = false;
     };
+
+    /** 获取课件详情 */
+    const getDetail = async () => {
+      try {
+        const res: any = await request.post(
+          state.platformApi + `/tenantAlbumMusic/getLessonCoursewareDetail`,
+          {
+            data: {
+              lessonCoursewareId: route.query.id,
+              albumId: route.query.albumId
+            }
+          }
+        )
+        data.detail = res?.data || {}
+      } catch {
+        //
+      }
+    }
+    getDetail()
     getList();
 
+
+    const handleClick = (item: any) => {
+      if(data.detail.id && !data.detail.play) {
+        if(route.query.buyStatus !== '1') {
+          if (!browser().isApp) {
+            onDownloadApp()
+            return
+          }
+          onSubmit()
+          return
+        }
+      }
+      if (browser().isApp) {
+        postMessage({
+          api: 'openWebView',
+          content: {
+            url: `${location.origin}${location.pathname}#/coursewarePlay?lessonId=${route.query.id}&source=search&kId=${item.id}&search=${encodeURIComponent(data.search)}`,
+            orientation: 0,
+            isHideTitle: true,
+            statusBarTextColor: false,
+            isOpenLight: true,
+            showLoadingAnim: true
+          }
+        });
+      } else {
+        router.push({
+          path: '/coursewarePlay',
+          query: {
+            lessonId: route.query.id,
+            kId: item.id,
+            search: data.search,
+            source: 'search'
+          }
+        });
+      }
+    }
+
+    const onSubmit = async () => {
+      const url =
+        state.platformApi + 
+        '/tenantGroupAlbum/buyAlbumInfo?tenantGroupAlbumId=' +
+        (route.query.taId || '')
+      const { data } = await request.get(url)
+      const details = data[0]
+      orderStatus.orderObject.orderType = 'TENANT_ALBUM'
+      orderStatus.orderObject.orderName = details.name
+      orderStatus.orderObject.orderDesc = details.name
+      orderStatus.orderObject.actualPrice = details.actualPrice
+      orderStatus.orderObject.orderNo = ''
+      orderStatus.orderObject.orderList = [
+        {
+          orderType: 'TENANT_ALBUM',
+          goodsName: details.name,
+          actualPrice: details.actualPrice,
+          price: details.actualPrice,
+          ...details
+        }
+      ]
+
+      const res = await request.post(state.platformApi + '/userOrder/getPendingOrder', {
+        data: {
+          goodType: 'TENANT_ALBUM',
+          bizId: details.id
+        }
+      })
+
+      const result = res.data
+      if (result) {
+        Dialog.confirm({
+          title: '提示',
+          message: '您有一个未支付的订单,是否继续支付?',
+          theme: 'round-button',
+          className: 'confirm-button-group',
+          cancelButtonText: '取消订单',
+          confirmButtonText: '继续支付'
+        })
+          .then(async () => {
+            orderStatus.orderObject.orderNo = result.orderNo
+            orderStatus.orderObject.actualPrice = result.actualPrice
+            orderStatus.orderObject.discountPrice = result.discountPrice
+            orderStatus.orderObject.paymentConfig = {
+              ...result.paymentConfig,
+              paymentVendor: result.paymentVendor,
+              paymentVersion: result.paymentVersion
+            }
+
+            routerToALBUM(details.id)
+          })
+          .catch(() => {
+            Dialog.close()
+            // 只用取消订单,不用做其它处理
+            cancelPaymentALBUM(result.orderNo)
+          })
+      } else {
+        routerToALBUM(details.id)
+      }
+    }
+    const cancelPaymentALBUM = async (orderNo: string) => {
+      try {
+        await request.post('/api-student/userOrder/orderCancel/v2', {
+          data: {
+            orderNo
+          }
+        })
+      } catch {
+        //
+      }
+    }
+    const routerToALBUM = (id: string) => {
+      router.push({
+        path: '/orderDetail',
+        query: {
+          orderType: 'ALBUM',
+          album: id
+        }
+      })
+    }
+    const onDownloadApp = () => {
+      Dialog.alert({
+        title: '提示',
+        message: '请在酷乐秀APP中使用',
+        confirmButtonColor: '#2dc7aa'
+      }).then(() => {
+        window.location.href = location.origin + '/student/#/download'
+      })
+    }
+
     return () => (
       <div class={styles.courseListSearch}>
         <TheSticky position="top">
@@ -242,12 +378,14 @@ export default defineComponent({
                             <ChildNode
                               id={route.query.id as any}
                               search={data.search}
-                              isLock={isLock.value}
                               list={item.children}
                               collapse={item.collapse}
                               onUpdate:collapse={(val: any) => {
                                 item.collapse = val;
                               }}
+                              onHandleClick={(item: any) => {
+                                handleClick(item)
+                              }}
                             />
                           )}
                         </>