<template>
	<!-- 顶部导航栏 -->
	<custom-nav-bar :left="true" leftText="" @leftClick="" title="新增方案"></custom-nav-bar>

	<view class="create-container">
		<u-form ref="form" :model="formData" :rules="rules">
			<u-form-item label="方案名称" prop="scenarioName" required>
				<u-input v-model="formData.scenarioName" placeholder="请输入方案名称" />
			</u-form-item>
			<u-form-item label="总时长" prop="irrigateTotalDuration" required>
				<u-input v-model="formData.irrigateTotalDuration" placeholder="请输入总时长" />
			</u-form-item>
			<u-form-item label="轮灌组数" prop="groupNum" required>
				<u-input v-model="formData.groupNum" placeholder="请输入轮灌组数" />
			</u-form-item>
			<u-form-item label="自动调压" prop="isAutoAdjust" required>
				<u-radio-group v-model="formData.isAutoAdjust" color="#39ac4f">
					<u-radio label="是" name="male"></u-radio>
					<u-radio label="否" name="female"></u-radio>
				</u-radio-group>
			</u-form-item>
			<u-form-item label="最小压力" prop="pressureMin" required>
				<u-input v-model="formData.pressureMin" placeholder="请输入最小压力" />
			</u-form-item>
			<u-form-item label="最大压力" prop="pressureMax" required>
				<u-input v-model="formData.pressureMax" placeholder="请输入最大压力" />
			</u-form-item>
			<view class="form-btn">
				<u-button type="success" size="large" text="确定" @click="confirm" />
				<u-button size="large" text="取消" @click="close" />
			</view>
		</u-form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				landId: null,
				formData: {
					landId: '', //地块id
					scenarioName: '轮灌方案1', //浇灌方案名称
					irrigateTotalDuration: 12, //浇灌总时长
					groupNum: 5, //轮灌组数
					scenarioType: 2, //方案类型（1手动 2自动）
					isAutoAdjust: 0, //是否自动调压（0否1是）
					pressureMin: '0', //压力最小值
					pressureMax: '0', //压力最大值
					status: '0', //状态（0启用 1禁用）
					delFlag: '0', //删除状态（0存在 2删除）
				},
				rules: {
					username: [{
						required: true,
						message: '请输入任务名称',
						trigger: ['change', 'blur']
					}]
				}

			};
		},
		onLoad() {
			if (getApp().ijs.land) {
				this.formData.landId = getApp().ijs.land.id;
			}
		},
		methods: {
			openPopup() {
				this.$refs.groupPopup.open();
			},
			closePopup() {
				this.$refs.groupPopup.close();
			},
			close() {
				uni.navigateBack();
			},
			confirm() {
				uni.navigateTo({
					url: `/pages/irrigation/scenario/scenarioGroup?item=${JSON.stringify(this.formData)}`
				});
			},

		}
	}
</script>

<style lang="scss" scoped>
	body {
		background-color: #fff;
	}

	// 表单
	.create-container {
		padding: 0 20px;
		background-color: #FFF;

		// .custom-input {
		//   width: 280px;
		// }
		// .form-item {
		// 	margin-left: 20px;
		// 	display: flex;
		// 	align-items: flex-start;
		// 	width: 100%;
		// }
		::v-deep .u-form-item__body__left {
			width: 80px !important;
		}
	}

	// 弹出框
	.popup-content {
		padding: 20px;
		background-color: #fff;
		text-align: center;
	}
</style>