weixinAnswerSetting.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. <template>
  2. <section class="content">
  3. <LinkTitlesCustom
  4. :current-paths="['考试管理', '考试信息', '微信小程序作答设置']"
  5. />
  6. <div class="box box-info">
  7. <div class="box-body">
  8. <el-form
  9. ref="searchForm"
  10. :model="searchForm"
  11. :inline="true"
  12. label-width="70px"
  13. >
  14. <el-form-item label="课程代码">
  15. <el-input
  16. v-model="searchForm.courseCode"
  17. class="input"
  18. clearable
  19. ></el-input>
  20. </el-form-item>
  21. <el-form-item label="课程名称">
  22. <el-input
  23. v-model="searchForm.courseName"
  24. class="input"
  25. clearable
  26. ></el-input>
  27. </el-form-item>
  28. <el-form-item label="状态">
  29. <el-select
  30. v-model="searchForm.weixinAnswerEnabled"
  31. class="input"
  32. clearable
  33. >
  34. <el-option label="全部" value=""></el-option>
  35. <el-option label="启用" value="true"></el-option>
  36. <el-option label="禁用" value="false"></el-option>
  37. </el-select>
  38. </el-form-item>
  39. <el-form-item>
  40. <el-button
  41. size="small"
  42. type="primary"
  43. icon="el-icon-search"
  44. @click="doSearch(1)"
  45. >查询</el-button
  46. >
  47. <el-button
  48. size="small"
  49. type="primary"
  50. icon="el-icon-arrow-left"
  51. @click="back"
  52. >返回</el-button
  53. >
  54. </el-form-item>
  55. </el-form>
  56. <div class="block-seperator"></div>
  57. <el-button
  58. size="small"
  59. type="danger"
  60. icon="el-icon-edit"
  61. :disabled="noBatchSelected"
  62. @click="batchEnabled(true)"
  63. >批量启用</el-button
  64. >
  65. <el-button
  66. size="small"
  67. type="danger"
  68. icon="el-icon-edit"
  69. :disabled="noBatchSelected"
  70. @click="batchEnabled(false)"
  71. >批量禁用</el-button
  72. >
  73. <el-button
  74. size="small"
  75. type="primary"
  76. icon="el-icon-upload2"
  77. @click="settingDialogOpen"
  78. >导入设置</el-button
  79. >
  80. <el-button
  81. size="small"
  82. type="primary"
  83. icon="el-icon-download"
  84. @click="exportSetting"
  85. >导出设置</el-button
  86. >
  87. <div style="width: 100%; margin-bottom: 10px"></div>
  88. <el-table
  89. :data="tableData"
  90. style="width: 100%; text-align: center"
  91. border
  92. @selection-change="selectChange"
  93. >
  94. <el-table-column type="selection" width="50"></el-table-column>
  95. <el-table-column prop="courseCode" label="课程代码"></el-table-column>
  96. <el-table-column prop="courseName" label="课程名称"></el-table-column>
  97. <el-table-column label="状态">
  98. <template slot-scope="scope">
  99. <span>{{ scope.row.weixinAnswerEnabled ? "启用" : "禁用" }}</span>
  100. </template>
  101. </el-table-column>
  102. </el-table>
  103. <div class="page pull-right">
  104. <el-pagination
  105. :current-page="searchForm.pageNo"
  106. :page-size="searchForm.pageSize"
  107. :page-sizes="[10, 20, 50, 100, 200, 300]"
  108. :total="totalElements"
  109. layout="total, sizes, prev, pager, next, jumper"
  110. @current-change="handlePagerNo"
  111. @size-change="handlePagerSize"
  112. ></el-pagination>
  113. </div>
  114. </div>
  115. <el-dialog
  116. title="导入配置"
  117. width="520px"
  118. :visible.sync="settingDialog"
  119. @close="settingDialogClose"
  120. >
  121. <el-form>
  122. <el-row>
  123. <el-form-item style="margin-left: 20px">
  124. <el-upload
  125. ref="upload"
  126. class="form_left"
  127. accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
  128. action="/api/ecs_exam_work/exam/course/import/weixinAnswerEnabledSetting"
  129. :file-list="fileList"
  130. :data="uploadData"
  131. :headers="uploadHeaders"
  132. :on-success="uploadSuccess"
  133. :on-error="uploadError"
  134. :auto-upload="false"
  135. :multiple="false"
  136. >
  137. <el-button
  138. slot="trigger"
  139. size="small"
  140. type="primary"
  141. icon="el-icon-search"
  142. >
  143. 选择文件
  144. </el-button>
  145. &nbsp;
  146. <el-button
  147. size="small"
  148. type="primary"
  149. icon="el-icon-check"
  150. @click="doUpload"
  151. >
  152. 确认上传
  153. </el-button>
  154. <el-button
  155. size="small"
  156. type="primary"
  157. icon="el-icon-refresh"
  158. @click="clearFiles"
  159. >
  160. 清空文件
  161. </el-button>
  162. <el-button
  163. size="small"
  164. type="primary"
  165. icon="el-icon-download"
  166. @click="downloadTemplate"
  167. >
  168. 下载模板
  169. </el-button>
  170. <div slot="tip" class="el-upload__tip">
  171. 只能上传xlsx格式的文件!
  172. </div>
  173. </el-upload>
  174. </el-form-item>
  175. </el-row>
  176. </el-form>
  177. </el-dialog>
  178. </div>
  179. </section>
  180. </template>
  181. <script>
  182. import { EXAM_WORK_API } from "@/constants/constants.js";
  183. import { mapState } from "vuex";
  184. export default {
  185. data() {
  186. return {
  187. searchForm: {
  188. examId: null,
  189. courseCode: "",
  190. courseName: "",
  191. weixinAnswerEnabled: null,
  192. pageNo: 1,
  193. pageSize: 10,
  194. },
  195. loading: false,
  196. tableData: [],
  197. totalElements: 0,
  198. selectedCourseIds: [],
  199. settingDialog: false,
  200. fileList: [],
  201. uploadHeaders: {},
  202. uploadData: {
  203. examId: null,
  204. },
  205. };
  206. },
  207. computed: {
  208. ...mapState({ user: (state) => state.user }),
  209. noBatchSelected() {
  210. return this.selectedCourseIds.length === 0;
  211. },
  212. },
  213. created() {
  214. this.searchForm.examId = this.$route.params.id;
  215. this.doSearch(1);
  216. },
  217. methods: {
  218. back() {
  219. this.$router.push({ path: "/examwork/examInfo" });
  220. },
  221. doSearch(pageNo) {
  222. this.searchForm.pageNo = pageNo;
  223. let url = EXAM_WORK_API + "/exam/course/list";
  224. this.$httpWithMsg.post(url, this.searchForm).then((response) => {
  225. this.tableData = response.data.content;
  226. this.totalElements = response.data.totalElements;
  227. });
  228. },
  229. settingDialogOpen() {
  230. this.settingDialog = true;
  231. this.fileList = [];
  232. this.uploadData.examId = this.searchForm.examId;
  233. this.uploadHeaders = {
  234. key: this.user.key,
  235. token: this.user.token,
  236. };
  237. },
  238. settingDialogClose() {
  239. this.settingDialog = false;
  240. },
  241. doUpload() {
  242. if (!this.checkUpload()) {
  243. return false;
  244. }
  245. this.$refs.upload.submit();
  246. },
  247. checkUpload() {
  248. let fileList = this.$refs.upload.uploadFiles;
  249. if (fileList.length == 0) {
  250. this.$notify({
  251. message: "上传文件不能为空!",
  252. type: "error",
  253. });
  254. return false;
  255. }
  256. if (fileList.length > 1) {
  257. this.$notify({
  258. message: "每次只能上传一个文件!",
  259. type: "error",
  260. });
  261. return false;
  262. }
  263. for (let file of fileList) {
  264. if (!file.name.endsWith(".xlsx")) {
  265. this.$notify({
  266. message: "只能上传xlsx格式的文件!",
  267. type: "error",
  268. });
  269. this.clearFiles();
  270. return false;
  271. }
  272. }
  273. return true;
  274. },
  275. uploadSuccess(response) {
  276. console.log(response);
  277. this.$notify({
  278. message: "上传成功!",
  279. type: "success",
  280. });
  281. this.settingDialogClose();
  282. this.doSearch(1);
  283. },
  284. uploadError(response) {
  285. // console.log(response);
  286. let json = JSON.parse(response.message);
  287. if (response.status != 200) {
  288. this.$notify({
  289. message: "上传失败!" + json.desc,
  290. type: "error",
  291. });
  292. }
  293. },
  294. clearFiles() {
  295. this.fileList = [];
  296. this.$refs.upload.clearFiles();
  297. },
  298. downloadTemplate() {
  299. window.location.href =
  300. EXAM_WORK_API + "/exam/course/download/weixinAnswerEnabledTemplate";
  301. },
  302. exportSetting() {
  303. this.$confirm("确认导出设置?", "提示", {
  304. confirmButtonText: "确定",
  305. cancelButtonText: "取消",
  306. type: "warning",
  307. }).then(() => {
  308. let url =
  309. EXAM_WORK_API +
  310. "/exam/course/export/weixinAnswerEnabledSetting?examId=" +
  311. this.searchForm.examId;
  312. if (this.searchForm.weixinAnswerEnabled) {
  313. url += "&weixinAnswerEnabled=" + this.searchForm.weixinAnswerEnabled;
  314. }
  315. window.open(url);
  316. });
  317. },
  318. batchEnabled(enabled) {
  319. this.$confirm(enabled ? "确认启用?" : "确认禁用?", "提示", {
  320. confirmButtonText: "确定",
  321. cancelButtonText: "取消",
  322. type: "warning",
  323. }).then(() => {
  324. let courseIds = this.selectedCourseIds.join(",");
  325. let url =
  326. EXAM_WORK_API +
  327. "/exam/course/weixinAnswerEnabled?examId=" +
  328. this.searchForm.examId +
  329. "&enabled=" +
  330. enabled +
  331. "&courseIds=" +
  332. courseIds;
  333. this.$http.post(url).then(() => {
  334. this.$notify({
  335. type: "success",
  336. message: enabled ? "批量启用成功!" : "批量禁用成功!",
  337. });
  338. this.doSearch(1);
  339. });
  340. });
  341. },
  342. handlePagerNo(pageNo) {
  343. this.doSearch(pageNo);
  344. },
  345. handlePagerSize(pageSize) {
  346. this.searchForm.pageSize = pageSize;
  347. this.doSearch(1);
  348. },
  349. selectChange(row) {
  350. this.selectedCourseIds = [];
  351. row.forEach((element) => {
  352. this.selectedCourseIds.push(element.courseId);
  353. });
  354. },
  355. },
  356. };
  357. </script>
  358. <style scoped>
  359. .input {
  360. width: 180px;
  361. }
  362. </style>