answer.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  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 {
  31. padding: 10px 20px;
  32. border:1px solid #ccc;
  33. border-radius: 5px;
  34. margin-bottom:10px!important;
  35. }
  36. .el-form-item__content {
  37. line-height: 1;
  38. }
  39. .el-form-item__label {
  40. float: none;
  41. font-weight: 600;
  42. display: block;
  43. line-height: 20px;
  44. margin-bottom: 10px;
  45. text-align: left;
  46. }
  47. .el-radio {
  48. width: 93% !important;
  49. }
  50. .el-radio:not(:last-child) {
  51. margin-bottom: 10px;
  52. }
  53. .el-radio__label {
  54. font-size: 14px;
  55. padding-left: 10px;
  56. line-height: 20px !important;
  57. white-space: normal;
  58. display: inline-block !important;
  59. vertical-align: top;
  60. }
  61. .el-checkbox-group {
  62. display: flex;
  63. flex-direction: column;
  64. }
  65. .el-checkbox__label {
  66. font-size: 14px;
  67. padding-left: 10px;
  68. line-height: 20px !important;
  69. white-space: normal;
  70. display: inline-block !important;
  71. vertical-align: top;
  72. }
  73. .el-checkbox {
  74. width: 93% !important;
  75. }
  76. .el-checkbox:not(:last-child) {
  77. margin-bottom: 10px !important;
  78. }
  79. .message_desc {
  80. /* width: 80%; */
  81. margin: auto;
  82. text-indent: 25px;
  83. color: #1c388c;
  84. font-size: 14px;
  85. padding-bottom: 10px;
  86. }
  87. /*批注信息*/
  88. .tool_text {
  89. width: 315px;
  90. }
  91. .tool_text p {
  92. margin-bottom: 10px;
  93. }
  94. .toolText_img img {
  95. width: 100px;
  96. height: 100px;
  97. margin-bottom: 5px
  98. }
  99. .toolText_img img:nth-child(odd) {
  100. margin-right: 5px;
  101. }
  102. .group_title {
  103. font-size: 16px;
  104. font-weight: bold;
  105. padding: 10px 20px;
  106. margin:0px;
  107. }
  108. .groupMain {
  109. border: 1px solid #ccc;
  110. border-radius: 5px;
  111. margin-bottom:10px;
  112. }
  113. .groupMain .el-form-item{
  114. border:0px;
  115. }
  116. .el-message-box{
  117. width: 315px!important;
  118. }
  119. </style>
  120. <body>
  121. <div id="app">
  122. <div class="item-main">
  123. <!-- <img src="static/survey_logo.png" alt="" class="survey_logo" /> -->
  124. <h5 align="center" class="tpl_title">{{ title }}</h5>
  125. <div class="message_desc">{{messageData.desc}}</div>
  126. <el-form ref="form2" :model="form2" class="tpl_form over_y" :rules="rules1.rules" v-if="this.form2.status==1">
  127. <template v-for="(item, index) in widgetList">
  128. <el-form-item :key="index" :label="(index+1)+'、'+(item.label)+item.cntype" :prop="item.label"
  129. v-if="item.type != 'group'">
  130. <span style="color:#409eff;font-size:12px;">{{item.noteDesc}}</span>
  131. <el-tooltip class="item" effect="dark" content="Left Bottom 提示文字" placement="bottom-end">
  132. <i v-if="item.noteDesc||item.noteImgs" class="el-icon-info"
  133. style="position: absolute; top: -28px; right: 0px"></i>
  134. <div slot="content" class='tool_text'>
  135. <p>{{item.noteDesc}}</p>
  136. <div class='toolText_img'>
  137. <img :src="item" alt="" v-for="(item,index) in item.noteImgs" :key="index" />
  138. </div>
  139. </div>
  140. </el-tooltip>
  141. <el-input v-if="item.type == 'input'" v-model="form2[item.label]" :placeholder="item.placeholder">
  142. </el-input>
  143. <el-input v-if="item.type == 'textarea'" type="textarea" v-model="form2[item.label]"
  144. :placeholder="item.placeholder" :rows=4></el-input>
  145. <el-radio-group v-if="item.type == 'radio'" v-model="form2[item.label]" class="cus_select">
  146. <el-radio :label="iitem.label" v-for="(iitem, index) in item.items" :key="index">{{ iitem.label }}
  147. </el-radio>
  148. </el-radio-group>
  149. <el-checkbox-group v-else-if="item.type == 'checkbox'" v-model="form2[item.label]" class="cus_select">
  150. <el-checkbox :label="iitem.label" v-for="(iitem, index) in item.items" :key="index"></el-checkbox>
  151. </el-checkbox-group>
  152. <el-upload v-if="item.type == 'image'" action="/api/admin/uploadfile" list-type="picture-card"
  153. :data="{ type: item.label }"
  154. :on-success="(value)=> imageChange(item.label, value)"
  155. :on-remove="(file,filelist)=> handleRemove(item.label, file,filelist)"
  156. >
  157. <i class="el-icon-plus"></i>
  158. </el-upload>
  159. <el-upload v-if="item.type == 'file'" class="upload-demo" ref="upload" action="/api/admin/uploadfile"
  160. :data="{ type: item.label }"
  161. :on-success="(value)=> imageChange(item.label, value)"
  162. :on-remove="(file,filelist)=> handleRemove(item.label, file,filelist)">
  163. <!-- <el-button slot="trigger" size="small" type="primary">选取文件</el-button> -->
  164. <el-button style="margin-left: 10px" size="small" type="primary" plain>添加文件</el-button>
  165. <!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div> -->
  166. </el-upload>
  167. </el-form-item>
  168. <!-- 域组件展示 -->
  169. <h6 v-if="item.type == 'group'" align="center" class="group_title" :key="'revire_g' + index">
  170. {{ item.label }}
  171. </h6>
  172. <section class="groupMain" v-if="item.type == 'group'" :key="'review_gi' + index">
  173. <template v-for="(iitem, index) in item.children">
  174. <el-form-item :prop="iitem.label + '(' + item.label + ')'" :key="'review_gc' + index"
  175. :label="iitem.label + iitem.cntype">
  176. <span style="color:#409eff;font-size:12px;">{{iitem.noteDesc}}</span>
  177. <el-tooltip class="item" effect="dark" content="Left Bottom 提示文字" placement="bottom-end">
  178. <i v-if="iitem.noteDesc || iitem.noteImgs" class="el-icon-info"
  179. style="position: absolute; top: -28px; right: 0px"></i>
  180. <div slot="content" class="tool_text">
  181. <p>{{ iitem.noteDesc }}</p>
  182. <div class="toolText_img">
  183. <img :src="iitem" alt="" v-for="(iitem, index) in iitem.noteImgs"
  184. :key="'review_gc_noteimgs' + index" />
  185. </div>
  186. </div>
  187. </el-tooltip>
  188. <el-input :class="iitem.require ? 'require' : ''" v-if="iitem.type == 'input'"
  189. v-model="form2[iitem.label + '(' + item.label + ')']" :placeholder="iitem.placeholder"></el-input>
  190. <el-input :class="iitem.require ? 'require' : ''" v-if="iitem.type == 'textarea'" type="textarea"
  191. v-model="form2[iitem.label + '(' + item.label + ')']" :placeholder="iitem.placeholder"></el-input>
  192. <el-radio-group class="cus_select" v-if="iitem.type == 'radio'"
  193. v-model="form2[iitem.label + '(' + item.label + ')']" :class="iitem.require ? 'require' : ''">
  194. <el-radio :label="iiitem.label" v-for="(iiitem, index) in iitem.items" :key="'review_gcr' + index">{{
  195. iiitem.label }}</el-radio>
  196. </el-radio-group>
  197. <el-checkbox-group class="cus_select" v-if="iitem.type == 'checkbox'"
  198. v-model="form2[iitem.label + '(' + item.label + ')']" :class="iitem.require ? 'require' : ''">
  199. <el-checkbox :label="iiitem.label" v-for="(iiitem, index) in iitem.items" :key="'review_gcc' + index">
  200. {{ iiitem.label }}</el-checkbox>
  201. </el-checkbox-group>
  202. <el-upload :class="iitem.require ? 'require' : ''" v-if="iitem.type == 'image'"
  203. v-model="form2[iitem.label + '(' + item.label + ')']" action="/api/admin/uploadfile"
  204. list-type="picture-card" :on-preview="handlePreview"
  205. :on-remove="(file,filelist)=> handleRemove(iitem.label + '(' + item.label + ')', file,filelist)"
  206. :on-success="(value)=> imageChange(iitem.label + '(' + item.label + ')', value)"
  207. >
  208. <i class="el-icon-plus"></i>
  209. </el-upload>
  210. <el-upload v-if="iitem.type == 'file'" class="upload-demo" ref="upload" action="/api/admin/uploadfile"
  211. :on-remove="(file,filelist)=> handleRemove(iitem.label + '(' + item.label + ')', file,filelist)"
  212. :on-success="(value)=> imageChange(iitem.label + '(' + item.label + ')', value)"
  213. :file-list="fileList" :auto-upload="false">
  214. <!-- <el-button slot="trigger" size="small" type="primary">选取文件</el-button> -->
  215. <el-button style="margin-left: 10px" size="small" type="primary" plain @click="submitUpload">添加文件
  216. </el-button>
  217. <!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div> -->
  218. </el-upload>
  219. </el-form-item>
  220. </template>
  221. </section>
  222. <!-- 域组件end -->
  223. </template>
  224. <el-form-item v-if="widgetList.length" style="border:0px;">
  225. <el-button size="medium" type="primary" @click="saveResult"
  226. style="width: 100%;height: 45px;font-size: 16px;margin-top:20px;" :disabled="form2.status==0">
  227. {{this.form2.status==1?"提交":"该问卷已禁用"}}</el-button>
  228. </el-form-item>
  229. </el-form>
  230. <el-button v-else size="medium" type="primary" style="width: 100%;height: 45px;font-size: 16px;margin-top:20px;"
  231. :disabled="form2.status==0">
  232. {{this.form2.status==1?"提交":"该问卷已禁用"}}</el-button>
  233. </div>
  234. </div>
  235. </body>
  236. <!-- import Vue before Element -->
  237. <script src="static/jquery.min.js"></script>
  238. <script src="static/vue.js"></script>
  239. <!-- import JavaScript -->
  240. <script src="static/index.js"></script>
  241. <script>
  242. new Vue({
  243. el: '#app',
  244. data: function () {
  245. return {
  246. messageData: {},
  247. rules1: {
  248. rules: {},
  249. },
  250. type: null,
  251. form2: {},
  252. widgetList: [],
  253. id: '',
  254. title: '',
  255. show: 0
  256. }
  257. },
  258. methods: {
  259. handlePreview() { },
  260. handleRemove(label,file,filelist){
  261. let imgs=[];
  262. for(let i=0;i<filelist.length;i++){
  263. imgs.push(filelist[i].response.data)
  264. }
  265. this.form2[label]=imgs
  266. },
  267. imageChange(label,data){
  268. this.form2[label].push(data.data)
  269. },
  270. getData() {
  271. let url = "/api/admin/message"
  272. if (this.type == 1) {
  273. url = "/api/admin/message/out"
  274. }
  275. $.ajax({
  276. url: url,
  277. method: 'get',
  278. data: {
  279. id: this.id
  280. },
  281. success: res => {
  282. document.getElementById('app').style.display = 'block'
  283. this.form2.status = res.data.status
  284. let widgetList = res.data.widget;
  285. this.messageData = res.data;
  286. let rules1 = {};
  287. let _this = this;
  288. widgetList.forEach((i) => {
  289. if (i.type == "checkbox"||i.type == "image") {
  290. // _this.form2[i.label] = [] ;
  291. _this.$set(_this.form2, i.label, []);
  292. }
  293. //组装rules
  294. if (i.type == "input" && i.require) {
  295. rules1[i.label] = [
  296. { required: true, message: i.placeholder, trigger: "blur" },
  297. ];
  298. }
  299. if (i.type == "textarea" && i.require) {
  300. rules1[i.label] = [
  301. { required: true, message: i.placeholder, trigger: "blur" },
  302. ];
  303. }
  304. if (i.type == "radio" && i.require) {
  305. rules1[i.label] = [
  306. { required: true, message: i.placeholder, trigger: "change" },
  307. ];
  308. }
  309. if (i.type == "checkbox" && i.require) {
  310. rules1[i.label] = [
  311. { required: true, message: i.placeholder, trigger: "change" },
  312. ];
  313. }
  314. if (i.type == "image" && i.require) {
  315. rules1[i.label] = [
  316. { required: true, message: i.placeholder, trigger: "change" },
  317. ];
  318. }
  319. // 域组件rules
  320. if (i.type == "group") {
  321. i.children.forEach((item) => {
  322. if (item.type == "input" && item.require) {
  323. rules1[item.label + "(" + i.label + ")"] = [
  324. {
  325. required: true,
  326. message: item.placeholder,
  327. trigger: "blur",
  328. },
  329. ];
  330. }
  331. if (item.type == "textarea" && item.require) {
  332. rules1[item.label + "(" + i.label + ")"] = [
  333. {
  334. required: true,
  335. message: item.placeholder,
  336. trigger: "blur",
  337. },
  338. ];
  339. }
  340. if (item.type == "radio" && item.require) {
  341. rules1[item.label + "(" + i.label + ")"] = [
  342. {
  343. required: true,
  344. message: item.placeholder,
  345. trigger: "change",
  346. },
  347. ];
  348. }
  349. if (item.type == "checkbox" && item.require) {
  350. _this.$set(_this.form2, item.label + "(" + i.label + ")", []);
  351. rules1[item.label + "(" + i.label + ")"] = [
  352. {
  353. required: true,
  354. message: item.placeholder,
  355. trigger: "change",
  356. },
  357. ];
  358. }
  359. if (item.type == "image" && item.require) {
  360. _this.$set(_this.form2, item.label+'('+i.label+')', []);
  361. rules1[item.label + "(" + i.label + ")"] = [
  362. {
  363. required: true,
  364. message: item.placeholder,
  365. trigger: "change",
  366. },
  367. ];
  368. }
  369. });
  370. }
  371. });
  372. this.$set(this.rules1, "rules", rules1);
  373. this.title = res.data.name
  374. this.widgetList = widgetList
  375. },
  376. error: res => {
  377. if (res.status == 403) {
  378. window.location.href = "/survey/login.html?id=" + this.id + "&type=" + this.type
  379. }
  380. }
  381. })
  382. },
  383. saveResult() {
  384. let url = "/api/admin/message/survey/result"
  385. if (this.type == 1) {
  386. url = "/api/admin/message/survey/result/out"
  387. }
  388. this.$refs["form2"].validate((valid) => {
  389. if (valid) {
  390. let result = JSON.stringify(this.form2);
  391. $.ajax({
  392. url: url,
  393. method: 'post',
  394. data: {
  395. message_id: this.id,
  396. result: result,
  397. },
  398. success: res => {
  399. if (res.code == 0) {
  400. // this.$alert('提交成功', "提交成功", {
  401. // center: true,
  402. // showClose: false,
  403. // confirmButtonText: '确定',
  404. // type: "success"
  405. // });
  406. window.location.href = "/survey/success.html?title=" + encodeURIComponent(res.data)
  407. } else {
  408. this.$alert("提交失败请稍后再试!", "提交失败", {
  409. center: true,
  410. showClose: false,
  411. confirmButtonText: '确定',
  412. type: "error"
  413. });
  414. }
  415. }
  416. })
  417. } else {
  418. this.$alert("有必填项没有填写!", "提交失败", {
  419. center: true,
  420. showClose: false,
  421. confirmButtonText: '确定',
  422. type: "error"
  423. });
  424. }
  425. });
  426. },
  427. handleSuccess(res, file) {
  428. this.form2[res.data.type] = res.data.url;
  429. },
  430. },
  431. created() {
  432. var search = window.location.search.split('?')[1].split('&');
  433. this.id = search[0].split('=')[1]
  434. this.type = search[1].split('=')[1]
  435. this.getData()
  436. }
  437. })
  438. </script>
  439. </html>