JXDS18FUJT 1 жил өмнө
parent
commit
85e7487b20

+ 7 - 0
src/api/index.ts

@@ -121,6 +121,13 @@ const api = {
             url:"student/exam/info/myList",
             method:'get'
         })
+    },
+    //查询当前用户考试会员列表
+    studentVipExamList():AxiosPromise<studentVipExamList>{
+        return request({
+            url:"student/vip/exam/list",
+            method:'get'
+        })
     }
 
     

+ 21 - 8
src/api/type.d.ts

@@ -3,14 +3,14 @@ interface Res {
     msg: string;
 }
 interface loginGzhcode extends Res {
-    data:{
-        token:string
-        thirdResult:{
-            nickname:string
-            openid:string
-            sex:'0'|'1'
-            headimgurl:string
-            unionid:string
+    data: {
+        token: string
+        thirdResult: {
+            nickname: string
+            openid: string
+            sex: '0' | '1'
+            headimgurl: string
+            unionid: string
         }
     }
 }
@@ -87,4 +87,17 @@ interface studentVipVideoList extends Res {
         "permission": number
     }[]
 
+}
+interface studentVipExamList extends Res {
+    rows: {
+        "createTime": string,
+        "updateTime": string,
+        "id": number,
+        "userId": number,
+        "unionId": string,
+        "examId": number,
+        "examName": string,
+        "expirationTime": string
+    }[]
+    total: number
 }

+ 3 - 0
src/utils/request.ts

@@ -52,6 +52,9 @@ request.interceptors.response.use((res) => {
 				if (res.data.msg == "微信授权无效,请重新授权") {
 					window.location.replace("https://nbjk1-h5.zzxcx.net/")
 				}
+				Toast.fail({
+					message:res.data.msg
+				})
 
 				break;
 			default:

+ 44 - 16
src/views/courseCatalog/components/courseCatalog/index.tsx

@@ -3,6 +3,7 @@ import React, { useEffect, useRef, useState } from "react";
 import api from '~/api'
 import vip_angle from "./../../../../assets/images/vip_angle.png";
 import try_angle from "./../../../../assets/images/try_angle.png";
+import { Toast } from 'react-vant';
 export const CourseCatalog: React.FC = (props: any) => {
     const wxPay = () => {
         // WX.config()
@@ -14,7 +15,7 @@ export const CourseCatalog: React.FC = (props: any) => {
             "foreType": 2,
             "goodsId": query.get('id') || "",
             "goodsType": 1,
-            "phoneType": isIOS?1:2
+            "phoneType": isIOS ? 1 : 2
         }).then(res => {
             if (WeixinJSBridge) {
                 WeixinJSBridge.invoke("getBrandWCPayRequest", res.data.data, async function (res: any) {
@@ -22,6 +23,10 @@ export const CourseCatalog: React.FC = (props: any) => {
                         // 使用以上方式判断前端返回,微信团队郑重提示:
                         //res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
                         console.log('支付成功')
+                        window.setTimeout(()=>{
+                            window.location.reload()
+                        },1500)
+
                     }
                 });
             }
@@ -33,6 +38,8 @@ export const CourseCatalog: React.FC = (props: any) => {
         })
         // wx.chooseWXPay()
     }
+    const id = Number(new URLSearchParams(window.location.search).get("id") || '0')
+    const myExamIds = useRef<number[]>([])
     const [list, setList] = useState([{
         "createTime": "2023-05-09 21:43:53",
         "updateTime": "2023-05-11 13:42:22",
@@ -66,6 +73,20 @@ export const CourseCatalog: React.FC = (props: any) => {
 
             })
         }
+        Toast.loading({
+            message:'加载中'
+        })
+        api.studentVipExamList().then(res => {
+            console.log(res)
+            myExamIds.current = res.data.rows.map(item => {
+                return item.examId
+            })
+            // myExamIds.current=[1]
+            Toast.clear()
+
+
+
+        })
     }, [])
 
     return (
@@ -104,26 +125,33 @@ export const CourseCatalog: React.FC = (props: any) => {
 
                 className="pay"
             >
-                <div onClick={()=>{
-                    wxPay()
+                {
+                    !myExamIds.current.includes(Number(id)) ? <div onClick={() => {
+                        wxPay()
 
-                }} className="pay-text">
-                    <span
-                    >立即支付&nbsp;&nbsp;¥{price}</span>
+                    }} className="pay-text">
+                        <span
+                        >立即支付&nbsp;&nbsp;¥{price}</span>
 
-                    {/* <span >已购买</span> */}
-                </div>
-                <img
 
-                    style={{ width: '100%' }}
+                    </div> : <span className="pay-text">已购买</span>
+                }
+
+                {
+                    !myExamIds.current.includes(Number(id)) ? <img
+
+                        style={{ width: '100%' }}
+
+                        src="https://ndata.zzxcx.net/ctjk/mp-wx/courseCatalog/payBg.png"
+                    ></img> : <img
+                        style={{ width: '100%' }}
+
+                        src="https://ndata.zzxcx.net/ctjk/mp-wx/courseCatalog/alreadyPay.png"
+                    ></img>
 
-                    src="https://ndata.zzxcx.net/ctjk/mp-wx/courseCatalog/payBg.png"
-                ></img>
-                {/* <img
-                    style={{ width: '100%' }}
+                }
+               
 
-                    src="https://ndata.zzxcx.net/ctjk/mp-wx/courseCatalog/alreadyPay.png"
-                ></img> */}
             </div>
             <div className="advantage">
                 <div className="advantage-title"> 实拍优势</div>