questionnaireDia.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <template>
  2. <div >
  3. <el-dialog
  4. title="问卷调查"
  5. :visible.sync="dialogVisiblePwd"
  6. :append-to-body="true"
  7. :close-on-click-modal="false"
  8. @closed="handleClosed"
  9. width="780px"
  10. top="5vh"
  11. >
  12. <div style="padding: 10px 40px 0;" class="questionnaire-container" id="questionnaire-container">
  13. <div class="questionnaire-title">
  14. {{ questionList[0]&&questionList[0].Option?questionList[0].Option[0]:'尊敬的用户,感谢您使用系统,以下是对系统使用的调研问卷,我们期待您真实的反馈' }}
  15. </div>
  16. <el-form :model="quesitionForm" ref="questionRef" label-position="top" size="small">
  17. <el-form-item :label="index+1+'.'+item.Question" :prop="item.QuestionnaireId+''"
  18. :rules="item.IsMust?{required:true,message:'该题为必答题',trigger:['blur','change']}:''"
  19. v-for="(item,index) in questionList.slice(1)" :key="item.QuestionnaireId">
  20. <el-radio-group v-model="quesitionForm[item.QuestionnaireId]" v-if="item.Type==1">
  21. <el-radio :label="it" v-for="(it,ind) in item.Option" :key="it">{{ it }}</el-radio>
  22. </el-radio-group>
  23. <el-checkbox-group v-model="quesitionForm[item.QuestionnaireId]"
  24. v-else-if="item.Type==2">
  25. <el-checkbox :label="it" v-for="(it,ind) in item.Option" :key="it">{{ it }}</el-checkbox>
  26. </el-checkbox-group>
  27. <el-input v-else rows="5" v-model="quesitionForm[item.QuestionnaireId]" type="textarea" placeholder="请输入文本"></el-input>
  28. </el-form-item>
  29. </el-form>
  30. <div style="text-align: center;padding:40px 0 ;">
  31. <el-button @click="submitQuestion(1)" type="primary" style="width: 120px;" size="40">提交</el-button>
  32. <el-button @click="submitQuestion(0)" style="width: 120px;margin-left: 28px;" size="40">以后再填</el-button>
  33. </div>
  34. </div>
  35. </el-dialog>
  36. </div>
  37. </template>
  38. <script>
  39. import { homeInterface } from "api/api.js";
  40. export default {
  41. name:'questionnaireDia',
  42. data() {
  43. return {
  44. quesitionForm:{}
  45. }
  46. },
  47. watch:{
  48. questionList:{
  49. handler:function(value,old){
  50. // console.log(value);
  51. // 初始化数据
  52. value.map((item,index) =>{
  53. if(index ==0) return
  54. if(item.Type==2){
  55. this.$set(this.quesitionForm,item.QuestionnaireId,[])
  56. }else{
  57. this.$set(this.quesitionForm,item.QuestionnaireId,'')
  58. }
  59. })
  60. console.log(this.quesitionForm);
  61. },
  62. deep:true,
  63. immediate:true
  64. }
  65. },
  66. props:{
  67. dialogVisiblePwd: {
  68. type: Boolean,
  69. default: false,
  70. },
  71. questionList:{
  72. type: Array,
  73. default: () =>[],
  74. }
  75. },
  76. methods:{
  77. submitQuestion(isFill){
  78. if(isFill!=1){
  79. homeInterface.questionnaireSubmit({List:[],IsFill:isFill}).then(res=>{
  80. if(res.Ret == 200){
  81. this.$emit('update:dialogVisiblePwd',false)
  82. }
  83. })
  84. }else{
  85. this.$refs.questionRef.validate((valid)=>{
  86. if(valid){
  87. let paramList = this.questionList.map((item)=>{
  88. if(item.Type==4 || this.quesitionForm[item.QuestionnaireId].length==0) return undefined
  89. return {
  90. QuestionnaireId:item.QuestionnaireId,
  91. Options:Array.isArray(this.quesitionForm[item.QuestionnaireId])?
  92. this.quesitionForm[item.QuestionnaireId].join('~#'):this.quesitionForm[item.QuestionnaireId],
  93. Type:item.Type
  94. }
  95. }).filter(Boolean)
  96. // console.log(paramList);
  97. if(paramList.length==0){
  98. this.$emit('update:dialogVisiblePwd',false)
  99. return
  100. }
  101. homeInterface.questionnaireSubmit({List:paramList,IsFill:isFill}).then(res=>{
  102. if(res.Ret == 200){
  103. this.$message.success('提交成功')
  104. this.$emit('submitSuccess')
  105. this.$emit('update:dialogVisiblePwd',false)
  106. }
  107. })
  108. }
  109. })
  110. }
  111. },
  112. handleClosed(){
  113. this.$refs.questionRef.resetFields()
  114. this.$emit('update:dialogVisiblePwd',false)
  115. }
  116. },
  117. created(){
  118. }
  119. }
  120. </script>
  121. <style lang="scss" scoped>
  122. .questionnaire-container{
  123. .questionnaire-title{
  124. font-weight: 500;
  125. font-size: 16px;
  126. color: #333333;
  127. margin-bottom: 15px;
  128. }
  129. }
  130. </style>
  131. <style lang="scss">
  132. #questionnaire-container{
  133. .el-form-item__label{
  134. font-weight: 5000;
  135. font-size: 16px;
  136. color: #333333;
  137. }
  138. .el-radio__label,.el-checkbox__label,.el-textarea__inner{
  139. color: #666666;
  140. }
  141. .el-checkbox-group,.el-radio-group{
  142. margin-left: -40px;
  143. }
  144. .el-radio,.el-checkbox{
  145. margin-right: 0;
  146. margin-left: 40px;
  147. }
  148. }
  149. </style>