<template>
	<view class="page">
		<u-navbar title="运营配置" :border-bottom="false" :background="bgc" title-color='#000' title-size='36'
			height='45'></u-navbar>
		<view class="card">
			<view class="card_li">
				<view class="tops">
					<view class="card_left">
						运营区名称
					</view>
					<view class="card_right">
						<input type="text" v-model="form.name" placeholder="运营区名称" class="input"
							placeholder-style="color:#C7CDD3">
					</view>
				</view>

			</view>
		<!-- 	<view class="card_li" v-for="(service, index) in customServices" :key="index">
				<view class="rule">
					<view class=""
						style="width: 100%;display: flex;flex-wrap: nowrap;align-items: center;margin-bottom: 20rpx;">
						客服{{(index + 1)}}
						<input type="text" v-model="service.name" placeholder=" " class="input"
							placeholder-style="color:#C7CDD3">

					</view>

					电话:
					<input type="text" v-model="service.phone" placeholder=" " class="input"
						placeholder-style="color:#C7CDD3">
					<view class="btns1" @click="addService"
						v-if=" index === customServices.length - 1 &&  customServices.length < 3 ">
						添加
					</view>
					<view class="btns2" @click="removeService(index)" v-if="index > 0">
						删除
					</view>
				</view>
			</view> -->
		</view>
		<view class="card">
			<view class="card_li">
				<view class="tops">
					<view class="card_left">
						实名认证
					</view>
					<view class="card_right">
						<u-switch v-model="form.authentication"></u-switch>
					</view>

				</view>
				<view class="tips">
					开启后用户骑行前必须先进行实名认证才可使用
				</view>
			</view>
			<view class="card_li">
				<view class="tops">
					<view class="card_left">
						还车是否拍照审核
					</view>
					<view class="card_right">
						<u-switch v-model="form.returnVerify"></u-switch>
					</view>

				</view>
				<view class="tips">
					开启后则需用户拍摄视频后审核订单方可退还押金
				</view>
			</view>
			<view class="card_li">
				<view class="tops">
					<view class="card_left">
						短信通知服务
					</view>
					<view class="card_right">
						<u-switch v-model="form.msgSwitch"></u-switch>
					</view>

				</view>
				<view class="tips">
					开启短信通知，短信费用0.1元/条，从余额中扣除
				</view>
			</view>
			<view class="card_li">
				<view class="tops">
					<view class="card_left">
						强制停车点还车
					</view>
					<view class="card_right">
						<u-switch v-model="form.parkingReturn"></u-switch>
					</view>

				</view>
				<view class="tips">
					开启则必须在停车点才可还车，停车点存在误差
				</view>
			</view>
			<view class="card_li" v-if="form.parkingReturn == false">
				<view class="tops">
					<view class="card_left">
						运营区外还车
					</view>
					<view class="card_right">
						<u-switch v-model="form.areaOutReturn"></u-switch>
					</view>

				</view>
				<view class="tips">
					开启后可以在运营区范围外还车
				</view>
			</view>
			<view class="card_li">
				<view class="tops">
					<view class="card_left">
						运营区外调度费
					</view>
					<view class="card_right">

						<input type="number" v-model="form.dispatchFee" placeholder=" " class="input"
							placeholder-style="color:#C7CDD3" style="width: 100rpx;">元
					</view>

				</view>
				<view class="tips" style="text-align: left;">
					设置车辆超出运营区外产生的调度费用
				</view>
			</view>
			<view class="card_li">
				<view class="tops">
					<view class="card_left">
						停车点外调度费
					</view>
					<view class="card_right">

						<input type="number" v-model="form.vehicleManagementFee" placeholder=" " class="input"
							placeholder-style="color:#C7CDD3" style="width: 100rpx;">元
					</view>

				</view>
				<view class="tips" style="text-align: left;">
					设置车辆超出停车点外产生的调度费用
				</view>
			</view>
			<view class="card_li">
				<view class="tops">
					<view class="card_left">
						还车误差
					</view>
					<view class="card_right">

						<input type="number" v-model="form.error" placeholder=" " class="input"
							placeholder-style="color:#C7CDD3" style="width: 100rpx;">米
					</view>

				</view>
				<view class="tips" style="text-align: left;">
					允许用户在规划的停车点外多少米还车
				</view>
			</view>
			<view class="card_li">
				<view class="tops">
					<view class="card_left">
						禁行区内断电
					</view>
					<view class="card_right">
						<u-switch v-model="form.noRidingOutage"></u-switch>
					</view>

				</view>
				<view class="tips">
					开启后当进入禁行区内将进行断电
				</view>
			</view>
			<view class="card_li">
				<view class="tops">
					<view class="card_left">
						运营区域外断电
					</view>
					<view class="card_right">
						<u-switch v-model="form.areaOutOutage"></u-switch>
					</view>

				</view>
				<view class="tips">
					开启后当进入运营区域外内将进行断电
				</view>
			</view>
			<view class="card_li">
				<view class="tops">
					<view class="card_left">
						低于电量(%)不得骑行
					</view>
					<view class="card_right">

						<input type="number" v-model="form.undercharge" placeholder=" " class="input"
							placeholder-style="color:#C7CDD3" style="width: 100rpx;">%
					</view>

				</view>
				<view class="tips" style="text-align: left;">
					当车辆电量低于多少时无法解锁用车
				</view>
			</view>
			<view class="card_li" @click="toMap()">
				<view class="tops">
					<view class="card_left">
						电子围栏设置	
					</view>
					<view class="card_right">
						<view class="iconfont icon-xiangyou1">
							
						</view>
					</view>
			
				</view>
				<view class="tips" style="text-align: left;">
					设置车辆可以正常行驶的区域
				</view>
			</view>
		</view>



		<view class="btn_box">
			<view class="btn1" @click="backpage()">
				取消
			</view>
			<view class="btn2" @click="sub">
				保存
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bgc: {
					backgroundColor: "#fff",
				},

				list: [],
				form: {

				},
				deptInfo: {},
				areaId: '',
				customServices: []

			}
		},
		onLoad(e) {

		},
		onShow() {
			if (uni.getStorageSync('adminAreaid')) {
				this.areaId = uni.getStorageSync('adminAreaid')
			}
			this.getAreaInfo()
			// this.getdept()
		},

		methods: {
			toMap(){
				uni.navigateTo({
					url:'/page_shanghu/guanli/msp_set?areaId='+this.areaId
				})
			},
			addService() {
				if (this.customServices.length < 3) {
					this.customServices.push({
						name: "",
						phone: ""
					});
				}
			},
			removeService(index) {
				if (index > 0 && this.customServices.length > 1) {
					this.$delete(this.customServices, index);
					this.$set(this.form, `serviceName${index + 1}`, "");
					this.$set(this.form, `servicePhone${index + 1}`, "");
				}
			},
			getAreaInfo() {
				this.$u.get(`/bst/area/${this.areaId}`).then((res) => {
					if (res.code == 200) {
						this.form = res.data
						this.form.ruleIds = res.ruleIds
						// 初始化 customServices 数组
						this.customServices = [];
						for (let i = 1; i <= 3; i++) {
							if (
								res.data[`serviceName${i}`] ||
								res.data[`servicePhone${i}`]
							) {
								this.customServices.push({
									name: res.data[`serviceName${i}`] || "",
									phone: res.data[`servicePhone${i}`] || "",
								});
							}
						}
						// 如果 customServices 为空，添加一个默认的服务
						if (this.customServices.length === 0) {
							this.customServices.push({
								name: "",
								phone: ""
							});
						}
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				})
			},
			backpage() {
				uni.navigateBack()
			},
			// getdept() {
			// 	let data = {
			// 		areaId: this.areaId
			// 	}
			// 	this.$u.get(`/appVerify/getDept?`, data).then((res) => {
			// 		if (res.code == 200) {
			// 			this.deptInfo = res.data
			// 			// this.list = res.data

			// 		} else {
			// 			// 处理接口返回错误的情况
			// 		}
			// 	}).catch(error => {
			// 		// 处理接口请求失败的情况
			// 	});

			// },

			// 选中任一radio时，由radio-group触发
			radioGroupChange(e) {
				console.log(e);
				if (e == '按分钟') {
					this.data.rentalUnit = 'minutes'
				} else {
					this.data.rentalUnit = 'hours'
				}
			},
			sub() {
				let data = {
					...this.form
				}
				this.$u.put(`/bst/area`, data).then((res) => {
					if (res.code == 200) {
						uni.showToast({
							title: '修改成功',
							icon: 'success',
							duration: 1000
						});
						setTimeout(() => {
							uni.navigateBack()
						}, 1100)
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 1000
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {}

	.page {
		padding-bottom: 300rpx;

		.choose_part {
			position: fixed;
			top: 530rpx;
			left: 54rpx;
			z-index: 110;
			width: 644rpx;
			padding: 40rpx 48rpx;
			background: #FFFFFF;
			border-radius: 26rpx 26rpx 26rpx 26rpx;

			.part_box {
				margin-top: 40rpx;
				display: flex;
				flex-wrap: wrap;

				.part:nth-child(3n) {
					margin-right: 0;
				}

				.part {
					margin-top: 10rpx;
					position: relative;
					margin-right: 36rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					// width: 160rpx;
					// height: 60rpx;
					padding: 4rpx 8rpx;
					background: #F0F0F0;
					border-radius: 6rpx 6rpx 6rpx 6rpx;
					border: 1rpx solid #F0F0F0;
					font-weight: 500;
					font-size: 32rpx;

					color: #3D3D3D;

					image {
						position: absolute;
						right: 0;
						bottom: 0;
						width: 34rpx;
						height: 34rpx;
					}
				}

				.act {
					background: #DCEDFF;
					border: 1rpx solid #4297F3;
					color: #4297F3;
				}
			}

			.tit {
				width: 100%;
				text-align: center;
				font-weight: 600;
				font-size: 36rpx;
				color: #3D3D3D;
			}

			.btn {
				margin-top: 60rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				width: 552rpx;
				height: 88rpx;
				background: #4C97E7;
				border-radius: 10rpx 10rpx 10rpx 10rpx;
				font-weight: 600;
				font-size: 36rpx;
				color: #FFFFFF;
			}
		}


		.btn_box {
			position: fixed;
			width: 750rpx;
			bottom: 50rpx;
			display: flex;
			flex-wrap: nowrap;
			align-content: center;
			justify-content: center;
			z-index: 100;

			.btn1 {
				margin-right: 52rpx;
				display: flex;
				flex-wrap: nowrap;
				align-items: center;
				justify-content: center;
				width: 310rpx;
				height: 100rpx;
				background: #E2F2FF;
				font-weight: 500;
				font-size: 40rpx;
				color: #4C97E7;
			}

			.btn2 {
				display: flex;
				flex-wrap: nowrap;
				align-items: center;
				justify-content: center;
				width: 310rpx;
				height: 100rpx;
				background: #4C97E7;
				font-weight: 500;
				font-size: 40rpx;
				color: #FFFFFF;
			}
		}

		.card {
			padding: 0 24rpx;
			margin: 0 auto;
			margin-top: 24rpx;
			width: 672rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 4rpx 22rpx 0rpx rgba(0, 0, 0, 0.07);
			border-radius: 10rpx 10rpx 10rpx 10rpx;

			.card_li:last-child {
				border-bottom: 1rpx solid #fff;
			}

			.tips {
				width: 100%;
				// text-align: right;
				font-weight: 400;
				font-size: 22rpx;
				color: #999;
			}

			.card_li {
				width: 100%;
				padding-top: 24rpx;
				display: flex;
				flex-wrap: wrap;
				// align-content: center;
				// justify-content: space-between;
				border-bottom: 1rpx solid #D8D8D8;
				padding-bottom: 18rpx;

				.rule {
					display: flex;
					flex-wrap: wrap;
					align-items: center;
					font-weight: 400;
					font-size: 30rpx;
					color: #3D3D3D;

					.input {
						margin-left: 6rpx;
						margin-right: 6rpx;
						padding: 6rpx;

						border: 1rpx solid #ccc;
						border-radius: 20rpx;
						width: 250rpx;

					}

					.btns1 {
						margin-left: auto;
						padding: 10rpx 20rpx;
						background: #DCEDFF;
						border-radius: 6rpx 6rpx 6rpx 6rpx;
						font-weight: 400;
						font-size: 30rpx;
						color: #4297F3;
					}

					.btns2 {
						margin-left: auto;
						padding: 10rpx 20rpx;
						background: #FFDBDB;
						border-radius: 6rpx 6rpx 6rpx 6rpx;
						font-weight: 400;
						font-size: 30rpx;
						color: #FF1C1C;
					}
				}

				.tops {
					width: 100%;
					display: flex;
					flex-wrap: nowrap;
					align-items: center;

					.card_left {
						font-weight: 400;
						font-size: 30rpx;
						color: #333;
						font-weight: 600;
					}

					.card_right {
						margin-left: auto;
						display: flex;
						flex-wrap: nowrap;
						align-items: center;
                        color: #000;
						
						span {
							font-weight: 400;
							font-size: 30rpx;
							color: #000;
						}

						.input {
							height: 60rpx;
							line-height: 60rpx;
                            padding-left: 20rpx;
                            box-sizing: border-box;
                            margin-right: 10rpx;
							border: 1rpx solid #ccc;
							border-radius: 20rpx;
							width: 400rpx;
							text-align: left;
							/* 输入框内容靠右显示 */
						}
					}
				}

			}


		}
	}
</style>