<template>
	<view class="content">
		<!-- 用户信息 -->
		<view class="userCard flex align_center justify_between" @click="toUser">
			<view class="userCard-info flex align_center justify_between">
				<view>
					<u-image v-if="!hasLogin" src="/static/def_personal_avatar.png" width="60" height="60"></u-image>
					<open-data v-else type="userAvatarUrl" class="user-photo"></open-data>
				</view>
				<view>
					<view v-if="!hasLogin" style="font-size: 40rpx;">
						请点击登录
					</view>
					<view v-else>
						<view>{{userInfo.userNameCN}}</view>
						<view>{{userInfo.orgName}}</view>
					</view>
				</view>
			</view>
			<view>
				<u-icon name="arrow-right"></u-icon>
			</view>
		</view>
		<!-- 套餐记录 -->
		<view class="list-box">
			<view class="scroll-box">
				<view class="flex align_center justify_between item-box" v-for="item in 26" @click="toDetail(item)">
					<view class="l_box">99会员礼包</view>
					<view class="flex align_center r_box">
						<view>
							<view>2022-05-28</view>
							<view>高新天佑店</view>
						</view>
						<view>
							<u-icon name="arrow-right"></u-icon>
						</view>
					</view>
				</view>
				<!-- <view style="padding: 20upx;">
					<u-empty :src="`/static/nodata.png`" icon-size="180" :text="noDataText" img-width="120" v-if="vinList.length==0 && status!='loading'" mode="list"></u-empty>
					<u-loadmore v-if="status=='loading'" :status="status" />
				</view> -->
				<view class="des">请登录后查看套餐记录</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
	    mapState,
	    mapMutations,
	} from 'vuex'
	import { listLookUp, getLookUpDatas } from '@/api/data.js';
	import { scanVinLogQueryRoll, getScanVinLogList }from '@/api/car.js'
	export default {
		components: {
		},
		data() {
			return {
				status: 'loading',
				noDataText: '暂无数据',
				vinList: [],
			}
		},
		computed: {
			...mapState(['hasLogin']),
			userInfo(){
				return this.$store.state.vuex_userInfo
			}
		},
		onReady() {
			// 检测是否登录
			this.$store.dispatch('checkLogin',()=>{
				this.pageInit()
			})
		},
		onLoad() {
			// 获取数据字典
			this.getListLookUp();
			// 获取支付，收款方式
			this.getLookUpList('PAY_PROCUCT_TYPE', 'vuex_paymentTypeList');
			// 刷新首页数据
			uni.$on("refashHome",()=>{
				this.pageInit()
			})
		},
		onUnload() {
			uni.$off('refashHome')
		},
		// 下拉刷新
		onPullDownRefresh(){
			this.pageInit()
			setTimeout(function () {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onShareAppMessage() {},
		methods: {
			pageInit(){
				if(this.hasLogin){
					// 获取扫描记录
					this.getVinLog()
				}
			},
			//  获取数据字典
			getListLookUp() {
				const _this = this;
				listLookUp({ pageNo: 1, pageSize: 1000 }).then(res => {
					if (res.status == 200) {
						_this.$store.state.vuex_allLookUp = res.data;
					}
				});
			},
			// 或某一项字典列表，参数code
			getLookUpList(code, vuexKey) {
				getLookUpDatas({ type: code }).then(res => {
					if (res.status == 200) {
						this.$store.state[vuexKey] = res.data || [];
					}
				});
			},
			getVinLog(){
				this.vinList  = []
				this.status = "loading"
				getScanVinLogList({pageNo:1,pageSize:10}).then(res => {
					this.vinList = res.data.list || []
					this.vinList = this.vinList.filter(item => item.vinCode)
					this.status = 'nomore'
				})
			},
			toUser(){
				if(!this.hasLogin){
					uni.navigateTo({
						url:"/pages/login/login"
					})
				}
			},
			toDetail(item){
				uni.navigateTo({
					url:"/pages/bundelDetail/index"
				})
			}
		}
	}
</script>

<style lang="less">
	.content {
		margin: 0;
		padding: 0;
		height: 100vh;
		display: flex;
		flex-direction: column;
		.userCard{
			padding:1.2em 1em;
			background-image: linear-gradient(#58c4c4 10%,#65e2e2);
			.userCard-info{
				> view{
					&:last-child{
						margin-left: 0.5em;
						>view{
							padding: 0.2em;
						}
					}
				}
			}
			.user-photo{
				display: block;
				width: 120rpx;
				height: 120rpx;
				border-radius: 50%;
				overflow: hidden;
			}
		}
		.ml10{
			margin-left: 0.2em;
		}
		.list-box{
			flex-grow: 1;
			overflow: auto;
			.scroll-box{
				height: 100%;
				.item-box{
					border-bottom: 1px solid #eee;
					padding: 1em;
					&:active{
						background: #f8f8f8;
					}
					.l_box{
						font-size: 1.1em;
						flex-grow: 1;
					}
					.r_box{
						color: #999;
						> view{
							padding: 0 0.1em;
						}
					}
				}
				.des{
					text-align: center;
					padding: 3em 0;
					color: #999;
					font-size: 0.9em;
				}
			}
		}
	}
</style>
