answer.html 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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 lang="scss" scoped>
  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. .survey_logo {
  27. width: 125px;
  28. }
  29. /* 选项样式 */
  30. .el-form-item__content{
  31. line-height: 1;
  32. }
  33. .el-form-item__label {
  34. float: none;
  35. font-weight: 600;
  36. display: block;
  37. line-height: 20px;
  38. margin-bottom: 10px;
  39. text-align: left;
  40. }
  41. .el-radio{
  42. width: 93%!important;
  43. }
  44. .el-radio:not(:last-child){
  45. margin-bottom: 10px;
  46. }
  47. .el-radio__label {
  48. font-size: 14px;
  49. padding-left: 10px;
  50. line-height: 20px!important;
  51. white-space: normal;
  52. display: inline-block !important;
  53. vertical-align: top;
  54. }
  55. .el-checkbox-group{
  56. display:flex;
  57. flex-direction: column;
  58. }
  59. .el-checkbox__label {
  60. font-size: 14px;
  61. padding-left: 10px;
  62. line-height: 20px!important;
  63. white-space: normal;
  64. display: inline-block !important;
  65. vertical-align: top;
  66. }
  67. .el-checkbox{
  68. width: 93%!important;
  69. }
  70. .el-checkbox:not(:last-child){
  71. margin-bottom: 10px!important;
  72. }
  73. .message_desc{
  74. /* width: 80%; */
  75. margin:auto;
  76. text-indent: 25px;
  77. color: #1c388c;
  78. font-size: 14px;
  79. padding-bottom:10px;
  80. }
  81. </style>
  82. <body>
  83. <div id="app">
  84. <div class="item-main">
  85. <!-- <img src="static/survey_logo.png" alt="" class="survey_logo" /> -->
  86. <h5 align="center" class="tpl_title">{{ title }}</h5>
  87. <div class="message_desc">{{messageData.desc}}</div>
  88. <el-form ref="form2" :model="form2" class="tpl_form over_y" :rules="rules1.rules" v-if="this.form2.status==1">
  89. <el-form-item v-for="(item, index) in widgetList" :key="index" :label="(index+1)+'、'+(item.label)+item.cntype"
  90. :prop="item.label">
  91. <el-input v-if="item.type == 'input'" v-model="form2[item.label]" :placeholder="item.placeholder"></el-input>
  92. <el-input v-if="item.type == 'textarea'" type="textarea" v-model="form2[item.label]"
  93. :placeholder="item.placeholder" :rows=4></el-input>
  94. <el-radio-group v-if="item.type == 'radio'" v-model="form2[item.label]" class="cus_select">
  95. <el-radio :label="iitem.label" v-for="(iitem, index) in item.items" :key="index">{{ iitem.label }}
  96. </el-radio>
  97. </el-radio-group>
  98. <el-checkbox-group v-else-if="item.type == 'checkbox'" v-model="form2[item.label]" class="cus_select">
  99. <el-checkbox :label="iitem.label" v-for="(iitem, index) in item.items" :key="index"></el-checkbox>
  100. </el-checkbox-group>
  101. <el-upload v-if="item.type == 'image'" action="/api/admin/uploadfile" list-type="picture-card"
  102. :data="{ type: item.label }" :on-success="handleSuccess">
  103. <i class="el-icon-plus"></i>
  104. </el-upload>
  105. <el-upload v-if="item.type == 'file'" class="upload-demo" ref="upload" action="/api/admin/uploadfile"
  106. :data="{ type: item.label }" :on-success="handleSuccess">
  107. <!-- <el-button slot="trigger" size="small" type="primary">选取文件</el-button> -->
  108. <el-button style="margin-left: 10px" size="small" type="primary" plain>添加文件</el-button>
  109. <!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div> -->
  110. </el-upload>
  111. </el-form-item>
  112. <el-form-item v-if="widgetList.length">
  113. <el-button size="medium" type="primary" @click="saveResult"
  114. style="width: 100%;height: 45px;font-size: 16px;margin-top:20px;" :disabled="form2.status==0">
  115. {{this.form2.status==1?"提交":"该问卷已禁用"}}</el-button>
  116. </el-form-item>
  117. </el-form>
  118. <el-button v-else size="medium" type="primary" style="width: 100%;height: 45px;font-size: 16px;margin-top:20px;" :disabled="form2.status==0">
  119. {{this.form2.status==1?"提交":"该问卷已禁用"}}</el-button>
  120. </div>
  121. </div>
  122. </body>
  123. <!-- import Vue before Element -->
  124. <script src="static/jquery.min.js"></script>
  125. <script src="static/vue.js"></script>
  126. <!-- import JavaScript -->
  127. <script src="static/index.js"></script>
  128. <script>
  129. new Vue({
  130. el: '#app',
  131. data: function () {
  132. return {
  133. messageData:{},
  134. rules1: {
  135. rules: {},
  136. },
  137. type: null,
  138. form2: {},
  139. widgetList: [],
  140. id: '',
  141. title: '',
  142. show: 0
  143. }
  144. },
  145. methods: {
  146. getData() {
  147. let url = "/api/admin/message"
  148. if (this.type == 1) {
  149. url = "/api/admin/message/out"
  150. }
  151. $.ajax({
  152. url: url,
  153. method: 'get',
  154. data: {
  155. id: this.id
  156. },
  157. success: res => {
  158. document.getElementById('app').style.display = 'block'
  159. this.form2.status = res.data.status
  160. let widgetList = res.data.widget;
  161. this.messageData = res.data;
  162. let rules1 = {};
  163. for (let i = 0; i < widgetList.length; i++) {
  164. if (widgetList[i].type == 'checkbox') {
  165. let key = widgetList[i].label
  166. this.$set(this.form2, key, [])
  167. }
  168. //组装rules
  169. var item = widgetList[i];
  170. if (item.type == "input" && item.require) {
  171. rules1[item.label] = [
  172. { required: true, message: item.placeholder, trigger: "blur" },
  173. ];
  174. }
  175. if (item.type == "textarea" && item.require) {
  176. rules1[item.label] = [
  177. { required: true, message: item.placeholder, trigger: "blur" },
  178. ];
  179. }
  180. if (item.type == "radio" && item.require) {
  181. rules1[item.label] = [
  182. { required: true, message: item.placeholder, trigger: "change" },
  183. ];
  184. }
  185. if (item.type == "checkbox" && item.require) {
  186. rules1[item.label] = [
  187. { required: true, message: item.placeholder, trigger: "change" },
  188. ];
  189. }
  190. }
  191. this.$set(this.rules1, "rules", rules1);
  192. this.title = res.data.name
  193. this.widgetList = widgetList
  194. },
  195. error: res => {
  196. if (res.status == 403) {
  197. window.location.href = "/survey/login.html?id=" + this.id + "&type=" + this.type
  198. }
  199. }
  200. })
  201. },
  202. saveResult() {
  203. let url = "/api/admin/message/survey/result"
  204. if (this.type == 1) {
  205. url = "/api/admin/message/survey/result/out"
  206. }
  207. this.$refs["form2"].validate((valid) => {
  208. if (valid) {
  209. let result = JSON.stringify(this.form2);
  210. $.ajax({
  211. url: url,
  212. method: 'post',
  213. data: {
  214. message_id: this.id,
  215. result: result,
  216. },
  217. success: res => {
  218. if (res.code == 0) {
  219. // this.$alert('提交成功', "提交成功", {
  220. // center: true,
  221. // showClose: false,
  222. // confirmButtonText: '确定',
  223. // type: "success"
  224. // });
  225. window.location.href = "/survey/success.html?title=" + encodeURIComponent(res.data)
  226. } else {
  227. this.$alert("提交失败请稍后再试!", "提交失败", {
  228. center: true,
  229. showClose: false,
  230. confirmButtonText: '确定',
  231. type: "error"
  232. });
  233. }
  234. }
  235. })
  236. }else{
  237. this.$alert("有必填项没有填写!", "提交失败", {
  238. center: true,
  239. showClose: false,
  240. confirmButtonText: '确定',
  241. type: "error"
  242. });
  243. }
  244. });
  245. },
  246. handleSuccess(res, file) {
  247. this.form2[res.data.type] = res.data.url;
  248. },
  249. },
  250. created() {
  251. var search = window.location.search.split('?')[1].split('&');
  252. this.id = search[0].split('=')[1]
  253. this.type = search[1].split('=')[1]
  254. this.getData()
  255. }
  256. })
  257. </script>
  258. </html>