ModifySourceDetail.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <el-dialog
  3. custom-class="side-dialog"
  4. :visible.sync="modalIsShow"
  5. :title="title"
  6. width="500px"
  7. :modal="true"
  8. :close-on-click-modal="false"
  9. :close-on-press-escape="false"
  10. append-to-body
  11. @open="visibleChange"
  12. >
  13. <el-form
  14. ref="modalFormComp"
  15. :model="modalForm"
  16. :rules="rules"
  17. label-width="120px"
  18. >
  19. <el-form-item prop="name" label="题型名称">
  20. <el-input
  21. v-model="modalForm.name"
  22. placeholder="请输入题型名称"
  23. clearable
  24. >
  25. </el-input>
  26. </el-form-item>
  27. <el-form-item label="题型类型" prop="questionType">
  28. <el-radio-group
  29. v-model="modalForm.questionType"
  30. size="medium"
  31. style="line-height: 46px"
  32. :disabled="isEdit"
  33. >
  34. <el-radio
  35. v-for="item in QUESTION_TYPES"
  36. :key="item.code"
  37. :label="item.code"
  38. >{{ item.name }}</el-radio
  39. >
  40. </el-radio-group>
  41. </el-form-item>
  42. </el-form>
  43. <div slot="footer">
  44. <el-button type="primary" :disabled="loading" @click="confirm"
  45. >确认</el-button
  46. >
  47. <el-button @click="cancel">取消</el-button>
  48. </div>
  49. </el-dialog>
  50. </template>
  51. <script>
  52. import { updateSourceDetailApi } from "../api";
  53. import { QUESTION_TYPES } from "@/constants/constants";
  54. const initModalForm = {
  55. id: "",
  56. name: "",
  57. courseId: "",
  58. questionType: "",
  59. rootOrgId: "",
  60. };
  61. export default {
  62. name: "ModifySourceDetail",
  63. props: {
  64. instance: {
  65. type: Object,
  66. default() {
  67. return {};
  68. },
  69. },
  70. },
  71. data() {
  72. return {
  73. modalIsShow: false,
  74. QUESTION_TYPES,
  75. modalForm: {
  76. ...initModalForm,
  77. },
  78. rules: {
  79. name: [
  80. {
  81. required: true,
  82. message: "请输入题型名称",
  83. trigger: "change",
  84. },
  85. {
  86. max: 100,
  87. message: "题型名称不能超过100",
  88. trigger: "change",
  89. },
  90. ],
  91. questionType: [
  92. {
  93. required: true,
  94. message: "请输入试题类型",
  95. trigger: "change",
  96. },
  97. ],
  98. },
  99. loading: false,
  100. };
  101. },
  102. computed: {
  103. isEdit() {
  104. return !!this.instance.id;
  105. },
  106. title() {
  107. return (this.isEdit ? "编辑" : "新增") + "题型";
  108. },
  109. },
  110. methods: {
  111. visibleChange() {
  112. this.modalForm = this.$objAssign(initModalForm, this.instance);
  113. },
  114. cancel() {
  115. this.modalIsShow = false;
  116. },
  117. open() {
  118. this.modalIsShow = true;
  119. },
  120. async confirm() {
  121. const valid = await this.$refs.modalFormComp.validate().catch(() => {});
  122. if (!valid) return;
  123. if (this.loading) return;
  124. this.loading = true;
  125. const datas = { ...this.modalForm };
  126. const res = await updateSourceDetailApi(datas).catch(() => {});
  127. this.loading = false;
  128. if (!res) return;
  129. this.$message.success("修改成功!");
  130. this.$emit("modified", { ...this.modalForm, id: res.data });
  131. this.cancel();
  132. },
  133. },
  134. };
  135. </script>