最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

antd+vue實現(xiàn)動態(tài)驗證循環(huán)屬性表單的思路

 更新時間:2021年09月16日 17:05:02   作者:魏知非  
今天通過本文給大家分享antd+vue實現(xiàn)動態(tài)驗證循環(huán)屬性表單的思路,代碼簡單易懂,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友參考下吧

希望實現(xiàn)查詢表單的某些屬性可以循環(huán)驗證必填項:

需求:

1.名稱,對比項,備注必填,默認為一行,可增加多行

2.根據(jù)名稱,動態(tài)請求對比項列表,名稱變化時,清空該行當(dāng)前選擇的對比項

思路:將整個搜索分成了兩個表單,分別去做驗證。一個是可動態(tài)添加的循環(huán)表單form,另一個為普通表單dateForm

html

			<a-form :form="form" @keyup.enter.native='searchQuery'>
				<div class="dynamic-wrap">
					<div v-for="(item,index) in formList" :key="index">
						<a-row :gutter="24">
							<a-col :span="6">
								<a-form-item label="名稱" :labelCol="{span: 7}" :wrapperCol="{span: 17}">
									<a-select placeholder='請選擇名稱'
									          v-decorator="[`equipment[${index}]`,{ initialValue: formList[index] ? formList[index].equipment : '', rules: [{ required: true, message: '請選擇設(shè)備!' }]}]"
									          @change="(e)=>equipChange(e,index)">
										<a-select-option v-for='options in formList[index].eqpList' :key='options.name' :value='options.name'>
											{{ options.name }}
										</a-select-option>
									</a-select>
								</a-form-item>
							</a-col>
							<a-col :span="6">
								<a-form-item label="對比項" :labelCol="{span: 7}" :wrapperCol="{span: 17}">
									<a-select
										placeholder="請選擇對比項"
										v-decorator="[`dataCode[${index}]`,{initialValue: formList[index] ? formList[index].dataCode : '',rules: [{ required: true, message: '請選擇對比項!' }]}]">
										<a-select-option v-for='option in formList[index].dataTypeList' :key='option.name' :value='option.name'>
											{{ option.name }}
										</a-select-option>
									</a-select>
								</a-form-item>
							</a-col>
							<a-col :span="6">
								<a-form-item label="備注" :labelCol="{span: 6}" :wrapperCol="{span: 18}">
									<a-input v-decorator="[`remark[${index}]`]" placeholder="請輸入備注"></a-input>
								</a-form-item>
							</a-col>
							<a-col :span="2" style="padding-left: 0px">
								<a-form-item :labelCol="{span: 0}" :wrapperCol="{span: 24}">
									<template v-if="formList.length > 1">
										<a-icon type="delete" @click="removeRow(index)"/>
									</template>
								</a-form-item>
							</a-col>
						</a-row>
					</div>
				</div>
			</a-form>
 
			<a-form :form="dateForm" inline @keyup.enter.native='searchQuery'>
				<a-form-item label='查詢?nèi)掌? :labelCol="{span: 8}" :wrapperCol="{span: 16}"
				             style="display: inline-block;width: 300px;">
					<a-date-picker
						style="width: 200px;"
						class='query-group-cust'
						v-decorator="['startTime', { rules: [{ required: true, message: '請選擇開始時間!' }] }]"
						:disabled-date='disabledStartDate'
						format='YYYY-MM-DD'
						placeholder='請選擇開始時間'
						@change='handleStart($event)'
						@openChange='handleStartOpenChange'></a-date-picker>
				</a-form-item>
				<span :style="{ display: 'inline-block', width: '24px', textAlign: 'center' }">-</span>
				<a-form-item style="display: inline-block;width: 200px;">
					<a-date-picker
						style="width: 200px;"
						class='query-group-cust'
						v-decorator="['endTime', { rules: [{ required: true, message: '請選擇結(jié)束時間!' }] }]"
						:disabled-date='disabledEndDate'
						format='YYYY-MM-DD'
						placeholder='請選擇結(jié)束時間'
						@change='handleEnd($event)'
						:open='endOpen'
						@openChange='handleEndOpenChange'></a-date-picker>
				</a-form-item>
				<span style="margin-left: 10px">
				        <a-button type='primary' :disabled='loading' @click='searchQuery' icon='search'>查詢</a-button>
				        <a-button type='primary' @click='searchReset' icon='search' style='margin-left:10px'>重置</a-button>
				        <a-button type="primary" icon="plus" @click="addRow" style='margin-left:10px'>新增查詢條件</a-button>
			        </span>
			</a-form>
			<p>查詢條件為:{{searchData}}</p>

js

initForm() {
				// 首先請求設(shè)備列表,存放在eqpList中
				// 初始化form表單
				this.formList.push({
					equipment: '',
					dataCode: '',
					remark: '',
					eqpList: this.eqpList,
					dataTypeList: []
				})
			},
			// 刪除一行
			handleRemove(index) {
				if (this.formList.length === 1) {
					return
				}
				this.formList.splice(index, 1)
			},
			// 新增一行
			handleAdd() {
				this.formList.push({
					equipment: '',
					dataCode: '',
					remark: '',
					eqpList: this.eqpList, // 可以根據(jù)接口動態(tài)獲取,這里便于演示,直接賦值了
					dataTypeList: [],// 可以根據(jù)接口動態(tài)獲取并根據(jù)設(shè)備去關(guān)聯(lián)
				})
			},
			equipChange(value, index) {
				// change賦值
				this.formList[index].equipment = value;
				//同步更新 當(dāng)前選擇的設(shè)備對應(yīng)的對比項列表
				this.handleEqpIdentity(value, index)
			},
			// 根據(jù)設(shè)備查詢對應(yīng)的對比項列表
			handleEqpIdentity(value, index) {
				this.dataTypeList = []; //清空dataTypeList
				this.formList[index].dataTypeList = []; // 清空當(dāng)前行的 dataTypeList
				//根據(jù)新的設(shè)備名稱 獲取對應(yīng)的對比項列表
				getAction(this.url.getDataTypeList, {equipment: value})
					.then((res) => {
						if (res.success) {
							this.dataTypeList = res.result;
							this.formList[index].dataTypeList = this.dataTypeList;
							// this.formList[index].dataCode = ''; 直接賦值為空 是無效的
							//需使用 getFieldValue, setFieldsValue
							let dataCode1Arr = this.form.getFieldValue('dataCode');
							if (dataCode1Arr.length !== 0) {
								dataCode1Arr[index] = ''
							}
							this.form.setFieldsValue({dataCode: dataCode1Arr})
						} else {
							this.$message.warning(res.message)
						}
					})
					.catch(() => {
						this.$message.error('獲取失敗,請重試!')
					})
			},
// 點擊查詢
			searchQuery() {
				// 先驗證循環(huán)表單
				const {form: {validateFields}} = this
				validateFields((error, values) => {
					if (!error) {
						this.dateForm.validateFields((dateErr, dateValues) => {
							//再驗證日期搜索表單
							dateValues.startTime = moment(dateValues.startTime).format('YYYY-MM-DD')
							dateValues.endTime = moment(dateValues.endTime).format('YYYY-MM-DD')
							if (!dateErr) {
								this.loading = true;
								let formData = Object.assign({}, dateValues);
								//整理成后臺所需的數(shù)據(jù)結(jié)構(gòu)
								// 循環(huán)表單
								let searchArr = [];
								(values[`equipment`]).forEach((item, index) => {
									const obj = {
										equipment: item,
										remark: values[`remark`][index],
										dataCode: values[`dataCode`][index]
									}
									searchArr.push(obj);
 
								})
								// 日期表單
								if (!dateValues.startTime) {
									formData.startTime = moment(new Date()).format('YYYY-MM-DD')
								}
								formData.eqpInfoParamVoList = searchArr;
								this.searchData = JSON.parse(formData)
							  //	請求接口
							}
						})
					}
				})
			},

到此這篇關(guān)于antd vue實現(xiàn)動態(tài)驗證循環(huán)屬性表單的文章就介紹到這了,更多相關(guān)antd vue動態(tài)驗證循環(huán)屬性表單內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 在Vue開發(fā)過程中解決和預(yù)防內(nèi)存泄漏問題的方法詳解

    在Vue開發(fā)過程中解決和預(yù)防內(nèi)存泄漏問題的方法詳解

    Vue作為一款流行的前端框架,已經(jīng)在許多項目中得到廣泛應(yīng)用,然而,隨著我們在Vue中構(gòu)建更大規(guī)模的應(yīng)用程序,我們可能會遇到一個嚴重的問題,那就是內(nèi)存泄漏,因此,我們需要認識到在Vue開發(fā)過程中,內(nèi)存泄漏問題的重要性,本文將給大家介紹如何解決和預(yù)防內(nèi)存泄漏問題
    2023-10-10
  • uniapp 小程序和app map地圖上顯示多個酷炫動態(tài)的標(biāo)點效果(頭像后端傳過來)

    uniapp 小程序和app map地圖上顯示多個酷炫動態(tài)的標(biāo)點效果(頭像后端傳過來)

    這篇文章主要介紹了uniapp 小程序和app map地圖上顯示多個酷炫動態(tài)的標(biāo)點效果(頭像后端傳過來),本文通過示例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-09-09
  • Vue手寫實現(xiàn)異步更新詳解

    Vue手寫實現(xiàn)異步更新詳解

    這篇文章主要介紹了Vue手寫實現(xiàn)異步更新詳解,文章圍繞主題展開詳細的內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下,希望對你的學(xué)習(xí)有所幫助
    2022-08-08
  • Vue代碼整潔之去重方法整理

    Vue代碼整潔之去重方法整理

    在本篇文章里小編給大家整理的是關(guān)于Vue代碼整潔之去重的相關(guān)知識點內(nèi)容,需要的朋友們學(xué)習(xí)下。
    2019-08-08
  • 解決vue打包后vendor.js文件過大問題

    解決vue打包后vendor.js文件過大問題

    這篇文章主要介紹了解決vue打包后vendor.js文件過大問題,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-07-07
  • vue組件開發(fā)之slider組件使用詳解

    vue組件開發(fā)之slider組件使用詳解

    這篇文章主要為大家詳細介紹了vue組件開發(fā)之slider組件的使用方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-08-08
  • 如何在Vue.JS中使用圖標(biāo)組件

    如何在Vue.JS中使用圖標(biāo)組件

    這篇文章主要介紹了如何在Vue.JS中使用圖標(biāo)組件,文中講解非常細致,代碼幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-08-08
  • 詳解mpvue scroll-view自動回彈bug解決方案

    詳解mpvue scroll-view自動回彈bug解決方案

    設(shè)置了scroll-top的scroll-view組件,在組件所在vue實例data發(fā)生改變時會自動回彈到最上方,非常具有實用價值,需要的朋友可以參考下
    2018-10-10
  • vue-resource 攔截器(interceptor)的使用詳解

    vue-resource 攔截器(interceptor)的使用詳解

    本篇文章主要介紹了vue-resource 攔截器(interceptor)的使用詳解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-07-07
  • vue父子組件通訊的所有方法小結(jié)

    vue父子組件通訊的所有方法小結(jié)

    本文將介紹父組件與子組件之間傳遞數(shù)據(jù)的四種方法,以一個簡單的小demo為例,通過實例全方位解析和代碼演示,便于大家理解,需要的朋友可以參考下
    2024-07-07

最新評論

平阳县| 云安县| 南城县| 竹北市| 通榆县| 襄城县| 岑巩县| 宜黄县| 多伦县| 大埔区| 广汉市| 莲花县| 沙河市| 昌都县| 通山县| 郓城县| 鸡西市| 聂拉木县| 千阳县| 上蔡县| 东台市| 乃东县| 界首市| 富民县| 淮安市| 黑水县| 赤城县| 驻马店市| 德令哈市| 中西区| 铅山县| 舟曲县| 红河县| 襄垣县| 石城县| 岳池县| 万全县| 阜新市| 铜川市| 两当县| 会昌县|