Bläddra i källkod

表单验证提交完善

liyangzheng 1 år sedan
förälder
incheckning
ac6a8cf3c0
1 ändrade filer med 69 tillägg och 36 borttagningar
  1. 69 36
      pagesA/fire/fire_station/people_fireStation/people_fireStation.vue

+ 69 - 36
pagesA/fire/fire_station/people_fireStation/people_fireStation.vue

@@ -155,45 +155,78 @@
 		},
 		methods: {
 			addNewPeople() {
-				const newPerson = {
-					name: '',
-					userNum: '',
-					phone: '',
-					worker: "",
-					power: "",
-					// 其他字段
-				};
-				this.membersList.push(newPerson);
+				const MAX_LENGTH = 1; // 假设你想限制数组最大长度为6
+				if (this.membersList.length < MAX_LENGTH) {
+					const newPerson = {
+						name: '',
+						userNum: '',
+						phone: '',
+						worker: '',
+						power: '',
+						// 其他字段
+					};
+					this.membersList.push(newPerson);
+				} else {
+					// 达到最大数量,给出提示或执行其他操作
+					uni.showToast({
+						title: '只支持一位添加',
+						icon: 'none', // 图标类型,可选值:'success', 'loading', 'none'
+						duration: 2000, // 持续时间,单位为毫秒,默认值为 1500
+						mask: false, // 是否显示透明蒙层,防止触摸穿透,默认值为 false
+						success() {
+							console.log('toast消息提示显示成功');
+						},
+						fail(err) {
+							console.error('toast消息提示显示失败', err);
+						}
+					});
+				}
 			},
+
 			addSure() {
-				creatFirePeople({
-					duty: this.membersList[0].power,
-					empName: this.membersList[0].name,
-					empType: this.membersList[0].worker,
-					idcardno: this.membersList[0].userNum,
-					microstationid: this.fireStationId - 0,
-					mobile: this.membersList[0].phone,
-				}).then(res => {
-					if (res.data) {
-						this.getAllFire()
-						uni.showToast({
-							title: '添加成功',
-							icon: 'success', // 图标类型,可选值:'success', 'loading', 'none'
-							duration: 2000, // 持续时间,单位为毫秒,默认值为 1500
-							mask: false, // 是否显示透明蒙层,防止触摸穿透,默认值为 false
-							success() {
-								console.log('toast消息提示显示成功');
-							},
-							fail(err) {
-								console.error('toast消息提示显示失败', err);
-							}
-						});
-						this.membersList = []
-					}
-					console.log(res, 'r11111');
-				})
-				// console.log(this.membersList, 'memberList');
+				if (!this.userRules && !this.phoneRules && !this.nameRules) {
+					creatFirePeople({
+						duty: this.membersList[0].power,
+						empName: this.membersList[0].name,
+						empType: this.membersList[0].worker,
+						idcardno: this.membersList[0].userNum,
+						microstationid: this.fireStationId - 0,
+						mobile: this.membersList[0].phone,
+					}).then(res => {
+						if (res.data) {
+							this.getAllFire()
+							uni.showToast({
+								title: '添加成功',
+								icon: 'success', // 图标类型,可选值:'success', 'loading', 'none'
+								duration: 2000, // 持续时间,单位为毫秒,默认值为 1500
+								mask: false, // 是否显示透明蒙层,防止触摸穿透,默认值为 false
+								success() {
+									console.log('toast消息提示显示成功');
+								},
+								fail(err) {
+									console.error('toast消息提示显示失败', err);
+								}
+							});
+							this.membersList = []
+						}
+						console.log(res, 'r11111');
+					})
+					// console.log(this.membersList, 'memberList');
 
+				} else {
+					uni.showToast({
+						title: '请检查表单项',
+						icon: 'none', // 图标类型,可选值:'success', 'loading', 'none'
+						duration: 2000, // 持续时间,单位为毫秒,默认值为 1500
+						mask: false, // 是否显示透明蒙层,防止触摸穿透,默认值为 false
+						success() {
+							console.log('toast消息提示显示成功');
+						},
+						fail(err) {
+							console.error('toast消息提示显示失败', err);
+						}
+					});
+				}
 			},
 			change(e) {
 				console.log("e:", e);