蝙蝠岛资源网 Design By www.hbtsch.com

本文实例为大家分享了vue+element实现动态加载表单的具体代码,供大家参考,具体内容如下

一、问卷动态加载表单

vue+element实现动态加载表单

//html
<el-form :model="quesPaper" status-icon label-width="100px" label-position="top" size="small" v-loading="paperLoading" >  
 <el-form-item
 v-for="n in paperForm.answerList"
 :label="n.questionRepository.question"
 :key="n.key"
 >
 <!-- 单选 -->
 <el-radio-group v-model="n.optionId" v-if="n.questionRepository.type === 1">
 <el-radio v-for="(i, idx) in n.questionOption" :label="i.id" :key="idx" class="mb5">{{ i.questionOption }}</el-radio>
 </el-radio-group>
 <!-- 多选 -->
 <el-checkbox-group v-model="n.optionId" v-if="n.questionRepository.type === 2">
 <el-checkbox v-for="(i, idx) in n.questionOption" :label="i.id" :key="idx">{{ i.questionOption }}</el-checkbox>
 </el-checkbox-group>
 <!-- 填空 -->
 <el-input type="textarea" style="width: 600px" class="fl" v-model="n.answer" v-if="n.questionRepository.type === 3" :rows="4" placeholder="请输入内容" ></el-input>
 </el-form-item>


 <el-row class="mt20" type="flex" justify="start">
 <el-col :span="5">
 <el-button type="primary" size="small" @click.stop="saveStageAnswer">保存问卷</el-button>
 </el-col>
 </el-row>
</el-form>

//data数据
paperForm: { // 问卷表单
 answerList:[{
 questionRepository:'',
 questionOption:[],

 questionId: '',
 optionId:'',
 answer: ''
 }]
 },
//接口
getPaperByDrugStatus(drugStatus, id){ // 根据用药状态获取问卷
 this.paperLoading = true
 this.$axios.get(this.$api + 'xxx/xxx"text-align: center">vue+element实现动态加载表单

特点:

1.每一行的输入框,根据后台返回值,动态生成,数量可增可减。
2.行数根据自己设置的值 5 ,自动循环生成。
3.验证需要:prop和:rules,如果不验证,就删了

<template>
<!-- 录入数据 -->
 <div class="DialyInputDetail" >
 <div class="fw fz16 color6 mb20 mt10">批量录入<span class="colorRed">{{tabHeader.monthStr}}</span>数据</div>
 <el-form status-icon label-width="100px" :model="newForm" ref='newForm' label-position="top" size="small"> 
 <table border="1" class="fw fz14 color6 table">
 <tr>
  <td rowspan='2'>患者请用姓名<br/>或病历号模糊筛选</td>
  <td :colspan="tabHeader.firstTables.length" class="tc colorRed lh40">以下信息每1个月登记一次</td>
  <td :colspan="tabHeader.secondTables.length" class="tc colorRed lh40">以下信息每3个月登记一次</td>
  <td :colspan="tabHeader.thirdTables.length" class="tc colorRed lh40">以下信息每6个月登记一次</td>
 </tr>
 <tr class="lh40">
  <td v-for="item in tabHeader.firstTables" :key="item.name" class="tc">{{item.name}}</td>
  <td v-for="n in tabHeader.secondTables" :key="n.name" class="tc">{{n.name}}</td>
  <td v-for="z in tabHeader.thirdTables" :key="z.nam" class="tc">{{z.name}}</td>
 </tr>
 
 <tr v-for="(w,index) in newForm.colList" :key="index+'a'" >
  <td> 
  <el-form-item
  :prop="'colList.'+index+'.patientId'"
  >
  <!--- :rules="{required: true, message: '不能为空', trigger: 'blur'}"-->
  <el-select v-model="w.patientId" size="small" style="width: 100px" filterable clearable>
  <el-option
   v-for="(ite, idx) in patientArr"
   :label="ite.patient" 
   :key="idx"
   :value="ite.id">
  </el-option>
  </el-select>
  </el-form-item>
  </td>
  <td class="tc" v-for="(n,j) in w.itemDataList" :key="j">
  <el-form-item
  :prop="'colList.'+index+'.itemDataList.' + j + '.itemValue'"
  >
  <!-- :rules="{required: true, message: '不能为空', trigger: 'blur'}"-->
  <el-select v-model="n.itemValue" size="small" style="width: 100px" v-if="n.type == 2" filterable clearable>
  <el-option
   v-for="(i, idx) in n.opts"
   :label="i" 
   :key="idx"
   :value="i">
  </el-option>
  </el-select>
  <el-input style="width: 100px" size="small" v-model="n.itemValue" v-if="n.type == 1" ></el-input>
  </el-form-item>
  </td>
 </tr>
 </table>  
 <el-row class="mt20" type="flex" justify="start">
 <el-col :span="5">
  <el-button type="primary" size="small" @click="submitNew('newForm')">提交数据</el-button>
 </el-col>
 </el-row>
 </el-form>
 </div>
</template>

<script>
import Vue from 'vue'

export default {
 name: 'DialyInputDetail',
 props:['dialysisId','dialysisCenter'],
 data() {
 return {
 tabHeader:{
 firstTables:[],
 secondTables:[],
 thirdTables:[],
 colNub:[]
 },
 dialyDetail:{},
 newForm:{
 id:'',
 colList:[
  // {
  // patientId:123,  //患者id
  // createUserId:123,  //当前用户id
  // createUserName:"管理员" ,
  // itemDataList:[{
  // itemId:'',
  // itemValue:'',
  // type:1
  // }] 
  // }
 ],
 },
 patientArr:[],
 }
 },
 created () { 
 this.getMedRdTables(this.dialysisId)
 this.getPatient(this.dialysisId)
 },
 methods: {
 getMedRdTables(id){//获取录入tab
 this.$axios.get(this.$my.api + '/bms/input/getMedRdTables"htmlcode">
data(){
 return {
 formList:[{
 patient:'',
 caseNumber:'',
 year:'',
 sex:'',
 dialysisAge:'',
 primaryDisease:'',
 diagnosis:'',
 creatinine:'',
 gfr:'',
 weekTreatTimes:'',
 weekDialysisHours:''
 },{
 patient:'',
 caseNumber:'',
 year:'',
 sex:'',
 dialysisAge:'',
 primaryDisease:'',
 diagnosis:'',
 creatinine:'',
 gfr:'',
 weekTreatTimes:'',
 weekDialysisHours:''
 },{
 patient:'',
 caseNumber:'',
 year:'',
 sex:'',
 dialysisAge:'',
 primaryDisease:'',
 diagnosis:'',
 creatinine:'',
 gfr:'',
 weekTreatTimes:'',
 weekDialysisHours:''
 }]
 },
 methods:{
 submitData(){
 let param={
 dialysisId:this.$route.query.id,
 dialysisCenter:this.$route.query.name,
 createUserName:JSON.parse(localStorage.getItem('userInfo')).session.name,
 createUserId:JSON.parse(localStorage.getItem('userInfo')).session.id,
 patientList:nweArr
 }
 // 部分必选 start
 let ok = false
 // 需要必选的值
 let rules = [{name:'patient',msg:'姓名'},{name:'caseNumber',msg:'身份证'},{name:'year',msg:'年龄'},{name:'sex',msg:'性别'}]
  this.formList.map((item)=>{
  //每一行,是否有值
  let hangNoVal = Object.keys(item).every(n=>item[n] == '')
  if(!hangNoVal){ //任意一个有值
  for(let i of rules){ 
  if(item[i.name] == ''){//必填项是否有值
   this.$message({
   message: i.msg+'不能为空!',
   type: 'error',
   duration: 1500
   })
   break
  }
  }
  }else{
  ok = true
  }
  })
  if(ok){
  this.$message({
  message: '请填写,再提交',
  type: 'error',
  duration: 1500
  })
  return false
  }
 // 部分必选 end
 this.$axios.post(this.$my.api + '/bms/input/bathSavePat',param).then(res => { 
 if(res.data&&res.data.code === 200){ 
 //ok
 } 
 }).catch(function (error) {})
 },
 }
}

//情况二:有输入,才必填
// 部分必选 start
let ok = []
let no = ''
 // 需要必选的值
 let rules = [{name:'patient',msg:'姓名'},{name:'caseNumber',msg:'身份证'},{name:'year',msg:'年龄'},{name:'sex',msg:'性别'}]
 this.formList.map((item)=>{
 //每一行,是否有值
 let hangNoVal = Object.keys(item).every(n=>item[n] == '')
 if(!hangNoVal){ //任意一个有值
  ok.push(false)
  for(let i of rules){ 
  if(item[i.name] == ''){//必填项是否有值
  no = true
  this.$message({
   message: i.msg+'不能为空!',
   type: 'error',
   duration: 1500
  })
  break
  }
  }
 }else{
  ok.push(true)
 }
 })
 if(ok.every(n=>n == true)){
 this.$message({
  message: '请填写,再提交',
  type: 'error',
  duration: 1500
 })
 return false
 }
 if(no){
 return false
 }
 // 部分必选 end

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

标签:
vue,element动态加载表单,vue动态加载表单,vue加载表单

蝙蝠岛资源网 Design By www.hbtsch.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
蝙蝠岛资源网 Design By www.hbtsch.com

评论“vue+element实现动态加载表单”

暂无vue+element实现动态加载表单的评论...

《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线

暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。

艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。

《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。