Ver código fonte

修改返回

wangxy 6 dias atrás
pai
commit
e938219e34

+ 1 - 1
pages.json

@@ -115,7 +115,7 @@
 			}
 		},
 		{
-			"path" : "pages/chanpinShop/orderHistory",
+			"path" : "pages/chanpinMy/duihuanma",
 			"style" :
 			{
 				"navigationStyle": "custom"

+ 1 - 0
pages/chanpinMy/components/duihuanma/duihuanmaDialog.vue

@@ -58,6 +58,7 @@ const props = defineProps({
     type: String,
   },
 });
+
 const tipSmallPopup = ref(null); // 索引
 const duihuamaValue = ref(''); // 索引
 const $emit = defineEmits(['confirm-btn'])

+ 118 - 0
pages/chanpinMy/duihuanma.vue

@@ -0,0 +1,118 @@
+<template>
+	<view class="icon-title-navBar-box">
+		<view @click="handleBack" class="nav-bar-icon"></view>
+		<text class="nav-bar-title">使用兑换码</text>
+	</view>
+	<view>
+		<view class="tip-content-box">
+			<icon class="head-img-box" :style="{backgroundImage: 'url(' + myInfoData.icon + ')'}"></icon>
+			<view>{{ myInfoData.nickName }}</view>
+			<view>{{ myInfoData.userName }}</view>
+			<input class="duihuan-input" type="text" focus v-model="duihuamaValue" placeholder="请输入兑换码" />
+			<view class="tip-btn-box">
+				<view class="confirm-btn" @click="confirmBtn"></view>
+			</view>
+		</view>
+	</view>
+
+	<!-- 失败 -->
+	<duihuanError ref="dhErrRef"></duihuanError>
+	<!-- 成功 -->
+	<duihuanSuccess ref="dhSucRef"></duihuanSuccess>
+</template>
+
+<script setup>
+	import {
+		ref,reactive
+	} from 'vue';
+	import duihuanError from "./components/duihuanma/duihuanError";
+	import duihuanSuccess from "./components/duihuanma/duihuanSuccess";
+	import {
+		duihuanmaCode,
+	} from '@/api/my.js'
+	import cacheManager from '@/utils/cacheManager';
+  import {toast} from "@/utils/common";
+  import {myInfo} from "@/api/my";
+  import {
+    onLoad,
+    onShow
+  } from '@dcloudio/uni-app';
+
+	const duihuamaValue = ref(''); // 索引
+	const dhErrRef = ref(null);
+	const dhSucRef = ref(null);
+	const myInfoData = reactive({
+		userName: '',
+		nickName: '',
+		icon: '',
+	});
+
+	onLoad(() => {
+		getMyInfo();
+	})
+
+	// 获取用户数据
+	function getMyInfo() {
+		myInfo({}).then(res => {
+			myInfoData.userName = res.data.userName;
+			myInfoData.nickName = res.data.nickName;
+			if (res.data.nickName) {
+				myInfoData.nickName = res.data.nickName;
+			} else {
+				myInfoData.nickName = '鹅状元';
+			}
+			if (res.data.icon) {
+				myInfoData.icon = res.data.icon;
+			} else {
+				getUserImg(res.data.growthType)
+			}
+		})
+	}
+
+	// 获取用户头像
+	function getUserImg(data) {
+		switch (data) {
+			case 0:
+				myInfoData.icon = 'static/images/my/head-img0.png'
+				break;
+			case 1:
+				myInfoData.icon = 'static/images/my/head-img1.png'
+				break;
+			case 2:
+				myInfoData.icon = 'static/images/my/head-img2.png'
+				break;
+			case 3:
+				myInfoData.icon = 'static/images/my/head-img3.png'
+				break;
+			default:
+				myInfoData.icon = 'static/images/my/head-unlogin-img.png'
+				break;
+		}
+	}
+
+
+	function handleBack() {
+		uni.navigateBack()
+	}
+
+	// 确认
+	function confirmBtn() {
+		let req = {
+			code: duihuamaValue.value
+		}
+		duihuanmaCode(req).then(res => {
+			if (res.code == 0) {
+				toast('兑换成功')
+				// 清空缓存
+				cacheManager.remove("contentInfo");
+				duihuamaValue.value = '';
+			} else {
+				toast('兑换失败请重试或联系管理员')
+			}
+		})
+	}
+</script>
+
+<style>
+
+</style>

+ 19 - 13
pages/chanpinMy/my.vue

@@ -31,22 +31,17 @@
           <icon class="list-icon yysz-icon"></icon>
           <text>商城</text>
         </view>
-				<view v-if="appleCode=='true'&&currentPlatform=='ios' || currentPlatform=='android'" class="list-item"
+			<!-- <view v-if="appleCode=='true'&&currentPlatform=='ios' || currentPlatform=='android'" class="list-item" -->
+			<view class="list-item"
 					@click="duihuamaDuihuan">
-					<icon class="list-icon duihuanma-icon"></icon>
+					<icon class="list-icon yysz-icon"></icon>
 					<text>兑换码</text>
 				</view>
-
-<!--				<view class="list-item" @click="test">
-					<icon class="list-icon yysz-icon"></icon>
-					<text>test</text>
-				</view>-->
 			</view>
 		</view>
 
-		<duihuanmaDialog ref="duihuanmaDialogRef" :icon="myInfoData.icon" title="兑换" :userName="myInfoData.userName" :nickName="myInfoData.nickName"></duihuanmaDialog>
 		
-		<loginComp ref="loginRef"></loginComp>
+		<loginComp ref="loginRef" @success="handleSuccess"></loginComp>
 		<!-- 底部 -->
 		<custom-tab-bar :show="true" :current-index="currentTabIndex" />
 	</view>
@@ -72,6 +67,7 @@
 		reactive,
 		ref
 	} from "vue";
+  import {getUserIsYouke} from "../../utils/common";
 
 	let appleCode =ref(null)
 	let currentPlatform = ref(null);
@@ -87,7 +83,6 @@
 		icon: '',
 	});
 	let pageFrom = ref(null)
-	let duihuanmaDialogRef = ref(null)
 
 	onShow(() => {
 		currentTabIndex.value = 3
@@ -160,15 +155,26 @@
 
 	function duihuamaDuihuan() {
 		// 兑换码兑换策略
-		if (authInfo.value.youke) {
+		if (getUserIsYouke()) {
 			// 非登录 -- 登录
-			
+			loginRef.value.showPopup()
 		} else {
 			// 已登录
-			duihuanmaDialogRef.value.handleShow();
+			uni.navigateTo({
+				url:'/pages/chanpinMy/duihuanma'
+			})
 		}
 	}
 
+  function handleSuccess(authInfo) {
+    // 登录成功更改用户名
+    myInfoData.userName = authInfo.userName;
+    // 前往兑换码
+    uni.navigateTo({
+      url:'/pages/chanpinMy/duihuanma'
+    })
+  }
+
 	onLoad((options) => {
 		uni.hideTabBar()
 		getAuthData();

+ 0 - 13
pages/chanpinShop/orderHistory.vue

@@ -1,13 +0,0 @@
-<template>
-	<view>
-		
-	</view>
-</template>
-
-<script setup>
-
-</script>
-
-<style>
-
-</style>

+ 1 - 0
utils/common.js

@@ -147,6 +147,7 @@ export function convertTimeToSeconds(timeStr) {
     return totalSeconds.toString();
 }
 
+// 当前用户是否是非游客
 export function getUserIsYouke() {
 	const auth = cacheManager.get('auth');
 	if (!auth) {