<template>
	<view class="content" :class="hasShopiing?'':'bg-1'">
		<view class="content-body">
			<!-- 头部栏 -->
			<view class="header-box">
				<UniStatusBar></UniStatusBar>
				<view class="title flex align_center" :style="{height:(navHeight+'px')}">
					<u-image src="/static/logo-h.png" width="349" height='40'></u-image>
					<!-- 版本提示 -->
					<text class="version" v-if="showVersion">体验版</text>
				</view>
			</view>
			<!-- 浮动头部 -->
			<view class="header-box headerFixed" v-if="hasShopiing&&showFixed">
				<UniStatusBar></UniStatusBar>
				<view class="title flex align_center" :style="{height:(navHeight+'px')}">
					<view class="search-head" @click="toSearch">
						<uni-search-bar readonly radius="100" bg-color="#fff" placeholder="请输入商品名称/产品编码/原厂编码" clearButton="auto" cancelButton="none"/>
					</view>
				</view>
			</view>
			<view class="cbody" :class="hasShopiing?'bg-0':''">
				<view :class="hasShopiing?'shopping':'body-box bg-blue'">
					<!-- 滚动区域 -->
					<view class="scroll-list" v-if="!hasShopiing">
						<scrollBox v-if="list.length&&!hasRedPacket" :list="list"></scrollBox>
						<scrollBox v-if="slist.length&&hasRedPacket" :list="slist"></scrollBox>
					</view>
					<!-- 保证金 -->
					<view class="notices flex align_center" v-if="bondRecord" @click="toPayBondAmount">
						<view><u-icon name="volume" color="#f2a557" :size="28" :margin-right='15'></u-icon> 您有一笔保证金待支付 ￥{{bondRecord.bondAmount}}</view> 
						<!-- <text class="text">立即支付>></text> -->
					</view>
					<!-- 待取货提醒 -->
					<view class="notices flex align_center" v-if="!bondRecord&&orderTodo" @click="toOrder">
						<view><u-icon name="volume" color="#f2a557" :size="28" :margin-right='15'></u-icon> 您有待取货的货架订单哦！</view> <text class="text">立即处理>></text>
					</view>
					<!-- 去认证门店 -->
					<view class="notices flex" v-if="hasLogin&&userInfo&&userInfo.sysUserFlag == '0'">
						<!-- 门店审核不通过 -->
						<view class="flex justify_between align_center" v-if="storeApply&&storeApply.auditStatus=='REFUSE'&&storeApply.readFlag=='0'">
							<view><u-icon name="volume" color="#f2a557" :size="28" :margin-right='15'></u-icon> 门店认证资料审核不通过，请重新提交审核！</view> <text class="text" @click="toKnow">知道了</text>
						</view>
						<view class="flex justify_between align_center" v-else>
							<view><u-icon name="volume" color="#f2a557" :size="28" :margin-right='15'></u-icon> {{storeApply&&storeApply.auditStatus=='WAIT'?'认证门店审核中':'您还未认证门店'}}</view> <text class="text" @click="authStore">{{storeApply&&storeApply.auditStatus=='WAIT'?'查看':'去认证'}}</text>
						</view>
					</view>
					<!-- 名片 -->
					<view class="userCard flex align_center justify_between" v-if="!hasShopiing">
						<view class="userCard-info flex align_center">
							<view>
								<u-image shape='circle' v-if="!hasLogin" src="/static/def_personal_avatar.png" width="90" height="90"></u-image>
								<u-image shape='circle' v-else :src="avatarUrl||'/static/def_personal_avatar.png'" width="90" height="90"></u-image>
							</view>
							<view class="user-info" @click="toUser">
								<view v-if="!hasLogin" style="font-size: 40rpx;">
									请点击登录
								</view>
								<view v-else>
									<view class="user-name">{{userInfo.userNameCN || userInfo.mobile}}</view>
									<view v-if="hasLogin&&userInfo&&userInfo.sysUserFlag == '0'">
										<u-tag text="个人用户" mode="dark" type="warning" shape="circle" size="mini" />
									</view>
									<view v-else>{{userInfo.orgName}}</view>
								</view>
							</view>
						</view>
						<view @click="toUser">
							<text v-if="hasLogin&&userInfo&&userInfo.sysUserFlag == '0'" class="user-rz">
								{{storeApply&&storeApply.auditStatus=='WAIT'?'认证门店审核中':'认证成为门店'}}
							</text>
							<uni-icons type="arrowright" size="20" color="#999"></uni-icons>
						</view>
					</view>
					<!-- 搜索 -->
					<view class="search-head" v-if="hasShopiing" @click="toSearch">
						<uni-search-bar readonly radius="100" bg-color="#fff" placeholder="请输入商品名称/产品编码/原厂编码" clearButton="auto" cancelButton="none"/>
					</view>
				</view>
				<view :class="hasShopiing?'body-box1':'body-box'">	
					<!-- 扫描按钮 -->
					<view class="action-button flex" v-if="userInfo.sysUserFlag == '1'&&!hasShopiing">
						<view class="f1" @click="openTakeGood(1)">
							<view class="icons"><u-icon name="bianmachaxun" custom-prefix="custom-icon"></u-icon></view>
							<view class="tits">产品编码取货</view>
						</view>
						<view class="f2" @click="openTakeGood(0)">
							<view class="icons"><u-icon name="saoma" custom-prefix="custom-icon"></u-icon></view>
							<view class="tits">二维码/条形码取货</view>
						</view>
					</view>
					<!-- banner -->
					<view class="banner">
						<u-swiper mode="dot" bg-color="" img-mode="widthFix" @click="clickBanner" :interval="3000" :height="hasShopiing?280:350" :list="imgList"></u-swiper>
					</view>
					<!-- 快捷导航 -->
					<view class="quick-nav pa-box" v-if="hasShopiing&&navList.length">
						<iconItemsList :list="navList" type="img" :isLogin="true" :sysUserFlag="userInfo.sysUserFlag" :iconSize="45" @callback="onNavFun"></iconItemsList>
					</view>
					<!-- 产品分类 -->
					<view class="ptype-nav pa-box" v-if="hasShopiing&&productTypeList.length">
						<swiper class="swiper" :style="{height:navHeight==44?'160px':'160px'}" @change="e=>{currentPtypeDot=e.detail.current}">
							<swiper-item v-for="(item, idx) in productTypeList" :index="idx" :key="item.id">
								<iconItemsList :isLogin="hasLogin" circle :sysUserFlag="userInfo.sysUserFlag" :list="item.list" type="img"></iconItemsList>
							</swiper-item>
						</swiper>
						<view class="indicator-dots" v-if="productTypeList.length>1">
							<view v-for="(item,idx) in productTypeList" :key="idx" :class="currentPtypeDot==idx?'indicator-dots-active':''" ></view>
						</view>
					</view>
					<!-- 产品列表 -->
					<view class="product-box" v-if="hasShopiing && totalhotPage>0">
						<u-divider bg-color="" half-width="0" color="#666" use-slot :fontSize="28">
							<image style="width: 16px;height:16px;" src="../../static/hot.png"></image> 
							<text style="margin: 0 5px;font-weight: bold;">热门推荐</text>
							<image style="width: 16px;height:16px;" src="../../static/hot.png"></image>
						</u-divider>
						<view class="product-list">
							<!-- 产品列表 -->
							<productItem
							v-for="(item,index) in productList"
							:key="index" 
							:list="item" 
							:index="index"
							:itemWidth="(screenWidth-25)*0.5"
							:gap="5"
							:isLogin="hasLogin"
							:sysUserFlag="userInfo.sysUserFlag"
							></productItem>
							<view style="padding: 50upx 0;">
								<u-empty :src="`/static/nodata.png`" icon-size="180" :text="noDataText" img-width="120" v-if="totalhotPage==0 && status!='loading'" mode="list"></u-empty>
								<u-loadmore v-else  color="#999" :fontSize="24" :status="status" />
							</view>
						</view>
					</view>
				</view>
				<!-- 扫描记录 -->
				<view class="list-box" v-if="!hasShopiing">
					<!-- 扫描记录 -->
					<u-cell-group :border="false">
						<u-cell-item title="VIN查询历史" @click="toAllRecord" :title-style="{fontSize:'1em'}" value="全部">
							<u-icon slot="icon" size="32" color="#066cff" style="margin-right: 0.3em;" name="order"></u-icon>
						</u-cell-item>
					</u-cell-group>
					<u-cell-group :border="false" v-if="hasLogin">
						<u-cell-item v-for="item in vinList" 
						@click="toChoosePart(item)" 
						:key="item.id" 
						:title="item.vinCode" 
						:title-style="{fontSize:'1em'}" 
						:label="userInfo&&userInfo.sysUserFlag == '0' ? item.createDate : (item.brandName +' '+item.modelName)">
							<text slot="icon"></text>
						</u-cell-item>
						<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>
					</u-cell-group>
					<view class="des" v-if="vinList.length&&hasLogin">仅展示最近5条记录，点击“全部”查看更多</view>
					<view class="des" v-if="!hasLogin">请登录后查看历史记录</view>
				</view>
			</view>
		</view>
		<!-- tab栏 -->
		<u-tabbar :list="vuex_tabBarList" :mid-button-size="80" :before-switch="beforeSwitch" :midButton="vuex_tabBarList.length==5"></u-tabbar>
	</view>
</template>

<script>
	import {
	    mapState,
	    mapMutations,
	} from 'vuex'
	import scrollBox from '@/components/scrollBox.vue'
	import UniStatusBar from '@/components/uni-status-bar/uni-status-bar.vue'
	import iconItemsList from '@/components/icon-items-list/icon-items-list.vue'
	import productItem from './productItem.vue'
	import { shelfBondRecordWaitPayRecord, findStoreShelf, shelfGetTotalWaitQty, getProductfindByScanCode, queryQplsConfig } from '@/api/shelf.js'
	import { xprhStoreApplyRead } from '@/api/xprh.js'
	import { findCurrentRewardRule } from '@/api/rewardRule.js'
	import { listLookUp, getLookUpDatas, getCurrUserInfo } from '@/api/data.js';
	import { scanVinLogQueryRoll, getScanVinLogList, getScanGetMaxQty }from '@/api/car.js'
	import { shopBannerList } from '@/api/video.js'
	import { getRewardRollList } from '@/api/rewardRule.js'
	import { getShopStatus, getCartCount } from '@/api/cart.js'
	import { getShopCategory, getShopProductList } from '@/api/shop.js'
	import { openWebView, clickTab, toAuthStore, clickBannerList, toLogin } from "@/utils/index.js"
	export default {
		components: {
			iconItemsList, // 图标网格
			scrollBox, // 无缝滚动组件
			UniStatusBar, // 状态栏组件
			productItem // 产品列表
		},
		data() {
			const _this = this
			return {
				status: 'loading',
				noDataText: '暂无数据',
				hasShopiing: true, // 是否开通商城
				bondRecord: null, // 保证金
				list:[], // 扫描记录滚动
				slist:[], // 红包滚动
				vinList: [], // 扫描记录
				orderTodo: null, // 待取货的货架订单信息
				avatarUrl:'', // 用户图像
				navHeight: '44', // 头部高度
				scanMaxNums: 10, // 扫描VIN仅限10次
				carouselList: [] ,// 修理厂促销活动列表
				productTypeList: [], // 产品分类
				currentPtypeDot: 0, // 当前产品分类页
				screenWidth: 325, // 屏幕宽度
				productList:[], // 热门产品
				hotProductPageNo: 1 ,// 热门产品页码
				hotProductpageSize:10, // 热门产品每页数量
				totalhotPage: 0, // 热门产品总页数
				showFixed: false, // 是否显示浮动头部
				isCheckLogin:false, // 是否正在检查登录
			}
		},
		computed: {
			...mapState(['hasLogin','vuex_vinScanNums','vuex_tabBarList']),
			// 显示开发版本信息
			showVersion () {
				const baseUrl = getApp().globalData.baseUrl
				return baseUrl.indexOf(".test.") >= 0 || baseUrl.indexOf('192.168') >=0
			},
			// 是否有数字货架
			hasShelf(){
				return this.$store.state.vuex_storeShelf
			},
			// 登录用户信息
			userInfo(){
				return this.$store.state.vuex_userInfo
			},
			// 是否有门店申请信息
			storeApply(){
				return this.$store.state.vuex_storeAuthInfo || null
			},
			// 是否有红包
			hasRedPacket(){
				const rule = this.$store.state.vuex_rewardRule
				return rule&&rule.ruleStatus == 'release'
			},
			// banner 图片列表
			imgList(){
				let list = [
					{
						image: '/static/banner1.jpg',
						activeType: ''
					}
				]
				const newList = []
				// 红包
				if(this.hasRedPacket&&this.hasShelf){
					newList.push(
					{
						image: '/static/banner2.jpg',
						activeType: 'redPacket'
					})
				}
				return this.carouselList.length>0 ? newList.concat(this.carouselList) : list.concat(newList)
			},
			// 快捷导航
			navList(){
				const list = [
					{
						id:'n0',
						auth: this.hasLogin,
						ignoreAuth: false,
						icon:'/static/nav_icon1.jpg',
						name: '产品编码取货',
						color:'#056cd9',
						url: 'openTakeGood1',
						target: 'fun'
					},
					{
						id:'n1',
						auth: this.hasLogin,
						ignoreAuth: false,
						icon:'/static/nav_icon2.jpg',
						name: '二维/条码取货',
						color:'#f44336',
						url:'openTakeGood0',
						target: 'fun'
					},
					{
						id:'n3',
						auth: true,
						ignoreAuth: true,
						icon:'/static/nav_icon3.jpg',
						name: '视频教程',
						color:'#03a9f4',
						url:'/pagesB/videos/index',
						target: 'page'
					},
					{
						id:'n2',
						auth: this.hasLogin,
						ignoreAuth: true,
						icon:'/static/nav_icon4.jpg',
						name: 'VIN查询历史',
						color:'#ff9800',
						url:'/pagesA/vinRecord/vinRecord',
						target: this.hasLogin ? 'page' : 'fun'
					}
				]
				return list
			}
		},
		onReady() {
			// 获取导航栏高度
			const res = uni.getSystemInfoSync()
			this.screenWidth = res.windowWidth
			const system = res.platform
			if (system === 'android') {
				this.navHeight = 48
			} else if (system === 'ios') {
				this.navHeight = 44
			}
		},
		onLoad() {
			this.orderTodo = null
			this.bondRecord = null
			this.vinList = []
			// 视频类型
			this.getLookUpList('CONTENT_CATEGORY', 'vuex_videoTypeList');
			// 检测是否登录
			this.isCheckLogin = true
			this.$store.dispatch('checkLogin',(isLogin)=>{
				this.isCheckLogin = false
				// 获取数据字典
				this.getListLookUp();
				// 获取支付，收款方式
				this.getLookUpList('PAY_PROCUCT_TYPE', 'vuex_paymentTypeList');
				// 价格类型
				this.getLookUpList('PRICE_SHOW_TYPE', 'vuex_priceTypeList');
				// 初始化页面
				this.pageInit(0)
			})
			// 刷新首页数据
			uni.$on("refashHome",()=>{
				this.pageInit(2)
			})
			// 刷新购物车
			uni.$on("refashCart",()=>{
				this.cartCount()
			})
		},
		// 页面卸载
		onUnload() {
			uni.$off('refashHome')
			uni.$off('refashProm')
			uni.$off('refashCart')
		},
		onHide() {
			// 用户头像
			this.avatarUrl = uni.getStorageSync('userPhoto');
			// 重新刷新
			if(!this.isCheckLogin){
				this.pageInit(1)
			}
		},
		// 下拉刷新
		onPullDownRefresh(){
			this.pageInit(2)
			setTimeout(function () {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onShareAppMessage() {},
		// 页面滚动
		onPageScroll(e) {
			this.showFixed = e.scrollTop > 120
		},
		// 滚动到底部,加载热门产品
		onReachBottom() {
			if(this.hasShopiing && this.hotProductPageNo < this.totalhotPage){
				this.hotProductPageNo++
				this.getProductList()
			}
		},
		methods: {
			// 去认证
			authStore(){
				uni.navigateTo({
					url: '/pages/storeManage/storeAuth'
				})
			},
			// 初始化页面
			pageInit(flag){
				// 已登录
				if(this.hasLogin){
					// 已认证用户
					if(this.userInfo.sysUserFlag == '1'){
						// 查询是否有数字货架
						this.getStoreShelf(flag)
					}else{// 游客
						// 获取扫描次数
						this.$store.dispatch("getScanNums")
						// 获取最大扫描次数
						this.getMaxQty()
						// 查询门店认证信息
						this.findLastApply()
						// 获取扫描记录
						this.getVinLog()
						if(this.hasShopiing){
							this.showShopPage(flag)
						}else{
							this.showNoShopPage()
						}
					}
				}else{
					// 未登录
					this.hasShopiing = true
					// 隐藏促销模块
					this.hidePromoTab()
					if(this.hasShopiing){
						this.showShopPage(flag)
					}else{
						this.showNoShopPage()
					}
				}
			},
			// 查询是否支持数字货架, flag: true 再次刷新，false 首次加载，只加载一次
			getStoreShelf(flag){
				findStoreShelf().then(res => {
						this.$store.state.vuex_storeShelf = res.data;
						// 有数字货架
						if(res.data){
							// 查询是否有商城
							this.getHasShopping(flag)
							// 只需加载一次
							if(flag==0){
								// 更新用户信息
								this.getCurrUserInfo()
								// 保证金查询
								this.getShelfBWPayRecord()
								// 获取订单信息
								this.shelfGetTotalWaitQty()
								// 获取价格权限配置
								this.getPriceCofig()
							}
						}else{
							// 没有数字货架，隐藏促销模块
							this.hidePromoTab()
						}
				})
			},
			// 最新用户信息
			getCurrUserInfo(){
				getCurrUserInfo().then(res => {
					if(res.data){
						this.$store.state.vuex_userInfo.userNameCN = res.data.name;
						this.$store.state.vuex_userInfo.mobile = res.data.mobile;
						this.$store.state.vuex_userInfo.adminId = res.data.id;
						this.$store.state.vuex_userPhoto = res.data.photo;
						uni.setStorageSync('userPhoto', res.data.photo);
					}
				})
			},
			// 获取价格配置
			getPriceCofig(){
				const data = this.$store.state.vuex_storeShelf
				queryQplsConfig({shelfSn: data.shelfSn}).then(res => {
					this.$store.state.vuex_configPrice = res.data || null
				})
			},
			// 商城信息, flag: true 再次刷新，false 只加载一次
			getHasShopping(flag){
				getShopStatus().then(res => {
					this.hasShopiing = res.data && res.data.paramValue == 1
					// 有商城
					if(this.hasShopiing){
						this.showShopPage(flag)
					}else{
						// 没有商城
						this.showNoShopPage(flag)
					}
					// 查询红包活动
					this.getRedPacketRule()
				})
			},
			// 显示开通商城的页面
			showShopPage(flag){
				// 隐藏tab 视频，显示tab购物车
				if(this.hasLogin && this.userInfo && this.userInfo.sysUserFlag == '1'){
					// 显示促销模块
					this.showPromoTab()
					this.cartCount()
				}else{
					this.$store.state.vuex_cartTotal = 0
					this.showCatTab()
				}
				// 获取轮播数据，包括促销活动
				this.getCarousel(1)
				// 商品分类
				this.getGoodType(flag)
				// 获取推荐产品
				this.getHotProductList(flag)
			},
			// 显示未没有开通商城的界面
			showNoShopPage(flag){
				this.productTypeList = []
				this.productList = []
				// 获取轮播数据，包括促销活动
				this.getCarousel(0)
				// 隐藏促销模块
				this.hidePromoTab()
				// 隐藏tab 购物车，显示tab视频
				this.showVideoTab()
				// 滚动扫描记录
				this.getScrollLog()
				// 获取扫描记录
				if(this.hasLogin){
					this.getVinLog()
				}
			},
			// 购物车数量
			cartCount(){
				getCartCount({}).then(res => {
					if(res.status == 200){
						this.$store.state.vuex_cartTotal = res.data?res.data.qty:0
						this.showCatTab()
					}
				})
			},
			// 商品一级分类
			getGoodType(flag){
				this.productTypeList = []
				getShopCategory({categoryLevel: 1}).then(res => {
					const list = res.data || []
					const ret = []
					list.forEach(item => {
						ret.push({
							id: item.id,
							categorySn: item.categorySn,
							auth: true,
							ignoreAuth: false,
							name: item.categoryName,
							icon: item.iconUrl,
							url: '/pagesB/shopiing/shopProduct?clzId='+item.categorySn+'&clzName='+item.categoryName+"&shopCategoryCount="+item.shopCategoryCount+'&shopProductCount='+item.shopProductCount,
							target: 'page'
						})
					})
					// 转成二维数组
					for(let i=0;i<ret.length;i=i+8){
						this.productTypeList.push({
							id: 'swiper-item-'+i,
							list: ret.slice(i,(i+8)>ret.length?ret.length:(i+8))
						})
					}
				})
			},
			// 商品列表查询
			getHotProductList(flag){
				console.log(flag)
				this.hotProductPageNo = 1
				// 不是show 刷新列表
				if(flag!=1){
					this.productList = []
					this.hotProductpageSize = 10
				}else{
					// 刷新列表
					let count = 0
					this.productList.forEach(item => {
						count += item.length
					})
					this.hotProductpageSize = count||10
				}
				this.getProductList(flag)
			},
			getProductList(flag){
				this.status = "loading"
				const dealerSn = this.hasLogin && this.userInfo && this.userInfo.sysUserFlag == '1' ? this.$store.state.vuex_storeShelf.dealerSn : ''
				// 获取推荐产品	
				 getShopProductList({pageNo:this.hotProductPageNo,pageSize:this.hotProductpageSize,hotFlag:1, status: 1, dealerSn: dealerSn}).then(res => {
					 if(res.status == 200){
						 const list = res.data ? res.data.list : []
						 list.map(item=>{
							  const a = item.shopPromoProduct
							  if(a){
								  item.promoType = a.promoType
								  item.resultValue = a.resultValue
								  item.conditionValue = a.conditionValue
								  item.discountType = a.discountType
								  item.promoProductSn = a.promoProductSn
								  item.promoSn = a.promoSn
								  item.orginPrice = item.price
								  // 特价
								  if(item.promoType=='PROMO_PROD'){
									  item.price = item.conditionValue
								  }
							  }
							  item.priceStr = Number(item.price).toFixed(2).toString().split('.')
							  delete item.shopPromoProduct
						 })
						 if(flag!=1){
							 this.productList.push(list)
						 }else{
							 // 刷新
							 this.productList = [list]
						 }
						 this.status = res.data.count>=this.list.length ? "nomore" : 'loadmore'
						 // 判断是否最后一页
						 const maxPages = Math.ceil(res.data.count / 10)
						 this.totalhotPage = maxPages
						 this.status = this.hotProductPageNo >= maxPages ? "nomore" : 'loadmore'
						 this.noDataText = this.status == 'nomore' ? '没有更多了' : '更多商品'
					 }else{
						 this.status = "nomore"
						 this.noDataText = res.message || '没有更多了'
					 }
				 })
			},
			// 获取上方滚动扫描记录
			getScrollLog(){
				scanVinLogQueryRoll({pageNo:1,pageSize:50}).then(res => {
					this.list = res.data.list || []
					this.list.map(item => {
						item.placeText = item.userName + '刚刚扫描了一个VIN'
					})
				})
			},
			// 获取当前门店扫描记录
			getVinLog(){
				this.vinList  = []
				this.status = "loading"
				// VISITOR：游客，EMPLOYEE：雇员
				getScanVinLogList({ pageNo:1, pageSize:5, identifyType: this.userInfo.identifyType }).then(res => {
					this.vinList = res.data&&res.data.list || []
					this.vinList = this.vinList.filter(item => item.vinCode)
					this.status = 'nomore'
				})
			},
			// tab单击
			beforeSwitch(index){
				const row = this.$store.state.vuex_tabBarList[index] // 当前tab
				const isNoAuth = this.userInfo ? this.userInfo.sysUserFlag == '0' : false // 是否认证门店
				return clickTab(row,this.hasLogin,isNoAuth,this.vuex_vinScanNums < this.vuex_scanMaxNums)
			},
			// 去搜索产品
			toSearch(event){
				if(this.hasLogin){
					// 游客去认证
					if(this.userInfo.sysUserFlag == '0'){
						toAuthStore()
					}else{
						uni.navigateTo({
							url:'/pagesB/shopiing/searchProduct?queryWord='+event.value+'&clzId='
						})
					}
				}else{
					toLogin()
				}
			},
			// 轮播图片
			getCarousel(flag){
				this.carouselList = []
				// 获取所有促销活动数据
				shopBannerList({promoFlag:flag}).then(res => {
					if(res.status == 200){
						res.data&&res.data.map(item => {
							item.image = item.imageUrl
						})
						this.carouselList = res.data
					}
				})
			},
			// 快速导航单击
			onNavFun(item){
				if(item.auth){
					// 非游客
					if(this.userInfo.sysUserFlag == '1'){
						// 编码取货
						if(item.url=='openTakeGood1'){
							this.openTakeGood(1)
						}
						// 扫码取货
						if(item.url=='openTakeGood0'){
							this.openTakeGood(0)
						}
					}else{
						// 去认证
						toAuthStore()
					}
				}else{
					toLogin()
				}
			},
			//  获取数据字典
			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 || [];
					}
				});
			},
			// 获取最大扫描数
			getMaxQty(){
				getScanGetMaxQty().then(res => {
					this.scanMaxNums = res.data || 10
					this.$store.state.vuex_scanMaxNums = this.scanMaxNums
				})
			},
			// 获取最新申请门店
			findLastApply(){
				const mobile = this.userInfo.mobile
				this.$store.dispatch('getSotreAuth',mobile)
			},
			// 知道审核不通过
			toKnow(){
				uni.showLoading({
					title: "正在提交"
				})
				xprhStoreApplyRead({sn:this.storeApply.applySn}).then(res => {
					if(res.status == 200){
						this.findLastApply()
					}
					uni.hideLoading()
				})
			},
			// 待取货数量合计
			shelfGetTotalWaitQty(){
				shelfGetTotalWaitQty({billState:'WAIT'}).then(res => {
					if(res.status == 200){
						this.orderTodo = res.data;
					}
				})
			},
			// 货架订单列表
			toOrder(){
				if(this.hasShelf){
					uni.navigateTo({
						url: "/pagesA/digitalShelf/orderList"
					})
				}else{
					uni.showToast({
						icon:'none',
						title: '门店没有关联数字货架，无法使用此功能！'
					})
				}
			},
			// 显示购物车tab
			showCatTab(){
				const videoIndex = this.$store.state.vuex_tabBarList.findIndex(item => item.text == '视频')
				const catIndex = this.$store.state.vuex_tabBarList.findIndex(item => item.text == '购物车')
				if(catIndex<0 && videoIndex >= 0){
					// 替换视频为购物车
					this.$store.state.vuex_tabBarList.splice(videoIndex,1,{
						"pagePath": "/pages/cart/index",
						"iconPath": "/static/tab/tab_cart_normal.png",
						"selectedIconPath": "/static/tab/tab_cart_pressed.png",
						"text": "购物车",
						'customIcon': false,
						'count': this.$store.state.vuex_cartTotal,
						'isDot': false
					})
				}
				// 购物车已存在
				if(catIndex>=0){
					this.$store.state.vuex_tabBarList[catIndex].count = this.$store.state.vuex_cartTotal
				}
			},
			// 显示视频tab，隐藏购物车
			showVideoTab(){
				const videoIndex = this.$store.state.vuex_tabBarList.findIndex(item => item.text == '视频')
				const catIndex = this.$store.state.vuex_tabBarList.findIndex(item => item.text == '购物车')
				if(videoIndex<0 && catIndex >= 0){
					// 替换购物车为视频
					this.$store.state.vuex_tabBarList.splice(catIndex,1,{
						"pagePath": "/pages/videos/index",
						"iconPath": "/static/tab/tab_video_normal.png",
						"selectedIconPath": "/static/tab/tab_video_pressed.png",
						"text": "视频",
						'customIcon': false,
					})
				}
			},
			// 显示促销模块
			showPromoTab(){
				// 添加促销模块
				const promoIndex = this.$store.state.vuex_tabBarList.findIndex(item => item.text == '促销')
				if(promoIndex<0){
					this.$store.state.vuex_tabBarList.splice(1,0,{
						"pagePath": "/pages/promo/index",
						"iconPath": "/static/tab/tab_promo_normal.png",
						"selectedIconPath": "/static/tab/tab_promo_pressed.png",
						"text": "促销",
						'customIcon': false,
					})
				}
				// 居中透出显示扫描按钮
				const scanTab = this.$store.state.vuex_tabBarList.find(item => item.text == '扫描VIN')
				if(scanTab){
					scanTab.iconPath = "/static/tab/tab_scan_mid.png"
					scanTab.midButton = true
				}
			},
			// 隐藏促销模块
			hidePromoTab(){
				// 删除促销模块
				const promoIndex = this.$store.state.vuex_tabBarList.findIndex(item => item.text == '促销')
				if(promoIndex > -1){
					this.$store.state.vuex_tabBarList.splice(promoIndex,1)
				}
				// 扫描按钮不局中
				const scanTab = this.$store.state.vuex_tabBarList.find(item => item.text == '扫描VIN')
				if(scanTab){
					scanTab.iconPath = "/static/tab/tab_scan_normal.png"
					scanTab.midButton = false
				}
			},
			// 查询是有红包活动
			getRedPacketRule(){
				findCurrentRewardRule().then(res => {
					this.$store.state.vuex_rewardRule = res.data;
					// 商城未开通时调用
					if(res.data && !this.hasShopiing){
						this.getRedScroll()
					}
				})
			},
			// 红包奖励信息
			getRedScroll(){
				getRewardRollList({pageNo:1,pageSize:50}).then(res => {
					this.slist = res.data || []
					this.slist.map(item => {
						item.placeText = item.userName + '刚刚得到了'+item.totalRewardAmount+'元 红包奖励'
					})
				})
			},
			// 获取保证金金额
			getShelfBWPayRecord(){
				const data = this.$store.state.vuex_storeShelf
				shelfBondRecordWaitPayRecord({shelfSn: data.shelfSn, storeSn: data.storeSn}).then(res => {
					console.log(res,'获取保证金金额')
					this.bondRecord = res.data
				})
			},
			// 保证金支付
			toPayBondAmount(){},
			openTakeGood(index){
				// 已有数字货架
				if(this.hasShelf){
					this.clickAction(index)
				}else{
					uni.showToast({
						icon:'none',
						title: '门店没有关联数字货架，无法使用此功能！'
					})
				}
			},
			// 选择取货方式
			clickAction(index){
				const shelfSn = this.hasShelf.shelfSn
				const _this = this
				// 扫描
				if(index == 0){
					uni.scanCode({
						success: function (ret) {
							const params = {
								codeType: ret.scanType == 'QR_CODE' ? 0 : 1
							}
							// 二维码
							if(ret.scanType == 'QR_CODE'){
								const result = ret.result.split("&")
								params.productSn = result[2] // 产品编码sn
							}else{
								params.qrCode = ret.result
							}
							uni.showLoading({
								title: "正在查询产品..."
							})
							// 确认取货
							getProductfindByScanCode(params).then(res => {
								if(res.status == 200 && res.data){
									if(res.data.currentInven){
										const billSource = ret.scanType == 'QR_CODE' ? 'qr_code': 'bar_code'
										const retData = Object.assign({shelfSn: shelfSn, billSource: billSource},res.data)
										_this.$store.state.vuex_tempData = retData
										uni.navigateTo({
											url: '/pagesA/queryByCode/confirmQh'
										})
									}else{
										uni.showModal({
											title: '提示',
											content: '产品库存为0，无法取货！',
											confirmText: '好的',
											showCancel: false
										})
									}
								}else{
									uni.showModal({
										title: '提示',
										content: '产品不属于此货架，请重新扫描！',
										confirmText: '好的',
										showCancel: false
									})
								}
								uni.hideLoading()
							})
						}
					});
				}else{
					// 按编码搜索
					uni.navigateTo({
						url: '/pagesA/queryByCode/queryByCode'
					})
				}
			},
			// 单击banner
			clickBanner(index){
				clickBannerList(this.imgList[index],this.hasLogin,this.userInfo&&this.userInfo.sysUserFlag == '1')
			},
			// 查看扫描VIN记录
			toAllRecord(){
				if(this.hasLogin){
					uni.navigateTo({
						url: "/pagesA/vinRecord/vinRecord"
					})
				}else{
					toLogin()
				}
			},
			// 查看用户信息
			toUser(){
				if(this.hasLogin){
					if(this.userInfo.sysUserFlag == '1'){
						// 用户详细信息
						uni.navigateTo({
							url: '/pages/personData/personData'
						})
					}else{
						// 或 门店认证
						toAuthStore()
					}
				}else{
					toLogin()
				}
			},
			// 选择配件
			toChoosePart(item){
				item.text = item.modelInfo
				uni.navigateTo({
					url: "/pagesA/digitalShelf/choosePart?vinNumber="+item.vinCode+"&carList="+encodeURIComponent(JSON.stringify(item))+'&type=log'
				})
			},
		}
	}
</script>

<style lang="less">
	page{
		background-color: #ffffff;
	}
	.bg-0{
		position: relative;
		> view{
			z-index:1;
			position: relative;
		}
		&::after{
			/* 这个伪类的作用就是一个圆弧的背景色 */
			width: 130%;
			height: 30vh;
			position: absolute;
			/*设置水平居中*/
			left: -15%;
			/* 之所以left:20%,是因为width:140%，若width:160%，那么left:30%才能水平居中 */
			top: 0; 
			/*层叠顺序，最底层显示*/
			content: '';
			/*分别对应 左上 右上 右下 左下 可以修改成其它颜色*/
		    background: linear-gradient(to bottom, #86defa, #ffffff);  
		}
	}
	.bg-1{
		background-image: linear-gradient(#86defa 0%,#cdeff9 20%,#ffffff 30%);
	}
	.content {
		margin: 0;
		padding: 0;
		display: flex;
		flex-direction: column;
		.content-body{
			flex-grow: 1;
		}
		.header-box{
			z-index: 5;
			padding: 0em 1em;
			background: #066cff;
			 .title{
				 padding: 0;
			 }
			 .version{
				 color: #FFEB3B;
				 font-size: 0.8em;
				 margin-left: 1em;
			 }
		}
		.headerFixed{
			padding: 0 0.5rem;
			width: 100%;
			z-index: 10;
			left: 0;
			top:0;
			position: fixed;
			background: #066cff;
			/deep/ .uni-searchbar{
				padding: 0;
				.uni-searchbar__box{
					height: 30px;
				}
			}
		}
		.cbody{
			flex-grow: 1;
			overflow-y: auto;
			overflow-x: hidden;
			.notices{
				padding: 0.5em 0 0;
				font-size: 0.9em;
				margin-top: 0.5rem;
				view{
					color: #ffaf46;
					flex-grow: 1;
				}
				.text{
					color: #ffffff;
					margin-left: 1em;
				}
			}
			.pa-box{
				background: #fff;
				border-radius: 6px;
				margin: 10px 0;
				padding: 10px 0;
				border: 1px solid #eee;
			}
			.product-box{
				margin: 10px 0;
			}
			.ptype-nav{
				position: relative;
				.indicator-dots{
					width: 100%;
					height: 3px;
					display: flex;
					align-items: center;
					justify-content: center;
					position: absolute;
					left: 0;
					bottom:5px;
				}
				.indicator-dots > view{
					width: 10px;
					height: 3px;
					background: #e7e7e7;
					display: inline-block;
				}
				.indicator-dots >.indicator-dots-active{
					background: #00aaff;
				}
			}
		}
		.body-box{
			padding: 0em 1em 0.8em;
			z-index: 4;
			.banner{
				margin-top: 20rpx;
			}
			.action-button{
				padding:40upx 0 0 0;
				justify-content: space-between;
				> view{
					display: flex;
					align-items: center;
					color: #fff;
					border-radius: 10rpx;
					width: 49%;
					padding: 6rpx 0;
					box-shadow: 0rem 0.3rem 0.5rem #d9dada;
				}
				.f1{
					background: #2196f3;
				}
				.f2{
					background: #FF9800;
				}
				.icons{
					font-size: 50rpx;
					color: #fff;
					width: 80rpx;
					height: 80rpx;
					text-align:center;
					display: flex;
					align-items: center;
					flex-direction: column;
					justify-content: center;
				}
				.tits{
					font-size:28rpx;
				}
			}
		}
		.body-box1{
			padding: 0em 10px 0.8em;
		}
		.bg-blue{
			position: relative;
			z-index: 1;
			> view{
				z-index: 100;
				position: relative;
			}
			&::after{
				/* 这个伪类的作用就是一个圆弧的背景色 */
				width: 130%;
				height: 100%;
				position: absolute;
				/*设置水平居中*/
				left: -15%;
				/* 之所以left:20%,是因为width:140%，若width:160%，那么left:30%才能水平居中 */
				top: -10%; 
				/*层叠顺序，最底层显示*/
				content: '';
				border-radius: 0 0 50% 50%;
				/*分别对应 左上 右上 右下 左下 可以修改成其它颜色*/
			    background: linear-gradient(to bottom, #066cff, #056bf9);  
			}
			.userCard{
				position:relative;
				left:0;
				bottom:-0.8rem;
				padding: 0.5rem;
				background: #fff;
				border-radius: 0.8rem;
				box-shadow: 0rem 0.3rem 0.5rem #bcdede;
				.userCard-info{
					flex-grow:1;
					> view{
						&:last-child{
							margin-left: 0.5em;
							line-height: 1.5em;
							.user-name{
								font-size: 1rem;
							}
							>view{
								padding: 0.2em;
							}
						}
					}
					.user-info{
						flex-grow:1;
					}
				}
				.user-rz{
					font-size: 0.8rem;
					color:#58aff5;
				}
			}
		}
		.shopping{
			padding: 0;
			.notices{
				padding: 0.5em 10px 0;
				margin-top: 0.2rem;
				.text{
					color: #066cff;
				}
			}
		}
		.list-box{
			padding: 0 1em;
			overflow: auto;
			.des{
				text-align: center;
				padding: 1em 0;
				color: #999;
				font-size: 0.8em;
			}
		}
	}
</style>
