data_previllege_add_exam.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <template>
  2. <el-dialog
  3. ref="dialog"
  4. title="添加考试"
  5. width="900px"
  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. rootOrgId: { type: String, default: "" },
  92. },
  93. data() {
  94. return {
  95. visible: false,
  96. form: {
  97. name: "",
  98. examType: "",
  99. },
  100. rules: {},
  101. loading: false,
  102. paginationShow: false,
  103. tableData: [],
  104. noBatchSelected: true,
  105. currentPage: 1,
  106. pageSize: 10,
  107. total: 10,
  108. };
  109. },
  110. methods: {
  111. async search() {
  112. var param = new URLSearchParams({
  113. ...this.form,
  114. rootOrgId: this.rootOrgId,
  115. });
  116. var url =
  117. EXAM_WORK_API +
  118. "/exam/queryPage/" +
  119. (this.currentPage - 1) +
  120. "/" +
  121. this.pageSize +
  122. "?" +
  123. param;
  124. this.loading = true;
  125. return this.$httpWithMsg.get(url).then((response) => {
  126. this.tableData = response.data.list;
  127. this.total = response.data.total;
  128. this.loading = false;
  129. this.paginationShow = true;
  130. });
  131. },
  132. async openDialog() {
  133. this.visible = true;
  134. try {
  135. await this.search();
  136. } catch (error) {
  137. console.log(error);
  138. this.$notify({ type: "error", title: "获取考试列表失败" });
  139. }
  140. },
  141. closeDialog() {
  142. this.visible = false;
  143. },
  144. handleSizeChange(val) {
  145. this.pageSize = val;
  146. this.currentPage = 1;
  147. this.search();
  148. },
  149. handleCurrentChange(val) {
  150. this.currentPage = val;
  151. this.search();
  152. },
  153. async submitForm() {
  154. try {
  155. await this.$refs.form.validate();
  156. } catch (error) {
  157. console.log("校验失败", error);
  158. return;
  159. }
  160. const refIds = this.$refs.table.selection.map((v) => v.id);
  161. console.log(refIds);
  162. if (refIds.length === 0) {
  163. this.$notify({ type: "warning", message: "请先选择一行或多行" });
  164. return;
  165. }
  166. try {
  167. this.loading = true;
  168. // await saveActivity(data);
  169. await this.$httpWithMsg.post(CORE_API + "/user/data/rule/add", {
  170. refIds,
  171. type: "EXAM",
  172. userId: this.userId,
  173. });
  174. this.$emit("reload");
  175. this.$notify({ title: "保存成功", type: "success" });
  176. this.closeDialog();
  177. } finally {
  178. this.loading = false;
  179. }
  180. },
  181. },
  182. };
  183. </script>
  184. <style></style>