ModifyNormalScore.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <el-dialog
  3. :visible.sync="modalIsShow"
  4. title="平时成绩编辑"
  5. top="10vh"
  6. width="550px"
  7. :close-on-click-modal="false"
  8. :close-on-press-escape="false"
  9. append-to-body
  10. @open="visibleChange"
  11. >
  12. <el-form
  13. ref="modalFormComp"
  14. :model="modalForm"
  15. :key="modalForm.id"
  16. label-width="100px"
  17. >
  18. <el-form-item
  19. prop="name"
  20. label="考生姓名:"
  21. :rules="{
  22. required: true,
  23. message: '考生姓名不能为空,最多30字符',
  24. max: 30,
  25. trigger: 'change',
  26. }"
  27. >
  28. <el-input
  29. v-model.trim="modalForm.name"
  30. placeholder="考生姓名"
  31. clearable
  32. ></el-input>
  33. </el-form-item>
  34. <el-form-item label="考生学号:">
  35. {{ modalForm.studentCode }}
  36. </el-form-item>
  37. <el-form-item
  38. v-for="(item, index) in modalForm.normalScore"
  39. :key="index"
  40. :label="`${item.name}:`"
  41. :prop="`normalScore.${index}.score`"
  42. :rules="{
  43. required: true,
  44. message: '分数不能为空',
  45. trigger: 'change',
  46. }"
  47. >
  48. <el-input-number
  49. v-model="item.score"
  50. class="width-80"
  51. size="small"
  52. :min="0"
  53. :max="1000"
  54. :step="0.01"
  55. step-strictly
  56. :controls="false"
  57. >
  58. </el-input-number>
  59. </el-form-item>
  60. </el-form>
  61. <div slot="footer">
  62. <el-button type="primary" :disabled="isSubmit" @click="submit"
  63. >确认</el-button
  64. >
  65. <el-button @click="cancel">取消</el-button>
  66. </div>
  67. </el-dialog>
  68. </template>
  69. <script>
  70. import { deepCopy } from "@/plugins/utils";
  71. import { normalScoreSave } from "../api";
  72. const initModalForm = {
  73. id: null,
  74. name: "",
  75. studentCode: "",
  76. normalScore: [],
  77. };
  78. export default {
  79. name: "ModifyNormalScore",
  80. props: {
  81. instance: {
  82. type: Object,
  83. default() {
  84. return {};
  85. },
  86. },
  87. },
  88. data() {
  89. return {
  90. modalIsShow: false,
  91. isSubmit: false,
  92. modalForm: { ...initModalForm },
  93. };
  94. },
  95. methods: {
  96. visibleChange() {
  97. this.modalForm = this.$objAssign(initModalForm, this.instance);
  98. this.modalForm.normalScore = deepCopy(this.instance.normalScore);
  99. },
  100. cancel() {
  101. this.modalIsShow = false;
  102. },
  103. open() {
  104. this.modalIsShow = true;
  105. },
  106. async submit() {
  107. const valid = await this.$refs.modalFormComp.validate().catch(() => {});
  108. if (!valid) return;
  109. if (this.isSubmit) return;
  110. this.isSubmit = true;
  111. const datas = {
  112. id: this.modalForm.id,
  113. name: this.modalForm.name,
  114. score: JSON.stringify(this.modalForm.normalScore),
  115. };
  116. const data = await normalScoreSave(datas).catch(() => {});
  117. this.isSubmit = false;
  118. if (!data) return;
  119. this.$message.success("修改成功!");
  120. this.$emit("modified");
  121. this.cancel();
  122. },
  123. },
  124. };
  125. </script>