answer.html 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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="static/index.css">
  10. </head>
  11. <style>
  12. body{margin:0px;padding:0px;}
  13. #app{
  14. display: none;
  15. }
  16. .tpl_title {
  17. font-size: 18px;
  18. margin: 10px 0;
  19. }
  20. .item-main{
  21. padding:10px 15px;
  22. }
  23. .el-form-item__label{
  24. font-weight:600;
  25. float:none;
  26. }
  27. .el-message-box{
  28. width:80%;
  29. }
  30. .survey_logo{
  31. width: 125px;
  32. }
  33. </style>
  34. <body>
  35. <div id="app">
  36. <div class="item-main">
  37. <img src="static/survey_logo.png" alt="" class="survey_logo" />
  38. <h5 align="center" class="tpl_title">{{ title }}</h5>
  39. <el-form ref="form" :model="form2" class="tpl_form over_y">
  40. <el-form-item
  41. v-for="(item, index) in widgetList"
  42. :key="index"
  43. :label="(index+1)+'、'+(item.label)"
  44. >
  45. <el-input
  46. v-if="item.type == 'input'"
  47. v-model="form2[item.label]"
  48. :placeholder="item.placeholder"
  49. ></el-input>
  50. <el-input
  51. v-if="item.type == 'textarea'"
  52. type="textarea"
  53. v-model="form2[item.label]"
  54. :placeholder="item.placeholder"
  55. :rows=4
  56. ></el-input>
  57. <el-radio-group
  58. v-if="item.type == 'radio'"
  59. v-model="form2[item.label]"
  60. >
  61. <el-radio
  62. :label="iitem.label"
  63. v-for="(iitem, index) in item.items"
  64. :key="index"
  65. >{{ iitem.label }}</el-radio
  66. >
  67. </el-radio-group>
  68. <el-checkbox-group
  69. v-else-if="item.type == 'checkbox'"
  70. v-model="form2[item.label]"
  71. >
  72. <el-checkbox
  73. :label="iitem.label"
  74. v-for="(iitem, index) in item.items"
  75. :key="index"
  76. ></el-checkbox>
  77. </el-checkbox-group>
  78. <el-upload
  79. v-if="item.type == 'image'"
  80. action="/api/admin/uploadfile"
  81. list-type="picture-card"
  82. :data="{ type: item.label }"
  83. :on-success="handleSuccess"
  84. >
  85. <i class="el-icon-plus"></i>
  86. </el-upload>
  87. <el-upload
  88. v-if="item.type == 'file'"
  89. class="upload-demo"
  90. ref="upload"
  91. action="/api/admin/uploadfile"
  92. :data="{ type: item.label }"
  93. :on-success="handleSuccess"
  94. >
  95. <!-- <el-button slot="trigger" size="small" type="primary">选取文件</el-button> -->
  96. <el-button
  97. style="margin-left: 10px"
  98. size="small"
  99. type="primary"
  100. plain
  101. >添加文件</el-button
  102. >
  103. <!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div> -->
  104. </el-upload>
  105. </el-form-item>
  106. <el-form-item v-if="widgetList.length">
  107. <el-button
  108. size="medium"
  109. type="primary"
  110. @click="saveResult"
  111. style="width: 100%;height: 45px;font-size: 16px;margin-top:20px;"
  112. :disabled="form2.status==0"
  113. >{{this.form2.status==1?"提交":"该问卷已禁用"}}</el-button
  114. >
  115. </el-form-item>
  116. </el-form>
  117. </div>
  118. </div>
  119. </body>
  120. <!-- import Vue before Element -->
  121. <script src="static/jquery.min.js"></script>
  122. <script src="static/vue.js"></script>
  123. <!-- import JavaScript -->
  124. <script src="static/index.js"></script>
  125. <script>
  126. new Vue({
  127. el: '#app',
  128. data: function() {
  129. return {
  130. type:null,
  131. form2:{
  132. },
  133. widgetList:[],
  134. id:'',
  135. title:'',
  136. show:0
  137. }
  138. },
  139. methods:{
  140. getData(){
  141. let url = "/api/admin/message"
  142. if(this.type==1){
  143. url = "/api/admin/message/out"
  144. }
  145. $.ajax({
  146. url:url,
  147. method:'get',
  148. data:{
  149. id:this.id
  150. },
  151. success:res=>{
  152. document.getElementById('app').style.display='block'
  153. this.form2.status = res.data.status
  154. let widgetList=res.data.widget;
  155. for(let i=0;i<widgetList.length;i++){
  156. if(widgetList[i].type=='checkbox'){
  157. let key = widgetList[i].label
  158. this.$set(this.form2, key, [])
  159. }
  160. }
  161. this.title = res.data.name
  162. this.widgetList=widgetList
  163. },
  164. error:res=>{
  165. if(res.status==403){
  166. window.location.href="/survey/login.html?id="+this.id+"&type="+this.type
  167. }
  168. }
  169. })
  170. },
  171. saveResult(){
  172. let url = "/api/admin/message/survey/result"
  173. if(this.type==1){
  174. url = "/api/admin/message/survey/result/out"
  175. }
  176. let result = JSON.stringify(this.form2);
  177. $.ajax({
  178. url:url,
  179. method:'post',
  180. data:{
  181. message_id: this.id,
  182. result: result,
  183. },
  184. success:res=>{
  185. if (res.code == 0) {
  186. this.$alert('提交成功',"提交成功", {
  187. center:true,
  188. showClose:false,
  189. confirmButtonText: '确定',
  190. type:"success"
  191. });
  192. window.location.href="/survey/success.html?title="+encodeURIComponent(res.data)
  193. } else {
  194. this.$alert("提交失败请稍后再试!","提交失败", {
  195. center:true,
  196. showClose:false,
  197. confirmButtonText: '确定',
  198. type:"error"
  199. });
  200. }
  201. }
  202. })
  203. },
  204. handleSuccess(res, file) {
  205. this.form2[res.data.type] = res.data.url;
  206. },
  207. },
  208. created(){
  209. var search=window.location.search.split('?')[1].split('&');
  210. this.id=search[0].split('=')[1]
  211. this.type = search[1].split('=')[1]
  212. this.getData()
  213. }
  214. })
  215. </script>
  216. </html>