<template>
	<!-- 我的 -->
	<view class="safeDistance">
		<view style="padding: 20rpx;">
			<view class="card_mine">
				<view class="card_avatar" v-if="token != ''">
					<image class="mine_image" src="../../static/portrait.png" mode=""></image>
					<view class="card_user_title">
						<view class="mine_phone">{{userInfo.username}}</view>
						<view class="mine_phone">{{userInfo.nickName}}</view>
					</view>
				</view>
				<view class="card_avatar" v-else @click="login">
					<image class="mine_image" src="../../static/portrait.png" mode=""></image>
					<view class="mine_title">登录/注册</view>
				</view>
			</view>
			<view class="order_card">
				<view class="order_head">
					<view class="head_left">我的运单</view>
					<!-- <view class="head_right">
					<view class="head_left">全部</view>
					<u-icon name="arrow-right"></u-icon>
				</view> -->
				</view>
				<view class="card_order">
					<view class="item_order" v-for="(item,index) in tableList" :key="index" @click="goOrder(index)">
						<view class="card_tab_image center_in"
							:style="{background: item.bgColor,backgroundColor:item.colorBg}">
							<span class="iconfont icon_image" :class="item.icon"></span>
						</view>
						<view class="order_title">{{item.title}}</view>
					</view>
				</view>
			</view>
			<view class="card_system">
				<view class="space_between" @click="changePassword">
					<view style="display: flex;align-items: center;">
						<view class="card_edit_icon center_in">
							<u-icon name="setting" size="22" color="#ffffff"></u-icon>
						</view>
						<view class="option_title">修改密码</view>
					</view>
					<u-icon name="arrow-right" size="20"></u-icon>
				</view>
			</view>
			<view class="card_system">
				<view class="space_between" @click="logOut">
					<view style="display: flex;align-items: center;">
						<view class="card_icon_set center_in">
							<span class="iconfont icon-tuichudenglu"></span>
						</view>
						<view class="option_title">退出登录</view>
					</view>
					<u-icon name="arrow-right" size="20"></u-icon>
				</view>
			</view>
			<!-- <view class="card_system">
				<view class="space_between" @click="handleCheckVersion">
					<view style="display: flex;align-items: center;">
						<view class="card_icon_set center_in violet">
							<u-icon name="info" size="20" color="#ffffff"></u-icon>
						</view>
						<view class="option_title">版本更新</view>
					</view>
					<u-icon name="arrow-right" size="20"></u-icon>
				</view>
			</view> -->
			<!-- <view class="card_system">
			<view class="space_between" @click="bluetoothPrinting">
				<view style="display: flex;align-items: center;">
					<view class="card_edit_icon center_in">
						<u-icon name="setting" size="22" color="#ffffff"></u-icon>
					</view>
					<view class="option_title">蓝牙打印</view>
				</view>
				<u-icon name="arrow-right" size="20"></u-icon>
			</view>
		</view> -->
			<u-modal :show="logoutShow" showCancelButton :title="title" :content='content' @cancel="cancel"
				@confirm="confirm"></u-modal>
		</view>
	</view>
</template>

<script>
	const ENV = require('../../.env.js')
	export default {
		props: {
			token: {
				type: String,
				default: () => '',
			},
			userInfo: {
				type: Object,
				default: () => {},
			},
		},
		data() {
			return {
				tableList: [],
				list: [{
					title: '全部',
					icon: 'icon-dingdan',
					colorBg: '#4bc7fc',
					bgColor: 'linear-gradient(to right, #84d4f6, #4bc7fc)',
				}, {
					title: '已下单',
					icon: 'icon-cancel',
					colorBg: '#9ddd54',
					bgColor: 'linear-gradient(to right, #b9f377, #9ddd54)',
				}, {
					title: '配送中',
					icon: 'icon-delivery',
					colorBg: '#4bc7fc',
					bgColor: 'linear-gradient(to right, #84d4f6, #4bc7fc)',
				}, {
					title: '已送达',
					icon: 'icon-yisongda',
					colorBg: '#1cc723',
					bgColor: 'linear-gradient(to right, #54ef5a, #1cc723)',
				}, {
					title: '已取消',
					icon: 'icon-yiquxiao',
					colorBg: '#fe880e',
					bgColor: 'linear-gradient(to right, #f69f45, #fe880e)',
				}],
				logoutShow: false,
				title: '确定退出？',
				content: '退出登录后将无法查看运单，重新登录后即可查看',
				innerVer: null,
				version: null,
				isCheckVersion: false
			}
		},
		created() {
			this.tableList = this.list
		},
		methods: {
			// 修改密码
			changePassword() {
				if (this.token) {
					uni.navigateTo({
						url: '/pages/mine/password'
					});
				} else {
					uni.$u.toast('请先登录')
				}
			},
			// 登录注册
			login() {
				uni.navigateTo({
					url: '/pages/login'
				});
			},
			// 订单页面
			goOrder(index) {
				if (this.token) {
					uni.navigateTo({
						url: '/pages/order/index?current=' + index
					});
				} else {
					uni.$u.toast('请先登录')
				}
			},
			// 退出登录
			logOut() {
				if (this.token) {
					this.logoutShow = true
				} else {
					uni.$u.toast('请先登录')
				}
			},
			// 版本更新
			versionUpdating() {
				// https: //coldlogistics.coldbaozhida.com/smartAppversion.json
			},
			handleCheckVersion() {
				let _this = this;
				// #ifdef APP-PLUS 
				_this.isCheckVersion = true;
				plus.screen.lockOrientation('portrait-primary') // 竖屏锁定
				plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
					_this.innerVer = widgetInfo.version;
					_this.version = widgetInfo.versionCode;
					uni.request({
						url: ENV.APP_LINK_URL + '/smartAppversion.json?_t=' + new Date()
							.getTime(), //版本检测
						method: 'GET',
						header: {},
						success: (result) => {
							console.log(result.data.code, 14)
							if (result.data.code === 0) {
								setTimeout(() => {
									_this.isCheckVersion = false;
								}, 100);
								if (result.data.version - _this.version > 0) { // 如果最新版本大于现在已经安装的App的版本
									uni.showModal({
										title: "更新提示",
										content: "发现新版本,请确认下载更新?",
										success: (res) => {
											if (res.confirm) {
												uni.showLoading({
													title: '下载更新包中...'
												});
												uni.downloadFile({
													url: result.data.url,
													success: (downloadResult) => {
														uni.hideLoading();
														if (downloadResult
															.statusCode === 200
														) {
															plus.runtime
																.install(
																	downloadResult
																	.tempFilePath, {
																		force: true
																	},
																	function() {
																		console
																			.log(
																				'App安装成功！'
																			);
																		uni.showModal({
																			title: 'App安装成功!',
																			showCancel: false
																		})
																		plus.runtime
																			.restart();
																	},
																	function(
																		e) {
																		console
																			.log(
																				'App安装失败！'
																			);
																	})
														}
													}
												});
											}
										}
									})
								} else {
									uni.showModal({
										title: '当前已是最新版本',
										showCancel: false
									})
								}
							}
						}
					})
				})
				// #endif
			},
			// 蓝牙打印
			bluetoothPrinting() {
				uni.navigateTo({
					url: '/pages/mine/bluetooth'
				});
			},
			// 确定退出登录
			confirm() {
				this.$cache.removeToken()
				this.$cache.removeCache('userInfo')
				uni.redirectTo({
					url: '/pages/login'
				})
			},
			// 取消
			cancel() {
				this.logoutShow = false
			},
		}
	}
</script>

<style lang="scss">
	.card_user_title {
		display: flex;
		flex-direction: column;
		align-items: flex-start;
	}

	.card_mine {
		margin-top: 30rpx;
		padding: 0rpx 30rpx;
		background-color: #fff;
		border-radius: 20rpx;
	}

	.mine_image {
		width: 100rpx;
		height: 100rpx;
		border-radius: 50%;
	}

	.mine_phone {
		margin-left: 20rpx;
		font-size: 30rpx;
	}

	.mine_title {
		margin-left: 20rpx;
		font-size: 40rpx;
		font-weight: bold;
	}

	.card_avatar {
		display: flex;
		align-items: center;
		padding-top: 30rpx;
		padding-bottom: 30rpx;
	}

	.order_card {
		margin-top: 20rpx;
		background-color: #fff;
		padding: 20rpx;
		border-radius: 20rpx;
	}

	.order_head {
		position: relative;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding-bottom: 20rpx;
	}

	.order_head:before {
		content: " ";
		position: absolute;
		left: 0;
		bottom: 0;
		width: 100%;
		height: 1px;
		border-top: 1px solid #e7e6e4;
		-webkit-transform-origin: 0 0;
		transform-origin: 0 0;
		-webkit-transform: scaleY(0.5);
		transform: scaleY(0.5);
	}

	.head_left {
		margin-right: 10rpx;
	}

	.head_right {
		display: flex;
		align-items: center;
	}

	.card_order {
		margin-top: 30rpx;
		display: flex;
		justify-content: space-around;
	}

	.item_order {
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.card_tab_image {
		width: 80rpx;
		height: 80rpx;
		border-radius: 50%;
	}

	.order_title {
		margin-top: 6rpx;
		font-size: 25rpx;
	}

	.icon_image {
		color: #fff;
		font-size: 37rpx;
	}

	.card_system {
		margin-top: 20rpx;
		background-color: #fff;
		padding: 30rpx 20rpx;
		border-radius: 20rpx;
	}

	.card_mine_option {
		position: relative;
		margin: 20rpx 0rpx;
		padding-bottom: 30rpx;
	}

	.option_title {
		margin-left: 10rpx;
		font-size: 28rpx;
		font-weight: 500;
	}

	.card_edit_icon {
		width: 55rpx;
		height: 55rpx;
		border-radius: 50%;
		background-color: #ff9900;
	}

	.card_icon_set {
		width: 55rpx;
		height: 55rpx;
		border-radius: 50%;
		background-color: #fa3534;

		span {
			color: #fff;
			font-size: 40rpx;
		}
	}

	.violet {
		background-color: #fe654a !important;
	}
</style>