answer.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  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 0px;
  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. <el-tooltip class="item" effect="dark" content="Left Bottom 提示文字" placement="bottom-end">
  131. <i v-if="item.noteDesc||item.noteImgs" class="el-icon-info"
  132. style="position: absolute; top: -28px; right: 0px"></i>
  133. <div slot="content" class='tool_text'>
  134. <p>{{item.noteDesc}}</p>
  135. <div class='toolText_img'>
  136. <img :src="item" alt="" v-for="(item,index) in item.noteImgs" :key="index" />
  137. </div>
  138. </div>
  139. </el-tooltip>
  140. <el-input v-if="item.type == 'input'" v-model="form2[item.label]" :placeholder="item.placeholder">
  141. </el-input>
  142. <el-input v-if="item.type == 'textarea'" type="textarea" v-model="form2[item.label]"
  143. :placeholder="item.placeholder" :rows=4></el-input>
  144. <el-radio-group v-if="item.type == 'radio'" v-model="form2[item.label]" class="cus_select">
  145. <el-radio :label="iitem.label" v-for="(iitem, index) in item.items" :key="index">{{ iitem.label }}
  146. </el-radio>
  147. </el-radio-group>
  148. <el-checkbox-group v-else-if="item.type == 'checkbox'" v-model="form2[item.label]" class="cus_select">
  149. <el-checkbox :label="iitem.label" v-for="(iitem, index) in item.items" :key="index"></el-checkbox>
  150. </el-checkbox-group>
  151. <el-upload v-if="item.type == 'image'" action="/api/admin/uploadfile" list-type="picture-card"
  152. :data="{ type: item.label }"
  153. :on-success="(value)=> imageChange(item.label, value)"
  154. :on-remove="(file,filelist)=> handleRemove(item.label, file,filelist)"
  155. >
  156. <i class="el-icon-plus"></i>
  157. </el-upload>
  158. <el-upload v-if="item.type == 'file'" class="upload-demo" ref="upload" action="/api/admin/uploadfile"
  159. :data="{ type: item.label }"
  160. :on-success="(value)=> imageChange(item.label, value)"
  161. :on-remove="(file,filelist)=> handleRemove(item.label, file,filelist)">
  162. <!-- <el-button slot="trigger" size="small" type="primary">选取文件</el-button> -->
  163. <el-button style="margin-left: 10px" size="small" type="primary" plain>添加文件</el-button>
  164. <!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div> -->
  165. </el-upload>
  166. </el-form-item>
  167. <!-- 域组件展示 -->
  168. <h6 v-if="item.type == 'group'" align="center" class="group_title" :key="'revire_g' + index">
  169. {{ item.label }}
  170. </h6>
  171. <section class="groupMain" v-if="item.type == 'group'" :key="'review_gi' + index">
  172. <template v-for="(iitem, index) in item.children">
  173. <el-form-item :prop="iitem.label + '(' + item.label + ')'" :key="'review_gc' + index"
  174. :label="iitem.label + iitem.cntype">
  175. <el-tooltip class="item" effect="dark" content="Left Bottom 提示文字" placement="bottom-end">
  176. <i v-if="iitem.noteDesc || iitem.noteImgs" class="el-icon-info"
  177. style="position: absolute; top: -28px; right: 0px"></i>
  178. <div slot="content" class="tool_text">
  179. <p>{{ iitem.noteDesc }}</p>
  180. <div class="toolText_img">
  181. <img :src="iitem" alt="" v-for="(iitem, index) in iitem.noteImgs"
  182. :key="'review_gc_noteimgs' + index" />
  183. </div>
  184. </div>
  185. </el-tooltip>
  186. <el-input :class="iitem.require ? 'require' : ''" v-if="iitem.type == 'input'"
  187. v-model="form2[iitem.label + '(' + item.label + ')']" :placeholder="iitem.placeholder"></el-input>
  188. <el-input :class="iitem.require ? 'require' : ''" v-if="iitem.type == 'textarea'" type="textarea"
  189. v-model="form2[iitem.label + '(' + item.label + ')']" :placeholder="iitem.placeholder"></el-input>
  190. <el-radio-group class="cus_select" v-if="iitem.type == 'radio'"
  191. v-model="form2[iitem.label + '(' + item.label + ')']" :class="iitem.require ? 'require' : ''">
  192. <el-radio :label="iiitem.label" v-for="(iiitem, index) in iitem.items" :key="'review_gcr' + index">{{
  193. iiitem.label }}</el-radio>
  194. </el-radio-group>
  195. <el-checkbox-group class="cus_select" v-if="iitem.type == 'checkbox'"
  196. v-model="form2[iitem.label + '(' + item.label + ')']" :class="iitem.require ? 'require' : ''">
  197. <el-checkbox :label="iiitem.label" v-for="(iiitem, index) in iitem.items" :key="'review_gcc' + index">
  198. {{ iiitem.label }}</el-checkbox>
  199. </el-checkbox-group>
  200. <el-upload :class="iitem.require ? 'require' : ''" v-if="iitem.type == 'image'"
  201. v-model="form2[iitem.label + '(' + item.label + ')']" action="/api/admin/uploadfile"
  202. list-type="picture-card" :on-preview="handlePreview"
  203. :on-remove="(file,filelist)=> handleRemove(iitem.label + '(' + item.label + ')', file,filelist)"
  204. :on-success="(value)=> imageChange(iitem.label + '(' + item.label + ')', value)"
  205. >
  206. <i class="el-icon-plus"></i>
  207. </el-upload>
  208. <el-upload v-if="iitem.type == 'file'" class="upload-demo" ref="upload" action="/api/admin/uploadfile"
  209. :on-remove="(file,filelist)=> handleRemove(iitem.label + '(' + item.label + ')', file,filelist)"
  210. :on-success="(value)=> imageChange(iitem.label + '(' + item.label + ')', value)"
  211. :file-list="fileList" :auto-upload="false">
  212. <!-- <el-button slot="trigger" size="small" type="primary">选取文件</el-button> -->
  213. <el-button style="margin-left: 10px" size="small" type="primary" plain @click="submitUpload">添加文件
  214. </el-button>
  215. <!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div> -->
  216. </el-upload>
  217. </el-form-item>
  218. </template>
  219. </section>
  220. <!-- 域组件end -->
  221. </template>
  222. <el-form-item v-if="widgetList.length" style="border:0px;">
  223. <el-button size="medium" type="primary" @click="saveResult"
  224. style="width: 100%;height: 45px;font-size: 16px;margin-top:20px;" :disabled="form2.status==0">
  225. {{this.form2.status==1?"提交":"该问卷已禁用"}}</el-button>
  226. </el-form-item>
  227. </el-form>
  228. <el-button v-else size="medium" type="primary" style="width: 100%;height: 45px;font-size: 16px;margin-top:20px;"
  229. :disabled="form2.status==0">
  230. {{this.form2.status==1?"提交":"该问卷已禁用"}}</el-button>
  231. </div>
  232. </div>
  233. </body>
  234. <!-- import Vue before Element -->
  235. <script src="static/jquery.min.js"></script>
  236. <script src="static/vue.js"></script>
  237. <!-- import JavaScript -->
  238. <script src="static/index.js"></script>
  239. <script>
  240. new Vue({
  241. el: '#app',
  242. data: function () {
  243. return {
  244. messageData: {},
  245. rules1: {
  246. rules: {},
  247. },
  248. type: null,
  249. form2: {},
  250. widgetList: [],
  251. id: '',
  252. title: '',
  253. show: 0
  254. }
  255. },
  256. methods: {
  257. handlePreview() { },
  258. handleRemove(label,file,filelist){
  259. let imgs=[];
  260. for(let i=0;i<filelist.length;i++){
  261. imgs.push(filelist[i].response.data)
  262. }
  263. this.form2[label]=imgs
  264. },
  265. imageChange(label,data){
  266. this.form2[label].push(data.data)
  267. },
  268. getData() {
  269. let url = "/api/admin/message"
  270. if (this.type == 1) {
  271. url = "/api/admin/message/out"
  272. }
  273. $.ajax({
  274. url: url,
  275. method: 'get',
  276. data: {
  277. id: this.id
  278. },
  279. success: res => {
  280. document.getElementById('app').style.display = 'block'
  281. this.form2.status = res.data.status
  282. let widgetList = res.data.widget;
  283. this.messageData = res.data;
  284. let rules1 = {};
  285. let _this = this;
  286. widgetList.forEach((i) => {
  287. if (i.type == "checkbox"||i.type == "image") {
  288. // _this.form2[i.label] = [] ;
  289. _this.$set(_this.form2, i.label, []);
  290. }
  291. //组装rules
  292. if (i.type == "input" && i.require) {
  293. rules1[i.label] = [
  294. { required: true, message: i.placeholder, trigger: "blur" },
  295. ];
  296. }
  297. if (i.type == "textarea" && i.require) {
  298. rules1[i.label] = [
  299. { required: true, message: i.placeholder, trigger: "blur" },
  300. ];
  301. }
  302. if (i.type == "radio" && i.require) {
  303. rules1[i.label] = [
  304. { required: true, message: i.placeholder, trigger: "change" },
  305. ];
  306. }
  307. if (i.type == "checkbox" && i.require) {
  308. rules1[i.label] = [
  309. { required: true, message: i.placeholder, trigger: "change" },
  310. ];
  311. }
  312. if (i.type == "image" && i.require) {
  313. rules1[i.label] = [
  314. { required: true, message: i.placeholder, trigger: "change" },
  315. ];
  316. }
  317. // 域组件rules
  318. if (i.type == "group") {
  319. i.children.forEach((item) => {
  320. if (item.type == "input" && item.require) {
  321. rules1[item.label + "(" + i.label + ")"] = [
  322. {
  323. required: true,
  324. message: item.placeholder,
  325. trigger: "blur",
  326. },
  327. ];
  328. }
  329. if (item.type == "textarea" && item.require) {
  330. rules1[item.label + "(" + i.label + ")"] = [
  331. {
  332. required: true,
  333. message: item.placeholder,
  334. trigger: "blur",
  335. },
  336. ];
  337. }
  338. if (item.type == "radio" && item.require) {
  339. rules1[item.label + "(" + i.label + ")"] = [
  340. {
  341. required: true,
  342. message: item.placeholder,
  343. trigger: "change",
  344. },
  345. ];
  346. }
  347. if (item.type == "checkbox" && item.require) {
  348. _this.$set(_this.form2, item.label + "(" + i.label + ")", []);
  349. rules1[item.label + "(" + i.label + ")"] = [
  350. {
  351. required: true,
  352. message: item.placeholder,
  353. trigger: "change",
  354. },
  355. ];
  356. }
  357. if (item.type == "image" && item.require) {
  358. _this.$set(_this.form2, item.label+'('+i.label+')', []);
  359. rules1[item.label + "(" + i.label + ")"] = [
  360. {
  361. required: true,
  362. message: item.placeholder,
  363. trigger: "change",
  364. },
  365. ];
  366. }
  367. });
  368. }
  369. });
  370. this.$set(this.rules1, "rules", rules1);
  371. this.title = res.data.name
  372. this.widgetList = widgetList
  373. },
  374. error: res => {
  375. if (res.status == 403) {
  376. window.location.href = "/survey/login.html?id=" + this.id + "&type=" + this.type
  377. }
  378. }
  379. })
  380. },
  381. saveResult() {
  382. let url = "/api/admin/message/survey/result"
  383. if (this.type == 1) {
  384. url = "/api/admin/message/survey/result/out"
  385. }
  386. this.$refs["form2"].validate((valid) => {
  387. if (valid) {
  388. let result = JSON.stringify(this.form2);
  389. $.ajax({
  390. url: url,
  391. method: 'post',
  392. data: {
  393. message_id: this.id,
  394. result: result,
  395. },
  396. success: res => {
  397. if (res.code == 0) {
  398. // this.$alert('提交成功', "提交成功", {
  399. // center: true,
  400. // showClose: false,
  401. // confirmButtonText: '确定',
  402. // type: "success"
  403. // });
  404. window.location.href = "/survey/success.html?title=" + encodeURIComponent(res.data)
  405. } else {
  406. this.$alert("提交失败请稍后再试!", "提交失败", {
  407. center: true,
  408. showClose: false,
  409. confirmButtonText: '确定',
  410. type: "error"
  411. });
  412. }
  413. }
  414. })
  415. } else {
  416. this.$alert("有必填项没有填写!", "提交失败", {
  417. center: true,
  418. showClose: false,
  419. confirmButtonText: '确定',
  420. type: "error"
  421. });
  422. }
  423. });
  424. },
  425. handleSuccess(res, file) {
  426. this.form2[res.data.type] = res.data.url;
  427. },
  428. },
  429. created() {
  430. var search = window.location.search.split('?')[1].split('&');
  431. this.id = search[0].split('=')[1]
  432. this.type = search[1].split('=')[1]
  433. this.getData()
  434. }
  435. })
  436. </script>
  437. </html>