answer.html 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=no,
  6. width=device-width,initial-scale=1.0">
  7. <title>问卷调查</title>
  8. <!-- import CSS -->
  9. <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
  10. </head>
  11. <style>
  12. .tpl_title {
  13. font-size: 18px;
  14. margin-bottom: 20px;
  15. }
  16. .el-form-item__label{
  17. float:none;
  18. }
  19. </style>
  20. <body>
  21. <div id="app">
  22. <div class="item-main">
  23. <img src="static/survey_logo.png" alt="" class="survey_logo" />
  24. <h5 align="center" class="tpl_title">{{ title }}</h5>
  25. <el-form ref="form" :model="form2" class="tpl_form over_y">
  26. <el-form-item
  27. v-for="(item, index) in widgetList"
  28. :key="index"
  29. :label="item.label"
  30. >
  31. <el-input
  32. v-if="item.type == 'input'"
  33. v-model="form2[item.label]"
  34. :placeholder="item.placeholder"
  35. ></el-input>
  36. <el-input
  37. v-if="item.type == 'textarea'"
  38. type="textarea"
  39. v-model="form2[item.label]"
  40. :placeholder="item.placeholder"
  41. ></el-input>
  42. <el-radio-group
  43. v-if="item.type == 'radio'"
  44. v-model="form2[item.label]"
  45. >
  46. <el-radio
  47. :label="iitem.label"
  48. v-for="(iitem, index) in item.items"
  49. :key="index"
  50. >{{ iitem.label }}</el-radio
  51. >
  52. </el-radio-group>
  53. <el-checkbox-group
  54. v-else-if="item.type == 'checkbox'"
  55. v-model="form2[item.label]"
  56. >
  57. <el-checkbox
  58. :label="iitem.label"
  59. v-for="(iitem, index) in item.items"
  60. :key="index"
  61. ></el-checkbox>
  62. </el-checkbox-group>
  63. <el-upload
  64. v-if="item.type == 'image'"
  65. action="/api/admin/uploadfile"
  66. list-type="picture-card"
  67. :data="{ type: item.label }"
  68. :on-success="handleSuccess"
  69. >
  70. <i class="el-icon-plus"></i>
  71. </el-upload>
  72. <el-upload
  73. v-if="item.type == 'file'"
  74. class="upload-demo"
  75. ref="upload"
  76. action="/api/admin/uploadfile"
  77. :data="{ type: item.label }"
  78. :on-success="handleSuccess"
  79. >
  80. <!-- <el-button slot="trigger" size="small" type="primary">选取文件</el-button> -->
  81. <el-button
  82. style="margin-left: 10px"
  83. size="small"
  84. type="primary"
  85. plain
  86. >添加文件</el-button
  87. >
  88. <!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div> -->
  89. </el-upload>
  90. </el-form-item>
  91. <el-form-item v-if="widgetList.length">
  92. <el-button
  93. size="medium"
  94. type="primary"
  95. @click="saveResult"
  96. style="width: 100%"
  97. >提交</el-button
  98. >
  99. </el-form-item>
  100. </el-form>
  101. </div>
  102. </div>
  103. </body>
  104. <!-- import Vue before Element -->
  105. <script src="static/jquery.min.js"></script>
  106. <script src="static/vue.js"></script>
  107. <!-- import JavaScript -->
  108. <script src="https://unpkg.com/element-ui/lib/index.js"></script>
  109. <script>
  110. new Vue({
  111. el: '#app',
  112. data: function() {
  113. return {
  114. form2:{
  115. },
  116. widgetList:[],
  117. id:'',
  118. title:'',
  119. show:0
  120. }
  121. },
  122. methods:{
  123. getData(){
  124. $.ajax({
  125. url:'https://test.scxjc.club/api/admin/message',
  126. method:'get',
  127. data:{
  128. id:this.id
  129. },
  130. success:res=>{
  131. let widgetList=res.data.widget;
  132. for(let i=0;i<widgetList.length;i++){
  133. if(widgetList[i].type=='checkbox'){
  134. let key = widgetList[i].label
  135. this.$set(this.form2, key, [])
  136. }
  137. }
  138. this.title = res.data.name
  139. this.widgetList=widgetList
  140. }
  141. })
  142. },
  143. saveResult(){
  144. let result = JSON.stringify(this.form2);
  145. $.ajax({
  146. url:'/api/admin/message/survey/result',
  147. method:'post',
  148. data:{
  149. message_id: this.id,
  150. result: result,
  151. },
  152. success:res=>{
  153. if (res.code == 0) {
  154. //this.$message({
  155. // type: "success",
  156. // message: "保存成功!",
  157. //});
  158. alert("保存成功!")
  159. } else {
  160. //this.$message.error("保存失败!");
  161. alert("保存成功!")
  162. }
  163. this.form2 = {}
  164. }
  165. })
  166. },
  167. handleSuccess(res, file) {
  168. this.form2[res.data.type] = res.data.url;
  169. },
  170. },
  171. created(){
  172. var search=window.location.search.split('?')[1].split('&');
  173. this.id=search[0].split('=')[1]
  174. this.getData()
  175. }
  176. })
  177. </script>
  178. </html>