answer.html 16 KB

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