Просмотр исходного кода

填报数据根据每个字段增加校验

yf_zhb 2 лет назад
Родитель
Сommit
69ea06c17b

+ 106 - 14
MingGaoApp/pages/my/formRecord/fieldSurveys.vue

@@ -38,10 +38,10 @@
 					<u-switch v-model="baseForm.is_std" activeValue="是" inactiveValue="否"></u-switch>
 				</u-form-item>
 				<u-form-item label="调查株数:" labelWidth="100" prop="check_num" borderBottom>
-					<u--input v-model="baseForm.check_num" border="none" type="number"></u--input>
+					<u--input v-model="baseForm.check_num" border="none" type="number" :maxlength="9"></u--input>
 				</u-form-item>
 				<u-form-item label="危害株数:" labelWidth="100" prop="harm_num" borderBottom>
-					<u--input v-model="baseForm.harm_num" border="none" type="number"></u--input>
+					<u--input v-model="baseForm.harm_num" border="none" type="number" :maxlength="9"></u--input>
 				</u-form-item>
 				<u-form-item label="危害部位:" labelWidth="100" prop="harm_place" borderBottom>
 					<u--input v-model="baseForm.harm_place" border="none"></u--input>
@@ -109,28 +109,118 @@
 					sample_num: '', // 样本编号
 				},
 				rules: {
-					'inspect_name': {
+					'inspect_name': [{
+							type: 'string',
+							required: true,
+							message: '请填写踏查点名称',
+							trigger: ['blur', 'change']
+						},
+						{
+							min: 1,
+							max: 50,
+							message: '长度为1-50',
+							trigger: ['blur', 'change']
+						}
+					],
+					'inspect_area': [{
+							type: 'string',
+							required: true,
+							message: '请填写踏查点面积',
+							trigger: ['blur', 'change']
+						},
+						{
+							min: 1,
+							max: 50,
+							message: '长度为1-50',
+							trigger: ['blur', 'change']
+						}
+					],
+					'pest_name': [{
+							type: 'string',
+							required: true,
+							message: '请填写物种名称',
+							trigger: ['blur', 'change']
+						},
+						{
+							min: 1,
+							max: 50,
+							message: '长度为1-50',
+							trigger: ['blur', 'change']
+						}
+					],
+					'harm_place': [{
+							type: 'string',
+							required: true,
+							message: '请填写危害部位',
+							trigger: ['blur', 'change']
+						},
+						{
+							min: 1,
+							max: 50,
+							message: '长度为1-50',
+							trigger: ['blur', 'change']
+						}
+					],
+					'harm_rate': [{
+						type: 'number',
+						min: 0,
+						max: 100,
+						transform(value) {
+							return Number(value);
+						},
+						message: '0-100之间',
+						trigger: ['blur', 'change']
+					}],
+					'harm_obj': [{
+							type: 'string',
+							required: true,
+
+							message: '请填写危害对象',
+							trigger: ['blur', 'change']
+						},
+						{
+							min: 1,
+							max: 50,
+							message: '长度为1-50',
+							trigger: ['blur', 'change']
+						}
+					],
+					'occurs_area': [{
+							required: true,
+							message: '请填写发生面积',
+							trigger: ['blur', 'change']
+						},
+						{
+							min: 1,
+							max: 50,
+							message: '长度为1-50',
+							trigger: ['blur', 'change']
+						}
+					],
+					'occurs_name': {
 						type: 'string',
 						required: true,
-						message: '请填写踏查点名称',
+						message: '请选择',
 						trigger: ['blur', 'change']
 					},
 					'lng': {
-						type: 'string',
-						required: true,
-						message: '请填写经度',
+						max: 50,
+						message: '长度不能超过50',
 						trigger: ['blur', 'change']
 					},
 					'lat': {
-						type: 'string',
-						required: true,
-						message: '请填写纬度',
+						max: 50,
+						message: '长度不能超过50',
 						trigger: ['blur', 'change']
 					},
 					'height': {
-						type: 'string',
-						required: true,
-						message: '请填写海拔',
+						max: 50,
+						message: '长度不能超过50',
+						trigger: ['blur', 'change']
+					},
+					'sample_num': {
+						max: 50,
+						message: '长度不能超过50',
 						trigger: ['blur', 'change']
 					}
 				},
@@ -249,6 +339,8 @@
 				this.baseForm.occurs = lastInfo ? lastInfo.value : firstInfo.value;
 				this.baseForm.occurs_name = lastInfo ? firstInfo.label + '/' + lastInfo.label : firstInfo.label;
 				this.show = false;
+				
+				this.$refs.uForm.validate()
 			},
 			changeHandler(e) {
 				const {
@@ -283,7 +375,7 @@
 						this.submitLoading = false;
 					})
 				}).catch(errors => {
-					console.log(errors,'validate')
+					console.log(errors, 'validate')
 					uni.$u.toast('校验失败')
 				})
 			}

+ 326 - 34
MingGaoApp/pages/my/formRecord/samplePlot.vue

@@ -14,13 +14,14 @@
 					<u--input v-model="baseForm.sample_area" border="none" suffixIcon="亩"></u--input>
 				</u-form-item>
 				<u-form-item label="经度:" labelWidth="100" prop="lng" borderBottom>
-					<u--input v-model="baseForm.lng" border="none"></u--input>
+					<u--input v-model="baseForm.lng" border="none" type="digit" :maxlength="10"></u--input>
 				</u-form-item>
 				<u-form-item label="纬度:" labelWidth="100" prop="lat" borderBottom>
-					<u--input v-model="baseForm.lat" border="none"></u--input>
+					<u--input v-model="baseForm.lat" border="none" type="digit" :maxlength="10"></u--input>
 				</u-form-item>
 				<u-form-item label="海拔:" labelWidth="100" prop="height" borderBottom>
-					<u--input v-model="baseForm.height" border="none" suffixIcon="米"></u--input>
+					<u--input v-model="baseForm.height" border="none" type="digit" suffixIcon="米" :maxlength="10">
+					</u--input>
 				</u-form-item>
 				<u-form-item label="发生境:" labelWidth="100" prop="occurs_name" borderBottom @click="handleOccursClick">
 					<u--input v-model="baseForm.occurs_name" placeholder="请选择" disabled disabledColor="#ffffff"
@@ -31,12 +32,12 @@
 				<u-form-item label="物种名称:" labelWidth="100" prop="pest_name" borderBottom>
 					<u--input v-model="baseForm.pest_name" border="none"></u--input>
 				</u-form-item>
-				<u-form-item label="拉丁学名:" labelWidth="100" prop="pest_name_1" borderBottom>
-					<u--input v-model="baseForm.pest_name_1" border="none"></u--input>
-				</u-form-item>
-				<u-form-item label="当地俗名:" labelWidth="100" prop="pest_name_2" borderBottom>
+				<u-form-item label="拉丁学名:" labelWidth="100" prop="pest_name_2" borderBottom>
 					<u--input v-model="baseForm.pest_name_2" border="none"></u--input>
 				</u-form-item>
+				<u-form-item label="当地俗名:" labelWidth="100" prop="pest_name_3" borderBottom>
+					<u--input v-model="baseForm.pest_name_3" border="none"></u--input>
+				</u-form-item>
 				<u-form-item label="是否需要协助调查:" labelWidth="140" prop="is_check" borderBottom>
 					<u-switch v-model="baseForm.is_check" activeValue="是" inactiveValue="否"></u-switch>
 				</u-form-item>
@@ -157,7 +158,7 @@
 					height: '', // 海拔
 					sample_area: '', //标准样地面积
 					occurs: '', // 发生境
-					occurs_name:'',
+					occurs_name: '',
 					pest_name: '', //物种名称
 					pest_name_2: '', //拉丁学名
 					pest_name_3: '', //当地俗名
@@ -192,12 +193,45 @@
 					is_gather: '是', //  是否采集标本 是/否
 				},
 				rules: {
-					'sample_addr': {
-						type: 'string',
-						required: true,
-						message: '请填写标准样地地点名称',
-						trigger: ['blur', 'change']
-					},
+					'sample_addr': [{
+							type: 'string',
+							required: true,
+							message: '请填写标准样地地点名称',
+							trigger: ['blur', 'change']
+						},
+						{
+							min: 1,
+							max: 50,
+							message: '长度为1-50',
+							trigger: ['blur', 'change']
+						}
+					],
+					'sample_num': [{
+							type: 'string',
+							required: true,
+							message: '请填写标准样地编号',
+							trigger: ['blur', 'change']
+						},
+						{
+							min: 1,
+							max: 50,
+							message: '长度为1-50',
+							trigger: ['blur', 'change']
+						}
+					],
+					'sample_area': [{
+							type: 'string',
+							required: true,
+							message: '请填写标准样地面积',
+							trigger: ['blur', 'change']
+						},
+						{
+							min: 1,
+							max: 50,
+							message: '长度为1-50',
+							trigger: ['blur', 'change']
+						}
+					],
 					'lng': {
 						type: 'string',
 						required: true,
@@ -216,12 +250,268 @@
 						message: '请填写海拔',
 						trigger: ['blur', 'change']
 					},
-					'sample_area': {
+					'occurs_name': {
 						type: 'string',
 						required: true,
-						message: '请填写标准样地面积',
+						message: '请选择',
 						trigger: ['blur', 'change']
 					},
+					'pest_name': [{
+							type: 'string',
+							required: true,
+							message: '请填写物种名称',
+							trigger: ['blur', 'change']
+						},
+						{
+							min: 1,
+							max: 50,
+							message: '长度为1-50',
+							trigger: ['blur', 'change']
+						}
+					],
+					'harm_crop': [{
+							type: 'string',
+							required: true,
+							message: '请填写危害作物',
+							trigger: ['blur', 'change']
+						},
+						{
+							min: 1,
+							max: 50,
+							message: '长度为1-50',
+							trigger: ['blur', 'change']
+						}
+					],
+					'pest_name_2': [{
+						max: 50,
+						message: '长度不能超过50',
+						trigger: ['blur', 'change']
+					}],
+					'pest_name_3': [{
+						max: 50,
+						message: '长度不能超过50',
+						trigger: ['blur', 'change']
+					}],
+					// 1
+					'check_num_1': [{
+							type: 'string',
+							required: true,
+							message: '请填写',
+							trigger: ['blur', 'change']
+						},
+						{
+							min: 1,
+							max: 9,
+							message: '长度为1-9',
+							trigger: ['blur', 'change']
+						}
+					],
+					'harm_num_1': [{
+							type: 'string',
+							required: true,
+							message: '请填写',
+							trigger: ['blur', 'change']
+						},
+						{
+							min: 1,
+							max: 9,
+							message: '长度为1-9',
+							trigger: ['blur', 'change']
+						}
+					],
+					'harm_rate_1': [{
+							type: 'number',
+							required: true,
+							message: '请填写危害率',
+							trigger: ['blur', 'change']
+						},
+						{
+							type: 'number',
+							min: 0,
+							max: 100,
+							transform(value) {
+								return Number(value);
+							},
+							message: '0-100之间',
+							trigger: ['blur', 'change']
+						}
+					],
+					//2
+					'check_num_2': [{
+							type: 'string',
+							required: true,
+							message: '请填写',
+							trigger: ['blur', 'change']
+						},
+						{
+							min: 1,
+							max: 9,
+							message: '长度为1-9',
+							trigger: ['blur', 'change']
+						}
+					],
+					'harm_num_2': [{
+							type: 'string',
+							required: true,
+							message: '请填写',
+							trigger: ['blur', 'change']
+						},
+						{
+							min: 1,
+							max: 9,
+							message: '长度为1-9',
+							trigger: ['blur', 'change']
+						}
+					],
+					'harm_rate_2': [{
+							type: 'number',
+							required: true,
+							message: '请填写危害率',
+							trigger: ['blur', 'change']
+						},
+						{
+							type: 'number',
+							min: 0,
+							max: 100,
+							transform(value) {
+								return Number(value);
+							},
+							message: '0-100之间',
+							trigger: ['blur', 'change']
+						}
+					],
+					// 3
+					'check_num_3': [{
+							type: 'string',
+							required: true,
+							message: '请填写',
+							trigger: ['blur', 'change']
+						},
+						{
+							min: 1,
+							max: 9,
+							message: '长度为1-9',
+							trigger: ['blur', 'change']
+						}
+					],
+					'harm_num_3': [{
+							type: 'string',
+							required: true,
+							message: '请填写',
+							trigger: ['blur', 'change']
+						},
+						{
+							min: 1,
+							max: 9,
+							message: '长度为1-9',
+							trigger: ['blur', 'change']
+						}
+					],
+					'harm_rate_3': [{
+							type: 'number',
+							required: true,
+							message: '请填写危害率',
+							trigger: ['blur', 'change']
+						},
+						{
+							type: 'number',
+							min: 0,
+							max: 100,
+							transform(value) {
+								return Number(value);
+							},
+							message: '0-100之间',
+							trigger: ['blur', 'change']
+						}
+					],
+					// 4
+					'check_num_4': [{
+							type: 'string',
+							required: true,
+							message: '请填写',
+							trigger: ['blur', 'change']
+						},
+						{
+							min: 1,
+							max: 9,
+							message: '长度为1-9',
+							trigger: ['blur', 'change']
+						}
+					],
+					'harm_num_4': [{
+							type: 'string',
+							required: true,
+							message: '请填写',
+							trigger: ['blur', 'change']
+						},
+						{
+							min: 1,
+							max: 9,
+							message: '长度为1-9',
+							trigger: ['blur', 'change']
+						}
+					],
+					'harm_rate_4': [{
+							type: 'number',
+							required: true,
+							message: '请填写危害率',
+							trigger: ['blur', 'change']
+						},
+						{
+							type: 'number',
+							min: 0,
+							max: 100,
+							transform(value) {
+								return Number(value);
+							},
+							message: '0-100之间',
+							trigger: ['blur', 'change']
+						}
+					],
+					//5
+					'check_num_5': [{
+							type: 'string',
+							required: true,
+							message: '请填写',
+							trigger: ['blur', 'change']
+						},
+						{
+							min: 1,
+							max: 9,
+							message: '长度为1-9',
+							trigger: ['blur', 'change']
+						}
+					],
+					'harm_num_5': [{
+							type: 'string',
+							required: true,
+							message: '请填写',
+							trigger: ['blur', 'change']
+						},
+						{
+							min: 1,
+							max: 9,
+							message: '长度为1-9',
+							trigger: ['blur', 'change']
+						}
+					],
+					'harm_rate_5': [{
+							type: 'number',
+							required: true,
+							message: '请填写危害率',
+							trigger: ['blur', 'change']
+						},
+						{
+							type: 'number',
+							min: 0,
+							max: 100,
+							transform(value) {
+								return Number(value);
+							},
+							message: '0-100之间',
+							trigger: ['blur', 'change']
+						}
+					],
 				},
 				habitatList: [{
 						label: '公共绿地',
@@ -279,20 +569,20 @@
 						]
 					},
 					{
-						label: '水库道路周边地块',
+						label: '水库道路周边地块、荒地(待建地、城乡失管地等)',
 						value: '4'
 					},
-					{
-						label: '荒地',
-						value: '5',
-						children: [{
-							label: '待建地',
-							value: '5-1'
-						}, {
-							label: '城乡失管地',
-							value: '5-2'
-						}, ]
-					}
+					// {
+					// 	label: '荒地',
+					// 	value: '5',
+					// 	children: [{
+					// 		label: '待建地',
+					// 		value: '5-1'
+					// 	}, {
+					// 		label: '城乡失管地',
+					// 		value: '5-2'
+					// 	}, ]
+					// }
 				],
 				harmObjectList: [{
 					label: '农作物',
@@ -329,27 +619,27 @@
 				],
 				submitLoading: false,
 				columnData: [],
-				show:false
+				show: false
 			}
 		},
 		computed: {
 			occurs_columns() {
 				const level1DataList = [];
-		
+
 				forEach(this.habitatList, item => {
 					level1DataList.push({
 						label: item.label,
 						value: item.value
 					})
-		
+
 					if (isEmpty(item.children)) {
 						this.columnData.push([])
 					} else {
 						this.columnData.push(item.children)
 					}
 				})
-			
-		
+
+
 				return [
 					level1DataList,
 					this.columnData[0]
@@ -367,10 +657,12 @@
 				console.log('before confirm --------------14', value)
 				const firstInfo = first(value);
 				const lastInfo = last(value);
-			
+
 				this.baseForm.occurs = lastInfo ? lastInfo.value : firstInfo.value;
 				this.baseForm.occurs_name = lastInfo ? firstInfo.label + '/' + lastInfo.label : firstInfo.label;
 				this.show = false;
+				
+				this.$refs.uForm.validate()
 			},
 			changeHandler(e) {
 				const {

+ 91 - 21
MingGaoApp/pages/my/formRecord/trapRecord.vue

@@ -47,22 +47,23 @@
 						<u-row class="mb-10">
 							<u-col span="12">
 								<u--input style="background-color: #fff;" v-model="item.harm_crop" placeholder="危害农作物"
-									border="surround"></u--input>
+									border="surround" maxlength="50"></u--input>
 							</u-col>
 						</u-row>
 						<u-row class="mb-10" gutter="10">
 							<u-col span="6">
 								<u--input type="number" style="background-color: #fff;" v-model="item.female_num"
-									border="surround" placeholder="雌"></u--input>
+									border="surround" placeholder="雌" maxlength="9" ></u--input>
 							</u-col>
 							<u-col span="6">
 								<u--input type="number" style="background-color: #fff;" v-model="item.male_num"
-									placeholder="雄" border="surround"></u--input>
+									placeholder="雄" border="surround"  maxlength="9"></u--input>
 							</u-col>
 						</u-row>
 						<u-row class="mb-10">
 							<u-col span="12">
-								<u--textarea v-model="item.remarks" placeholder="备注" border="surround"></u--textarea>
+								<u--textarea count maxlength="200" v-model="item.remarks" placeholder="备注"
+									border="surround"></u--textarea>
 							</u-col>
 						</u-row>
 					</view>
@@ -115,28 +116,84 @@
 					 */
 				},
 				rules: {
-					'sample_addr': {
-						type: 'string',
-						required: true,
-						message: '请填写标准样地地点',
-						trigger: ['blur', 'change']
-					},
+					'sample_addr': [{
+							type: 'string',
+							required: true,
+							message: '请填写标准样地地点',
+							trigger: ['blur', 'change']
+						},
+						{
+							min: 1,
+							max: 50,
+							message: '长度为1-50',
+							trigger: ['blur', 'change']
+						}
+					],
+					'sample_num': [{
+							type: 'string',
+							required: true,
+							message: '请填写标准样地编号',
+							trigger: ['blur', 'change']
+						},
+						{
+							min: 1,
+							max: 50,
+							message: '长度为1-50',
+							trigger: ['blur', 'change']
+						}
+					],
+					'sample_area': [{
+							type: 'string',
+							required: true,
+							message: '请填写标准样地面积',
+							trigger: ['blur', 'change']
+						},
+						{
+							min: 1,
+							max: 50,
+							message: '长度为1-50',
+							trigger: ['blur', 'change']
+						}
+					],
+					'trap_number': [{
+							type: 'string',
+							required: true,
+							message: '请填写诱捕器编号',
+							trigger: ['blur', 'change']
+						},
+						{
+							min: 1,
+							max: 50,
+							message: '长度为1-50',
+							trigger: ['blur', 'change']
+						}
+					],
+					'inducer_name': [{
+							type: 'string',
+							required: true,
+							message: '请填写诱剂名称',
+							trigger: ['blur', 'change']
+						},
+						{
+							min: 1,
+							max: 50,
+							message: '长度为1-50',
+							trigger: ['blur', 'change']
+						}
+					],
 					'lng': {
-						type: 'string',
-						required: true,
-						message: '请填写经度',
+						max: 50,
+						message: '长度不能超过50',
 						trigger: ['blur', 'change']
 					},
 					'lat': {
-						type: 'string',
-						required: true,
-						message: '请填写纬度',
+						max: 50,
+						message: '长度不能超过50',
 						trigger: ['blur', 'change']
 					},
 					'height': {
-						type: 'string',
-						required: true,
-						message: '请填写海拔',
+						max: 50,
+						message: '长度不能超过50',
 						trigger: ['blur', 'change']
 					},
 				},
@@ -275,7 +332,7 @@
 			submit() {
 				this.$refs.uForm.validate().then(res => {
 					uni.$u.toast('校验通过')
-					this.submitLoading = true;
+
 					const pestList = this.baseForm.pest_list.map((item) => {
 						return assign({}, item, {
 							pest_total: Math.floor(item.male_num * 1 + item.female_num * 1)
@@ -286,7 +343,19 @@
 						pest_list: JSON.stringify(pestList)
 					});
 					
-					console.log(payload,'submit 1')
+
+
+					const isValiad = pestList.every(item => {
+						return item.pest_id && item.pest_name && (item.male_num > 0 || item.female_num > 0)
+					})
+
+					if (!isValiad) {
+						uni.$u.toast('请填写害虫相关信息,害虫名字和雌雄数量必填')
+						return
+					}
+
+					this.submitLoading = true;
+					console.log(payload, 'submit 1')
 					formRecordService.addTrapRecordForm(payload).then(res => {
 						console.log(res, '------------- add form success')
 						uni.$u.toast('提交成功')
@@ -301,6 +370,7 @@
 						this.submitLoading = false;
 					})
 				}).catch(errors => {
+					console.log(errors,'errors  ------------------')
 					uni.$u.toast('校验失败')
 				})
 			}

Разница между файлами не показана из-за своего большого размера
+ 47 - 16
MingGaoApp/unpackage/dist/dev/app-plus/app-service.js


+ 2 - 2
MingGaoApp/unpackage/dist/dev/app-plus/app-view.js

@@ -26510,7 +26510,7 @@ var render = function () {
                     model: {
                       value: _vm._$g(21, "v-model"),
                       callback: function () {},
-                      expression: "baseForm.pest_name_1",
+                      expression: "baseForm.pest_name_2",
                     },
                   }),
                 ],
@@ -26525,7 +26525,7 @@ var render = function () {
                     model: {
                       value: _vm._$g(23, "v-model"),
                       callback: function () {},
-                      expression: "baseForm.pest_name_2",
+                      expression: "baseForm.pest_name_3",
                     },
                   }),
                 ],