<template>
	<view>
	<view class="morePages">
		<view class="list-box" v-if="hasRedPacket&&hasShelf">
			<view class="list-title flex align_center justify_between" @click="toPage('/pages/morePage/redPacket')">
				<view><u-icon size="34" color="#f10000" name="red-packet-fill"></u-icon> <text style="color: #ff0000;margin-left: 10rpx;">红包奖励</text></view>
				<view>
					<u-icon size="28" color="#969799" name="arrow-right"></u-icon>
				</view>
			</view>
		</view>
		<view class="list-box" v-if="$hasPermissions('M_stockQueryList_mini')||$hasPermissions('M_stockPut_mini')">
			<view class="list-title">
				<u-icon size="38" name="bag"></u-icon> <text>货品管理</text>
			</view>
			<u-cell-group :border="false">
				<u-cell-item title="库存查询" v-if="$hasPermissions('M_stockQueryList_mini')" @click="toPage('/pages/stockQuery/stockQuery')" :title-style="{fontSize:'1em'}">
					<text slot="icon"></text>
				</u-cell-item>
				<u-cell-item title="补货记录" v-if="$hasPermissions('M_stockPut_mini')" @click="toPage('/pagesA/digitalShelf/stockPut')" :title-style="{fontSize:'1em'}">
					<text slot="icon"></text>
				</u-cell-item>
			</u-cell-group>
		</view>
		<view class="list-box" v-if="$hasPermissions('M_shelfOrder_mini')||$hasPermissions('M_tempShelfOrder_mini')">
			<view class="list-title">
				<u-icon size="34" name="order"></u-icon> <text>订单管理</text>
			</view>
			<u-cell-group :border="false">
				<u-cell-item title="货架订单" v-if="$hasPermissions('M_shelfOrder_mini')" @click="toPage('/pagesA/digitalShelf/orderList')" :title-style="{fontSize:'1em'}">
					<text slot="icon"></text>
				</u-cell-item>
				<u-cell-item title="急送订单" v-if="$hasPermissions('M_tempShelfOrder_mini')" @click="toPage('/pagesA/digitalShelf/tempOrderList/tempOrderList')" :title-style="{fontSize:'1em'}">
					<text slot="icon"></text>
				</u-cell-item>
			</u-cell-group>
		</view>
		<view class="list-box" v-if="$hasPermissions('M_stockQueryList_mini')||$hasPermissions('M_stockPut_mini')">
			<view class="list-title">
				<u-icon size="38" name="file-text"></u-icon> <text>电子质保单</text>
			</view>
			<u-cell-group :border="false">
				<u-cell-item title="创建质保单" v-if="$hasPermissions('M_stockPut_mini')" @click="toPage('/pagesA/qualityPolicy/creatOrder')" :title-style="{fontSize:'1em'}">
					<text slot="icon"></text>
				</u-cell-item>
				<u-cell-item title="质保单查询" v-if="$hasPermissions('M_stockPut_mini')" @click="toPage('/pagesA/qualityPolicy/searchOrder')" :title-style="{fontSize:'1em'}">
					<text slot="icon"></text>
				</u-cell-item>
			</u-cell-group>
		</view>
		<view class="list-box" v-if="$hasPermissions('M_settlementRecord_mini')||$hasPermissions('M_settlementManage_mini')">
			<view class="list-title">
				<u-icon size="36" name="rmb-circle"></u-icon> <text>结算管理</text>
			</view>
			<u-cell-group :border="false">
				<u-cell-item title="结算记录" v-if="$hasPermissions('M_settlementRecord_mini')" @click="toPage('/pagesA/digitalShelf/settlementRecord/settlementRecord')" :title-style="{fontSize:'1em'}">
					<text slot="icon"></text>
				</u-cell-item>
				<u-cell-item title="付款结算" v-if="$hasPermissions('M_settlementManage_mini')" @click="toPage('/pagesA/digitalShelf/settlementManage/settlementManage')" :title-style="{fontSize:'1em'}">
					<text slot="icon"></text>
				</u-cell-item>
			</u-cell-group>
		</view>
		<view class="list-box" v-if="$hasPermissions('M_employee_mini')||$hasPermissions('M_roleSetting_mini')||($hasPermissions('M_priceShow_mini')&&showPriceSet)">
			<view class="list-title">
				<u-icon size="32" name="home"></u-icon> <text>基础设置</text>
			</view>
			<u-cell-group :border="false">
				<u-cell-item title="员工管理" v-if="$hasPermissions('M_employee_mini')" @click="toPage('/pages/storeManage/personnel')" :title-style="{fontSize:'1em'}">
					<text slot="icon"></text>
				</u-cell-item>
			</u-cell-group>
			<u-cell-group :border="false">
				<u-cell-item title="岗位权限" v-if="$hasPermissions('M_roleSetting_mini')" @click="toPage('/pages/storeManage/roleSetting/roleSetting')" :title-style="{fontSize:'1em'}">
					<text slot="icon"></text>
				</u-cell-item>
			</u-cell-group>
			<u-cell-group :border="false">
				<u-cell-item title="价格权限/显示设置" v-if="$hasPermissions('M_priceShow_mini')&&showPriceSet" @click="toPage('/pages/storeManage/priceSetting/priceSetting')" :title-style="{fontSize:'1em'}">
					<text slot="icon"></text>
				</u-cell-item>
			</u-cell-group>
		</view>
		<view class="list-box" v-if="hasLogin&&dealerPhone">
			<view class="list-title flex justify_center phone" @click="call">
				<u-icon size="36" name="phone"></u-icon> <text>联系汽配商</text>
			</view>
		</view>
		<view class="list-box" v-if="hasLogin">
			<view class="list-title flex justify_center phone" @click="quitOut">
				<text>退出登录</text>
			</view>
		</view>
		<!-- 去认证 -->
		<u-popup v-model="showPopup" mode="center" :border-radius="20" closeable>
			<view style="background-color: #fff;padding: 1rem;">
				<u-image width="533" height="415" src="/static/authimg.jpg"></u-image>
				<view style="padding-top:1rem;" class="flex justify_center">
					<u-button @click="toAuthStore()" shape="circle" :custom-style="{background:'#066cff',color:'#fff',width:'350rpx'}">开始认证</u-button>
				</view>
			</view>
		</u-popup>
	</view>
	<u-tabbar :list="vuex_tabBarList" :before-switch="beforeSwitch" :mid-button="false"></u-tabbar>
	</view>
</template>

<script>
	import {
	    mapState,
	    mapMutations
	} from 'vuex'
	import { queryQplsConfig } from '@/api/shelf.js'
	export default {
		data() {
			return {
				dealerPhone: null,
				showPopup: false,
				showPriceSet: false,
				shelfSn: null
			}
		},
		computed: {
			...mapState(['hasLogin','vuex_vinScanNums','vuex_scanMaxNums','vuex_tabBarList']),
			hasShelf(){
				return !!this.$store.state.vuex_storeShelf
			},
			userInfo(){
				return this.$store.state.vuex_userInfo
			},
			storeApply(){
				return this.$store.state.vuex_storeAuthInfo
			},
			hasRedPacket(){
				const rule = this.$store.state.vuex_rewardRule
				return rule&&rule.ruleStatus == 'release'
			},
		},
		onShow() {
				const shelfInfo = this.$store.state.vuex_storeShelf
				this.shelfSn = shelfInfo ? shelfInfo.shelfSn : ''
				this.dealerPhone = shelfInfo&&shelfInfo.contactMobile ? shelfInfo.contactMobile : ''
				if(this.shelfSn){
					this.getPriceCofig()
				}
			},
		methods: {
			beforeSwitch(index){
				if(index==1){
					this.openCamera()
				}else{
					return true
				}
			},
			// 获取价格配置
			getPriceCofig(){
				queryQplsConfig({shelfSn: this.shelfSn}).then(res => {
					this.$store.state.vuex_configPrice = res.data || null
					const ret = [false,false]
					ret[0]= res.data.shelf_cost_show == '1'
					ret[1]= res.data.shelf_price_show == '1'
					this.showPriceSet = ret.filter(item => !!item).length > 0
				})
			},
			// 去扫描
			openCamera(){
				if(this.hasLogin){
					if(this.userInfo.sysUserFlag == '0'){
						if(this.vuex_vinScanNums < this.vuex_scanMaxNums){
							uni.navigateTo({
								url: "/pages/scan-frame/scan-frame"
							})
						}else{
							uni.showModal({
								title: '提示',
								content: '个人用户扫描VIN仅限10次，您的次数已用完！',
								confirmText: '好的',
								showCancel: false,
								success(res) {}
							})
						}
					}else{
						uni.navigateTo({
							url: "/pages/scan-frame/scan-frame"
						})
					}
				}else{
					uni.navigateTo({
						url: '/pages/login/login'
					})
				}
			},
			toPage(path){
				uni.navigateTo({
					url: path
				})
				return
				const _this = this
				if(this.hasLogin){
					// 游客未认证
					if(this.userInfo.sysUserFlag == '0'){
						if(this.storeApply&&this.storeApply.auditStatus=='WAIT'){
							uni.showModal({
								title: '提示',
								content: '门店认证资料审核中，请耐心等待！',
								confirmText: '知道了',
								showCancel: false
							})
						}
						// 如果审核已通过
						else if(this.storeApply&&this.storeApply.auditStatus=='PASS'){
							uni.showModal({
								title: '提示',
								content: '门店认证审核已通过，请重新登录！',
								confirmText: '去登录',
								showCancel: false,
								success() {
									_this.$store.dispatch('userLogout');
									uni.redirectTo({
										url: '/pages/login/login'
									});
								}
							})						
						}else{
							this.showPopup = true
						}
					}else{
						// 已有数字货架
						if(this.hasShelf){
							uni.navigateTo({
								url: path
							})
						}else{
							uni.showToast({
								icon:'none',
								title: '门店没有关联数字货架，无法使用此功能！'
							})
						}
					}
				}else{
					uni.navigateTo({
						url: '/pages/login/login'
					})
				}
			},
			toAuthStore(){
				this.showPopup = false
				uni.navigateTo({
					url: '/pages/storeManage/storeAuth'
				})
			},
			call(){
				this.callPhone(this.dealerPhone)
			},
			quitOut(){
				let _this = this
				uni.showModal({
					title: '提示',
					content: '确定退出登录吗？',
					success: (ret) => {
					  if(ret.confirm){
						  _this.$store.dispatch('userLogout');
						  uni.navigateTo({
						  	 url: '/pages/login/login'
						  });
					  }
					}
				})
				
			}
		}
	}
</script>

<style lang="less">
.morePages{
	width: 100%;
	padding: 30rpx;
	background-image: linear-gradient(#86defa 0%,#cdeff9 20%,#f8f8f8 30%);
	.list-box{
		background: #ffffff;
		margin-bottom: 30rpx;
		border-radius: 25rpx;
		overflow: hidden;
		box-shadow: 2rpx 2rpx 5rpx #eee;
		.list-title{
			padding:30rpx 20rpx;
			font-size: 30rpx;
			border-bottom: 2rpx solid #f8f8f8;
			> text{
				margin-left: 10rpx;
			}
		}
		&:first-child{
			box-shadow: 2rpx 2rpx 5rpx #cdeff9;
		}
	}
	.phone{
		color: #00aaff;
		&:active{
			opacity: 0.8;
			transform:scale(0.9);
		}
	}
}
</style>
