askList.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <template>
  2. <div class="pb_content">
  3. <div class="pb_head">
  4. <span>问卷调查</span>
  5. </div>
  6. <div class="pb_content_body">
  7. <div class="cd_bread">
  8. <el-breadcrumb separator-class="el-icon-arrow-right">
  9. <el-breadcrumb-item :to="{ path: '/ask?userid='+ userid }"
  10. >问卷调查</el-breadcrumb-item
  11. >
  12. <el-breadcrumb-item>查看已经提交的问卷</el-breadcrumb-item>
  13. </el-breadcrumb>
  14. </div>
  15. <div class="student_table">
  16. <el-table
  17. ref="table"
  18. :data="tableData"
  19. border
  20. stripe
  21. :height="tableHeight"
  22. :fit="true"
  23. v-loading="isLoading"
  24. style="width: 100%; height: 60%"
  25. :header-cell-style="{ background: '#f1f1f1' }"
  26. >
  27. <el-table-column
  28. prop="title"
  29. label="问卷调查标题"
  30. min-width="25"
  31. align="center"
  32. >
  33. </el-table-column>
  34. <el-table-column
  35. prop="name"
  36. label="提交者"
  37. min-width="25"
  38. align="center"
  39. >
  40. </el-table-column>
  41. <el-table-column
  42. prop="time"
  43. label="提交时间"
  44. min-width="25"
  45. align="center"
  46. >
  47. </el-table-column>
  48. <el-table-column label="操作" min-width="25">
  49. <template slot-scope="scope">
  50. <el-button @click="getAskList(scope.row)" type="text" size="small"
  51. >查看</el-button
  52. >
  53. <el-button
  54. @click="deleteAsk(scope.row.id)"
  55. type="text"
  56. size="small"
  57. >删除</el-button
  58. >
  59. </template>
  60. </el-table-column>
  61. </el-table>
  62. </div>
  63. <div class="student_page">
  64. <el-pagination
  65. background
  66. layout="prev, pager, next"
  67. :page-size="10"
  68. :total="total"
  69. @current-change="handleCurrentChange"
  70. >
  71. </el-pagination>
  72. </div>
  73. </div>
  74. <el-dialog
  75. title="查看"
  76. :visible.sync="dialogVisible1"
  77. :append-to-body="true"
  78. width="750px"
  79. :before-close="handleClose"
  80. class="dialog_diy"
  81. >
  82. <div>
  83. <div class="a_add_title">
  84. <!-- <el-input
  85. v-model="askTitle"
  86. placeholder="请输入问卷标题"
  87. style="width: 400px"
  88. ></el-input> -->
  89. <h1>{{ askTitle }}</h1>
  90. </div>
  91. <div class="a_addBox">
  92. <div
  93. class="a_add_box"
  94. v-for="(item, index) in itemCount"
  95. :key="index"
  96. >
  97. <div class="a_add_head">
  98. <div>
  99. <!-- {{ index + 1 + "、" }}
  100. <el-input
  101. class="a_add_head_input"
  102. v-model="askJson[index].askstitle"
  103. placeholder="请输入问卷题目..."
  104. ></el-input> -->
  105. <span>{{ index + 1 + "、" + askJson[index].askstitle }}</span>
  106. </div>
  107. </div>
  108. <div class="a_add_body">
  109. <div class="a_add_input">
  110. <el-radio-group v-model="radio[index]">
  111. <el-radio
  112. :label="checkIndex + 1 + ''"
  113. v-for="(item, checkIndex) in askJson[index].askItem"
  114. style="width: 150px; margin: 10px 10px 0 0"
  115. :key="checkIndex"
  116. disabled
  117. >{{ askJson[index].checkList[checkIndex] }}</el-radio
  118. >
  119. </el-radio-group>
  120. </div>
  121. </div>
  122. </div>
  123. </div>
  124. </div>
  125. <span slot="footer" class="dialog-footer">
  126. <el-button @click="dialogVisible1 = false">关 闭</el-button>
  127. </span>
  128. </el-dialog>
  129. </div>
  130. </template>
  131. <script>
  132. export default {
  133. data() {
  134. return {
  135. tableData: [],
  136. tableHeight: 500,
  137. isLoading: false,
  138. page: 1,
  139. total: 0,
  140. dialogVisible1: false,
  141. itemCount: 1,
  142. askTitle: "",
  143. askJson: [{ askstitle: "", askItem: 1, checkList: [] }],
  144. radio: [],
  145. userid: this.$route.query.userid,
  146. };
  147. },
  148. methods: {
  149. handleClose(done) {
  150. done();
  151. },
  152. goTo(path) {
  153. this.$router.push(path);
  154. },
  155. deleteAsk(id) {
  156. let params = [{ id: id }];
  157. this.$confirm("确定删除此学生的问卷吗?", "提示", {
  158. confirmButtonText: "确定",
  159. cancelButtonText: "取消",
  160. type: "warning",
  161. })
  162. .then(() => {
  163. this.ajax
  164. .post(this.$store.state.api + "deleteAskList", params)
  165. .then((res) => {
  166. this.$message({
  167. message: "删除成功",
  168. type: "success",
  169. });
  170. if (this.page != 1 && this.tableData.length == 1) {
  171. this.page--;
  172. }
  173. this.getAsk();
  174. })
  175. .catch((err) => {
  176. this.$message.error("删除失败");
  177. console.error(err);
  178. });
  179. })
  180. .catch(() => {});
  181. },
  182. handleCurrentChange(val) {
  183. this.page = val;
  184. this.getAsk();
  185. },
  186. //获取
  187. getAsk() {
  188. this.isLoading = true;
  189. let params = {
  190. uid: this.userid,
  191. page: this.page,
  192. };
  193. this.ajax
  194. .get(this.$store.state.api + "getAskList", params)
  195. .then((res) => {
  196. this.isLoading = false;
  197. this.total = res.data[0].length > 0 ? res.data[0][0].num : 0;
  198. this.tableData = res.data[0];
  199. })
  200. .catch((err) => {
  201. this.dialogVisible = false;
  202. console.error(err);
  203. });
  204. },
  205. getAskList(res) {
  206. this.askTitle = res.title;
  207. this.askJson = JSON.parse(res.askContent);
  208. this.radio = res.content.split(",");
  209. this.itemCount = this.askJson.length;
  210. this.dialogVisible1 = true;
  211. },
  212. changeHeight() {
  213. this.tableHeight =
  214. window.innerHeight - this.$refs.table.$el.offsetTop - 200;
  215. if (this.tableHeight <= 530) {
  216. this.tableHeight = 530;
  217. }
  218. // 监听窗口大小变化
  219. let self = this;
  220. window.onresize = function () {
  221. self.tableHeight =
  222. window.innerHeight - self.$refs.table.$el.offsetTop - 200;
  223. if (self.tableHeight <= 530) {
  224. self.tableHeight = 530;
  225. }
  226. };
  227. // this.$refs.table.$el.offsetTop:表格距离浏览器的高度 //200表示你想要调整的表格距离底部的高度(你可以自己随意调整),因为我们一般都有放分页组件的,所以需要给它留一个高度
  228. },
  229. },
  230. created() {
  231. this.$nextTick(function () {
  232. this.page = 1;
  233. this.changeHeight();
  234. this.getAsk();
  235. });
  236. },
  237. };
  238. </script>
  239. <style scoped>
  240. .dialog_diy >>> .el-dialog__header {
  241. background: #3d67bc !important;
  242. padding: 15px 20px;
  243. }
  244. .dialog_diy >>> .el-dialog__title {
  245. color: #fff;
  246. }
  247. .dialog_diy >>> .el-dialog__headerbtn {
  248. top: 19px;
  249. }
  250. .dialog_diy >>> .el-dialog__headerbtn .el-dialog__close {
  251. color: #fff;
  252. }
  253. .dialog_diy >>> .el-dialog__headerbtn .el-dialog__close:hover {
  254. color: #fff;
  255. }
  256. .dialog_diy >>> .el-dialog__body {
  257. max-height: 750px;
  258. overflow: auto;
  259. }
  260. .dialog_diy >>> .el-dialog {
  261. background: #fafafa;
  262. }
  263. .cd_bread {
  264. margin: 20px auto;
  265. }
  266. .student_table {
  267. margin: 20px 0;
  268. }
  269. .a_add_title {
  270. }
  271. .a_addBox {
  272. margin: 10px 0;
  273. background: #fff;
  274. padding: 15px;
  275. }
  276. .a_add_box {
  277. border-bottom: 2px solid #eee;
  278. padding-bottom: 10px;
  279. }
  280. .a_add_head {
  281. display: flex;
  282. align-items: center;
  283. justify-content: space-between;
  284. margin: 10px 0;
  285. font-size: 18px;
  286. }
  287. .a_add_head .a_add_head_input {
  288. width: 300px;
  289. }
  290. .a_add_head .a_add_head_div {
  291. display: flex;
  292. align-items: center;
  293. justify-content: space-between;
  294. }
  295. .a_add_body {
  296. display: flex;
  297. align-items: center;
  298. }
  299. .a_add_input {
  300. display: flex;
  301. align-items: center;
  302. flex-wrap: wrap;
  303. }
  304. .a_add_body_div {
  305. display: flex;
  306. align-items: center;
  307. justify-content: center;
  308. flex-direction: column;
  309. }
  310. </style>