<template>
	<view class="form_warp">
		<view class="form_intro">
			<view>如有填报问题，请咨询公共服务中心</view>
			<view>中心值班电话：<text @click="call(mobile)" class="tel">{{mobile}}</text></view>
		</view>
		<view class="form_item_box">
			<view class="form_item_title">基本信息</view>
			<!-- <view class="form_item">
				<view class="form_item_label">管理单位名称：</view>
				<view class="form_item_input picker">
					<picker v-if="pageType == 'add' && deptNameList.length > 1" :value="form.organizationNameIndex"
						:range="deptNameList" range-key="deptName" @change="bindDeptChange">
						<text class="picker_select"
							:style="form.organizationName?'color:#333;':''">{{form.organizationName?form.organizationName:'请选择'}}</text>
						<uni-icons type="right" size="16" color="#D4D4D4"></uni-icons>
					</picker>
					<text v-else>{{form.organizationName}}</text>
				</view>
			</view> -->
			<view class="form_item">
				<view class="form_item_label">统计日期：</view>
				<view class="form_item_input picker">
					<picker v-if="pageType == 'add'" mode="date" :value="form.statDate" @change="bindDateChange">
						<text class="picker_select"
							:style="form.statDate?'color:#333;':''">{{form.statDate?form.statDate:'请选择时段'}}</text>
						<uni-icons type="right" size="16" color="#D4D4D4"></uni-icons>
					</picker>
					<text v-else>{{form.statDate?form.statDate:''}}</text>
				</view>
			</view>
			<view class="form_item">
				<view class="form_item_label">统计时段：</view>
				<view class="form_item_input picker">
					<picker v-if="pageType == 'add'" :value="index" :range="array" range-key="dictLabel" @change="changeStatPeriod">
						<text class="picker_select"
							:style="index>-1?'color:#333;':''">{{index>-1?array[index].dictLabel:'请选择时段'}}</text>
						<uni-icons type="right" size="16" color="#D4D4D4"></uni-icons>
					</picker>
					<text v-else>{{index>-1?array[index].dictLabel:''}}</text>
				</view>
			</view>
			<view class="form_item">
				<view class="form_item_label">收费站驶入车辆数统计：</view>
				<view class="form_item_input">
					{{form.entranceVehicleCount === 0 ? form.entranceVehicleCount : form.entranceVehicleCount || ''}}
				</view>
			</view>
			<!-- 同比环比 -->
			<view class="form_item_rate"
				:class="checkNotEmpty(form.entranceVehicleCount) && form.entranceVehicleCount === yoyMomSumary.minusDaySummaryData.entranceVehicleCount ? 'danger' : ''">
				<view class="rate_item">
					<view class="rate_item_label"
						:style="checkNotEmpty(form.entranceVehicleCount) && form.entranceVehicleCount === yoyMomSumary.minusDaySummaryData.entranceVehicleCount ?'color: #EB4747':''">
						驶入车辆数统计环比</view>
					<view class="rate_item_input"
						:style="checkNotEmpty(form.entranceVehicleCount) && form.entranceVehicleCount === yoyMomSumary.minusDaySummaryData.entranceVehicleCount ?'color: #EB4747':''">
						{{formatDigit(form.entranceVehicleCountMom)}}%
					</view>
				</view>
				<view class="line"></view>
				<view class="rate_item">
					<view class="rate_item_label">驶入车辆数统计同比</view>
					<view class="rate_item_input">
						{{formatDigit(form.entranceVehicleCountYoy)}}%
					</view>
				</view>
			</view>
			<view class="form_item">
				<view class="form_item_label">收费站驶出车辆数统计：</view>
				<view class="form_item_input">
					{{form.exitVehicleCount === 0 ? form.exitVehicleCount : form.exitVehicleCount || ''}}
				</view>
			</view>
			<!-- 同比环比 -->
			<view class="form_item_rate"
				:class="checkNotEmpty(form.exitVehicleCount) && form.exitVehicleCount === yoyMomSumary.minusDaySummaryData.exitVehicleCount ? 'danger' : ''">
				<view class="rate_item">
					<view class="rate_item_label"
						:style="checkNotEmpty(form.exitVehicleCount) && form.exitVehicleCount === yoyMomSumary.minusDaySummaryData.exitVehicleCount ?'color: #EB4747':''">
						驶出车辆数统计环比</view>
					<view class="rate_item_input"
						:style="checkNotEmpty(form.exitVehicleCount) && form.exitVehicleCount === yoyMomSumary.minusDaySummaryData.exitVehicleCount ?'color: #EB4747':''">
						{{formatDigit(form.exitVehicleCountMom)}}%
					</view>
				</view>
				<view class="line"></view>
				<view class="rate_item">
					<view class="rate_item_label">驶出车辆数统计同比</view>
					<view class="rate_item_input">
						{{formatDigit(form.exitVehicleCountYoy)}}%
					</view>
				</view>
			</view>
		</view>
		<!-- 用户权限收费站 -->
		<view class="station_box">
			<view v-if="index < 9" :style="(index+1)%3 == 0 ? 'margin-right:0;':''" @click="changeStationIndex(index)"
				class="station_item" :class="[item.isFinish ? 'active' : '',index == stationIndex ? 'choosed' : '']"
				v-for="(item, index) in highwaySubDataList" :key="item.id">
				<view v-if='item.isFinish' class="tag">
					<uni-icons type="checkmarkempty" color="#fff" size="12"></uni-icons>
				</view>
				{{item.stationName}}
			</view>
			<view v-if="index >= 9 && showStaion" :style="(index+1)%3 == 0 ? 'margin-right:0;':''"
				@click="changeStationIndex(index)" class="station_item"
				:class="[item.isFinish ? 'active' : '',index == stationIndex ? 'choosed' : '']"
				v-for="(item, index) in highwaySubDataList" :key="item.id">
				<view v-if='item.isFinish' class="tag">
					<uni-icons type="checkmarkempty" color="#fff" size="12"></uni-icons>
				</view>
				{{item.stationName}}
			</view>
		</view>
		<view v-if="highwaySubDataList.length > 9" class="station_act" @click="showStaion = !showStaion">
			<uni-icons v-if="!showStaion" type="bottom" size="14" color="#2D8CF0" style="margin-right:10rpx;">
			</uni-icons>
			<uni-icons v-if="showStaion" type="top" size="14" color="#2D8CF0" style="margin-right:10rpx;"></uni-icons>
			{{showStaion?'收起':'展开'}}
		</view>
		<view class="form_item_box">
			<view class="form_item">
				<view class="form_item_label">收费站名称：</view>
				<view class="form_item_input text">{{form.highwaySubDataList[stationIndex].tollStationName}}</view>
			</view>
			<view class="form_item">
				<view class="form_item_label">高速公路名称：</view>
				<view class="form_item_input text">{{form.highwaySubDataList[stationIndex].highwayName}}</view>
			</view>
			<view class="form_item">
				<view class="form_item_label">收费站驶入车辆数：</view>
				<view class="form_item_input form_input">
					<uni-easyinput @blur="checkStationInfo(stationIndex)" @clear="checkStationInfo(stationIndex)"
						v-model="form.highwaySubDataList[stationIndex].entranceVehicleCount"
						placeholderStyle="color: #D4D4D4;font-size:28rpx;" placeholder="请输入车辆数" type="number"
						maxlength="30"></uni-easyinput>
				</view>
			</view>
			<!-- 同比环比 -->
			<view class="form_item_rate"
				:class="form.highwaySubDataList.length == 0 ? '' : checkNotEmpty(form.highwaySubDataList[stationIndex].entranceVehicleCount) && (form.highwaySubDataList[stationIndex].entranceVehicleCountMom === 0 || (form.highwaySubDataList[stationIndex].entranceVehicleCount === form.highwaySubDataList[stationIndex].exitVehicleCount)) ? 'danger' : '' ">
				<view class="rate_item">
					<view class="rate_item_label"
						:style="form.highwaySubDataList.length == 0 ? '' : checkNotEmpty(form.highwaySubDataList[stationIndex].entranceVehicleCount) && (form.highwaySubDataList[stationIndex].entranceVehicleCountMom === 0 || (form.highwaySubDataList[stationIndex].entranceVehicleCount === form.highwaySubDataList[stationIndex].exitVehicleCount)) ? 'color: #EB4747' : ''">
						驶入车辆数环比
						<uni-tooltip v-if="form.highwaySubDataList.length == 0 ? '' : checkNotEmpty(form.highwaySubDataList[stationIndex].entranceVehicleCount) && (form.highwaySubDataList[stationIndex].entranceVehicleCountMom === 0 || (form.highwaySubDataList[stationIndex].entranceVehicleCount === form.highwaySubDataList[stationIndex].exitVehicleCount)) ? 'color: #EB4747' : ''" content="预警:环比持平和驶入驶出车辆相同">
						  <uni-icons type="help" size="18" color="#EB4747"></uni-icons>
						</uni-tooltip>
					</view>
					<view class="rate_item_input"
						:style="form.highwaySubDataList.length == 0 ? '' : checkNotEmpty(form.highwaySubDataList[stationIndex].entranceVehicleCount) && (form.highwaySubDataList[stationIndex].entranceVehicleCountMom === 0 || (form.highwaySubDataList[stationIndex].entranceVehicleCount === form.highwaySubDataList[stationIndex].exitVehicleCount)) ? 'color: #EB4747' : ''">
						{{formatDigit(form.highwaySubDataList[stationIndex].entranceVehicleCountMom)}}%
					</view>
				</view>
				<view class="line"></view>
				<view class="rate_item">
					<view class="rate_item_label">驶入车辆数同比</view>
					<view class="rate_item_input">
						{{formatDigit(form.highwaySubDataList[stationIndex].entranceVehicleCountYoy)}}%
					</view>
				</view>
			</view>
			<view class="form_item">
				<view class="form_item_label">收费站驶出车辆数：</view>
				<view class="form_item_input form_input">
					<uni-easyinput @blur="checkStationInfo(stationIndex)" @clear="checkStationInfo(stationIndex)"
						v-model="form.highwaySubDataList[stationIndex].exitVehicleCount"
						placeholderStyle="color: #D4D4D4;font-size:28rpx;" placeholder="请输入车辆数" type="number"
						maxlength="30"></uni-easyinput>
				</view>
			</view>
			<!-- 同比环比 -->
			<view class="form_item_rate"
				:class="form.highwaySubDataList.length == 0 ? '' : checkNotEmpty(form.highwaySubDataList[stationIndex].exitVehicleCount) && (form.highwaySubDataList[stationIndex].exitVehicleCountMom === 0 || (form.highwaySubDataList[stationIndex].entranceVehicleCount === form.highwaySubDataList[stationIndex].exitVehicleCount)) ? 'danger' : '' ">
				<view class="rate_item">
					<view class="rate_item_label"
						:style="form.highwaySubDataList.length == 0 ? '' : checkNotEmpty(form.highwaySubDataList[stationIndex].exitVehicleCount) && (form.highwaySubDataList[stationIndex].exitVehicleCountMom === 0 || (form.highwaySubDataList[stationIndex].entranceVehicleCount === form.highwaySubDataList[stationIndex].exitVehicleCount)) ? 'color: #EB4747' : ''">
						驶出车辆数环比
						<uni-tooltip v-if="form.highwaySubDataList.length == 0 ? '' : checkNotEmpty(form.highwaySubDataList[stationIndex].exitVehicleCount) && (form.highwaySubDataList[stationIndex].exitVehicleCountMom === 0 || (form.highwaySubDataList[stationIndex].entranceVehicleCount === form.highwaySubDataList[stationIndex].exitVehicleCount))" content="预警:环比持平和驶入驶出车辆相同">
						  <uni-icons type="help" size="18" color="#EB4747"></uni-icons>
						</uni-tooltip>
					</view>
					<view class="rate_item_input"
						:style="form.highwaySubDataList.length == 0 ? '' : checkNotEmpty(form.highwaySubDataList[stationIndex].exitVehicleCount) && (form.highwaySubDataList[stationIndex].exitVehicleCountMom === 0 || (form.highwaySubDataList[stationIndex].entranceVehicleCount === form.highwaySubDataList[stationIndex].exitVehicleCount)) ? 'color: #EB4747' : ''">
						{{formatDigit(form.highwaySubDataList[stationIndex].exitVehicleCountMom)}}%
					</view>
				</view>
				<view class="line"></view>
				<view class="rate_item">
					<view class="rate_item_label">驶出车辆数同比</view>
					<view class="rate_item_input">
						{{formatDigit(form.highwaySubDataList[stationIndex].exitVehicleCountYoy)}}%
					</view>
				</view>
			</view>
			<view class="form_item">
				<view class="form_item_label">免收通行费车辆数：</view>
				<view class="form_item_input form_input">
					<uni-easyinput v-model="form.highwaySubDataList[stationIndex].tollExemptVehicleCount"
						placeholderStyle="color: #D4D4D4;font-size:28rpx;" placeholder="请输入车辆数" type="number"
						maxlength="30"></uni-easyinput>
				</view>
			</view>
			<view class="form_item">
				<view class="form_item_label">免收通行费金额：</view>
				<view class="form_item_input form_input">
					<uni-easyinput v-model="form.highwaySubDataList[stationIndex].tollExemptAmount"
						placeholderStyle="color: #D4D4D4;font-size:28rpx;" placeholder="请输入金额" type="digit"
						maxlength="30"></uni-easyinput>
				</view>
			</view>
			<view class="form_item">
				<view class="form_item_label">报送人员及联系方式：</view>
				<view class="form_item_input picker">
					<picker :value="form.highwaySubDataList[stationIndex].submitPersonnelContact" :range="submitPerson"
						@change="e => changeSubmitPerson(e, stationIndex)">
						<text class="picker_select"
							:style="form.highwaySubDataList[stationIndex].submitPersonnelContact?'color:#333;':''">{{form.highwaySubDataList[stationIndex].submitPersonnelContact?form.highwaySubDataList[stationIndex].submitPersonnelContact:'请选择报送人'}}</text>
						<uni-icons type="right" size="16" color="#D4D4D4"></uni-icons>
					</picker>
				</view>
			</view>
			<view class="form_item_remark">
				<view class="form_item_label">备注：</view>
				<view class="form_item_input">
					<uni-easyinput v-model="form.highwaySubDataList[stationIndex].remarks"
						placeholderStyle="color: #D4D4D4;font-size:28rpx;" placeholder="请输入备注信息" type="textarea"
						maxlength="200" autoHeight></uni-easyinput>
				</view>
			</view>
		</view>
		<!-- 底部按钮 -->
		<view class="foot_btn">
			<!-- <view class="act_btn" @click="doCancel">取消</view> -->
			<view class="act_btn blue" @click="doSubmit">{{btnText}}</view>
		</view>
	</view>
</template>
<script>
	import {
		checkNotEmpty,
		getDateStr
	} from "../../../common/util.js"
	export default {
		data() {
			return {
				form: {
					organizationName: '',
					statDate: '',
					statPeriod: '',
					entranceVehicleCount: '',
					entranceVehicleCountMom: '',
					entranceVehicleCountYoy: '',
					exitVehicleCount: '',
					exitVehicleCountMom: '',
					exitVehicleCountYoy: '',
					highwaySubDataList: [{}],
				}, //登录form
				highwaySubDataList: [], //收费站列表
				stationIndex: 0, //收费站选中索引
				submitPerson: [], //报送人
				array: [], //时段选择列表
				index: 2, //时段选择,默认0-24
				userInfo: {},
				yoyMom: {}, //同比环比
				yoyMomSumary: {
					minusDaySummaryData: {},
					minusYearSummaryData: {}
				},//汇总统计同环比
				showStaion: false, //展开收起
				pageType: '',
				deptNameList: [], //当前登录人所在单位
				btnText: '保存',
				mobile: getApp().globalData.mobile
			}
		},
		onLoad(options) {
			this.userInfo = uni.getStorageSync('userInfo');
			// let arr = uni.getStorageSync('deptName');
			// this.deptNameList = checkNotEmpty(arr) ? arr : [];
			if (options.type == 'add') {
				// this.form.organizationName = this.deptNameList.length > 0 ? this.deptNameList[0].deptName : '';
				// this.form.organizationNameIndex = this.deptNameList.length > 0 ? 0 : '';
				this.pageType = 'add';
				let now = new Date();
				this.form.statDate = getDateStr(now, -1); //默认前一天
				// this.queryStation('add');
				this.queryTime(); //统计时段
			}else if(options.item) {
				this.btnText = '修改并保存';
				let obj = JSON.parse(options.item);
				this.queryDetailInfo2(obj.statDate, obj.statPeriod);
			}
			else if (options.id) {
				this.btnText = '修改并保存';
				this.queryDetailInfo(options.id);
			}
			this.queryPerson();
		},
		methods: {
			call(tel) {
				uni.makePhoneCall({
					phoneNumber: tel
				});
			},
			checkNotEmpty(data) {
				return checkNotEmpty(data);
			},
			//只保留两位小数
			formatDigit(data) {
				return !checkNotEmpty(data) ? '--' : (data + '').indexOf('.') > -1 && (data + '').substring((data + '')
					.indexOf('.')).length > 2 ? data.toFixed(2) : data;
			},
			//id查询详情
			queryDetailInfo(id) {
				this.$request(getApp().globalData.baseUrl + '/api/biz/highwayParentDataController/selectById/' + id, {},
					'GET').then(res => {
					this.form = res.data;
					// if (checkNotEmpty(this.deptNameList)) {
					// 	let idx = this.deptNameList.findIndex(item => item.deptName == this.form.organizationName);
					// 	this.form.organizationNameIndex = idx > -1 ? idx : '';
					// 	if(!checkNotEmpty(this.form.organizationName)) {
					// 		this.form.organizationName = this.deptNameList.length > 0 ? this.deptNameList[0].deptName : '';
					// 		this.form.organizationNameIndex = this.deptNameList.length > 0 ? 0 : '';
					// 	}
					// }
					this.queryTime();
					this.queryStation();
				})
			},
			//日期和时段查询详情
			queryDetailInfo2(statDate, statPeriod) {
				this.$request(getApp().globalData.baseUrl + '/api/biz/highwayParentDataController/getSubData?statDate=' + statDate + '&statPeriod=' + statPeriod, {},
					'GET').then(res => {
					res.data.statDate = statDate;
					res.data.statPeriod = statPeriod;
					this.form = res.data;
					this.queryTime();
					this.queryStation();
				})
			},
			//同比环比查询
			queryYoYMom() {
				if (this.form.statDate && this.form.statPeriod) {
					//汇总统计
					this.$request(getApp().globalData.baseUrl +
						'/api/biz/highwayParentDataController/getSummaryDataYoYAndMoM?statDate=' + this.form.statDate +
						'&statPeriod=' + this.form.statPeriod + '&_t=' + Date.parse(new Date()), {}, "GET").then(
						res => {
							res.data.minusDaySummaryData = res.data.minusDaySummaryData ? res.data.minusDaySummaryData : {};
							res.data.minusYearSummaryData = res.data.minusYearSummaryData ? res.data.minusYearSummaryData : {};
							this.yoyMomSumary = res.data;
							//各收费站同环比查询
							this.$request(getApp().globalData.baseUrl +
								'/api/biz/highwayParentDataController/getYoYAndMoM?statDate=' + this.form.statDate +
								'&statPeriod=' + this.form.statPeriod + '&_t=' + Date.parse(new Date()), {}, "GET").then(
								res2 => {
									this.yoyMom = res2.data;
									//如果重新更改填报日期，重新计算同比环比
									if (this.highwaySubDataList.length > 0 && this.form.highwaySubDataList.length > 0) {
										this.highwaySubDataList.map((item, index) => {
											this.checkStationInfo(index);
										})
									}
								})
						})
				}
			},
			//切换管理单位
			bindDeptChange(e) {
				this.form.organizationNameIndex = e.detail.value;
				this.form.organizationName = this.deptNameList[e.detail.value].deptName;
			},
			//报送人
			// queryPerson() {
			// 	this.$request(getApp().globalData.baseUrl + '/api/biz/personnelContactInfoController/all?query=&_t=' + Date
			// 		.parse(new Date()), {}, "GET").then(res => {
			// 		let arr = [];
			// 		res.data.list.map(item => {
			// 			arr.push(item.name);
			// 		})
			// 		this.submitPerson = arr;
			// 	})
			// },
			queryPerson() {
				this.$request(getApp().globalData.baseUrl + '/api/user/getAllUserInDept', {}, "GET").then(res => {
					let arr = [];
					res.data.map(item => {
						arr.push(item.username + (item.mobile ? ',' + item.mobile : ''));
					})
					this.submitPerson = arr;
				})
			},
			changeSubmitPerson(e, index) {
				this.form.highwaySubDataList[index].submitPersonnelContact = this.submitPerson[e.detail.value];
				console.log(this.form.highwaySubDataList[index])
			},
			//切换当前编辑收费站索引
			changeStationIndex(index) {
				if (this.form.highwaySubDataList[this.stationIndex].entranceVehicleCount != '' && this.form
					.highwaySubDataList[this.stationIndex].exitVehicleCount != '') {
					this.highwaySubDataList[this.stationIndex].isFinish = true;
				} else {
					this.highwaySubDataList[this.stationIndex].isFinish = false;
				}
				this.stationIndex = index;
			},
			//计算收费站信息是否填写完整
			checkStationInfo(index) {
				this.highwaySubDataList[index].isFinish = checkNotEmpty(this.form.highwaySubDataList[index].entranceVehicleCount) &&
					checkNotEmpty(this.form.highwaySubDataList[index].exitVehicleCount);
				//统计计算
				let entranceVehicleCount = 0,
					exitVehicleCount = 0;
				this.form.highwaySubDataList.map(item => {
					entranceVehicleCount = entranceVehicleCount + (checkNotEmpty(item.entranceVehicleCount) ?
						parseInt(item
							.entranceVehicleCount) : 0);
					exitVehicleCount = exitVehicleCount + (checkNotEmpty(item.exitVehicleCount) ? parseInt(item
						.exitVehicleCount) : 0);
				})
				this.form.entranceVehicleCount = entranceVehicleCount;
				this.form.exitVehicleCount = exitVehicleCount;
				//收费站驶入车辆数统计
				this.form.entranceVehicleCountMom = this.$calcMom(this.form.entranceVehicleCount,this.yoyMomSumary.minusDaySummaryData.entranceVehicleCount);
				this.form.entranceVehicleCountYoy = this.$calcYoy(this.form.entranceVehicleCount, this.yoyMomSumary.minusYearSummaryData.entranceVehicleCount);

				//收费站驶出车辆数统计
				this.form.exitVehicleCountMom = this.$calcMom(this.form.exitVehicleCount, this.yoyMomSumary.minusDaySummaryData.exitVehicleCount);
				
				this.form.exitVehicleCountYoy = this.$calcYoy(this.form.exitVehicleCount, this.yoyMomSumary.minusYearSummaryData.exitVehicleCount);
			

				//收费站子表计算同比环比
				let idx = this.yoyMom.minusDaysList.findIndex(item => {
					return item.tollStationName == this.form.highwaySubDataList[index].tollStationName;
				});
				let idx2 = this.yoyMom.minusYearsList.findIndex(item => {
					return item.tollStationName == this.form.highwaySubDataList[index].tollStationName;
				});
				// console.log('收费站同比环比', idx, idx2, this.form.highwaySubDataList[index].tollStationName);
				if (idx > -1) {
					//环比
					let obj = this.yoyMom.minusDaysList[idx];
					// console.log(this.form.highwaySubDataList[index],obj)
					this.form.highwaySubDataList[index].entranceVehicleCountMom = this.$calcMom(this.form
							.highwaySubDataList[index].entranceVehicleCount, obj.entranceVehicleCount);
					this.form.highwaySubDataList[index].exitVehicleCountMom = this.$calcMom(this.form.highwaySubDataList[index].exitVehicleCount,obj.exitVehicleCount);
					
				} else {
					this.form.highwaySubDataList[index].entranceVehicleCountMom = '';
					this.form.highwaySubDataList[index].exitVehicleCountMom = '';
				}
				if (idx2 > -1) {
					//同比
					let obj = this.yoyMom.minusYearsList[idx2];
					// console.log(obj)
					this.form.highwaySubDataList[index].entranceVehicleCountYoy = this.$calcYoy(this.form
							.highwaySubDataList[index].entranceVehicleCount,obj.entranceVehicleCount);
							
					this.form.highwaySubDataList[index].exitVehicleCountYoy = this.$calcYoy(this.form
							.highwaySubDataList[index].exitVehicleCount, obj.exitVehicleCount);
				} else {
					this.form.highwaySubDataList[index].entranceVehicleCountYoy = '';
					this.form.highwaySubDataList[index].exitVehicleCountYoy = '';
				}
				// }
			},
			//收费站列表
			queryStation(type) {
				this.$request(getApp().globalData.baseUrl + '/api/biz/HighSpeedPermissionsInfo/findList?_t=' + Date
					.parse(
						new Date()), {}, 'GET').then(res => {
					this.highwaySubDataList = res.data;
					if (type == 'add') {
						this.form.highwaySubDataList = [];
						this.highwaySubDataList.map(item => {
							item.isFinish = false;
							this.form.highwaySubDataList.push({
								"entranceVehicleCount": '',
								"entranceVehicleCountMom": '',
								"entranceVehicleCountYoy": '',
								"exitToll": 0.0,
								"exitVehicleCount": '',
								"exitVehicleCountMom": '',
								"exitVehicleCountYoy": '',
								"highwayId": item.highWayLineCode,
								"highwayName": item.managementUnitName,
								"stationCode": item.stationCode,
								"submitPersonnelContact": this.userInfo.username + (this
									.userInfo.mobile ? ',' + this
									.userInfo.mobile : ''),
								"tollExemptAmount": 0.0,
								"tollExemptVehicleCount": 0,
								"tollExemptVehicleCountMom": 0.0,
								"tollExemptVehicleCountYoy": 0.0,
								"tollStationName": item.stationName,
								"remarks": '',
							})
						})
					} else {
						let arr = JSON.parse(JSON.stringify(this.form.highwaySubDataList));
						this.form.highwaySubDataList = [];
						this.highwaySubDataList.map(item => {
							let idx = arr.findIndex(item2 => {
								return item2.tollStationName == item.stationName && item2.highwayName == item.managementUnitName;
							});
							if (idx > -1) {
								item.isFinish = checkNotEmpty(arr[idx].entranceVehicleCount) && checkNotEmpty(arr[idx].exitVehicleCount) ? true : false;
								arr[idx].stationCode = item.stationCode;
								this.form.highwaySubDataList.push(arr[idx]);
							} else {
								item.isFinish = false;
								this.form.highwaySubDataList.push({
									"entranceVehicleCount": '',
									"entranceVehicleCountMom": '',
									"entranceVehicleCountYoy": '',
									"exitToll": 0.0,
									"exitVehicleCount": '',
									"exitVehicleCountMom": '',
									"exitVehicleCountYoy": '',
									"highwayId": item.highWayLineCode,
									"highwayName": item.managementUnitName,
									"stationCode": item.stationCode,
									"submitPersonnelContact": this.userInfo.username + (this
										.userInfo.mobile ? ',' + this
										.userInfo.mobile : ''),
									"tollExemptAmount": 0.0,
									"tollExemptVehicleCount": 0,
									"tollExemptVehicleCountMom": 0.0,
									"tollExemptVehicleCountYoy": 0.0,
									"tollStationName": item.stationName,
									"remarks": '',
								})
							}
						})
					}
				})
			},
			//取消
			doCancel() {
				uni.navigateBack();
			},
			//选择统计日期
			bindDateChange(e) {
				this.form.statDate = e.detail.value;
				if(this.pageType == 'add') {
					this.$request(getApp().globalData.baseUrl + '/api/biz/highwayParentDataController/getSubData?statDate=' + this.form.statDate + '&statPeriod=' + this.form.statPeriod, {},
						'GET').then(res => {
						res.data.statDate = this.form.statDate;
						res.data.statPeriod = this.form.statPeriod;
						this.form = res.data;
						this.queryStation();
						this.queryYoYMom();
					})
				}
				else {
					this.queryYoYMom();
				}
			},
			//统计时段切换
			changeStatPeriod(e) {
				this.index = e.detail.value;
				this.form.statPeriod = this.array[e.detail.value].dictValue;
				console.log('change 时段')
				if(this.pageType == 'add') {
					this.$request(getApp().globalData.baseUrl + '/api/biz/highwayParentDataController/getSubData?statDate=' + this.form.statDate + '&statPeriod=' + this.form.statPeriod, {},
						'GET').then(res => {
						res.data.statDate = this.form.statDate;
						res.data.statPeriod = this.form.statPeriod;
						this.form = res.data;
						this.queryStation();
						this.queryYoYMom();
					})
				}
				else {
					this.queryYoYMom();
				}
			},
			//时段
			queryTime() {
				this.$request(getApp().globalData.baseUrl + '/api/dict/dictList?dictType=highway_time' + '&_t=' + Date
					.parse(
						new Date()), {}, 'GET').then(res => {
					this.array = res.data;
					if (this.pageType == 'add') {
						let now = new Date();
						//11:00-13:30 默认选择0-12
						let dateStr = getDateStr(now, 0).replaceAll('-','/');
						if (new Date(dateStr + ' 11:00').getTime() < new Date().getTime() && new Date().getTime() <
							new Date(dateStr + ' 13:30').getTime()) {
							this.form.statPeriod = '0012';
							let idx = this.array.findIndex(item => item.dictValue == '0012');
							this.index = idx > -1 ? idx : '';
							if(idx > -1) {
								this.index = idx;
							}else {
								//字典值没有0-12 默认0-24
								this.form.statPeriod = '03'; //默认0-24
								let _idx = this.array.findIndex(item => item.dictValue == '03');
								this.index = _idx > -1 ? _idx : '';
							}
						} else {
							this.form.statPeriod = '03'; //默认0-24
							let idx = this.array.findIndex(item => item.dictValue == '03');
							this.index = idx > -1 ? idx : '';
						}
						//报送阶段 - 初始化汇总数据
						this.$request(getApp().globalData.baseUrl + '/api/biz/highwayParentDataController/getSubData?statDate=' + this.form.statDate + '&statPeriod=' + this.form.statPeriod, {},
							'GET').then(res => {
							res.data.statDate = this.form.statDate;
							res.data.statPeriod = this.form.statPeriod;
							this.form = res.data;
							console.log('add == queryTime', this.form)
							this.queryStation();
						})
					} else {
						let idx = this.array.findIndex(item => item.dictValue == this.form.statPeriod);
						this.index = idx > -1 ? idx : '';
					}
					this.queryYoYMom();
				})
			},
			//确认提交
			doSubmit() {
				if (this.form.statDate == '' || this.form.statPeriod == '') {
					uni.showToast({
						title: '报送日期和时段不能为空',
						icon: 'none'
					})
					return;
				}
				// console.log(JSON.stringify(this.form))
				// return;
				let checkList = true;
				if (this.form.highwaySubDataList.length > 0) {
					checkList = this.form.highwaySubDataList.every(item => {
						return checkNotEmpty(item.entranceVehicleCount) && checkNotEmpty(item.exitVehicleCount)
					})
				}
				if (!checkList) {
					uni.showToast({
						title: '收费站信息请填写完整',
						icon: 'none'
					})
					return;
				}
				uni.showModal({
					title: '提示',
					content: this.pageType == 'add' ? '您确认提交该条报送数据?' : '您确认将该条数据进行修改?',
					success: (res) => {
						if (res.confirm) {
							this.submitForm();
						}
					}
				})
			},
			submitForm() {
				uni.showLoading({
					title: '提交中...',
					mask: true
				})
				this.$request(getApp().globalData.baseUrl + '/api/biz/highwayParentDataController/saveOrUpdateV2', this
					.form,
					'POST').then(res => {
					uni.hideLoading();
					if (res.code == 200) {
						uni.showToast({
							title: '报送提交成功',
							icon: 'none',
							success: () => {
								if (this.form.id == undefined) {
									setTimeout(() => {
										uni.redirectTo({
											url: '/pages/highway/runData/list'
										})
									}, 300)
								} else {
									uni.navigateBack();
								}
							}
						})
					}
				}).catch(() => {
					uni.hideLoading();
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.form_warp {
		padding: 30rpx 30rpx 195rpx;

		.form_intro {
			color: #666;
			font-size: 26rpx;
			font-family: PingFang SC-Bold, PingFang SC;
			line-height: 48rpx;
			text-align: center;
			margin-bottom: 20rpx;

			.tel {
				color: #2D8CF0;
				font-weight: bold;
			}
		}

		.form_item_box {
			padding: 30rpx 20rpx 30rpx 30rpx;
			background-color: #fff;
			border-radius: 30rpx;

			//环比同比
			.form_item_rate {
				background: #F6F6F6;
				border: 1px solid #F6F6F6;
				padding: 30rpx;
				margin-bottom: 30rpx;
				border-radius: 30rpx;

				.line {
					height: 1px;
					background-color: #dfdfdf;
					margin: 30rpx 0;
				}

				.rate_item {
					display: flex;
					justify-content: space-between;
					font-size: 24rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;

					.rate_item_label {
						color: #666;
						font-size: 24rpx;
						display: flex;
						align-items: center;
						/deep/.uni-tooltip-popup{
							width: 200rpx;
						}
					}

					.rate_item_input {
						color: #333;
						font-size: 28rpx;
					}
				}

				&.danger {
					background-color: #FEF6F3;
					border-color: #F0622D;
				}
			}

			.form_item_title {
				color: #333;
				line-height: 42rpx;
				font-size: 30rpx;
				font-family: PingFang SC-Bold, PingFang SC;
				font-weight: bold;
				margin-bottom: 30rpx;
			}

			.form_item_remark {
				margin-bottom: 30rpx;

				.form_item_label {
					color: #333333;
					line-height: 42rpx;
					font-size: 30rpx;
					font-family: PingFang SC-Bold, PingFang SC;
					font-weight: bold;
					margin-bottom: 30rpx;
				}
				/deep/ .is-input-border{
					border-radius: 20rpx !important;
					border: 1px solid #c1c1c1 !important;
				}
			}

			.form_item {
				display: flex;
				align-items: center;
				justify-content: space-between;
				line-height: 37rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				margin-bottom: 30rpx;

				.form_item_label {
					width: 300rpx;
					color: #666666;
					font-size: 26rpx;
					word-break: break-all;
				}

				.form_item_input {
					color: #333;
					text-align: right;
					word-break: break-all;

					&.picker {
						flex: 1;
						// display: flex;
						// justify-content: space-between;

						// /deep/ picker {
						// 	flex: 1;
						// }

						.picker_select {
							flex: 1;
							color: #D4D4D4;
							font-size: 28rpx;
							font-family: PingFang SC-Regular, PingFang SC;
							font-weight: 400;
							text-align: right;
						}
					}

					//纯展示
					&.text {
						color: #333333;
						line-height: 40rpx;
						font-size: 28rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
					}

					//输入框
					&.form_input {
						/deep/ .is-input-border {
							border: 0 !important;

							.uni-easyinput__content-input {
								text-align: right;
							}
						}
					}
				}
			}
		}
	}

	//收费站
	.station_act {
		color: #2D8CF0;
		font-size: 24rpx;
		text-align: center;
		margin-bottom: 30rpx;
	}

	.station_box {
		display: flex;
		flex-wrap: wrap;
		justify-content: flex-start;
		margin-top: 30rpx;

		.station_item {
			flex: 1;
			width: calc((100% - 46rpx) / 3);
			min-width: calc((100% - 46rpx) / 3);
			max-width: calc((100% - 46rpx) / 3);
			height: 60rpx;
			color: #666666;
			line-height: 60rpx;
			font-size: 26rpx;
			font-family: PingFang SC-Regular, PingFang SC;
			font-weight: 400;
			border-radius: 20rpx;
			border: 1rpx solid #C1C1C1;
			text-align: center;
			margin-bottom: 30rpx;
			margin-right: 16rpx;
			overflow: hidden;

			&.active {
				position: relative;
				color: #1ECE5F;
				border-color: #1ECE5F;
				background: #EBFAF2;

				.tag {
					position: absolute;
					top: 0;
					right: 0;
					width: 34rpx;
					height: 23rpx;
					color: #fff;
					line-height: 23rpx;
					background: #1ECE5F;
					border-radius: 0rpx 20rpx 0rpx 5rpx;
					text-align: center;
				}
			}

			&.choosed {
				border-color: #2D8CF0 !important;
			}
		}
	}

	.foot_btn {
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
		display: flex;
		justify-content: space-between;
		padding: 40rpx 30rpx;
		background-color: #f5f5f5;
		z-index: 99;

		.act_btn {
			width: 690rpx;
			height: 90rpx;
			color: #666666;
			font-size: 28rpx;
			line-height: 90rpx;
			font-family: PingFang SC-Regular, PingFang SC;
			font-weight: 400;
			text-align: center;
			background: #F6F6F6;
			border-radius: 100rpx;
			border: 1rpx solid #C1C1C1;

			&.blue {
				color: #fff;
				background: #2D8CF0;
				border-color: #2D8CF0;
			}
		}
	}

	button {
		background-color: #007aff;
		color: #ffffff;
	}
</style>
