feat: 主要完成了分享功能

This commit is contained in:
Tony 2024-07-16 11:24:28 +08:00
parent d8d5469671
commit 9fa8c96910
16 changed files with 295 additions and 221 deletions

View File

@ -48,6 +48,7 @@ const config = {
}, },
webpackChain(chain, webpack) { webpackChain(chain, webpack) {
chain.merge({ chain.merge({
performance: { maxEntrypointSize: 100000000, maxAssetSize: 300000000 },
plugin: { plugin: {
install: { install: {
plugin: UnifiedWebpackPluginV5, plugin: UnifiedWebpackPluginV5,

View File

@ -5,8 +5,8 @@
"appid": "wx2062eafa5dfc8ffb", "appid": "wx2062eafa5dfc8ffb",
"setting": { "setting": {
"urlCheck": true, "urlCheck": true,
"es6": true, "es6": false,
"enhance": true, "enhance": false,
"compileHotReLoad": false, "compileHotReLoad": false,
"postcss": false, "postcss": false,
"preloadBackgroundData": false, "preloadBackgroundData": false,

View File

@ -3,6 +3,6 @@
"projectname": "crab-wxapp", "projectname": "crab-wxapp",
"setting": { "setting": {
"compileHotReLoad": true, "compileHotReLoad": true,
"urlCheck": true "urlCheck": false
} }
} }

View File

@ -28,7 +28,6 @@ export const request = ({
} }
if (isToken) header['Authorization'] = 'Bearer ' + Taro.getStorageSync('token') if (isToken) header['Authorization'] = 'Bearer ' + Taro.getStorageSync('token')
Taro.showLoading({ title: '加载中...' }) Taro.showLoading({ title: '加载中...' })
console.log("发起请求中");
wx.request({ wx.request({
url: baseUrl + url + (requestParams ? ('?' + requestParams) : ''), url: baseUrl + url + (requestParams ? ('?' + requestParams) : ''),

View File

@ -30,4 +30,12 @@ export const addressDelete = (params) => {
method: 'DELETE', method: 'DELETE',
params params
}) })
}
export const updateAddress = (data) => {
return request({
url: 'wechat/v1/adoption-order/updateaddress',
method: 'PUT',
data
})
} }

View File

@ -25,10 +25,20 @@ export const tickPage = (params) => {
}) })
} }
// 根据ID获取订单信息
export const getOrderInfoById = (params) => { export const getOrderInfoById = (params) => {
return request({ return request({
url: 'wechat/v1/ticket/page', url: 'wechat/v1/adoption-order/get',
method: 'GET', method: 'GET',
params params
}) })
}
// 赠送好友
export const adoptionGiveOther = (data) => {
return request({
url: 'wechat/v1/adoption-order/giveOther',
method: 'PUT',
data
})
} }

View File

@ -1,7 +1,7 @@
import { Image, View, PageContainer, Input } from "@tarojs/components"; import { Image, View, PageContainer, Input, Button } from "@tarojs/components";
import Taro from "@tarojs/taro"; import Taro from "@tarojs/taro";
import { useState } from "react"; import { useState } from "react";
import { APPID, IMG_BASE_URL, SECRET } from "../../config"; import { IMG_BASE_URL } from "../../config";
const larvea = IMG_BASE_URL + 'pagesHome/larvea.png' const larvea = IMG_BASE_URL + 'pagesHome/larvea.png'
@ -9,7 +9,7 @@ export default function LoginForm(props) {
const { show, setShow, onConfirm } = props const { show, setShow, onConfirm } = props
const [userNickName, setUserNickName] = useState<string>('') const [userNickName, setUserNickName] = useState<string>('')
const [userSignature, setUserSignature] = useState<string>('') const [userSignature, setUserSignature] = useState<string>('')
const [avatar, setAvatar] = useState<string>('') const [avatar, setAvatar] = useState<string>(larvea)
return ( return (
<PageContainer <PageContainer
show={show} show={show}
@ -21,60 +21,36 @@ export default function LoginForm(props) {
<View className="px-5 py-5 pb-8"> <View className="px-5 py-5 pb-8">
<View></View> <View></View>
<View className="w-full flex flex-col items-center"> <View className="w-full flex flex-col items-center">
<View className="rounded-full p-1 bg-white py-[1rem]" onClick={() => { <View className="rounded-full p-1 bg-white py-[1rem]">
Taro.chooseImage({ <Button openType="chooseAvatar" onChooseAvatar={(e) => {
success: (e) => { const tempAvatarUrl = e.detail.avatarUrl
console.log("e", e); if (!tempAvatarUrl) return
console.log("e", e); let res = ''
const { tempFilePaths } = e; try {
if (Array.isArray(tempFilePaths) && tempFilePaths.length === 0) return const base64 = Taro.getFileSystemManager().readFileSync(tempAvatarUrl, "base64");
let res = '' if (base64) res = "data:image/jpg;base64," + base64;
try { } catch (error) {
const base64 = Taro.getFileSystemManager().readFileSync(tempFilePaths[0], "base64"); console.warn("=> utilssearch.ts error imgToBase64", error);
if (base64) { throw error;
res = "data:image/jpg;base64," + base64; } finally { setAvatar(res) }
} }} className="w-[120px] h-[120px] rounded-full overflow-hidden relative p-0">
} catch (error) { <Image src={avatar} className="w-[120px] h-[120px]" mode="aspectFit" />
console.warn("=> utilssearch.ts error imgToBase64", error);
throw error;
} finally {
setAvatar(res)
}
}
})
}}>
<View className="w-[120px] h-[120px] rounded-full overflow-hidden relative">
<Image src={avatar ? avatar : larvea} className="w-full h-full" mode="aspectFill" />
<View className="flex justify-center w-full py-[.1rem] absolute bottom-0 bg-[#00000090] text-[#fff] text-[.6rem]"> <View className="flex justify-center w-full py-[.1rem] absolute bottom-0 bg-[#00000090] text-[#fff] text-[.6rem]">
</View> </View>
</View> </Button>
</View> </View>
<View className="p-[1rem] mb-[.8rem] rounded-[.3rem] bg-[#f5f5f5] shadow-md w-[88%] flex justify-between items-center"> <View className="p-[1rem] mb-[.8rem] rounded-[.3rem] bg-[#f5f5f5] shadow-md w-[88%] flex justify-between items-center">
<Input value={userNickName} placeholder="请输入昵称" style={{ width: 'calc(100% - 6rem)' }} onInput={(e) => { <Input
setUserNickName((e.target as any).value) type="nickname"
}} /> value={userNickName}
<View className="text-[#5EC45F]" onClick={() => { placeholder="请输入昵称"
Taro.getUserProfile({ style={{ width: 'calc(100% - 6rem)' }}
desc: '用于完善会员资料', onInput={(e) => {
success: async (res) => { console.log("nickName =>", e);
const { userInfo, signature } = res; setUserNickName((e.target as any).value)
const { nickName, avatarUrl } = userInfo; }}
if (nickName) setUserNickName(nickName) />
if (avatarUrl) setAvatar(avatarUrl)
Taro.login({
success: (_res) => {
console.log("RES LOGIN", _res);
const { code } = _res
if (signature) setUserSignature(code) // 先用code顶替
}
})
},
fail: (error) => {
console.warn("error", error);
}
})
}}>使</View>
</View> </View>
<View <View
className="text-[#ffffff] rounded-full flex justify-center items-center !bg-[#5ec45f] !w-[88%] py-3 h-[3rem] mb-[2rem]" className="text-[#ffffff] rounded-full flex justify-center items-center !bg-[#5ec45f] !w-[88%] py-3 h-[3rem] mb-[2rem]"
@ -92,6 +68,11 @@ export default function LoginForm(props) {
success: (_res_) => { success: (_res_) => {
const { code } = _res_ const { code } = _res_
if (code) setUserSignature(code) if (code) setUserSignature(code)
if (onConfirm) onConfirm({
openId: code,
nickName: userNickName,
buyerImg: avatar
})
}, },
fail: () => { fail: () => {
Taro.showToast({ Taro.showToast({

View File

@ -1,11 +1,12 @@
import { View, ScrollView, Image, Text } from "@tarojs/components"; import { View, ScrollView, Image, Text, Button } from "@tarojs/components";
import { APP_FULL_HEIGHT, formatMoney, IMG_BASE_URL } from "../../config"; import { APP_FULL_HEIGHT, formatMoney, IMG_BASE_URL } from "../../config";
import HeaderNation from "../../components/HeaderNation"; import HeaderNation from "../../components/HeaderNation";
import OuterFrame from "../../components/OuterFrame"; import OuterFrame from "../../components/OuterFrame";
import StatusBar from "../../components/StatusBar"; import StatusBar from "../../components/StatusBar";
import Taro, { getCurrentInstance } from "@tarojs/taro" import Taro, { getCurrentInstance, useShareAppMessage } from "@tarojs/taro"
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { adoptionOrderPage } from "../../api/user"; import { adoptionOrderPage } from "../../api/user";
import { adoptionGiveOther } from '../../api/order'
import dayjs from "dayjs"; import dayjs from "dayjs";
const poster1 = IMG_BASE_URL + 'pageMe/poster1.png' const poster1 = IMG_BASE_URL + 'pageMe/poster1.png'
@ -31,11 +32,42 @@ export default function InviteFriends() {
console.log("订单", list); console.log("订单", list);
if (Array.isArray(list)) { if (Array.isArray(list)) {
const _item = list.filter(item => item.id === id) const _item = list.filter(item => item.orderNumber === id)
console.log("选中订单", _item);
if (_item.length > 0) setCurOrderItem(_item[0]) if (_item.length > 0) setCurOrderItem(_item[0])
} }
} }
useEffect(() => { getOrderInfo() }, []) useEffect(() => { getOrderInfo() }, [])
useShareAppMessage(async (res) => {
const userOpenId = Taro.getStorageSync("USER_OPEN_ID")
const { data } = await adoptionGiveOther({
originalOrderNumber: id,
openId: userOpenId
})
console.log("赠送接口返回", data);
if (!data) {
Taro.showToast({
title: '赠送失败!',
icon: 'error',
duration: 1400
})
return {}
}
console.log("useShareAppMessage", res)
if (res.from === 'button') {
// 来自页面内分享按钮
} else {
// 右上角分享好友
}
return {
title: '大闸蟹认养小程序', // 分享卡片的title
path: 'pages/login/index?shareId=' + curOrderItem.orderNumber, // 分享卡片的小程序路径
imageUrl: poster1 // 分享卡片的图片链接
};
})
return ( return (
<OuterFrame> <OuterFrame>
<StatusBar /> <StatusBar />
@ -100,7 +132,7 @@ export default function InviteFriends() {
</ScrollView> </ScrollView>
<View style={{ height: bottomNavBarHeight + 'px' }} className="flex flex-col items-center pt-2"> <View style={{ height: bottomNavBarHeight + 'px' }} className="flex flex-col items-center pt-2">
<View className="pb-2 text-[24px] text-[#5EC45F]"></View> <View className="pb-2 text-[24px] text-[#5EC45F]"></View>
<View className="primary-btn w-[85%] h-[2.3rem]"></View> <Button openType="share" className="bg-[#70cc37] rounded-full w-[85%] text-[#fff]"></Button>
</View> </View>
</OuterFrame> </OuterFrame>
) )

View File

@ -1,4 +1,4 @@
import { View, ScrollView, Image, Text } from "@tarojs/components"; import { View, ScrollView, Image, Text, Button } from "@tarojs/components";
import { APP_FULL_HEIGHT, IMG_BASE_URL } from "../../config"; import { APP_FULL_HEIGHT, IMG_BASE_URL } from "../../config";
import HeaderNation from "../../components/HeaderNation"; import HeaderNation from "../../components/HeaderNation";
import OuterFrame from "../../components/OuterFrame"; import OuterFrame from "../../components/OuterFrame";
@ -47,19 +47,21 @@ export default function MyCertificate() {
<Image src={card} className="w-full relative z-0 absolute top-0 left-0" mode="widthFix" /> <Image src={card} className="w-full relative z-0 absolute top-0 left-0" mode="widthFix" />
</View> </View>
</ScrollView> </ScrollView>
<View style={{ height: bottomNavBarHeight + 'px' }} className="flex justify-evenly pt-2"> <View style={{ height: bottomNavBarHeight + 'px' }} className="flex justify-evenly pt-0 items-center">
<View className="default-btn w-[45%] h-[2.3rem]"></View> <Button className="w-[45%] rounded-full bg-[#fff] text-[#74ce38] shadow-md" onClick={() => {
<View className="primary-btn w-[45%] h-[2.3rem]" onClick={() => { Taro.navigateBack()
Taro.navigateTo({ url: '/pageMe/myOrder/index' })
}}></Button>
<Button openType="share" className="w-[45%] rounded-full bg-[#74ce38] text-[#fff]" onClick={() => {
Taro.useShareAppMessage(() => { Taro.useShareAppMessage(() => {
console.log("SSS");
return { return {
title: '这是一个分享页面', // 分享卡片的title title: '这是一个分享页面', // 分享卡片的title
path: 'pageMe/inviteFriends/index', // 分享卡片的小程序路径 path: 'pageMe/inviteFriends/index', // 分享卡片的小程序路径
imageUrl: card // 分享卡片的图片链接 imageUrl: card // 分享卡片的图片链接
} }
}) })
}}></View> // Taro.showShareMenu({ withShareTicket: true })
}}></Button>
</View> </View>
</OuterFrame> </OuterFrame>
) )

View File

@ -57,7 +57,7 @@ export default function MyOrder() {
<View className="flex justify-between items-start py-1 pb-2"> <View className="flex justify-between items-start py-1 pb-2">
<View className="pr-3 grow">{item.planName}</View> <View className="pr-3 grow">{item.planName}</View>
<View <View
className="text-[#fa6642] w-[4rem] break-normal" className="text-[#fa6642] w-[4.6rem] break-normal"
style={{ style={{
color: item.status === '0' ? '#fa6642' : '#1ed76d' color: item.status === '0' ? '#fa6642' : '#1ed76d'
}} }}
@ -70,15 +70,16 @@ export default function MyOrder() {
</View> </View>
<View className="flex justify-between items-center"> <View className="flex justify-between items-center">
<View className="text-[#999999] text-[20px]">{dayjs(item.createTime).format('YYYY-MM-DD HH:mm:ss')}</View> <View className="text-[#999999] text-[20px]">{dayjs(item.createTime).format('YYYY-MM-DD HH:mm:ss')}</View>
<View <View
className="primary-btn !px-2 !py-1 text-[.8rem]" className="primary-btn !px-2 !py-1 text-[.8rem]"
onClick={() => { style={{ display: item.isPresented === '1' ? 'none' : 'block' }}
if (item.status === '0') Taro.navigateTo({ url: '/userInfo/confirmOrder/index?id=' + item.id }) // 未付款 onClick={() => {
if (item.status === '1') Taro.navigateTo({ url: '/pageMe/inviteFriends/index?id=' + item.id }) // 送好友 if (item.status === '0') Taro.navigateTo({ url: '/userInfo/confirmOrder/index?id=' + item.id }) // 未付款
}} if (item.status === '1') Taro.navigateTo({ url: '/pageMe/inviteFriends/index?id=' + item.orderNumber }) // 送好友
>{ }}
OperationMap[item.status] >{
}</View> OperationMap[item.status]
}</View>
</View> </View>
<View <View
className="bg-[#F4F7F3] text-[#5EC45F] text-[20px] p-[.4rem] px-2 mt-2 mb-[-.3rem]" className="bg-[#F4F7F3] text-[#5EC45F] text-[20px] p-[.4rem] px-2 mt-2 mb-[-.3rem]"

View File

@ -1,14 +1,15 @@
import { View, ScrollView, Image, Text } from "@tarojs/components"; import { View, ScrollView, Image, Text, Button } from "@tarojs/components";
import { APP_FULL_HEIGHT, IMG_BASE_URL } from "../../config"; import { APP_FULL_HEIGHT, IMG_BASE_URL } from "../../config";
import HeaderNation from "../../components/HeaderNation"; import HeaderNation from "../../components/HeaderNation";
import OuterFrame from "../../components/OuterFrame"; import OuterFrame from "../../components/OuterFrame";
import StatusBar from "../../components/StatusBar"; import StatusBar from "../../components/StatusBar";
import Taro from "@tarojs/taro" import Taro, { useShareAppMessage } from "@tarojs/taro"
import './index.scss' import './index.scss'
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { adoptionOrderCircle } from "../../api/adoption"; import { adoptionOrderCircle } from "../../api/adoption";
const imgBg = IMG_BASE_URL + 'pages/bg_new.png' const imgBg = IMG_BASE_URL + 'pages/bg_new.png'
const homeBigBg = IMG_BASE_URL + '/pagesHome/homeBigBg.png'
interface CrabOwerItem { interface CrabOwerItem {
id: string id: string
@ -56,6 +57,14 @@ export default function AdoptionCircle() {
</View> </View>
) )
} }
useShareAppMessage(() => {
return {
title: '大闸蟹认养小程序', // 分享卡片的title
path: 'pages/login/index', // 分享卡片的小程序路径
imageUrl: imgBg // 分享卡片的图片链接
};
})
return ( return (
<OuterFrame> <OuterFrame>
<StatusBar /> <StatusBar />
@ -78,7 +87,7 @@ export default function AdoptionCircle() {
<View className="w-full bg-white box-border text-[25px] grow shadow-xl rounded-xl"> <View className="w-full bg-white box-border text-[25px] grow shadow-xl rounded-xl">
<View className="bg-[#f2fbeb] rounded-md p-3 px-5 flex items-center justify-between"> <View className="bg-[#f2fbeb] rounded-md p-3 px-5 flex items-center justify-between">
<View className="text-[#5D8D4F]"></View> <View className="text-[#5D8D4F]"></View>
<View className="bg-[#5ec45f] p-[8px] px-4 rounded-full text-white"></View> <Button openType="share" className="bg-[#5ec45f] rounded-full text-white text-[23px] mx-0"></Button>
</View> </View>
<ScrollView <ScrollView
type="nested" type="nested"

View File

@ -1,5 +1,5 @@
import { Button, Input, View, Image } from "@tarojs/components" import { Button, Input, View, Image } from "@tarojs/components"
import Taro from "@tarojs/taro" import Taro, { getCurrentInstance } from "@tarojs/taro"
import { useEffect, useState } from "react" import { useEffect, useState } from "react"
import LoginForm from "../../components/LoginForm" import LoginForm from "../../components/LoginForm"
import { supabase } from "../../api/supabaseClient" import { supabase } from "../../api/supabaseClient"
@ -9,6 +9,11 @@ import useStore from "../../storage/index"
const loginBg = IMG_BASE_URL + 'pages/bg.png' const loginBg = IMG_BASE_URL + 'pages/bg.png'
const Login = () => { const Login = () => {
const { router } = getCurrentInstance()
// 通过分享链接打开此页面, shareId 其实是 orderNumber
const shareId = router && router.params && router.params.shareId
console.log("通过分享链接打开shareId=", shareId);
// Taro.navigateTo({ url: '/pageMe/myCertificate/index' }) // Taro.navigateTo({ url: '/pageMe/myCertificate/index' })
const setUserAvatar = useStore((store:any) => store.setUserAvatar) const setUserAvatar = useStore((store:any) => store.setUserAvatar)
const setUserName = useStore((store:any) => store.setUserName) const setUserName = useStore((store:any) => store.setUserName)

View File

@ -84,6 +84,7 @@ export default function Adoption() {
if (Array.isArray(data)) setRuleList(data.map(item => ({ ...item, value: 0 }))) if (Array.isArray(data)) setRuleList(data.map(item => ({ ...item, value: 0 })))
} }
const applyCount = (id, value) => { const applyCount = (id, value) => {
if (value < 0) return
setRuleList(ruleList.map(item => { setRuleList(ruleList.map(item => {
if (item.id === id) return { ...item, value } if (item.id === id) return { ...item, value }
return item return item
@ -219,16 +220,13 @@ export default function Adoption() {
<View className="flex justify-between py-1 text-[24px] items-center"> <View className="flex justify-between py-1 text-[24px] items-center">
<View>{item.specs}({formatMoney(item.singlePrice)}/)</View> <View>{item.specs}({formatMoney(item.singlePrice)}/)</View>
<View className="flex space-x-1 items-center"> <View className="flex space-x-1 items-center">
<View className="relative z-10 px-1" onClick={() => { <View className="relative z-10 w-[1.3rem] h-[1.3rem] text-[.9rem] bg-[#f5f5f5] flex justify-center items-center" onClick={() => {
applyCount(item.id, item.value-- ) applyCount(item.id, item.value - 1 )
}}>-</View> }}>-</View>
<Input value={item.value} className="w-[2.4rem] text-[.6rem] text-center relative z-0" type='number' placeholder='选择数量' onInput={(e) => { <Input disabled value={item.value} className="w-[2.1rem] text-[.6rem] text-center relative z-0 mx-1" type='number' placeholder='选择数量' onInput={(e) => {
console.log("rule Input", e.target);
applyCount(item.id, +(e.target as any).value) applyCount(item.id, +(e.target as any).value)
}}/> }}/>
<View className="relative z-10 px-1" onClick={() => { <View className="relative z-10 w-[1.3rem] h-[1.3rem] text-[.9rem] bg-[#f5f5f5] flex justify-center items-center" onClick={() => {
console.log("+1", item.value + 1);
applyCount(item.id, item.value + 1 ) applyCount(item.id, item.value + 1 )
}}>+</View> }}>+</View>
</View> </View>
@ -244,13 +242,15 @@ export default function Adoption() {
<View>(5/)</View> <View>(5/)</View>
</View> </View>
<View className="flex space-x-1 items-center"> <View className="flex space-x-1 items-center">
<View className="relative z-10 px-1" onClick={() => { <View className="relative z-10 w-[1.3rem] h-[1.3rem] text-[.9rem] bg-[#f5f5f5] flex justify-center items-center" onClick={() => {
setAmountCount((parseInt(amountCount) - 1).toString()) const _val = parseInt(amountCount) - 1
if (_val < 0) return
setAmountCount(_val.toString())
}}>-</View> }}>-</View>
<Input value={amountCount} className="w-[2.4rem] text-[.6rem] text-center relative z-0" type='number' placeholder='选择数量' onInput={(e) => { <Input disabled value={amountCount} className="w-[2.4rem] text-[.6rem] text-center relative z-0" type='number' placeholder='选择数量' onInput={(e) => {
setAmountCount((e.target as any).value) setAmountCount((e.target as any).value)
}}/> }}/>
<View className="relative z-10 px-1" onClick={() => { <View className="relative z-10 w-[1.3rem] h-[1.3rem] text-[.9rem] bg-[#f5f5f5] flex justify-center items-center" onClick={() => {
setAmountCount((parseInt(amountCount) + 1).toString()) setAmountCount((parseInt(amountCount) + 1).toString())
}}>+</View> }}>+</View>
</View> </View>

View File

@ -1,6 +1,6 @@
import { View,Image,Text, ScrollView } from "@tarojs/components"; import { View,Image,Text, ScrollView, Button } from "@tarojs/components";
import './index.scss' import './index.scss'
import Taro from "@tarojs/taro"; import Taro, { useShareAppMessage } from "@tarojs/taro";
import { IMG_BASE_URL } from "../config"; import { IMG_BASE_URL } from "../config";
import useStore from "../storage"; import useStore from "../storage";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
@ -25,7 +25,7 @@ const CropGrowth = ({ belongPlot, type, updatePeriod }) => {
const { list } = data; const { list } = data;
console.log("getDataList", list); console.log("getDataList", list);
if (Array.isArray(list)) { if (Array.isArray(list)) {
setDataList(list) setDataList(list.map(item => ({ ...item, imgId: item.imgId.replace("http://117.73.12.97:9000", "https://www.zhuangbeizz.cn/minio")})))
if (list.length > 0) { if (list.length > 0) {
updatePeriod(list[0]) updatePeriod(list[0])
} }
@ -191,6 +191,14 @@ export default function Monitor() {
} }
} }
useEffect(() => { getMyOrder() }, []) useEffect(() => { getMyOrder() }, [])
useShareAppMessage(() => {
return {
title: '大闸蟹认养小程序', // 分享卡片的title
path: 'pages/login/index', // 分享卡片的小程序路径
imageUrl: headerBg // 分享卡片的图片链接
};
})
return ( return (
<View className="relative"> <View className="relative">
<AdoptionCircle /> <AdoptionCircle />
@ -219,10 +227,10 @@ export default function Monitor() {
<View className="text-[22px] mt-1"></View> <View className="text-[22px] mt-1"></View>
</View> </View>
</View> </View>
<View className="flex items-center justify-center rounded-full px-[12px] py-[5px]" style={{ border: '1px solid #5EC45F' }}> <Button openType="share" className="flex items-center justify-center rounded-full mx-0" style={{ border: '1px solid #5EC45F' }}>
<Image src={shareIcon} className="w-[.8rem] h-[.6rem]" /> <Image src={shareIcon} className="w-[.8rem] h-[.6rem]" />
<View className="text-[#5EC45F] text-[20px] ml-[3px]"></View> <View className="text-[#5EC45F] text-[20px] ml-[3px]"></View>
</View> </Button>
</View> </View>
<View className="flex justify-between text-[20px] text-[#5EC45F] mt-1"> <View className="flex justify-between text-[20px] text-[#5EC45F] mt-1">
<View>{year}.{month}</View> <View>{year}.{month}</View>

View File

@ -5,13 +5,15 @@ import { View, ScrollView, Image } from "@tarojs/components";
import { APP_FULL_HEIGHT, IMG_BASE_URL } from "../../config"; import { APP_FULL_HEIGHT, IMG_BASE_URL } from "../../config";
import noData from './assets/noData.png' import noData from './assets/noData.png'
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import Taro, { useDidShow } from "@tarojs/taro"; import Taro, { getCurrentInstance, useDidShow } from "@tarojs/taro";
import { addressCreate, addressPage } from "../../api/me"; import { addressCreate, addressPage, updateAddress } from "../../api/me";
const arrow = IMG_BASE_URL + 'arrow.png' const arrow = IMG_BASE_URL + 'arrow.png'
export default function Address() { export default function Address() {
const bottomNavBarHeight = 80 const bottomNavBarHeight = 80
const { router } = getCurrentInstance()
const orderId = router?.params?.orderId
const NoData = () => { const NoData = () => {
return ( return (
<View className="flex flex-col items-center bg-white m-3 p-5 py-10 rounded-xl shadow-md"> <View className="flex flex-col items-center bg-white m-3 p-5 py-10 rounded-xl shadow-md">
@ -25,7 +27,17 @@ export default function Address() {
return ( return (
<View className="p-3 pb-0" key={item.id}> <View className="p-3 pb-0" key={item.id}>
<View className="bg-white p-4 px-5 flex items-center rounded-xl shadow-md" onClick={ <View className="bg-white p-4 px-5 flex items-center rounded-xl shadow-md" onClick={
() => Taro.navigateTo({ url: '/userInfo/addAddress/index?edit=true&id=' + item.id }) async () => {
if (!orderId) Taro.navigateTo({ url: '/userInfo/addAddress/index?edit=true&id=' + item.id })
else {
const data = await updateAddress({
id: orderId, addressNumber: item.addressNumber
})
console.log("更新地址", data);
Taro.navigateBack()
}
}
}> }>
<View className="grow"> <View className="grow">
<View className="text-[30px] flex space-x-2 items-center"> <View className="text-[30px] flex space-x-2 items-center">
@ -52,6 +64,8 @@ export default function Address() {
const openId = Taro.getStorageSync("USER_OPEN_ID") const openId = Taro.getStorageSync("USER_OPEN_ID")
const { data } = await addressPage({ openId }) const { data } = await addressPage({ openId })
const { list } = data const { list } = data
console.log("Address List", list);
if (Array.isArray(list)) setAddressList(list) if (Array.isArray(list)) setAddressList(list)
} }
useDidShow(() => { useDidShow(() => {
@ -60,7 +74,7 @@ export default function Address() {
return ( return (
<OuterFrame> <OuterFrame>
<StatusBar /> <StatusBar />
<HeaderNation title="收货地址"></HeaderNation> <HeaderNation title={orderId ? '选择收货地址' : "收货地址"}></HeaderNation>
<ScrollView <ScrollView
type="nested" type="nested"
scrollY scrollY
@ -81,36 +95,41 @@ export default function Address() {
style={{ height: bottomNavBarHeight + 'px' }} style={{ height: bottomNavBarHeight + 'px' }}
className="bg-[#f5f5f5] p-2 flex items-start pt-3 justify-evenly w-full" className="bg-[#f5f5f5] p-2 flex items-start pt-3 justify-evenly w-full"
> >
<View className="default-btn w-[45%]" onClick={() => { {
Taro.chooseAddress({ orderId ? <>
success: async (e) => { <View className="default-btn w-[45%]" onClick={() => {
console.log("E", e); Taro.chooseAddress({
const userOpenId = Taro.getStorageSync("USER_OPEN_ID") success: async (e) => {
const { data, code } = await addressCreate({ console.log("E", e);
openId: userOpenId, const userOpenId = Taro.getStorageSync("USER_OPEN_ID")
contact: e.userName, const { data, code } = await addressCreate({
phoneNumber: e.telNumber, openId: userOpenId,
areaInfo: e.provinceName + '/' + e.cityName + '/' + e.countyName, contact: e.userName,
fullAddress: e.detailInfo, phoneNumber: e.telNumber,
zipCode: e.postalCode, areaInfo: e.provinceName + '/' + e.cityName + '/' + e.countyName,
isDefault: '1', fullAddress: e.detailInfo,
remark: "", zipCode: e.postalCode,
userId: "", isDefault: '1',
deptId: "", remark: "",
tenant: "158" userId: "",
deptId: "",
tenant: "158"
})
if (code === 0) getAddressList()
else Taro.showToast({
title: '保存失败!',
icon: 'error',
duration: 1400
})
}
}) })
if (code === 0) getAddressList() }}></View>
else Taro.showToast({ <View className="primary-btn w-[45%]" onClick={() => {
title: '保存失败!', Taro.navigateTo({ url: '/userInfo/addAddress/index' })
icon: 'error', }}></View>
duration: 1400 </> : <>
}) </>
} }
})
}}></View>
<View className="primary-btn w-[45%]" onClick={() => {
Taro.navigateTo({ url: '/userInfo/addAddress/index' })
}}></View>
</View> </View>
</OuterFrame> </OuterFrame>
) )

View File

@ -44,63 +44,45 @@ const CalcLeftTime = ({ time }) => {
export default function ConfirmOrder() { export default function ConfirmOrder() {
const userAvatar = useStore((store:any) => store.userAvatar) const userAvatar = useStore((store:any) => store.userAvatar)
const bottomNavBarHeight = 130 const bottomNavBarHeight = 130
// 倒计时
const [leftTime, setLeftTime] = useState(100)
const Divider = () => { const Divider = () => {
return ( return (
<View className="bg-[#25252525] w-[calc(100% - 8px)] ml-[4px] h-[1px] my-1"></View> <View className="bg-[#25252525] w-[calc(100% - 8px)] ml-[4px] h-[1px] my-1"></View>
) )
} }
const [orderInfo, setOrderInfo] = useState<any>({}) const [orderInfo, setOrderInfo] = useState<any>({})
const { router } = getCurrentInstance() const { router } = getCurrentInstance()
console.log("ID" , router && router.params && router.params.id);
const OrderId = router && router.params && router.params.id const OrderId = router && router.params && router.params.id
// 获取订单信息
const getOrderInfo = async () => { const getOrderInfo = async () => {
if (!OrderId) return if (!OrderId) return
const userOpenId = Taro.getStorageSync("USER_OPEN_ID") const { data } = await getOrderInfoById({ orderId: OrderId })
const { data } = await getOrderInfoById({ if (data.orderId === OrderId) setOrderInfo(data)
id: OrderId,
serialNumber: 'JHLS202407012565376',
openId: userOpenId
})
const { list } = data;
if (!Array.isArray(list)) return
const _orderItem = list.filter(item => {
if (item.id === OrderId) return true;
return false
})
console.log("_orderItem", _orderItem[0]);
if (_orderItem && _orderItem.length > 0) setOrderInfo(_orderItem[0])
else { else {
Taro.navigateBack() Taro.navigateBack()
Taro.showToast({ Taro.showToast({ title: '获取订单失败!', icon: 'error', duration: 1400 })
title: '获取订单失败!',
icon: 'error',
duration: 1400
})
} }
} }
useEffect(() => { useDidShow(() => { getOrderInfo() })
getOrderInfo()
}, [])
const [defaultAdd, setDefaultAdd] = useState<any>({ const formatSpecs = (orderDetailList) => {
id: '' if (Array.isArray(orderDetailList)) {
}) const arr = orderDetailList.map(item => (item.specs.specs))
const getAddress = async () => { return arr.join(';\n')
const userOpenId = Taro.getStorageSync("USER_OPEN_ID") } else {
const { data } = await addressPage({ return ''
openId: userOpenId }
}) }
const { list } = data;
console.log("List", list); // 订单超时 返回true
if (!Array.isArray(list)) return const diabledPay = () => {
const _defaultAdd = list.filter(item => (item.isDefault === '1'))[0] if (!orderInfo?.orderCreateTime) return false
if (_defaultAdd) setDefaultAdd(_defaultAdd) const now = new Date().valueOf()
const limitTime = orderInfo.orderCreateTime + 1000 * 60 * 15
if (limitTime - now < 0) return true
return false
} }
useDidShow(() => { getAddress() })
return ( return (
<OuterFrame> <OuterFrame>
<StatusBar /> <StatusBar />
@ -115,52 +97,61 @@ export default function ConfirmOrder() {
className="pb-1 box-border overflow-hidden box-border" className="pb-1 box-border overflow-hidden box-border"
> >
<View className="p-3"> <View className="p-3">
<View className="bg-white p-4 px-5 flex items-center rounded-xl shadow-md" style={{ display: defaultAdd.id ? 'flex' : 'none' }}> {
<View className="grow"> orderInfo?.orderId ? (
<View className="text-[30px]"> <>
<Text>{defaultAdd.contact}</Text> {
<Text className="pl-[.4rem]">{defaultAdd.phoneNumber}</Text> orderInfo?.addressInfo?.id ? <View className="bg-white p-4 px-5 flex items-center rounded-xl shadow-md flex">
</View> <View className="grow">
<View className="text-[26px] mt-1">{defaultAdd.fullAddress}</View> <View className="text-[30px]">
</View> <Text>{orderInfo.addressInfo.contact}</Text>
<Image src={arrow} className="w-[14px] h-[20px]" onClick={() => { <Text className="pl-[.4rem]">{orderInfo.addressInfo.phoneNumber}</Text>
Taro.navigateTo({ url: '/userInfo/address/index' }) </View>
}} /> <View className="text-[26px] mt-1">
</View> <Text>{orderInfo.addressInfo.areaInfo}</Text>
<View <Text className="pl-2">{orderInfo.addressInfo.fullAddress}</Text>
className="text-[.7rem] bg-white p-4 px-5 flex items-center justify-center rounded-xl shadow-md" </View>
style={{ display: defaultAdd.id ? 'none' : 'flex' }} </View>
onClick={() => { <Image src={arrow} className="w-[14px] h-[20px]" onClick={() => {
Taro.navigateTo({ url: '/userInfo/address/index' }) Taro.navigateTo({ url: '/userInfo/address/index?orderId=' + OrderId })
}} }} />
> </View> : <View
<Image src={positionIcon} className="w-[.7rem] h-[.7rem] mr-[.3rem]" mode="heightFix" /> className="text-[1.1rem] bg-white p-4 px-5 flex items-center justify-center rounded-xl shadow-md flex"
<View></View> onClick={() => {
</View> Taro.navigateTo({ url: '/userInfo/address/index?orderId=' + OrderId })
<View className="bg-white p-3 mt-2 rounded-xl shadow-md"> }}
<View className="flex items-center"> >
<Image src={userAvatar} className="w-[3rem] h-[3rem] rounded-md shadow-sm" mode="aspectFill" /> <Image src={positionIcon} className="w-[1rem] h-[1rem] mr-[.3rem]" mode="heightFix" />
<View className="pl-2"> <View className="text-[.9rem] pl-[.3rem]"></View>
<View>{orderInfo.plotName}</View> </View>
<View className="text-[22px] text-[#999999] mt-[.3rem]">{orderInfo?.detail?.specs?.map(item => (item.specs)).join(';')}</View> }
</View> <View className="bg-white p-3 mt-2 rounded-xl shadow-md">
</View> <View className="flex items-center">
<View className="flex justify-between items-center text-[24px] mt-2"> <Image src={userAvatar} className="w-[3rem] h-[3rem] rounded-md shadow-sm" mode="aspectFill" />
<View className="text-[#999999]">:</View> <View className="pl-2">
<View style={{ display: orderInfo.expectStart ? 'block' : 'none' }}> <View>{orderInfo.plotName}</View>
<Text>{dayjs(orderInfo.expectStart).format("YYYY-MM-DD")}</Text> <View className="text-[22px] text-[#999999] mt-[.3rem]">{formatSpecs(orderInfo.orderDetailList)}</View>
<Text>-</Text> </View>
<Text>{dayjs(orderInfo.expectEnd).format("YYYY-MM-DD")}</Text> </View>
</View> <View className="flex justify-between items-center text-[24px] mt-2">
</View> <View className="text-[#999999]">:</View>
<View className="w-full py-2"><Divider /></View> <View style={{ display: orderInfo.orderExpectStart ? 'block' : 'none' }}>
<View className="flex flex-row-reverse text-[#FF663F]"> <Text>{dayjs(orderInfo.orderExpectStart).format("YYYY-MM-DD")}</Text>
<View> <Text>---</Text>
<Text className="text-[22px]"></Text> <Text>{dayjs(orderInfo.orderExpectEnd).format("YYYY-MM-DD")}</Text>
<Text className="pl-[.4rem] text-[26px]">{formatMoney(orderInfo.orderAmount || 0)}</Text> </View>
</View> </View>
</View> <View className="w-full py-2"><Divider /></View>
</View> <View className="flex flex-row-reverse text-[#FF663F]">
<View>
<Text className="text-[22px]"></Text>
<Text className="pl-[.4rem] text-[26px]">{formatMoney(orderInfo.orderAmount || 0)}</Text>
</View>
</View>
</View>
</>
) : null
}
</View> </View>
</ScrollView> </ScrollView>
<View <View
@ -170,13 +161,21 @@ export default function ConfirmOrder() {
<View className="py-2"> <View className="py-2">
<Text>:</Text> <Text>:</Text>
<Text className="pl-1"> <Text className="pl-1">
<CalcLeftTime time={orderInfo.createTime + 1000 * 60 * 15} /> <CalcLeftTime time={orderInfo.orderCreateTime + 1000 * 60 * 15} />
</Text> </Text>
</View> </View>
<View className="!py-[26px] primary-btn w-[85%]" onClick={async () => { <View className="!py-[26px] px-[16px] text-center text-[#fff] rounded-full w-[85%]" style={{ backgroundColor: diabledPay() ? '#777777' : '#63c632' }} onClick={async () => {
if (diabledPay()) {
Taro.showToast({
title: '订单超时!',
icon: 'error',
duration: 1400
})
return
}
const id = router && router.params && router.params.id const id = router && router.params && router.params.id
if (!id) return if (!id) return
if (!defaultAdd.id) { if (!orderInfo?.addressInfo?.id) {
Taro.showToast({ Taro.showToast({
title: '请选择地址', title: '请选择地址',
icon: 'error', icon: 'error',