answer.html 6.8 KB

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