From 15a55f79a84e5dab670d54a9dc0c6b9133a18441 Mon Sep 17 00:00:00 2001 From: Liuyi <candymxq888@outlook.com> Date: 星期一, 21 十月 2024 17:29:37 +0800 Subject: [PATCH] 添加更改用户头像,添加故障上报校验 --- pages/index/index.vue | 158 ++++++++++++++++++++++++++++++++-------------------- 1 files changed, 96 insertions(+), 62 deletions(-) diff --git a/pages/index/index.vue b/pages/index/index.vue index 6f3549d..2603032 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -1,6 +1,6 @@ <script setup> import { onMounted, ref } from "vue"; - import { getVipInfoApi,getUserInfo,reportLossApi,removeCardApi } from '../../api/index.js' + import { getVipInfoApi,getUserInfo,reportLossApi,removeCardApi,buyWaterApi } from '../../api/index.js' import { onShow,getCurrentPages } from '@dcloudio/uni-app' //状态栏高度 const topHeight = ref(0) @@ -33,7 +33,9 @@ await getVipInfoApi().then((res) =>{ if(res.code == 200 && res.data.id){ cardInfo.value.waterCardNumber = res.data.cardNumber - cardInfo.value.state = res.data.state == 2 ? true : false//state:2:挂失,1:正常 + cardInfo.value.cardType = res.data.cardType + //用户信息处理存储 + cardInfo.value.state = res.data.state == 2 ? true : false//state:2:挂失,1:正常 是否挂失 cardInfo.value.userCardType = res.data.userCardType == 2 ? true : false //userCardType:2:共享卡,1:正常卡 isLoss.value = cardInfo.value.state @@ -69,10 +71,24 @@ //调用二维码扫描接口 uni.scanCode({ scanType: ['qrCode'], - success: function (res) { + success: async function (res) { console.log('条码内容:' + res.result); - uni.navigateTo({ - url:'/pages/scanWater/index' + let data = { + cardType:cardInfo.value.cardType, + card:cardInfo.value.waterCardNumber, + sn:res.result + } + await buyWaterApi(data).then((res) =>{ + if(res.code == 200){ + uni.navigateTo({ + url:'/pages/scanWater/index' + }) + }else{ + uni.showToast({ + title:'扫码失败!', + icon:'none' + }) + } }) } }); @@ -103,29 +119,42 @@ navTo(url) }else if(isUrl == 2){ if(cardInfo.value.waterCardNumber){ - uni.showModal({ - title: '会员卡挂失', - content: '确认挂失会员卡?', - success: async function(res) { - if (res.confirm) { - await reportLossApi(cardInfo.value.waterCardNumber).then(async(res) =>{ - if(res.code == 200){ - uni.showToast({ - title: '已挂失', - duration: 2000, - }); - await getVipInfoApi().then((res) =>{ - if(res.code == 200){ - if(res.data.state == 2){ - isLoss.value = true + //不是共享卡且未挂失 + if(!isShareCard.value && !cardInfo.value.state){ + uni.showModal({ + title: '会员卡挂失', + content: '确认挂失会员卡?', + success: async function(res) { + if (res.confirm) { + await reportLossApi(cardInfo.value.waterCardNumber).then(async(res) =>{ + if(res.code == 200){ + uni.showToast({ + title: '已挂失', + duration: 2000, + }); + await getVipInfoApi().then((res) =>{ + if(res.code == 200){ + if(res.data.state == 2){ + isLoss.value = true + } } - } - }) - } - }) + }) + } + }) + } } - } - }) + }) + }else if(isShareCard.value){ + uni.showToast({ + title:'共享卡无权限', + icon:'none' + }) + }else if(cardInfo.value.state){ + uni.showToast({ + title:'已挂失', + icon:'none' + }) + } }else{ uni.showToast({ title:'未绑定会员卡!', @@ -134,48 +163,49 @@ } }else if(isUrl == 3){ if(cardInfo.value.waterCardNumber){ - uni.showModal({ - title: '会员卡注销', - content: '确认注销会员卡?', - success: async function(res) { - if (res.confirm) { - await removeCardApi(cardInfo.value.waterCardNumber).then(async(res) =>{ - if(res.code == 200){ - uni.showToast({ - title: '已注销', - duration: 2000, - icon:'none', - }); - await getVipInfoApi().then((res) =>{ - if(res.code == 200){ - if(!res.data.id){ - isVip.value = false - cardInfo.value.balance = '' - cardInfo.value.count = '' - cardInfo.value.waterCardNumber = '' - uni.setStorageSync('userInfo',JSON.stringify(cardInfo.value)) + if(!isShareCard.value){ + uni.showModal({ + title: '会员卡注销', + content: '确认注销会员卡?', + success: async function(res) { + if (res.confirm) { + await removeCardApi(cardInfo.value.waterCardNumber).then(async(res) =>{ + if(res.code == 200){ + uni.showToast({ + title: '已注销', + duration: 2000, + icon:'none', + }); + await getVipInfoApi().then((res) =>{ + if(res.code == 200){ + if(!res.data.id){ + isVip.value = false + cardInfo.value.balance = '' + cardInfo.value.count = '' + cardInfo.value.waterCardNumber = '' + uni.setStorageSync('userInfo',JSON.stringify(cardInfo.value)) + } } - } - }) - } - }) - }else{ - console.log('点击了取消8') + }) + } + }) + } } - } - }) - }else{ + }) + }else{ uni.showToast({ - title:'未绑定会员卡!', + title:'共享卡无权限', icon:'none' }) + } + }else{ + uni.showToast({ + title:'未绑定会员卡!', + icon:'none' + }) } }else{ - uni.showToast({ - title: '该功能正在升级中!', - duration: 2000, - icon:'none', - }); + upGrade() } } function upGrade(){ @@ -187,8 +217,10 @@ } onMounted( async() =>{ getTopHeight() + await getInfo() }) onShow(async() =>{ + getTopHeight() await getInfo() }) uni.showShareMenu({ @@ -210,7 +242,8 @@ <view class="content"> <view class="card-box" :style="{paddingTop:topHeight + 'rpx'}"> <view class="user-info" > - <image class="user-img" src='../../static/images/index/head.png' alt=''></image> + <image v-if="cardInfo.headImg" class="user-img" :src='cardInfo.headImg' alt=''></image> + <image v-else class="user-img" src='../../static/images/index/head.png' alt=''></image> <text @click="navTo('/pages/userInfo/index')">{{cardInfo.userName}}</text> <image @click="navTo('/pages/userInfo/index')" class="user-more"src="../../static/images/index/back.png"></image> <view class="user-add-card" @click="navTo('/pages/addCard/index')"> @@ -341,6 +374,7 @@ .user-img{ width:90rpx; height:90rpx; + border-radius:50%; margin-right:20rpx; } text{ -- Gitblit v1.9.3