277 lines
		
	
	
		
			6.1 KiB
		
	
	
	
		
			Vue
		
	
	
	
		
		
			
		
	
	
			277 lines
		
	
	
		
			6.1 KiB
		
	
	
	
		
			Vue
		
	
	
	
|  | <template> | ||
|  | 	<view class="content-box"> | ||
|  | 		<view class="content d-e-c"> | ||
|  | 			<picker :range="monthList" @change="changeMonth"> | ||
|  | 				<view class="picker-small"> | ||
|  | 					<text>{{ monthList[monthIndex] }}</text> | ||
|  | 					<u-icon name="arrow-down-fill" size="28rpx" color="#333"></u-icon> | ||
|  | 				</view> | ||
|  | 			</picker> | ||
|  | 		</view> | ||
|  | 
 | ||
|  | 		<view class="d-c d-c-c "> | ||
|  | 			<canvas canvas-id="etgpRPnElDWyuZKiOQsRDExvUInxSCkZ" id="etgpRPnElDWyuZKiOQsRDExvUInxSCkZ" class="charts" :style="'height: ' + cHeight + 'px;'" @touchend="tap" /> | ||
|  | 		</view> | ||
|  | 	</view> | ||
|  | </template> | ||
|  | 
 | ||
|  | <script> | ||
|  | import uCharts from '@/uni_modules/qiun-data-charts/js_sdk/u-charts/u-charts.js'; | ||
|  | var uChartsInstance = {}; | ||
|  | export default { | ||
|  | 	data() { | ||
|  | 		return { | ||
|  | 			now: 0, | ||
|  | 			monthList: [], | ||
|  | 			monthIndex: 0, | ||
|  | 			cWidth: 750, | ||
|  | 			cHeight: 700 | ||
|  | 		}; | ||
|  | 	}, | ||
|  | 	onReady() { | ||
|  | 		//这里的 750 对应 css .charts 的 width
 | ||
|  | 		//这里的 500 对应 css .charts 的 height
 | ||
|  | 		this.cWidth = uni.upx2px(750); | ||
|  | 		this.getServerData(); | ||
|  | 		this.monthList = [this.$t('ENU_DAY_T_1'), this.$t('ENU_DAY_T_2'), this.$t('ENU_DAY_T_3')]; | ||
|  | 		// this.cHeight = uni.upx2px(700);
 | ||
|  | 		// this.getServerData();
 | ||
|  | 	}, | ||
|  | 	methods: { | ||
|  | 		changeMonth(e) { | ||
|  | 			this.monthIndex = e.detail.value; | ||
|  | 			this.getServerData(); | ||
|  | 		}, | ||
|  | 		getServerData() { | ||
|  | 			let self = this; | ||
|  | 			self._get( | ||
|  | 				'member/api/active-member-census/activeMember', | ||
|  | 				{ | ||
|  | 					dateType: self.monthIndex + 1 | ||
|  | 				}, | ||
|  | 				res => { | ||
|  | 					let list = res.data; | ||
|  | 					let obj = { | ||
|  | 						categories: [], | ||
|  | 						series: [ | ||
|  | 							{ | ||
|  | 								data: [], | ||
|  | 								name: self.$t('S_C_18') | ||
|  | 							}, | ||
|  | 							{ | ||
|  | 								data: [], | ||
|  | 								name: self.$t('S_C_19') | ||
|  | 							} | ||
|  | 						] | ||
|  | 					}; | ||
|  | 					if (list && list.length > 0) { | ||
|  | 						list.forEach((item, index) => { | ||
|  | 							obj.categories.push(item.creationTime); | ||
|  | 							obj.series[0].data.push(self.formatNum(item.leftCoun) * 1 || 0); | ||
|  | 							obj.series[1].data.push(self.formatNum(item.rightCount) * 1 || 0); | ||
|  | 						}); | ||
|  | 					} | ||
|  | 					self.cHeight = uni.upx2px(120 * obj.categories.length + 200); | ||
|  | 					self.chartsDataColumn = JSON.parse(JSON.stringify(obj)); | ||
|  | 					console.log(self.chartsDataColumn); | ||
|  | 					self.drawCharts('etgpRPnElDWyuZKiOQsRDExvUInxSCkZ', self.chartsDataColumn); | ||
|  | 				} | ||
|  | 			); | ||
|  | 		}, | ||
|  | 		drawCharts(id, data) { | ||
|  | 			const ctx = uni.createCanvasContext(id, this); | ||
|  | 			uChartsInstance[id] = new uCharts({ | ||
|  | 				type: 'bar', | ||
|  | 				context: ctx, | ||
|  | 				width: this.cWidth, | ||
|  | 				height: this.cHeight, | ||
|  | 				categories: data.categories, | ||
|  | 				series: data.series, | ||
|  | 				animation: true, | ||
|  | 				timing: 'easeOut', | ||
|  | 				duration: 1000, | ||
|  | 				rotate: false, | ||
|  | 				rotateLock: false, | ||
|  | 				background: '#FFFFFF', | ||
|  | 				color: ['#33ba36', '#ffaf32'], | ||
|  | 				padding: [15, 30, 0, 5], | ||
|  | 				fontSize: 13, | ||
|  | 				fontColor: '#666666', | ||
|  | 				dataLabel: false, | ||
|  | 				dataPointShape: true, | ||
|  | 				dataPointShapeType: 'solid', | ||
|  | 				touchMoveLimit: 60, | ||
|  | 				enableScroll: false, | ||
|  | 				enableMarkLine: false, | ||
|  | 				legend: { | ||
|  | 					show: true, | ||
|  | 					position: 'top', | ||
|  | 					float: 'center', | ||
|  | 					padding: 5, | ||
|  | 					margin: 5, | ||
|  | 					backgroundColor: 'rgba(0,0,0,0)', | ||
|  | 					borderColor: 'rgba(0,0,0,0)', | ||
|  | 					borderWidth: 0, | ||
|  | 					fontSize: 13, | ||
|  | 					fontColor: '#666666', | ||
|  | 					lineHeight: 11, | ||
|  | 					hiddenColor: '#CECECE', | ||
|  | 					itemGap: 10 | ||
|  | 				}, | ||
|  | 				xAxis: { | ||
|  | 					boundaryGap: 'center', | ||
|  | 					disableGrid: false, | ||
|  | 					min: 0, | ||
|  | 					axisLine: false, | ||
|  | 					disabled: false, | ||
|  | 					axisLineColor: '#CCCCCC', | ||
|  | 					calibration: false, | ||
|  | 					fontColor: '#666666', | ||
|  | 					fontSize: 11, | ||
|  | 					lineHeight: 20, | ||
|  | 					marginTop: 0, | ||
|  | 					rotateLabel: false, | ||
|  | 					labelCount: 1, | ||
|  | 					rotateAngle: 45, | ||
|  | 					itemCount: 5, | ||
|  | 					splitNumber: 5, | ||
|  | 					gridColor: '#CCCCCC', | ||
|  | 					gridType: 'solid', | ||
|  | 					dashLength: 4, | ||
|  | 					gridEval: 1, | ||
|  | 					scrollShow: false, | ||
|  | 					scrollAlign: 'left', | ||
|  | 					scrollColor: '#A6A6A6', | ||
|  | 					scrollBackgroundColor: '#EFEBEF', | ||
|  | 					title: this.$t('N_I_106'), | ||
|  | 					titleFontSize: 11, | ||
|  | 					titleOffsetY: 0, | ||
|  | 					titleOffsetX: 0, | ||
|  | 					titleFontColor: '#666666', | ||
|  | 					formatter: '' | ||
|  | 				}, | ||
|  | 				yAxis: { | ||
|  | 					disabled: false, | ||
|  | 					disableGrid: false, | ||
|  | 					splitNumber: 5, | ||
|  | 					gridType: 'solid', | ||
|  | 					dashLength: 8, | ||
|  | 					gridColor: '#CCCCCC', | ||
|  | 					padding: 10, | ||
|  | 					showTitle: true, | ||
|  | 					data: [ | ||
|  | 						{ | ||
|  | 							type: 'categories', | ||
|  | 							position: 'left', | ||
|  | 							disabled: false, | ||
|  | 							axisLine: true, | ||
|  | 							axisLineColor: '#CCCCCC', | ||
|  | 							calibration: false, | ||
|  | 							fontColor: '#666666', | ||
|  | 							fontSize: 11, | ||
|  | 							textAlign: 'right', | ||
|  | 							title: '', | ||
|  | 							titleFontSize: 11, | ||
|  | 							titleOffsetY: 0, | ||
|  | 							titleOffsetX: 0, | ||
|  | 							titleFontColor: '#666666', | ||
|  | 							min: null, | ||
|  | 							max: null, | ||
|  | 							tofix: null, | ||
|  | 							unit: '', | ||
|  | 							formatter: '' | ||
|  | 						} | ||
|  | 					] | ||
|  | 				}, | ||
|  | 				extra: { | ||
|  | 					bar: { | ||
|  | 						type: 'group', | ||
|  | 						width: 60, | ||
|  | 						meterBorde: 1, | ||
|  | 						meterFillColor: '#FFFFFF', | ||
|  | 						activeBgColor: '#000000', | ||
|  | 						activeBgOpacity: 0.08, | ||
|  | 						seriesGap: 4, | ||
|  | 						categoryGap: 10, | ||
|  | 						barBorderCircle: false, | ||
|  | 						linearType: 'none', | ||
|  | 						linearOpacity: 1, | ||
|  | 						colorStop: 0, | ||
|  | 						barBorderRadius: [25, 25, 0, 0] | ||
|  | 					}, | ||
|  | 					tooltip: { | ||
|  | 						showBox: true, | ||
|  | 						showArrow: true, | ||
|  | 						showCategory: false, | ||
|  | 						borderWidth: 0, | ||
|  | 						borderRadius: 0, | ||
|  | 						borderColor: '#000000', | ||
|  | 						borderOpacity: 0.7, | ||
|  | 						bgColor: '#000000', | ||
|  | 						bgOpacity: 0.7, | ||
|  | 						gridType: 'solid', | ||
|  | 						dashLength: 4, | ||
|  | 						gridColor: '#CCCCCC', | ||
|  | 						boxPadding: 3, | ||
|  | 						fontSize: 13, | ||
|  | 						lineHeight: 20, | ||
|  | 						fontColor: '#FFFFFF', | ||
|  | 						legendShow: true, | ||
|  | 						legendShape: 'auto', | ||
|  | 						splitLine: true, | ||
|  | 						horizentalLine: false, | ||
|  | 						xAxisLabel: false, | ||
|  | 						yAxisLabel: false, | ||
|  | 						labelBgColor: '#FFFFFF', | ||
|  | 						labelBgOpacity: 0.7, | ||
|  | 						labelFontColor: '#666666' | ||
|  | 					}, | ||
|  | 					markLine: { | ||
|  | 						type: 'solid', | ||
|  | 						dashLength: 4, | ||
|  | 						data: [] | ||
|  | 					} | ||
|  | 				} | ||
|  | 			}); | ||
|  | 		}, | ||
|  | 		tap(e) { | ||
|  | 			uChartsInstance[e.target.id].touchLegend(e); | ||
|  | 			uChartsInstance[e.target.id].showToolTip(e); | ||
|  | 		} | ||
|  | 	} | ||
|  | }; | ||
|  | </script> | ||
|  | 
 | ||
|  | <style scoped> | ||
|  | page { | ||
|  | 	background-color: #fff; | ||
|  | } | ||
|  | 
 | ||
|  | .content { | ||
|  | 	padding: 26rpx 22rpx 26rpx 23rpx; | ||
|  | } | ||
|  | 
 | ||
|  | .content-box { | ||
|  | 	background-color: #ffffff; | ||
|  | 	min-height: 100vh; | ||
|  | } | ||
|  | 
 | ||
|  | .picker-small { | ||
|  | 	width: 232rpx; | ||
|  | 	height: 72rpx; | ||
|  | 	border: 1rpx solid #eeeeee; | ||
|  | 	border-radius: 15rpx; | ||
|  | 	font-size: 28rpx; | ||
|  | 	padding: 0 28rpx 0 20rpx; | ||
|  | 	display: flex; | ||
|  | 	justify-content: space-between; | ||
|  | 	align-items: center; | ||
|  | 	box-sizing: border-box; | ||
|  | } | ||
|  | 
 | ||
|  | .charts { | ||
|  | 	width: 750rpx; | ||
|  | 	height: 500rpx; | ||
|  | } | ||
|  | </style> |