groupTimeOption.vue 7.56 KB
<template>
	<view class="condition-wrapper">
		<headerComp :leftImgSrc="leftImg" @leftClick="backFun" :rightText="rightText" @rightClick="save"></headerComp>
		<view class="head-flex" :style="{ top: navheight + 'px'}">
			<view class="head-item" :class="{ 'active-item': activeType == 'mall' }" @tap="itemClick('mall')">{{ i18n.store }}</view>
			<view class="head-item" :class="{ 'active-item': activeType == 'gate' }" @tap="itemClick('gate')">出入口</view>
		</view>
		<view class="handle-content" v-show="activeType === 'mall'">
			<view class="condition-item" @tap="goStoreList">
				<span class="ctitle">{{ i18n.store }}</span>
				<span class="select-item">{{ multiSelectedMall.length ? multiSelectedMall[multiSelectedMall.length - 1].name : '' }}</span>
				<image class="rarrow" :src="rArrowImg" mode="widthFix"></image>
			</view>
			<!-- <view class="condition-item" @tap="goGateList">
				<span class="ctitle">监控点</span>
				<span class="select-item">{{ selectedGate.name }}</span>
				<image class="rarrow" src="../../static/analysis/rArrow.png" mode="widthFix"></image>
			</view> -->
			<view class="condition-item" @tap="dateHandle">
				<span class="ctitle">日期</span>
				<span class="select-item">{{ dateText || '' }}</span>
				<image class="rarrow" :src="rArrowImg" mode="widthFix"></image>
			</view>
		</view>
		<view class="handle-content" v-show="activeType === 'gate'">
			<view class="condition-item" @tap="goSingleStoreList">
				<span class="ctitle">{{ i18n.store }}</span>
				<span class="select-item">{{ selectedMall ? selectedMall.name : '' }}</span>
				<image class="rarrow" :src="rArrowImg" mode="widthFix"></image>
			</view>
			<view class="condition-item" @tap="goGateList">
				<span class="ctitle">监控点</span>
				<span class="select-item">{{ multiSelectedGate.length ? multiSelectedGate[multiSelectedGate.length - 1].name : '' }}</span>
				<image class="rarrow" :src="rArrowImg" mode="widthFix"></image>
			</view>
			<view class="condition-item" @tap="dateHandle">
				<span class="ctitle">日期</span>
				<span class="select-item">{{ dateText || '' }}</span>
				<image class="rarrow" :src="rArrowImg" mode="widthFix"></image>
			</view>
		</view>
		<awesome-picker
		  ref="picker"
		  :data="dateData"
		  :textConfirm="picker.textConfirm"
		  :colorConfirm="picker.colorConfirm"
		  :textCancel="picker.textCancel"
		  :colorCancel="picker.colorCancel"
		  :anchor="currentDate"
		  @confirm="dateConfirm">
		</awesome-picker>
	</view>
</template>

<script>
	import headerComp from '../../../components/header.vue'
	import leftImg from '../../../static/header/backArrow.png'
	import { mapState, mapActions } from 'vuex'
	
	export default {
		components: {
			headerComp,
		},
		onLoad(options) {
			this.activeType = options.type || 'mall';
			uni.getStorage({
				key: 'statusBarH',
				success: (res) => {
					if(res.data) {
						this.navheight = res.data;
					}
				}
			})
		},
		data() {
			return {
				rightText: '保存',
				leftImg: leftImg,
				rArrowImg: '../../../static/analysis/rArrow.png',
				activeType: '',
				navheight: 0,
				picker: {
					textTitle:'选择',
					textConfirm:'确定',
					textCancel:'取消',
					colorConfirm:'#ffffff',
					colorCancel:'#ffffff',
				},
				cacheTimeStr: '',
				cachePickerIdx: []
			}
		},
		created() {
			if(!this.selectedMall) {	// 处理刷新获取参数失败
				this.$store.dispatch('malls/getMallList', {
					data: {
						accountId: this.getStorage('accountId'),
						_t:Date.parse(new Date()) / 1000
					},
					header: {
						'Authorization': this.getStorage('atoken') //自定义请求头信息
					},
					isMultiple: true
				})
			}
			if(!this.dateText) {
				this.$store.dispatch('malls/getDateData', 15);
			}
		},
		computed: {
			i18n() {
				return this.$t("index")
			},
			...mapState({
				selectedMall: state => state.malls.checkedMallId,
				multiSelectedMall: state => state.malls.multiCheckedMallId,
				multiSelectedGate: state => state.malls.multiCheckedGateId,
				dateData: state => state.malls.dayDateData,
				dateText: state => state.malls.selectedDayTime,
				currentDate: state => state.malls.pickerDayDate
			})
		},
		watch: {
			selectedMall(val) {
				this.$store.dispatch('malls/getGateList', {
					data: {
						mallId: val.id,
						status: 1,
						isHasFace: 1,
						_t:Date.parse(new Date()) / 1000
					},
					header: {
						'Authorization': this.getStorage('atoken') //自定义请求头信息
					},
					isMultiple: true
				})
			}
		},
		methods: {
			backFun() {
				uni.navigateTo({
					url: '../groupTimeReport/groupTime'
				})
			},
			save() {
				if(this.activeType === 'gate') {
					if(!this.selectedMall) {
						uni.showToast({
							icon:'none',
							title:'请选择门店'
						});
					}
					if(!this.multiSelectedGate) {
						uni.showToast({
							icon:'none',
							title:'请选择出入口'
						});
					}
				} else {
					if(!this.multiSelectedMall) {
						uni.showToast({
							icon:'none',
							title:'请选择门店'
						});
					}
				}
				if(!this.dateText) {
					uni.showToast({
						icon:'none',
						title:'请选择日期'
					});
				}
				uni.navigateTo({
					url: `../groupTimeReport/groupTime?analysisLevel=${this.activeType}`
				})
			},
			itemClick(val) {
				this.activeType = val;
			},
			goStoreList() {
				uni.navigateTo({
					url:"../../conditionList/multiMallList?backUrl=../passenger/conditions/groupTimeOption&analysisLevel=" + this.activeType,
					animationType: 'slide-in-right',
					animationDuration: 200
				})
			},
			goSingleStoreList() {
				uni.navigateTo({
					url:"../../conditionList/mallList?backUrl=../passenger/conditions/groupTimeOption&analysisLevel=" + this.activeType,
					animationType: 'slide-in-right',
					animationDuration: 200
				})
			},
			goGateList() {
				uni.navigateTo({
					url:"../../conditionList/multiGateList?backUrl=../passenger/conditions/groupTimeOption&analysisLevel=" + this.activeType,
					animationType: 'slide-in-right',
					animationDuration: 200
				})
			},
			dateHandle() {
				this.$refs.picker.show();
				// console.log('currentDate', this.currentDate, this.dateData)
			},
			dateConfirm(item) {
				console.log(item);
				this.formatterTimeToStr(item);
				this.cachePickerIdx = item;
				if(this.cacheTimeStr && this.cachePickerIdx.length) {
					this.$store.dispatch('malls/updateDayDate', {
						dayTimeText: this.cacheTimeStr,
						dayPickerIdx: this.cachePickerIdx
					})
				}
				// console.log(this.cacheTimeStr, this.cachePickerIdx)
			},
			formatterTimeToStr(item) {
				this.cacheTimeStr = item.map(item => item.value)
					.join(',')
					.replace(/[\u4E00-\u9FA5]/g, '-')
					.replace(/\-/g, '')
					.replace(/,/g, '-');
				console.log('formatterTimeToStr', this.cacheTimeStr)
			}
		}
	}
</script>

<style>
	.head-flex {
		width: 543.47upx;
		display: flex;
		flex-direction: row;
		font-size: 32.6upx;
		color: #80b4ff;
		position: absolute;
		top: 0;
		left: 0;
		z-index: 10;
		height: 77.89upx;
		line-height: 77.89upx;
		right: 0;
		margin: auto;
	}
	
	.head-item {
		flex: 1;
		text-align: center;
		cursor: pointer;
	}
	
	.active-item {
		color: #fff;
	}
	
	.handle-content {
		
	}
	.condition-item {
		height: 90.57upx;
		line-height: 90.57upx;
		background: #FFFFFF;
		border-bottom: 1px solid #979797;
		position: relative;
	}
	.ctitle {
		font-size: 25.36upx;
		color: #333333;
		position: absolute;
		top: 0;
		left: 23.55upx;
	}
	.select-item {
		font-size: 25.36upx;
		color: #9B9B9B;
		position: absolute;
		top: 0;
		right: 45.28upx;
	}
	.rarrow {
		width: 10.86upx;
		height: 19.92upx;
		position: absolute!important;
		top: 38.04upx;
		right: 23.55upx;
	}
</style>