mine.vue 10.2 KB
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 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
<template>
	<view class="container">
		<view class="minetop flexone">
			<view class="minetopleft">
				<image src="../../static/zhuboimg.png" mode="" v-if="userinfo==''"></image>
				<image :src="userinfo.avatar" mode="" v-else></image>
			</view>
			<button class="minename" open-type="getUserInfo" @getuserinfo="wxGetUserInfo" v-if="userinfo==''">请先登录</button>
			<view class="minename" v-else>{{userinfo.nickname}}</view>
		</view>
		<view class="tixinglist flextwo">
			<view class="tixinglistitem" @click="tabclick(1)">
				<image src="../../static/kaishou.png" mode="" class="kaiimg"></image>
				<view class='kainame'>即将开售</view>
			</view>
			<view class="tixinglistitem" @click="tabclick(2)">
				<image src="../../static/jitixing.png" mode="" class="kaiimg"></image>
				<view class='kainame'>累计提醒</view>
			</view>
			<view class="tixinglistitem" @click="tabclick(3)">
				<image src="../../static/guanzhu.png" mode="" class="kaiimg"></image>
				<view class='kainame'>关注主播</view>
			</view>
			<view class="tixinglistitem" @click="tabclick(4)">
				<image src="../../static/xinyuandan.png" mode="" class="kaiimg"></image>
				<view class='kainame'>心愿商品</view>
			</view>
		</view>
		<view class="nodata" v-if="listshilist.length==0">暂无数据</view>
		<view v-else>
			<!-- 即将开售 -->
			<view class="kaishoulist" v-if="showclick==1">
				<view class="want flextwo">
					<view class="wantleft flexone">
						<image src="../../static/jikaishou.png" mode="" class="likeimg"></image>
						即将开售
					</view>
				</view>
				<goodlistone :listshilist="listshilist" :mine="1" @litixing="litixing" ></goodlistone>
			</view>
			<!-- 累计提醒 -->
			<view class="kaishoulist" v-if="showclick==2">
				<view class="want flextwo">
					<view class="wantleft flexone">
						<image src="../../static/jikaishou.png" mode="" class="likeimg"></image>
						累计提醒
					</view>
				</view>
				<leiji :listshilist="listshilist" @tixing="tixing"></leiji>
			</view>
			<!-- 关注主播 -->
			<view class="leiji" v-if="showclick==3">
				<view class="want flextwo">
					<view class="wantleft flexone">
						<image src="../../static/guaznhuzhu.png" mode="" class="likeimg"></image>
						关注主播
					</view>
				</view>
				<view class='leijiitem flextwo' v-for="(item,index) in listshilist" :key="index">
					<view class="leijiitemleft flexone">
						<image :src="item.avatar" mode="" class="leijiimg"></image>
						<view class="lejibox">
							<view class="lejiname">{{item.name}}</view>
							<view class='lejiatten' v-if="item.anchor_time!=null">{{item.anchor_time.title}}</view>
						</view>
					</view>
					<view class="canceldingyuebtn" @click="cancelzhu(index,item.id)">取消订阅</view>
				</view>
			</view>
			<!-- 心愿品类 -->
			<view class="leiji" v-if="showclick==4">
				<view class="want flextwo">
					<view class="wantleft flexone">
						<image src="../../static/xinyuangood.png" mode="" class="likeimg"></image>
						心愿品类
					</view>
				</view>
				<view class='leijiitem flextwo' v-for="(item,index) in listshilist" :key="index">
					<view class="leijiitemleft flexone">
						<image :src="item.image" mode="" class="leijiimg"></image>
						<view class="lejibox">
							<view class="lejiname">{{item.name}}</view>
						</view>
					</view>
					<view class="canceldingyuebtn" @click="cancelxin(index,item.id)">取消订阅</view>
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	import app from "../../App.vue";
	import goodlistone from "../../compontent/goodlistone.vue"
	import leiji from "../../compontent/leiji.vue"
	export default {
		components: {
			goodlistone,
			leiji
		},
		data() {
			return {
				showclick: 1,
				openid: "",
				session_key: '',
				encrypted_data: '',
				iv: "",
				userinfo: '', //用户信息
				page: 1,
				listshilist: [],
				showpull: true,
				dingyuenumk:[]
			}
		},
		onLoad() {},
		onShow() {
			this.get_sessionkey();
			if (uni.getStorageSync("token")) {
				this.getuserinfo()
			}
			this.listshilist = [];
			this.dingyuenumk=[]
			this.page = 1;
			this.getkaishou()
		},
		onReachBottom() {
			that = this
			let newpage = that.page;
			newpage++
			that.page = newpage;
			if (that.showpull == true) {
				console.log(38493409)
				Toast('没有更多了~')
			} else {
				if (that.showclick == 1 || that.showclick == 2) {
					that.getkaishou()
				}

			}
		},
		methods: {
			//子元素传来的值
			tixing(e) {
				this.listshilist = e
			},
			litixing(e){
				console.log(e)
				this.listshilist = e
			},
			// 获取即将开售和累计提醒
			getkaishou() {
				let that = this;
				let url = "user/getUserGoods";
				let param = {
					type: that.showclick,
					page: that.page,
					per_page: 20
				}
				console.log('参数', param)
				app.post(url, param, "post").then(r => {
					console.log('即将开售', r)
					that.listshilist = that.listshilist.concat(r.data);
					if (that.page > 1) {
						if (r.data.length == 0) {
							that.showpull = false
						}
					}
					that.listshilist.forEach(function(value,index,array){
						if(value.user_goods==1){
								if(that.dingyuenumk.indexOf(value.id)==-1){
									that.dingyuenumk.push(value.id);
									that.dingyuenumk=that.dingyuenumk
							}
						}
					})
					that.listshilist = that.listshilist;
					that.$forceUpdate();
					console.log(that.listshilist)

				}).catch(err => {
					console.log(err)
				})
			},
			// 获取主播列表
			getzhubolist() {
				let that = this;
				let url = "user/getAnchor";
				let param = {

					page: that.page,
					per_page: 20
				}
				console.log('参数', param)
				app.post(url, param, "post").then(r => {
					console.log('主播列表', r)
					that.listshilist = that.listshilist.concat(r.data);
					if (that.page > 1) {
						if (r.data.length == 0) {
							that.showpull = false
						}
					}
					

				}).catch(err => {
					console.log(err)
				})
			},
			// 心愿商品
			getxinyuan() {
				let that = this;
				let url = "user/getCategory";
				let param = {

					page: that.page,
					per_page: 20
				}
				console.log('参数', param)
				app.post(url, param, "post").then(r => {
					console.log('心愿商品', r)
					that.listshilist = that.listshilist.concat(r.data);
					if (that.page > 1) {
						if (r.data.length == 0) {
							that.showpull = false
						}
					}

				}).catch(err => {
					console.log(err)
				})
			},
			// 取消订阅主播
			cancelzhu(index, id) {
				let that = this;
				var url = "anchor/addUserAnchor"
				var param = {
					anchor_id: id
				}
				app.post(url, param, "post").then(res => {
					console.log('取消订阅', res)
					uni.showToast({
						title: "取消订阅成功",
						icon: "none"
					})
					console.log(index)
					let newlishsilist = that.listshilist;
					newlishsilist.splice(index, 1)
					that.listshilist = newlishsilist;
					that.$forceUpdate()
					

				}).catch(err => {
					console.log(err)
				})
			},
			// 取消心愿商品
			cancelxin(index,id){
				let that = this;
				var url = "category/addUserCate"
				var param = {
					cate_id: id
				}
				app.post(url, param, "post").then(res => {
					console.log('取消订阅', res)
					uni.showToast({
						title: "取消订阅成功",
						icon: "none"
					})
					console.log(index)
					let newlishsilist = that.listshilist;
					newlishsilist.splice(index, 1)
					that.listshilist = newlishsilist;
					that.$forceUpdate()
					
				
				}).catch(err => {
					console.log(err)
				})
			},
			tabclick(id) {
				this.showclick = id;
				this.page = 1;
				this.listshilist = [];
				this.dingyuenumk=[]
				if (this.showclick == 1 || this.showclick == 2) {
					this.getkaishou()
				} else if (this.showclick == 3) {
					if (uni.getStorageSync("token")) {
						this.getzhubolist()
					}
				} else if (this.showclick == 4) {
					this.getxinyuan()
				}


			},

			get_sessionkey() {
				let that = this;
				uni.login({
					provider: "weixin",
					success(r) {
						console.log(r)
						let url = "wechat/getSessionKey";
						app.post(url, {
							code: r.code
						}, "post").then(r => {
							console.log(r)
							that.session_key = r.session_key;
							that.openid = r.openid;

						}).catch(err => {})

					}
				})


			},
			// 微信登录
			wxGetUserInfo(e) {
				console.log(e)
				this.encrypted_data = e.detail.encryptedData
				this.iv = e.detail.iv
				this.login()
			},
			login() {
				let that = this;
				console.log('34898498')
				uni.login({
					provider: "weixin",
					success(r) {
						console.log(r, 6666)
						let url = "wechat/login";
						let param = {
							openid: that.openid,
							session_key: that.session_key,
							encrypted_data: that.encrypted_data,
							iv: that.iv,

						}
						console.log('参数', param)
						app.post(url, param, "post").then(r => {
							console.log('登陆成功', r);

							uni.setStorageSync("token", r.token)
							that.getuserinfo()

							// that.getuserinfo()

							// uni.setStorageSync('openid', r.openid);
							// uni.setStorageSync('session_key', r.session_key);
						}).catch(err => {
							console.log(err)
						})

					}
				})
			},
			// 获取用户信息
			getuserinfo() {
				let that = this;
				let url = "user/getUserInfo";
				let param = {

				}
				console.log('参数', param)
				app.post(url, param, "post").then(r => {
					console.log('用户信息', r)
					that.userinfo = r


					// that.getuserinfo()

					// uni.setStorageSync('openid', r.openid);
					// uni.setStorageSync('session_key', r.session_key);
				}).catch(err => {
					console.log(err)
				})
			}

		}

	}
</script>

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

	page {
		background: #f5f5f5;
	}

	.want {
		margin-top: 0
	}

	button {
		margin: 0px;
		padding: 0px;
		/*自定义边框*/
		border: none;
		/*消除默认点击蓝色边框效果*/
		outline: none;
		background: transparent;

	}

	button::after {
		border: none;
		outline: none;
		background: transparent;

	}

	button:focus {
		border: 0 none;
		outline: none;
		background: transparent;
		box-shadow: none;
	}

	button:active {
		border: 0 none;
		outline: none;
		background: transparent;
		box-shadow: none;
	}

	.register {
		width: 100%;
		height: 100%;
		background-color: rgba(0, 0, 0, 0.5);
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		z-index: 5;
	}
</style>