1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
<template>
	<view class="myContainer">
		<view class="myContainerUp">
			<view class="myContainerUp-logn">
				<view class="myContainerUp-logn_BgImage">
					<image src="/static/myImage/myBg.png" mode="widthFix" />
				</view>
				<!-- 头像star 未登录 -->
				<view class="logn_touxiang" v-if="!token">
					<image src="/static/myImage/ic_touxiang_default.png" mode="widthFix"></image>
				</view>
				<!-- 头像end -->
				<view class="logn_touxiang" v-else>
					<image :src="avatar" mode="widthFix"></image>
				</view>
				<view class="logn_text" style="z-index: 5;" v-if="!token" @click="denlu">
					请登录
				</view>
				<view class="login_text" style="position: relative;" v-else>
					<view class="text_title">
						{{nickName}}
					</view>
					<view class="text_Id">
						{{phone}}
					</view>
				</view>
			</view>
			<!-- 钱包部分star -->
			<view class="myContainerUp-wallet relative">
				<view class="walletBg  absolute">
					<image src="/static/myImage/ic_beijgn.png" mode="widthFix"></image>
				</view>
				<view class="wallet-contaner relative">
					<view class="contaner_show flex alignC">
						<view class="showImg">
							<image src="/static/myImage/ic_qianbao.png" mode="widthFix"></image>
						</view>
						<view class="showText">
							余额
						</view>
					</view>
					<view class="contaner_cate">
						<view class="cate_money">
							<text>¥</text>
							<view class="moneyNum">
								{{denglu_user_obj ? denglu_user_obj : 0}}
							</view>
						</view>
						<view class="cateBtn" @click="navTo_qianbao(Daili_status)">
							点击查看
						</view>
					</view>
				</view>
			</view>
			<!-- 钱包部分star -->
		</view>
		<view class="myContainerDown">
			<view class="dl-container" v-if="Daili_status_all">
				<!-- 立即申请 -->
				<view class="dl-shenheImg dl-img" v-if="Daili_status == 3" @click="to_shengqingDaili(Daili_status)">
					<image src="/static/myImage/dailiBg.png"></image>
				</view>
				<view class="dl-img" v-if="Daili_status == 2" @click="to_shengqingDaili(Daili_status)">
					<image src="/static/myImage/shenhe.png" mode="widthFix"></image>
				</view>
				<view class="dl-shenheImg dl-img" v-if="Daili_status == 0" @click="to_shengqingDaili(Daili_status)">
					<image src="/static/myImage/dailiShiBai.png" mode="widthFix"></image>
				</view>
			</view>
			<view class="dl-cate">
				<view class="cate_order cate_com" @click="navToOrder">
					<view class="order_img">
						<image src="/static/myImage/ic_my_function.png" mode="widthFix"></image>
					</view>
					<view class="order_text fontsize">
						我的订单
					</view>
					<view class="order_icon">
						<image src="/static/myImage/ic_arrow.png" mode="widthFix"></image>
					</view>
				</view>
				<view class="cate_address cate_com" @click="navToAddress">
					<view class="order_img">
						<image src="/static/myImage/ic_my_function8.png" mode="widthFix"></image>
					</view>
					<view class="order_text fontsize">
						地址管理
					</view>
					<view class="order_icon">
						<image src="/static/myImage/ic_arrow.png" mode="widthFix"></image>
					</view>
				</view>
				<view class="cate_Yh cate_com" @click="navTO">
					<view class="order_img">
						<image src="/static/myImage/ic_my_functionq.png" mode="widthFix"></image>
					</view>
					<view class="order_text fontsize">
						优惠券
					</view>
					<view class="order_icon">
						<image src="/static/myImage/ic_arrow.png" mode="widthFix"></image>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	//逻辑层
	import Login from '../../login.js'
	export default {
		data() {
			return {
				phone:'',//用户的电话
				token: '', // token
				avatar: '', // 头像
				nickName: '', // 昵称
				denglu_user_obj: '', //登录的用户数据,头像,昵称
				Daili_status: 3, //代理的状态 0 代表未通过(审核失败)  1代表通过 2审核中 3代表未申请
				Daili_status_all: true, //true代理图片存在
				showImg: true,
				qianBao_houtai_Arry: '', //钱包的数据
				wechats: 'wechat',
				/* 是否是代理状态 */
				qianBao: true,
				/* 钱包的状态切换 默认为0 即false */
			};
		},
		onShow() {
			this.Daili_status_all = false
			// code存在,意味已经授权登录了
			if (Login.getUrlCode('code')) {
				console.log(Login.getUrlCode('code'), "+++++++++++++++");
				// this.FormCode(Login.getUrlCode('code')) 
			}
			//获取授权登录 点击获取获取code ,换取token 用户信息
			//获取授权登录end
			this.login_again(); //避免重复登录,调用后台接口,渲染之前登录的信息,
			this.dailiStatus();
		}, 
		onLoad() {
			
		},
		methods: {
			login_again() {
				if (uni.getStorageSync("token")) {
					//已经存在登录过了,不用再登录,获取数据,渲染
					this.token = uni.getStorageSync('token');
					this.nickName = uni.getStorageSync('nickName');
					this.avatar = uni.getStorageSync('avatar');
					this.is_focus = uni.getStorageSync('is_focus');
					this.is_members = uni.getStorageSync('is_members');
					this.getQianbao(); //钱包详情的接口文档,需要登录后调用,渲染用户的钱包
				} else {
					//代表第一次登录,需要授权
					/* code存在,截取去Code */
					if (Login.getUrlCode('code')) {
						this.FormCode(Login.getUrlCode('code'))
					}
				}
			},
			denlu() {
				/**
				 * @点击登录
				 * */

				Login.GetLoginCode();
			},
			/**
			 * @提交CODE 登录的过程
			 * */
			FormCode(code) {
				let that = this;
				// (that.Daili_status == '') && (that.Daili_status_all = false)
				let parameters = {
					code,
					platform: 'wechat'
				};
				console.log(parameters);
				that.$rqs('/api/common/third', parameters, "GET").then(res => {
					if (res.data.code == 1) {
						console.log(res, "登录接口返回的数据————————————");
						that.avatar = res.data.data.userinfo.avatar;
						that.nickName = res.data.data.userinfo.nickname;
						that.token = res.data.data.userinfo.token;
						that.is_focus = res.data.data.userinfo.is_focus;
						that.is_members = res.data.data.userinfo.is_members;
						uni.setStorageSync("token", res.data.data.userinfo.token); // token
						uni.setStorageSync("nickName", res.data.data.userinfo.nickname); // 昵称
						uni.setStorageSync("avatar", res.data.data.userinfo.avatar); // 头像
						uni.setStorageSync("is_focus", res.data.data.userinfo.is_focus); // 是否关注
						uni.setStorageSync("is_members", res.data.data.userinfo.is_members); //是否入会
						// 支付
						uni.setStorageSync("openid", res.data.data.thirdinfo.openid); //openid
						uni.setStorageSync("access_token", res.data.data.thirdinfo.access_token); //access_token
						uni.setStorageSync("refresh", res.data.data.thirdinfo.refresh_token); //access_token
						// 检查代理状态
						that.$rqs("/api/agent/index").then(res => {
							if (res.data.code == 1) {
								that.Daili_status = res.data.data.status //拿到用户的代理状态
								that.Daili_status_all = true;
								console.log(that.Daili_status);
							} else {
								that.Daili_status = 3
								that.Daili_status_all = true
							}
						})
						this.getQianbao(); //钱包详情的接口文档,需要登录后调用,渲染用户的钱包
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
					}
				})
			},
			// 代理状态
			dailiStatus(){
				this.$rqs("/api/agent/index").then(res => {
					if (res.data.code == 1) {
						this.Daili_status = res.data.data.status //拿到用户的代理状态
						this.phone = res.data.data.mobile; // 用户手机号
						this.Daili_status_all = true;
						console.log(this.Daili_status);
					} else {
						this.Daili_status = 3
						this.Daili_status_all = true
					}
				})
			},
			//代理点击事件
			to_shengqingDaili(e) {
				console.log(e, "点击图片,传入的状态参数");
				if (uni.getStorageSync("token")) {
					console.log(e, "代理状态_________________");
					//e = 3 申请代理,2 = 审核中,0 审核失败
					if (e == 0) {
						this.daiLi();
						uni.navigateTo({
							url: './myDaili/myDaili'
						})
					}
					if (e == 2) {
						uni.navigateTo({
							url: './myDaili/myDaili?b=1'
						})
					}
					if (e == 3) {
						uni.navigateTo({
							url: './myDaili/myDaili'
						})
					}
				} else {
					uni.showToast({
						title: "请授权登录",
						icon: "error"
					})
				}
			},
			// 跳转到我的地址模块
			navToAddress() {
				if (uni.getStorageSync("token")) {
					uni.navigateTo({
						url: "../order/selectAddress/addAddress"
					})
				} else {
					uni.showToast({
						title: "请授权登录",
						icon: "error"
					})
				}
			},
			// 跳转到我的订单模块
			navToOrder() {
				if (uni.getStorageSync("token")) {
					uni.navigateTo({
						url: "my_Order/my_Order"
					})
				} else {
					uni.showToast({
						title: "请授权登录",
						icon: "error"
					})

				}
			},
			/* 跳转到钱包 */
			navTo_qianbao(e) {
				if (uni.getStorageSync('token')) {
					if (this.Daili_status == 3) {
						uni.showToast({
							title: "您未申请代理",
							icon:'none'
						})
					} else if(this.Daili_status == 2) {
						uni.showToast({
							title: "代理审核中",
							icon:'none'
						})
					}else if(this.Daili_status == 1){
						uni.navigateTo({
							url:'qianBao/qianBao'
						})
					}else if(this.Daili_status == 0){
						uni.showToast({
							title: "审核失败",
							icon:'none'
						})
					}
				} else {
					uni.showToast({
						title: "请授权登录",
						icon: "error"
					})
				}
			},
			//钱包详情的接口文档,需要登录,
			getQianbao() {
				console.log('调用调用调用调用调用调用调用调用money');
				if (uni.getStorageSync("token")) {
					let that = this;
					that.$rqs('/api/user/money').then(res => {
						if (res.data.code == 1) {
							console.log(res);
							console.log("钱包接口");
							that.denglu_user_obj = Number(res.data.data.user.money).toFixed(0); //登录的用户信息
							console.log(that.denglu_user_obj);
							that.qianBao_houtai_Arry = res.data.data.user;
						}
					})
				} else {
					uni.showToast({
						title: '请授权登录',
						icon: 'error'
					})
				}
			},
			//请求代理接口
			daiLi() {
				if (uni.setStorage("token")) {
					let data = {
						name: '',
						mobile: '',
						identity: '',
						unit: '',
					}
					this.$rqs('/api/agent/add', data).then(res => {
						console.log(res, "请求数据");
						uni.navigateTo({
							url: "myDaili/myDaili?showimg"
						})
					})
				} else {
					uni.showToast({
						title: "本地没有缓存token",
						icon: "error"
					})
				}

			},
			navToDailiaPage() {
				if (uni.getStorageSync("toekn")) {
					if (uni.showToast("token")) {
						show1 = this.showImg;
						console.log(show1, "AAAAAAAAAA");
						uni.navigateTo({
							url: "myDaili/myDaili"
						})
					} else {
						uni.showToast({
							title: "请授权",
							icon: "error"
						})
					}
				} else {
					uni.showToast({
						title: "本地没有缓存token,没有登陆了",
						icon: "none"
					})
				}
			},
			navTO() {
				if (uni.getStorageSync("token")) {
					uni.navigateTo({
						url: "./myYouHuiJuan/myYouHuiJuan"
					})
				} else {
					uni.showToast({
						title: "请授权登录",
						icon: "error"
					})
				}
			}
		},
	};
</script>

<style>
	@import url("./my.css");

	.cate_com {
		height: 72rpx;
		display: flex;
		margin-bottom: 32rpx;
		border-bottom: 2px solid #f1f1f1;

	}

	.ss {
		justify-content: space-between;
		display: flex;
	}
</style>