ModifyNormalScore.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 label="考生姓名:">
  19. {{ modalForm.examStudentName }}
  20. </el-form-item>
  21. <el-form-item label="考生学号:">
  22. {{ modalForm.examNumber }}
  23. </el-form-item>
  24. <el-form-item
  25. v-for="(item, index) in modalForm.normalScore"
  26. :key="index"
  27. :label="`${item.name}:`"
  28. :prop="`normalScore.${index}.score`"
  29. :rules="{
  30. required: true,
  31. message: '分数不能为空',
  32. trigger: 'change',
  33. }"
  34. >
  35. <el-input-number
  36. v-model="item.score"
  37. class="width-80"
  38. size="small"
  39. :min="0"
  40. :max="1000"
  41. :step="0.01"
  42. step-strictly
  43. :controls="false"
  44. >
  45. </el-input-number>
  46. </el-form-item>
  47. </el-form>
  48. <div slot="footer">
  49. <el-button type="primary" :disabled="isSubmit" @click="submit"
  50. >确认</el-button
  51. >
  52. <el-button @click="cancel">取消</el-button>
  53. </div>
  54. </el-dialog>
  55. </template>
  56. <script>
  57. import { deepCopy } from "@/plugins/utils";
  58. import { normalScoreSave } from "../api";
  59. const initModalForm = {
  60. id: null,
  61. examStudentName: "",
  62. examNumber: "",
  63. normalScore: [],
  64. };
  65. export default {
  66. name: "ModifyNormalScore",
  67. props: {
  68. instance: {
  69. type: Object,
  70. default() {
  71. return {};
  72. },
  73. },
  74. },
  75. data() {
  76. return {
  77. modalIsShow: false,
  78. isSubmit: false,
  79. modalForm: { ...initModalForm },
  80. };
  81. },
  82. methods: {
  83. visibleChange() {
  84. this.modalForm = this.$objAssign(initModalForm, this.instance);
  85. this.modalForm.normalScore = deepCopy(this.instance.normalScore);
  86. },
  87. cancel() {
  88. this.modalIsShow = false;
  89. },
  90. open() {
  91. this.modalIsShow = true;
  92. },
  93. async submit() {
  94. const valid = await this.$refs.modalFormComp.validate().catch(() => {});
  95. if (!valid) return;
  96. if (this.isSubmit) return;
  97. this.isSubmit = true;
  98. const datas = {
  99. id: this.modalForm.id,
  100. scoreNormal: JSON.stringify({
  101. normalScore: this.modalForm.normalScore,
  102. }),
  103. };
  104. const data = await normalScoreSave(datas).catch(() => {});
  105. this.isSubmit = false;
  106. if (!data) return;
  107. this.$message.success("修改成功!");
  108. this.$emit("modified");
  109. this.cancel();
  110. },
  111. },
  112. };
  113. </script>