diff --git a/src/App.vue b/src/App.vue index 7bd0892..a257c09 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,7 +1,12 @@ <script> +import useUserStore from '@/jtools/store/user' export default { onLaunch: function () { - console.log('App Launch') + useUserStore().queryVipList() + if(useUserStore().isLogin) { + useUserStore().getUserInfo() + useUserStore().searchUserVip() + } }, onShow: function () { console.log('App Show') diff --git a/src/jtools/api/login.js b/src/jtools/api/login.js index 6c3f231..181e52a 100644 --- a/src/jtools/api/login.js +++ b/src/jtools/api/login.js @@ -23,4 +23,11 @@ export function logout() { url: 'driver-api/tdSysUser/loginOut', method: 'get', }); +} + +export function getInfo() { + return request({ + url: 'driver-api/tdSysUser/info', + method: 'get', + }); } \ No newline at end of file diff --git a/src/jtools/api/vip.js b/src/jtools/api/vip.js index ee5f469..1df6e42 100644 --- a/src/jtools/api/vip.js +++ b/src/jtools/api/vip.js @@ -6,4 +6,12 @@ export function queryVip(data) { method: 'POST', data, }); +} + +export function getVipList(data) { + return request({ + url: 'driver-api/tdMember/queryMember', + method: 'POST', + data, + }); } \ No newline at end of file diff --git a/src/jtools/request/index.js b/src/jtools/request/index.js index f8e4f3c..90eeccd 100644 --- a/src/jtools/request/index.js +++ b/src/jtools/request/index.js @@ -16,7 +16,7 @@ function service(options = {}) { }); } else { options.header = { - Authorization: `Bearer ${token}` + Authorization: `${token}` }; } } @@ -34,7 +34,7 @@ function service(options = {}) { resolved(res.data); } else if(res.data.code != '0000') { uni.showToast({ - title: resp.message, + title: res.data.message, icon: 'none' }) resolved(res.data) diff --git a/src/jtools/store/user.js b/src/jtools/store/user.js index bd845df..e2e6e40 100644 --- a/src/jtools/store/user.js +++ b/src/jtools/store/user.js @@ -1,5 +1,6 @@ import { defineStore } from 'pinia'; -import { login,logout } from '@/jtools/api/login'; +import { login,logout,getInfo } from '@/jtools/api/login'; +import { queryVip,getVipList } from '@/jtools/api/vip' import constants from '@/jtools/constants'; import storage from '@/jtools/storage'; @@ -9,11 +10,13 @@ const useUserStore = defineStore({ token: storage.get('token'), isLogin: storage.get('isLogin'), // 是否登陆 userInfo: storage.get('userInfo'), // 用户信息 + currentCartype: storage.get('carType') || '1001', + vipOnList: [], + vipAllList: [] }), actions: { login(params) { - // commit('isLogin', true); return new Promise(async (resolve, reject) => { const resp = await login(params); if (resp.code === '0000') { @@ -40,13 +43,39 @@ const useUserStore = defineStore({ resolve(); }) }, + // 获取用户信息 + getUserInfo() { + getInfo().then(resp => { + if(resp.code == '0000') { + this.userInfo = resp.data + storage.set('userInfo', resp.data) + } + }) + }, resetUserData() { this.isLogin = false; this.token = ''; this.userInfo = {} + this.vipOnList = [] storage.remove('isLogin') storage.remove('token') storage.remove('userInfo') + }, + // 查询当前用户的vip开通情况 + searchUserVip() { + queryVip({ carTypeId: this.currentCartype,memberId: null, subject:'' }).then(resp => { + if(resp.code == '0000') { + this.vipOnList = resp.data + } + }) + }, + // 查询所有的vip + queryVipList() { + getVipList({ carTypeId: this.currentCartype,memberId: null, subject:'' }).then(resp => { + if(resp.code == '0000') { + this.vipAllList = resp.data + } + }) } }, }); diff --git a/src/pages/login/login.vue b/src/pages/login/login.vue index d4a1d45..2cf492c 100644 --- a/src/pages/login/login.vue +++ b/src/pages/login/login.vue @@ -57,19 +57,19 @@ getCode({ phone: this.login.phone }).then(resp => { - if (resp.code == '0000') { + // if (resp.code == '0000') { uni.showToast({ title: '发送成功!', icon: 'none' }) this.countDown = 60 this.js = setInterval(() => { - this.countDown; + this.countDown--; if (this.countDown == 0) { this.clear() } }, 1000) - } + // } }) } }, diff --git a/src/pages/me/index.vue b/src/pages/me/index.vue index e8ca953..fb14ed2 100644 --- a/src/pages/me/index.vue +++ b/src/pages/me/index.vue @@ -8,7 +8,7 @@ <view class="ml12"> <view class="flex ai-c fs18 cor-333 fwb"> <text class="mr10">{{ user.userName }}{{user.userId}}</text> - <image src="/static/image/mine/vip.png" mode="widthFix" style="width: 18px;"></image> + <image v-if="vipOn.length" src="/static/image/mine/vip.png" mode="widthFix" style="width: 18px;"></image> </view> <view class="mt5 fs14 cor-666">陪您学车 第{{ user.count }}天</view> </view> @@ -26,47 +26,52 @@ <view class="p15lr" style="transform: translateY(-90px);"> <view class="relative mb10" @tap="handleVip"> <image src="/static/image/mine/vip_bg.png" mode="widthFix" style="width: 100%;"></image> - <view class="absolute p15lr p10tb flex ai-c jc-sb" style="left: 0;top: 0;right: 0;height: 40px;"> + <view class="absolute p15lr p10tb flex ai-c jc-sb" style="left: 0;top: 0;right: 0;height: 40px;"> <view class="flex ai-c"> <view class="p3 br-p50" style="background-color: #873E1D;"> <image src="/static/image/mine/vip.png" mode="widthFix" style="width: 18px;height: 15px;"></image> </view> <text class="ml5 fs16 fwb" style="color: #7E4012FF;">VIP会员</text> </view> - <text class="fs12" style="color: #7E4012FF;">2024-12-12到期</text> + <text v-if="vipOn.length" class="fs12" style="color: #7E4012FF;">{{expireTime}}到期</text> </view> <view class="absolute flex ai-c jc-c" style="left: 0;top: 40px;right: 0;bottom: 0;"> <view class="text-center"> - <view class="fs18 fwb" style="color: #7E4012FF;">尊享科目一二三四全部付费权益</view> + <view v-if="vipOn.length" class="fs18 fwb" style="color: #7E4012FF;">{{vipText}}</view> <view class="study fs16 text-center" style="margin: 25px auto 0;color: #F6E99FFF;"> - 马上学习 + {{ vipOn.length?'马上学习':'开通会员'}} </view> </view> </view> </view> <view class="br8 bc-fff p15 z-index2"> <text class="fs16 cor-333">我的驾校</text> - <div class="mt12 flex ai-c jc-sb"> - <text class="fs18 cor-000 fwb">合肥八一驾校</text> - <u-button text="切换驾校" shape="circle" @click="handleChangeSchool"></u-button> - </div> - <u-line margin="14px 0 18px 0"></u-line> - <view class="flex ai-c" @tap="handleCallPhone"> - <view class="flex ai-c jc-c phone"> - <img src="/static/image/mine/phone.png" style="width: 12px;height: 12px;"> - <text class="ml2 fs12 cor-fff">客服热线</text> + <view v-if="user.schoolId"> + <div class="mt12 flex ai-c jc-sb"> + <text class="fs18 cor-000 fwb">{{user.schoolName}}</text> + <u-button text="切换驾校" shape="circle" @click="handleChangeSchool"></u-button> + </div> + <u-line margin="14px 0 18px 0"></u-line> + <view class="flex ai-c" @tap="handleCallPhone"> + <view class="flex ai-c jc-c phone"> + <img src="/static/image/mine/phone.png" style="width: 12px;height: 12px;"> + <text class="ml2 fs12 cor-fff">客服热线</text> + </view> + <text class="ml5 fs26 cor-333 fwb" style="line-height: 26px;">{{user.schoolPhone}}</text> </view> - <text class="ml5 fs26 cor-333 fwb" style="line-height: 26px;">0551-12345678</text> + </view> + <view v-else class="pt30 pb15"> + <u-button text="绑定驾校" shape="circle" @click="handleChangeSchool"></u-button> </view> </view> <view class="mt12 bc-fff br8"> <u-cell-group> - <u-cell size="large" title="我的资料" value="修改" isLink @tap="handleInfo"> + <u-cell size="large" title="我的资料" isLink @tap="handleInfo"> <template #icon> <img src="/static/image/mine/wdzl.png" style="width: 24px;height: 24px;"> </template> </u-cell> - <u-cell size="large" title="我的体检" value="查看报告" isLink @tap="handleTJ"> + <u-cell size="large" title="我的体检" isLink @tap="handleTJ"> <template #icon> <img src="/static/image/mine/wdtj.png" style="width: 24px;height: 24px;"> </template> @@ -78,7 +83,7 @@ </u-cell> </u-cell-group> </view> - <view class="flex ai-c jc-c mt12 br8 bc-fff" style="height: 50px;" @tap="handleLogout"> + <view v-if="isLogin" class="flex ai-c jc-c mt12 br8 bc-fff" style="height: 50px;" @tap="handleLogout"> <text class="fs16" style="color: #A09F9F;">退出登录</text> </view> </view> @@ -86,7 +91,6 @@ </template> <script> import useUserStore from '@/jtools/store/user' -import { queryVip } from '@/jtools/api/vip' export default { components: {}, computed: { @@ -94,7 +98,36 @@ export default { return useUserStore().isLogin }, user() { - return useUserStore().userInfo + let userInfo = useUserStore().userInfo + return { ...userInfo, count: this.dateDiff(userInfo.createTime) } + }, + vipOn() { + return useUserStore().vipOnList + }, + expireTime() { + if(this.vipOn.length) { + const t = this.vipOn.reduce((pre, cur) => { + if(Date.parse(pre) > Date.parse(cur.endDate)) { + return cur.endDate + } + return pre + }, '2099-12-31') + return t.split(' ')[0] + }else { + return '' + } + }, + vipText() { + if(this.vipOn.length) { + const t = this.vipOn.reduce((pre, cur) => { + return [...pre, ...cur.subjects.split(',').map(it =>['','一','二','三','四'][it])] + }, []) + let val = Array.from(new Set(t)) + val = val.length == 4 ? val.join('')+'全部':val.join('') + return `尊享科目${val}付费权益` + }else { + return '' + } } }, data() { @@ -102,30 +135,36 @@ export default { }; }, onShow() { - this.searchVip() }, methods: { - searchVip() { - queryVip().then(resp => { - if(resp.code == '0000') { - debugger - } - }) - }, handleVip() { - uni.navigateTo({ - url: '/pages/me/vip' - }) + if(this.isLogin) { + if(this.vipOn.length) { + uni.navigateTo({ + url: '/pages/me/vip' + }) + } else { + uni.navigateTo({ + url: '/pages/index/videoVip' + }) + } + } else { + this.toLogin() + } }, handleCallPhone() { uni.makePhoneCall({ - phoneNumber: '17318531354' + phoneNumber: this.user.schoolPhone }) }, handleChangeSchool() { - uni.navigateTo({ - url: '/pages/me/school' - }) + if(this.isLogin) { + uni.navigateTo({ + url: '/pages/me/school' + }) + } else { + this.toLogin() + } }, handleInfo() { if(this.isLogin) { @@ -152,7 +191,20 @@ export default { }, handleLogout() { useUserStore().logout() - } + }, + dateDiff(end){ + if(!end) { + return 1 + } + today = new Date(); + end = new Date(end); + if(end > today){ + days = parseInt(Math.abs(end - today) / 1000 / 60 / 60 / 24); + }else{ + days = parseInt(Math.abs(end - today) / 1000 / 60 / 60 / 24); // 如果不限制对比时间和当前时间大小可以不用if + } + return days + 1; + }, } } </script>