answer.html 17 KB

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