data_previllege_add_exam.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <el-dialog
  3. ref="dialog"
  4. title="添加考试"
  5. width="700px"
  6. :visible.sync="visible"
  7. @close="closeDialog"
  8. >
  9. <el-form
  10. ref="form"
  11. :model="form"
  12. :rules="rules"
  13. :inline="true"
  14. label-position="right"
  15. label-width="80px"
  16. >
  17. <el-row>
  18. <el-form-item label="考试名称">
  19. <el-input v-model="form.name" placeholder="请输入考试名称" />
  20. </el-form-item>
  21. <el-form-item label="考试类型">
  22. <ExamTypeSelect v-model="form.examType"></ExamTypeSelect>
  23. </el-form-item>
  24. <el-form-item>
  25. <el-button
  26. size="small"
  27. type="primary"
  28. icon="el-icon-search"
  29. @click="search"
  30. >
  31. 查询
  32. </el-button>
  33. </el-form-item>
  34. </el-row>
  35. <el-row>
  36. <div>
  37. <el-table
  38. ref="table"
  39. :data="tableData"
  40. border
  41. resizable
  42. stripe
  43. style="width: 100%"
  44. >
  45. <el-table-column type="selection" width="40" />
  46. <el-table-column width="85" label="考试ID">
  47. <span slot-scope="scope">{{ scope.row.id }}</span>
  48. </el-table-column>
  49. <el-table-column width="200" label="考试代码">
  50. <span slot-scope="scope">{{ scope.row.code }}</span>
  51. </el-table-column>
  52. <el-table-column label="考试名称">
  53. <span slot-scope="scope">{{ scope.row.name }}</span>
  54. </el-table-column>
  55. <el-table-column width="100" label="考试类型">
  56. <span slot-scope="scope">{{
  57. scope.row.examType | examTypeFilter
  58. }}</span>
  59. </el-table-column>
  60. </el-table>
  61. <div class="page pull-right">
  62. <el-pagination
  63. v-if="paginationShow"
  64. :current-page="currentPage"
  65. :page-size="pageSize"
  66. :page-sizes="[10, 20, 50, 100, 200, 300]"
  67. layout="total, sizes, prev, pager, next, jumper"
  68. :total="total"
  69. @current-change="handleCurrentChange"
  70. @size-change="handleSizeChange"
  71. />
  72. </div>
  73. </div>
  74. <div style="margin-bottom: 20px"></div>
  75. </el-row>
  76. <el-row class="d-flex justify-content-center mt-2">
  77. <el-button type="primary" :loading="loading" @click="submitForm"
  78. >确 定</el-button
  79. >
  80. <el-button @click="closeDialog">取 消</el-button>
  81. </el-row>
  82. </el-form>
  83. </el-dialog>
  84. </template>
  85. <script>
  86. import { CORE_API, EXAM_WORK_API } from "@/constants/constants";
  87. export default {
  88. name: "DataPrevillegeAddExamDialog",
  89. props: {
  90. userId: { type: String, default: "" },
  91. },
  92. data() {
  93. return {
  94. visible: false,
  95. form: {
  96. name: "",
  97. examType: "",
  98. },
  99. rules: {},
  100. loading: false,
  101. paginationShow: false,
  102. tableData: [],
  103. noBatchSelected: true,
  104. currentPage: 1,
  105. pageSize: 10,
  106. total: 10,
  107. };
  108. },
  109. methods: {
  110. async search() {
  111. var param = new URLSearchParams(this.form);
  112. var url =
  113. EXAM_WORK_API +
  114. "/exam/queryPage/" +
  115. (this.currentPage - 1) +
  116. "/" +
  117. this.pageSize +
  118. "?" +
  119. param;
  120. this.loading = true;
  121. return this.$httpWithMsg.get(url).then((response) => {
  122. this.tableData = response.data.list;
  123. this.total = response.data.total;
  124. this.loading = false;
  125. this.paginationShow = true;
  126. });
  127. },
  128. async openDialog() {
  129. this.visible = true;
  130. try {
  131. await this.search();
  132. } catch (error) {
  133. console.log(error);
  134. this.$notify({ type: "error", title: "获取考试列表失败" });
  135. }
  136. },
  137. closeDialog() {
  138. this.visible = false;
  139. },
  140. handleSizeChange(val) {
  141. this.pageSize = val;
  142. this.currentPage = 1;
  143. this.search();
  144. },
  145. handleCurrentChange(val) {
  146. this.currentPage = val;
  147. this.search();
  148. },
  149. async submitForm() {
  150. try {
  151. await this.$refs.form.validate();
  152. } catch (error) {
  153. console.log("校验失败", error);
  154. return;
  155. }
  156. const refIds = this.$refs.table.selection.map((v) => v.id);
  157. console.log(refIds);
  158. if (refIds.length === 0) {
  159. this.$notify({ type: "warning", message: "请先选择一行或多行" });
  160. return;
  161. }
  162. try {
  163. this.loading = true;
  164. // await saveActivity(data);
  165. await this.$httpWithMsg.post(CORE_API + "/user/data/rule/add", {
  166. refIds,
  167. type: "EXAM",
  168. userId: this.userId,
  169. });
  170. this.$emit("reload");
  171. this.$notify({ title: "保存成功", type: "success" });
  172. this.closeDialog();
  173. } finally {
  174. this.loading = false;
  175. }
  176. },
  177. },
  178. };
  179. </script>
  180. <style></style>