<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="data.name" placeholder="请输入套餐名称" class="input"
							placeholder-style="color:#C7CDD3">
					</view>
				</view>

			</view>
			<view class="card_li">
				<view class="tops">
					<view class="card_left">
						说明
					</view>
					<view class="card_right">
						<input type="text" v-model="data.instructions" placeholder="请输入说明内容" class="input"
							placeholder-style="color:#C7CDD3">
					</view>
				</view>

			</view>
		</view>
		<view class="card">
			<view class="card_li">
				<view class="tops">
					<view class="card_left">
						免费骑行
					</view>
					<view class="card_right">
						<input type="text" v-model="data.freeRideTime" placeholder="可以免费骑行的时间" class="input"
							placeholder-style="color:#C7CDD3">
					</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="text" v-model="data.autoRefundDeposit" placeholder="多少小时后自动退押金" class="input"
							placeholder-style="color:#C7CDD3">
					</view>

				</view>
				<view class="tips">
					多少小时后自动退押金(小时)
				</view>
			</view> -->
			<view class="card_li">
				<view class="tops">
					<view class="card_left">
						租赁单位
					</view>
					<view class="card_right">
						<u-radio-group v-model="timevalue" @change="radioGroupChange">
							<u-radio v-for="(item, index) in timeList" :key="index" :name="item.name"
								:disabled="item.disabled">
								{{item.name}}
							</u-radio>
						</u-radio-group>
					</view>
				</view>

			</view>
			<view class="card_li">
				<view class="rule">
					起步价
					<input type="text" v-model="startingPrice" placeholder=" " class="input"
						placeholder-style="color:#C7CDD3">
					元 含（ <input type="text" v-model="startingTime" placeholder=" " class="input"
						placeholder-style="color:#C7CDD3"> {{timevalue}}）
				</view>
				<view class="tips">
					<!-- 可以免费骑行的时间 -->
				</view>
			</view>
			<view class="card_li">
				<view class="rule">
					超出价
					<input type="text" v-model="timeoutPrice" placeholder=" " class="input"
						placeholder-style="color:#C7CDD3">
					元 /（ <input type="text" v-model="timeoutTime" placeholder=" " class="input"
						placeholder-style="color:#C7CDD3">{{timevalue}}
				</view>
				<view class="tips" style="text-align: left;">
					超出起步价后
				</view>
				<view class="tips" style="text-align: left;">
					注：
					1) 不是起步时间的仍按起步时间收取费用；超出起步时间后的均匀计算。
					2) 为避免免费用户使用，切勿频繁切换。
				</view>
			</view>
			<!-- <view class="card_li">
				<view class="tops">
					<view class="card_left">
						计费周期
					</view>
					<view class="card_right">
						订单生成后
						<input type="text" v-model="data.chargingCycleValue" placeholder="多少小时后自动退押金" class="input"
							placeholder-style="color:#C7CDD3" style="width: 100rpx;">小时
					</view>

				</view>
				<view class="tips" style="text-align: left;">
					1) 若计费周期为订单生成后X小时，每达到X小时，订单按规则重新计费，各周期内金额总和为订单总费用；
					2) 若计费周期为自定义时刻，每当达到该时刻，订单按规则重新计费，各周期内金额总和为订单总费用
				</view>
			</view> -->
			<view class="card_li">
				<view class="tops">
					<view class="card_left">
						预存
					</view>
					<view class="card_right">
						<input type="text" v-model="data.depositAmount" placeholder="多少小时后自动退押金" class="input"
							placeholder-style="color:#C7CDD3" style="width: 100rpx;">元
					</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",
				},
				showpart: false,
				list: [],
				Accessorylist: [],
				chooseIdxArr: [], // 存储选中的索引
				timevalue: '按分钟',
				timeList: [{
						name: '按分钟',
						disabled: false
					},
					{
						name: '按小时',
						disabled: false
					},

				],
				startingPrice: "",
				startingTime: '',
				timeoutPrice: '',
				timeoutTime: '',
				data: {
					name: '',
					instructions: '',
					status: "0",
					autoRefundDeposit: '0',
					orderExceedMinutes: '',
					orderExceedWarn: '',
					freeRideTime: '5',
					rentalUnit: 'minutes',
					ridingRule: '1',
					chargingCycle: '1',
					chargingCycleValue: '24',
					depositAmount: '200',
					timeoutTime: '',
					startingTime: '',
					orderNum:0,
					userId:'',
					startRule:{}
				},
				ruleId: '',
				userinfo:{}
			}
		},
		onLoad(e) {
			if (e.ruleId) {
				this.ruleId = e.ruleId
				this.getFeeInfo()
			}
		},
		onShow() {
			this.getinfo()
		},

		methods: {
            getinfo() {
            	this.$u.get("/getInfo").then((res) => {
            		if (res.code == 200) {
            			this.userinfo = res.user
						this.data.userId = this.userinfo.userId
            		} 
            	})
            },
			getFeeInfo() {
				this.$u.get(`/bst/suit/${this.ruleId}`).then((res) => {
					if (res.code == 200) {
						this.data = res.data;
						if (this.data.rentalUnit == 'minutes') {
							this.timevalue='按分钟'
						} else if (this.data.rentalUnit == 'hours') {
							this.timevalue='按小时'
						} else if (this.data.rentalUnit == 'day') {
							this.timevalue='按天'
						}
						if (this.data.area) {
							this.returnVerify = this.data.area.returnVerify;
						}
						// console.log("-------returnVerify------",this.returnVerify)
						// delete this.form.startRule;
						let json = res.data.startRule
						if (this.data.ridingRule == 1) {
							this.timeoutTime = json.timeoutTime
							this.startingPrice = json.startingPrice
							this.startingTime = json.startingTime
							this.timeoutPrice = json.timeoutPrice
						} else {
							this.rule = json.rule.slice(0, -1);
							// 获取数组的最后一个元素
							this.more = json.rule[json.rule.length - 1]
						}
						console.log(this.data, 'this.formthis.form')
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 1000
						})
					}
				})
			},
			backpage() {
				uni.navigateBack()
			},
			// 选中任一radio时，由radio-group触发
			radioGroupChange(e) {
				if (e == '按分钟') {
					this.data.rentalUnit = 'minutes'
				} else {
					this.data.rentalUnit = 'hours'
				}
			},
			sub() {
				let data = {
					...this.data,
					type:1
				}
				data.startRule = {}
				if (this.data.ridingRule == 2) {
					data.startRule.rule = this.rule
					data.startRule.enablelnterval = this.enablelnterval
				} else {
					data.startRule.timeoutTime = this.timeoutTime
					data.startRule.startingPrice = this.startingPrice
					data.startRule.startingTime = this.startingTime
					data.startRule.timeoutPrice = this.timeoutPrice
				}
				data.startRule = data.startRule
				console.log(data, 'mmmmmmmmmmmmm')
				if (this.ruleId != '') {
					this.$u.put(`/bst/suit`, 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: 2000
							})
						}
					})
				} else {
					this.$u.post(`/bst/suit`, 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: 2000
							})
						}
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	page {}

	.page {
		.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;

			.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: #6F6F6F;
			}

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

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

					.card_left {
						font-weight: 400;
						font-size: 30rpx;
						color: #3D3D3D;
					}

					.card_right {
						margin-left: auto;
						display: flex;
						flex-wrap: nowrap;
						align-items: center;

						// justify-content: space-between;
						span {
							font-weight: 400;
							font-size: 30rpx;
							color: #3D3D3D;
						}

						.input {
							padding-right: 10rpx;
							padding: 6rpx;

							border: 1rpx solid #ccc;
							border-radius: 20rpx;
							width: 400rpx;
							text-align: left;
							/* 输入框内容靠右显示 */
						}
					}
				}

			}


		}
	}
</style>