answer.html 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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. /*批注信息*/
  82. .tool_text{
  83. width:205px;
  84. }
  85. .tool_text p{
  86. margin-bottom:10px;
  87. }
  88. .toolText_img img{
  89. width:100px;
  90. margin-bottom:5px
  91. }
  92. .toolText_img img:nth-child(odd){
  93. margin-right: 5px;
  94. }
  95. </style>
  96. <body>
  97. <div id="app">
  98. <div class="item-main">
  99. <!-- <img src="static/survey_logo.png" alt="" class="survey_logo" /> -->
  100. <h5 align="center" class="tpl_title">{{ title }}</h5>
  101. <div class="message_desc">{{messageData.desc}}</div>
  102. <el-form ref="form2" :model="form2" class="tpl_form over_y" :rules="rules1.rules" v-if="this.form2.status==1">
  103. <el-form-item v-for="(item, index) in widgetList" :key="index" :label="(index+1)+'、'+(item.label)+item.cntype"
  104. :prop="item.label">
  105. <el-tooltip class="item" effect="dark" content="Left Bottom 提示文字" placement="bottom-end">
  106. <i v-if="item.noteDesc||item.noteImgs"
  107. class="el-icon-info"
  108. style="position: absolute; top: -28px; right: 0px"
  109. ></i>
  110. <div slot="content" class='tool_text'>
  111. <p>{{item.noteDesc}}</p>
  112. <div class='toolText_img'>
  113. <img :src="item" alt="" v-for="(item,index) in item.noteImgs" :key="index" />
  114. </div>
  115. </div>
  116. </el-tooltip>
  117. <el-input v-if="item.type == 'input'" v-model="form2[item.label]" :placeholder="item.placeholder"></el-input>
  118. <el-input v-if="item.type == 'textarea'" type="textarea" v-model="form2[item.label]"
  119. :placeholder="item.placeholder" :rows=4></el-input>
  120. <el-radio-group v-if="item.type == 'radio'" v-model="form2[item.label]" class="cus_select">
  121. <el-radio :label="iitem.label" v-for="(iitem, index) in item.items" :key="index">{{ iitem.label }}
  122. </el-radio>
  123. </el-radio-group>
  124. <el-checkbox-group v-else-if="item.type == 'checkbox'" v-model="form2[item.label]" class="cus_select">
  125. <el-checkbox :label="iitem.label" v-for="(iitem, index) in item.items" :key="index"></el-checkbox>
  126. </el-checkbox-group>
  127. <el-upload v-if="item.type == 'image'" action="/api/admin/uploadfile" list-type="picture-card"
  128. :data="{ type: item.label }" :on-success="handleSuccess">
  129. <i class="el-icon-plus"></i>
  130. </el-upload>
  131. <el-upload v-if="item.type == 'file'" class="upload-demo" ref="upload" action="/api/admin/uploadfile"
  132. :data="{ type: item.label }" :on-success="handleSuccess">
  133. <!-- <el-button slot="trigger" size="small" type="primary">选取文件</el-button> -->
  134. <el-button style="margin-left: 10px" size="small" type="primary" plain>添加文件</el-button>
  135. <!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div> -->
  136. </el-upload>
  137. </el-form-item>
  138. <el-form-item v-if="widgetList.length">
  139. <el-button size="medium" type="primary" @click="saveResult"
  140. style="width: 100%;height: 45px;font-size: 16px;margin-top:20px;" :disabled="form2.status==0">
  141. {{this.form2.status==1?"提交":"该问卷已禁用"}}</el-button>
  142. </el-form-item>
  143. </el-form>
  144. <el-button v-else size="medium" type="primary" style="width: 100%;height: 45px;font-size: 16px;margin-top:20px;"
  145. :disabled="form2.status==0">
  146. {{this.form2.status==1?"提交":"该问卷已禁用"}}</el-button>
  147. </div>
  148. </div>
  149. </body>
  150. <!-- import Vue before Element -->
  151. <script src="static/jquery.min.js"></script>
  152. <script src="static/vue.js"></script>
  153. <!-- import JavaScript -->
  154. <script src="static/index.js"></script>
  155. <script>
  156. new Vue({
  157. el: '#app',
  158. data: function () {
  159. return {
  160. messageData: {},
  161. rules1: {
  162. rules: {},
  163. },
  164. type: null,
  165. form2: {},
  166. widgetList: [],
  167. id: '',
  168. title: '',
  169. show: 0
  170. }
  171. },
  172. methods: {
  173. getData() {
  174. let url = "/api/admin/message"
  175. if (this.type == 1) {
  176. url = "/api/admin/message/out"
  177. }
  178. $.ajax({
  179. url: url,
  180. method: 'get',
  181. data: {
  182. id: this.id
  183. },
  184. success: res => {
  185. document.getElementById('app').style.display = 'block'
  186. this.form2.status = res.data.status
  187. let widgetList = res.data.widget;
  188. this.messageData = res.data;
  189. let rules1 = {};
  190. for (let i = 0; i < widgetList.length; i++) {
  191. if (widgetList[i].type == 'checkbox') {
  192. let key = widgetList[i].label
  193. this.$set(this.form2, key, [])
  194. }
  195. //组装rules
  196. var item = widgetList[i];
  197. if (item.type == "input" && item.require) {
  198. rules1[item.label] = [
  199. { required: true, message: item.placeholder, trigger: "blur" },
  200. ];
  201. }
  202. if (item.type == "textarea" && item.require) {
  203. rules1[item.label] = [
  204. { required: true, message: item.placeholder, trigger: "blur" },
  205. ];
  206. }
  207. if (item.type == "radio" && item.require) {
  208. rules1[item.label] = [
  209. { required: true, message: item.placeholder, trigger: "change" },
  210. ];
  211. }
  212. if (item.type == "checkbox" && item.require) {
  213. rules1[item.label] = [
  214. { required: true, message: item.placeholder, trigger: "change" },
  215. ];
  216. }
  217. }
  218. this.$set(this.rules1, "rules", rules1);
  219. this.title = res.data.name
  220. this.widgetList = widgetList
  221. },
  222. error: res => {
  223. if (res.status == 403) {
  224. window.location.href = "/survey/login.html?id=" + this.id + "&type=" + this.type
  225. }
  226. }
  227. })
  228. },
  229. saveResult() {
  230. let url = "/api/admin/message/survey/result"
  231. if (this.type == 1) {
  232. url = "/api/admin/message/survey/result/out"
  233. }
  234. this.$refs["form2"].validate((valid) => {
  235. if (valid) {
  236. let result = JSON.stringify(this.form2);
  237. $.ajax({
  238. url: url,
  239. method: 'post',
  240. data: {
  241. message_id: this.id,
  242. result: result,
  243. },
  244. success: res => {
  245. if (res.code == 0) {
  246. // this.$alert('提交成功', "提交成功", {
  247. // center: true,
  248. // showClose: false,
  249. // confirmButtonText: '确定',
  250. // type: "success"
  251. // });
  252. window.location.href = "/survey/success.html?title=" + encodeURIComponent(res.data)
  253. } else {
  254. this.$alert("提交失败请稍后再试!", "提交失败", {
  255. center: true,
  256. showClose: false,
  257. confirmButtonText: '确定',
  258. type: "error"
  259. });
  260. }
  261. }
  262. })
  263. } else {
  264. this.$alert("有必填项没有填写!", "提交失败", {
  265. center: true,
  266. showClose: false,
  267. confirmButtonText: '确定',
  268. type: "error"
  269. });
  270. }
  271. });
  272. },
  273. handleSuccess(res, file) {
  274. this.form2[res.data.type] = res.data.url;
  275. },
  276. },
  277. created() {
  278. var search = window.location.search.split('?')[1].split('&');
  279. this.id = search[0].split('=')[1]
  280. this.type = search[1].split('=')[1]
  281. this.getData()
  282. }
  283. })
  284. </script>
  285. </html>