-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.tsx
107 lines (99 loc) · 2.87 KB
/
demo.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import ListItem from "@/comps/ListItem";
import TabBar from "@/comps/TabBar";
import { ChildContext } from "@/service/context";
import { useAuth } from "@/service/hook";
import request from "@/service/request";
import { Base64 } from "@/service/utils";
import { Arrow } from "@taroify/icons";
import { View } from "@tarojs/components";
import { navigateTo, useRouter } from "@tarojs/taro";
import React, { useContext, useEffect, useState } from "react";
import "./list.scss";
const cusStyle = {
display: "flex",
alignItems: "center",
padding: "0 12px",
width: "280px",
height: "60px",
position: "static" as any,
};
export default function App() {
const childContext = useContext(ChildContext);
const [list, setList] = useState<any>([]);
const router = useRouter();
const { getAuth } = useAuth();
const checkPay = async (scaleTableCode) => {
if (wx._unLogin) {
navigateTo({
url: `/pages/login/index?returnUrl=${"/pages/evaluate/list"}`,
});
} else {
const res = await request({
url: "/order/check",
data: { scaleTableCode },
});
if (!res.data.hasPaidOrder) {
navigateTo({
url: `/orderPackage/pages/order/gmsPay?code=${scaleTableCode}`,
});
} else {
if (childContext.child.len) {
navigateTo({
url: `/childPackage/pages/choose?code=${scaleTableCode}&orderId=${res.data.orderId}`,
});
} else {
const returnUrl = Base64.encode(
`/childPackage/pages/choose?code=${scaleTableCode}&orderId=${res.data.orderId}`
);
navigateTo({
url: `/childPackage/pages/manage?code=${scaleTableCode}&returnUrl=${returnUrl}`,
});
}
}
}
};
const getList = async () => {
const res = await request({
url: "/scaleTable/list",
});
setList(res.data);
};
const getChild = async () => {
const res = await request({
url: "/children/list",
data: { pageNo: 1, pageSize: 1000 },
});
childContext.updateChild({ len: res.data.children?.length });
};
useEffect(() => {
if (router.params.channel || router.params.orgid || wx._orgId) {
getAuth(getList, {
channel: router.params.channel || "",
orgid: router.params.orgid || wx._orgId,
});
} else {
getList();
getChild();
}
}, []);
return (
<ScrollView className="index">
<View2 className="list-wrap">
{list?.map((v, i) => (
<View key={i} className="list" onClick={() => checkPay(v.code)}>
<ListItem
left={v.name}
right={
<Text className="arrow-icon">
<Arrow color="#fff" />
</Text>
}
customStyles={cusStyle}
/>
</View>
))}
</View2>
<TabBar current="index" />
</ScrollView>
);
}