|
@@ -2,23 +2,21 @@
|
|
|
import { kIsAndroid, kIsIOS } from "@/utils/tools";
|
|
import { kIsAndroid, kIsIOS } from "@/utils/tools";
|
|
|
import { View, Text, Image } from "@tarojs/components";
|
|
import { View, Text, Image } from "@tarojs/components";
|
|
|
import { useEffect, useState } from "react";
|
|
import { useEffect, useState } from "react";
|
|
|
-import { FlatList, Pressable } from "react-native";
|
|
|
|
|
-import Purchases from 'react-native-purchases'
|
|
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
|
import './product_list.scss'
|
|
import './product_list.scss'
|
|
|
import { ColorType } from "@/context/themes/color";
|
|
import { ColorType } from "@/context/themes/color";
|
|
|
import { payInfo, products } from "@/services/user";
|
|
import { payInfo, products } from "@/services/user";
|
|
|
import Taro from "@tarojs/taro";
|
|
import Taro from "@tarojs/taro";
|
|
|
-import showAlert from "@/components/basic/Alert";
|
|
|
|
|
import { useTranslation } from "react-i18next";
|
|
import { useTranslation } from "react-i18next";
|
|
|
import { AtActivityIndicator } from "taro-ui";
|
|
import { AtActivityIndicator } from "taro-ui";
|
|
|
import NoData from "@/components/view/NoData";
|
|
import NoData from "@/components/view/NoData";
|
|
|
import { setAccessData } from "@/store/access";
|
|
import { setAccessData } from "@/store/access";
|
|
|
|
|
|
|
|
-let useNavigation, TouchableOpacity;
|
|
|
|
|
|
|
+let useNavigation, TouchableOpacity, Purchases;
|
|
|
if (process.env.TARO_ENV == 'rn') {
|
|
if (process.env.TARO_ENV == 'rn') {
|
|
|
useNavigation = require("@react-navigation/native").useNavigation
|
|
useNavigation = require("@react-navigation/native").useNavigation
|
|
|
TouchableOpacity = require('react-native').TouchableOpacity
|
|
TouchableOpacity = require('react-native').TouchableOpacity
|
|
|
|
|
+ Purchases = require("react-native-purchases").default
|
|
|
}
|
|
}
|
|
|
export default function ProductList() {
|
|
export default function ProductList() {
|
|
|
const dispatch = useDispatch();
|
|
const dispatch = useDispatch();
|
|
@@ -40,21 +38,6 @@ export default function ProductList() {
|
|
|
if (navigation) {
|
|
if (navigation) {
|
|
|
navigation.setOptions({
|
|
navigation.setOptions({
|
|
|
gestureEnabled: !isPurchasing,
|
|
gestureEnabled: !isPurchasing,
|
|
|
- // headerLeft: () => (<TouchableOpacity activeOpacity={1} style={{ marginLeft: 5, padding: 5 }} onPress={() => {
|
|
|
|
|
- // if (!isPurchasing) {
|
|
|
|
|
- // navigation.goBack()
|
|
|
|
|
- // }
|
|
|
|
|
- // else {
|
|
|
|
|
- // showAlert({
|
|
|
|
|
- // title: '支付进行中',
|
|
|
|
|
- // content: '禁止返回',
|
|
|
|
|
- // showCancel: false
|
|
|
|
|
- // })
|
|
|
|
|
- // }
|
|
|
|
|
-
|
|
|
|
|
- // }}>
|
|
|
|
|
- // <Image style={{ width: 30, height: 30 }} src={require('@/assets/images/navi_back.png')} />
|
|
|
|
|
- // </TouchableOpacity>),
|
|
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
}, [isPurchasing])
|
|
}, [isPurchasing])
|
|
@@ -76,21 +59,27 @@ export default function ProductList() {
|
|
|
appUserID: user.id
|
|
appUserID: user.id
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
- // getProducts();
|
|
|
|
|
- // console.log('aaaa')
|
|
|
|
|
- // setTimeout(() => {
|
|
|
|
|
- // getProducts();
|
|
|
|
|
getSku();
|
|
getSku();
|
|
|
- // hi()
|
|
|
|
|
- // }, 2000)
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+ else {
|
|
|
|
|
+ getProducts();
|
|
|
|
|
+ }
|
|
|
}, [])
|
|
}, [])
|
|
|
|
|
|
|
|
- function getSku() {
|
|
|
|
|
- // Purchases.getOfferings().then(res=>{
|
|
|
|
|
|
|
+ function getProducts() {
|
|
|
|
|
+ setIsLoading(true)
|
|
|
|
|
+ products({ store: 'wechat' }).then(res => {
|
|
|
|
|
+ setPackages((res as any).data)
|
|
|
|
|
+ setShowErrorPage(false)
|
|
|
|
|
+ setIsLoading(false)
|
|
|
|
|
+ }).catch(e => {
|
|
|
|
|
+ setShowErrorPage(true)
|
|
|
|
|
+ setIsLoading(false)
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // })
|
|
|
|
|
|
|
+ function getSku() {
|
|
|
setIsLoading(true)
|
|
setIsLoading(true)
|
|
|
Promise.all([Purchases.getOfferings(), products({ store: kIsIOS ? 'app_store' : 'play_store' })]).then(list => {
|
|
Promise.all([Purchases.getOfferings(), products({ store: kIsIOS ? 'app_store' : 'play_store' })]).then(list => {
|
|
|
|
|
|
|
@@ -119,20 +108,8 @@ export default function ProductList() {
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async function getProducts() {
|
|
|
|
|
- console.log('product list get start')
|
|
|
|
|
- try {
|
|
|
|
|
- const offerings = await Purchases.getOfferings();
|
|
|
|
|
- console.log('product list offerings', offerings)
|
|
|
|
|
- console.log('product list detail', (offerings as any).current.availablePackages[1])
|
|
|
|
|
- console.log('dddd', JSON.stringify(offerings))
|
|
|
|
|
|
|
+ function createOrder(item: any) {
|
|
|
|
|
|
|
|
- if (offerings.current !== null && offerings.current.availablePackages.length !== 0) {
|
|
|
|
|
- setPackages((offerings as any).current.availablePackages);
|
|
|
|
|
- }
|
|
|
|
|
- } catch (e) {
|
|
|
|
|
- console.log('product list offerings error', e.message)
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async function pay(item: any) {
|
|
async function pay(item: any) {
|
|
@@ -186,11 +163,11 @@ export default function ProductList() {
|
|
|
<View style={{ height: 40 }} />
|
|
<View style={{ height: 40 }} />
|
|
|
{
|
|
{
|
|
|
packages.map((item, index) => {
|
|
packages.map((item, index) => {
|
|
|
- return <View className="product_item" key={index} onClick={() => pay(item)}>
|
|
|
|
|
- <Text className="product_title" style={{ color: ColorType.fast }}>{(item as any).product.title}</Text>
|
|
|
|
|
- <Text style={{ color: '#fff', fontSize: 16, marginTop: 5, marginBottom: 5 }}>{(item as any).product.description}</Text>
|
|
|
|
|
|
|
+ return <View className="product_item" key={index} onClick={() => process.env.TARO_ENV == 'weapp' ? createOrder(item) : pay(item)}>
|
|
|
|
|
+ <Text className="product_title" style={{ color: ColorType.fast }}>{process.env.TARO_ENV == 'weapp' ? (item as any).display_name : (item as any).product.title}</Text>
|
|
|
|
|
+ <Text style={{ color: '#fff', fontSize: 16, marginTop: 5, marginBottom: 5 }}>{process.env.TARO_ENV == 'weapp' ? (item as any).description : (item as any).product.description}</Text>
|
|
|
<View style={{ flexDirection: 'row', display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
|
|
<View style={{ flexDirection: 'row', display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
|
|
|
- <Text className="product_price">{(item as any).product.priceString}</Text>
|
|
|
|
|
|
|
+ <Text className="product_price">{process.env.TARO_ENV == 'weapp' ? '¥' + (item as any).price : (item as any).product.priceString}</Text>
|
|
|
<Image style={{ width: 24, height: 24 }} src={require('@/assets/images/arrow3.png')} />
|
|
<Image style={{ width: 24, height: 24 }} src={require('@/assets/images/arrow3.png')} />
|
|
|
</View>
|
|
</View>
|
|
|
|
|
|