<template>
	<view>
		<!-- <view class="home_page_body">
				<view @tap="jump(0)" class="home_page_body_flex">
					司机管理
				</view>
				<view @tap="jump(1)" class="home_page_body_flex">
					油品分发
				</view>
				<view @tap="close()" class="home_page_body_flex">
					退出
				</view>
			</view> -->
		<topBar height="267rpx" leftIcon='' title=" ">
			<view slot="coment">
				<view class="index_topbody">
					<view :style="{marginTop:'calc(267rpx - ' + shikHeig + ')'}" class="index_top_car">
						<view class="index_top_car_header_photo">
							<image style="width: 140rpx; height:140rpx;border-radius: 50%;" :src=" user.headPhoto || '/static/tx.png' "></image>
						</view>
						<view style="padding-top: 70rpx;">
							<view class="bgtext" style="">{{user.name?user.name:'暂未设置'}}</view>
							<view class="samlltext">({{user.roles[0].roleName}})</view>
						</view>
						<view class="carfooter" style="">
							<view>{{user.userPhone?user.userPhone:'暂未设置'}}</view>
							<view @tap="close()" class="samlltext" style="position: absolute;top: 0;right: 0;">退出登录
							</view>
						</view>
					</view>
			</view>
				</view>
		</topBar>
		<view class="index_list">
			<view class="index_list_item">
				<view class="index_list_item_left">
					<image style="width: 80rpx; height: 104rpx;margin-bottom: 15rpx;" src="@/static/sjgl.png"></image>
					<view class="left_text">司机管理</view>
				</view>
				<view class="index_list_item_right">
					<view v-if="jurisdiction('driver:info:list')" @tap="jump(0)" class="index_list_item_right_item">
						<image style="width: 43rpx; height: 43rpx;margin-right: 15rpx;" src="@/static/dirverList.png">
						</image>
						<view class="listtext">司机列表</view>
					</view>
					<view v-if="jurisdiction('driver:info:add')"  @tap="jump(2)" class="index_list_item_right_item">
						<image style="width: 43rpx; height: 43rpx;margin-right: 15rpx;" src="@/static/dirverIndex.png">
						</image>
						<view class="listtext">新增司机</view>
					</view>
				</view>
			</view>
			<view class="index_list_item">
				<view style="background: linear-gradient(-49deg, #FD885A 0%, #FAAB8C 100%);"
					class="index_list_item_left">
					<image style="width: 120rpx; height: 75rpx; margin-bottom: 15rpx;" src="@/static/ykff.png"></image>
					<view class="left_text">油品分发</view>
				</view>
				<view class="index_list_item_right">
					<view v-if="jurisdiction('distributeReverse:info:list')" @tap="jump(1)" class="index_list_item_right_item">
						<image style="width: 43rpx; height: 43rpx;margin-right: 15rpx;" src="@/static/oliList.png">
						</image>
						<view class="listtext">分发列表</view>
					</view>
					<view v-if="jurisdiction('distributeReverse:info:add')" @tap="jump(3)" class="index_list_item_right_item">
						<image style="width: 43rpx; height: 43rpx;margin-right: 15rpx;" src="@/static/addoli.png">
						</image>
						<view class="listtext">新增分发</view>
					</view>
				</view>
			</view>
			<view class="index_list_item">
				<view  style="background: linear-gradient(122deg, #EEBA5F 0%, #FBAF2B 100%);"class="index_list_item_left">
					<image style="width: 107rpx; height: 103rpx; margin-bottom: 15rpx;" src="@/static/order.png"></image>
					<view class="left_text">订单管理</view>
				</view>
				<view class="index_list_item_right">
					<view v-if="jurisdiction('oilOrder:info:list')"  @tap="jump(4)" class="index_list_item_right_item">
						<image style="width: 43rpx; height: 43rpx;margin-right: 15rpx;" src="@/static/orderList.png">
						</image>
						<view class="listtext">订单列表</view>
					</view>
					
				</view>
			</view>
			<view class="index_list_item">
				<view  style="background: linear-gradient(122deg, #EEBA5F 0%, #FBAF2B 100%);"
					class="index_list_item_left">
					<image style="width: 107rpx; height: 103rpx; margin-bottom: 15rpx;" src="@/static/order.png"></image>
					<view class="left_text">动销排名</view>
				</view>
				<view class="index_list_item_right">
					<view v-if="jurisdiction('ranking:info:list')"  @tap="jump(6)" class="index_list_item_right_item">
						<image style="width: 43rpx; height: 43rpx;margin-right: 15rpx;" src="@/static/orderList.png">
						</image>
						<view class="listtext"> 油站动销</view>
					</view>
					<view v-if="jurisdiction('ranking:info:list')"  @tap="jump(8)" class="index_list_item_right_item">
						<image style="width: 43rpx; height: 43rpx;margin-right: 15rpx;" src="@/static/orderList.png">
						</image>
						<view class="listtext"> 企业动销 </view>
					</view>
				</view>
			</view>
			<view class="index_list_item">
				<view  style="background: linear-gradient(122deg, #EEBA5F 0%, #FBAF2B 100%);"
					class="index_list_item_left">
					<image style="width: 107rpx; height: 103rpx; margin-bottom: 15rpx;" src="@/static/order.png"></image>
					<view class="left_text">调价管理</view>
				</view>
				<view class="index_list_item_right">
					<view   v-if="jurisdiction('priceAdjust:info:list')"  @tap="jump(5)" class="index_list_item_right_item">
						<image style="width: 43rpx; height: 43rpx;margin-right: 15rpx;" src="@/static/orderList.png">
						</image>
						<view class="listtext">调价申请</view>
					</view>
					<view v-if="jurisdiction('priceTask:info:list')"  @tap="jump(7)" class="index_list_item_right_item">
						<image style="width: 43rpx; height: 43rpx;margin-right: 15rpx;" src="@/static/orderList.png">
						</image>
						<view class="listtext">调价任务</view>
					</view>
					
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	// import topBar from '@/components/topbar'
	import oilIdentityApi from '@/api/oil-identity'
	export default {
		// components: {
		// 	topBar,
		// },
		data() {
			return {
				title: 'Hello',
				shikHeig: '',
				user: {
					authList:[]
				},
			}
		},
		onShow() {
			this.user = uni.getStorageSync('user')
			
		},
		onLoad() {
			try {
				let that = this
				let style = uni.getMenuButtonBoundingClientRect()
				const query = uni.createSelectorQuery().in(this);
				query.select('.index_top_car').boundingClientRect(data => {
					let shikHeig = Number(style.height) + Number(style.top) + (Number(data.height) / 2)
					that.shikHeig = shikHeig + 'px'
					console.log("得到布局位置信息" + JSON.stringify(data));
					console.log("节点离页面顶部的距离为" + data.top, shikHeig);
				}).exec();
			} catch (err) {
				console.log('失败')
			}
			this.upDate()
		},
		methods: {
			upDate(){
				console.log('检查更新中----');
				const updateManager = wx.getUpdateManager();
				updateManager.onCheckForUpdate(function (res) {
				  // 请求完新版本信息的回调
				  console.log(res.hasUpdate,'版本信息')
				})
				// updateManager.onUpdateFailed(function () {
				// 	console.log('安装包下载失败')
				//   // 新版本下载失败
				// });
				updateManager.onUpdateReady(function () {
				  wx.showModal({
				    title: '更新提示',
				    content: '新版本已经准备好，是否重启应用？',
				    success: function (res) {
						console.log(res,'****')
				      if (res.confirm) {
				        // 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
				        updateManager.applyUpdate()
				      }
				    }
				  })
				})
			},
			jurisdiction(e){
				// console.log(`%c  当前校验项:${e},校验结果:${this.user.authList.includes(e)},返回权限数据↓`,'color:red;font-size:50px;');
				// console.log(this.user.authList)
				return this.user.authList.includes(e)
			},
			jump(e) {
				switch (e) {
					case 0:
						uni.navigateTo({
							url: "/driverManagement/index/index",
							fail(e) {
								console.log(e, '--')
							},
						})
						break;
					case 1:
						uni.navigateTo({
							url: "/oilDistribution/index/index",
						})
						break;
						case 2:
						uni.navigateTo({
							url:'/driverManagement/addDiver/addDiver'
						})
						break
						case 3:
						uni.navigateTo({
							url:'/oilDistribution/distribute/distribute'
						})
						
						break
						case 4:
						uni.navigateTo({
							url:'/orderList/index/index'
						})
						break
						case 5:
						uni.navigateTo({
							url:'/priceAdjustment/page/index/index'
						})
						break
						case 6:
						uni.navigateTo({
							url:'/salesRanking/page/index/index' 
						})
						break
						case 7:
						uni.navigateTo({
							url:'/priceAdjustmentTask/page/index'
						})
						break
						case 8:
						uni.navigateTo({
							url:'/salesRanking/page/index/enterpriseIndex'
						})
						break
				}
			},
			close() {
				oilIdentityApi.logoutAuthSystem().then(res => {
					uni.redirectTo({
						url: '../login/login?type=1'
					})
				})
			}
		}
	}
</script>

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

	page {
		position: relative;
	}
</style>
