<template>
	<view class="form_warp">
		<view class="form_intro">
			<view>如有填报问题，请咨询公共服务中心</view>
			<view>中心值班电话：<text class="tel">66007587</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 select">
					{{form.organizationName}}
				</view>
			</view>
			<view class="form_item">
				<view class="form_item_label">统计日期：</view>
				<view class="form_item_input picker">
					<picker mode="date" :value="form.statDate" @change="bindDateChange">
						<text class="unselect_txt"
							:style="form.statDate?'color:#333;':''">{{form.statDate?form.statDate:'请选择时段'}}</text>
						<uni-icons type="right" size="16" color="#D4D4D4"></uni-icons>
					</picker>
				</view>
			</view>
			<view class="form_item">
				<view class="form_item_label">统计时段：</view>
				<view class="form_item_input picker">
					<picker :value="index" :range="array" range-key="dictLabel">
						<text class="unselect_txt"
							:style="index>-1?'color:#333;':''">{{index>-1?array[index].dictLabel:'请选择时段'}}</text>
						<uni-icons type="right" size="16" color="#D4D4D4"></uni-icons>
					</picker>
				</view>
			</view>
		</view>
		<!-- 用户权限收费站 -->
		<view class="station_box">
			<view @click="changeStationIndex(index)" class="station_item" :class="item.isFinish ? 'active' : ''" v-for="(item, index) in highwaySubDataList" :key="item.id">
				<view v-if='item.isFinish' class="tag">✓</uni-icons></view>
				{{item.stationName}}
			</view>
		</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 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">
				<view class="rate_item">
					<view class="rate_item_label">收费站入口车辆数环比(%)</view>
					<view class="rate_item_input">
						{{form.highwaySubDataList[stationIndex].tollExemptVehicleCountMom}}
					</view>
				</view>
				<view class="line"></view>
				<view class="rate_item">
					<view class="rate_item_label">收费站入口车辆数同比(%)</view>
					<view class="rate_item_input">
						{{form.highwaySubDataList[stationIndex].tollExemptVehicleCountYoy}}
					</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].exitVehicleCount" placeholderStyle="color: #D4D4D4;font-size:28rpx;" placeholder="请输入车辆数" type="number" maxlength="30"></uni-easyinput>
				</view>
			</view>
			<!-- 同比环比 -->
			<view class="form_item_rate danger">
				<view class="rate_item">
					<view class="rate_item_label" style="color: #EB4747">收费站出口车辆数环比(%)</view>
					<view class="rate_item_input" style="color: #EB4747">
						{{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">
						{{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="submitPersonIndex" :range="submitPerson" range-key="dictLabel">
						<text class="unselect_txt"
							:style="index>-1?'color:#333;':''">{{submitPersonIndex>-1?submitPerson[submitPersonIndex].dictLabel:'请选择报送人'}}</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].mark" 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">确认</view>
		</view>
	</view>
</template>
<script>
	import { getDateStr } from "../../../common/util.js"
	export default {
		data() {
			return {
				form: {
					organizationName: '',
					statDate: '',
					statPeriod: '',
					highwaySubDataList: []
				}, //登录form
				highwaySubDataList: [],//收费站列表
				stationIndex: 0,//收费站选中索引
				submitPerson: [],//报送人
				submitPersonIndex: -1, //报送人选择索引
				array: [], //时段选择列表
				index: 2, //时段选择,默认0-24
				userInfo: {},
				yoyMom: {},//同比环比
			}
		},
		onLoad(options) {
			this.userInfo = uni.getStorageSync('userInfo');
			if (!options.type || options.type == 'add') {
				let now =  new Date();
				this.form.statDate = getDateStr(now, -1);//默认前一天
				this.queryStation('add');
			} else if (options.item) {
				this.form = JSON.parse(options.item);
				this.queryStation();
			}
			this.queryTime();//统计时段
		},
		methods: {
			//切换当前编辑收费站索引
			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;
			},
			//收费站列表
			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.highwaySubDataList.map(item => {
							this.form.highwaySubDataList.push({
								"entranceVehicleCount": '',
								"entranceVehicleCountMom": 0.0,
								"entranceVehicleCountYoy": 0.0,
								"exitToll": 0.0,
								"exitVehicleCount": '',
								"exitVehicleCountMom": 0.0,
								"exitVehicleCountYoy": 0.0,
								"highwayId": item.highWayLineCode,
								"highwayName": item.highWayLineName,
								"submitPersonnelContact": this.userInfo.realName+','+this.userInfo.tel,
								"tollExemptAmount": 0.0,
								"tollExemptVehicleCount": 0,
								"tollExemptVehicleCountMom": 0.0,
								"tollExemptVehicleCountYoy": 0.0,
								"tollStationName": item.stationName,
								"remark": ''
							})
						})
					}else{
						this.highwaySubDataList.map(item => {
							let idx = this.form.highwaySubDataList.findIndex(item2 => {
								return item2.highwayId == item.highWayLineCode && item2.tollStationName == item.stationName;
							})
							if(idx > -1){
								this.form.highwaySubDataList.push(this.form.highwaySubDataList[idx]);
							}else{
								this.form.highwaySubDataList.push({
									"entranceVehicleCount": '',
									"entranceVehicleCountMom": 0.0,
									"entranceVehicleCountYoy": 0.0,
									"exitToll": 0.0,
									"exitVehicleCount": '',
									"exitVehicleCountMom": 0.0,
									"exitVehicleCountYoy": 0.0,
									"highwayId": item.highWayLineCode,
									"highwayName": item.highWayLineName,
									"submitPersonnelContact": this.userInfo.realName+','+this.userInfo.tel,
									"tollExemptAmount": 0.0,
									"tollExemptVehicleCount": 0,
									"tollExemptVehicleCountMom": 0.0,
									"tollExemptVehicleCountYoy": 0.0,
									"tollStationName": item.stationName,
									"remark": ''
								})
							}
						})
					}
				})
			},
			//取消
			doCancel() {
				uni.navigateBack();
			},
			//选择统计日期
			bindDateChange(e) {
				this.form.statDate = e.detail.value;
			},
			//时段
			queryTime() {
				this.$request(getApp().globalData.baseUrl + '/api/dict/dictList?dictType=airport_time' + '&_t=' + Date.parse(
					new Date()), {}, 'GET').then(res => {
					this.array = res.data;
				})
			},
			//确认提交
			doSubmit() {
				uni.showModal({
					title: '提示',
					content: '确认保存当前报送数据吗?',
					success: (res) => {
						if (res.confirm) {
							this.submitForm();
						}
					}
				})
			},
			submitForm() {
				// if (this.form.username == '' || this.form.password == '') {
				// 	uni.showToast({
				// 		title: '用户名密码不能为空',
				// 		icon: 'none'
				// 	})
				// 	return;
				// } else if (this.form.verCode == '') {
				// 	uni.showToast({
				// 		title: '验证码不能为空',
				// 		icon: 'none'
				// 	})
				// 	return;
				// }
				uni.showLoading({
					title: '提交中...',
					mask: true
				})
				this.$request(getApp().globalData.baseUrl + '/api/biz/highSpeedOperationController/saveOrUpdate', this.form, 'POST').then(res => {
					uni.hideLoading();
					if (res.code == 200) {
						uni.showToast({
							title: '报送提交成功',
							icon: 'none',
							success: () => {
								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;
					}
					.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;
				}
			}
			.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: 260rpx;
					color: #666666;
					font-size: 26rpx;
					word-break: break-all;
				}

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

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

						.picker_select {
							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_box {
		display: flex;
		flex-wrap: wrap;
		margin-top: 40rpx;

		.station_item {
			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;
			padding: 0 20rpx;
			margin-bottom: 40rpx;
			margin-right: 20rpx;

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

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

	.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: 329rpx;
			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>