ModifyTargetEvaluation.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <el-dialog
  3. :visible.sync="modalIsShow"
  4. :title="title"
  5. top="10vh"
  6. width="500px"
  7. :close-on-click-modal="false"
  8. :close-on-press-escape="false"
  9. append-to-body
  10. @open="visibleChange"
  11. >
  12. <el-form label-width="80px">
  13. <el-form-item label="评价方式:">
  14. <el-select
  15. v-model="selectedEvaluationIds"
  16. placeholder="请选择评卷方式"
  17. class="width-full"
  18. multiple
  19. @change="selectChange"
  20. >
  21. <el-option
  22. v-for="item in sources"
  23. :key="item.evaluationId"
  24. :value="item.evaluationId"
  25. :label="item.evaluationName"
  26. >
  27. </el-option>
  28. </el-select>
  29. </el-form-item>
  30. </el-form>
  31. <el-table :data="dataList" border>
  32. <el-table-column
  33. prop="evaluationName"
  34. label="评价方式"
  35. min-width="120"
  36. ></el-table-column>
  37. <el-table-column prop="courseCode" label="权重" width="130">
  38. <template slot-scope="scope">
  39. <el-input-number
  40. v-model="scope.row.weight"
  41. class="width-80"
  42. size="small"
  43. :min="0"
  44. :max="100"
  45. :step="1"
  46. step-strictly
  47. :controls="false"
  48. >
  49. </el-input-number>
  50. <span style="margin-left: 5px">%</span>
  51. </template>
  52. </el-table-column>
  53. </el-table>
  54. <div slot="footer">
  55. <el-button type="primary" @click="submit">确认</el-button>
  56. <el-button @click="cancel">取消</el-button>
  57. </div>
  58. </el-dialog>
  59. </template>
  60. <script>
  61. import { calcSum } from "@/plugins/utils";
  62. export default {
  63. name: "modify-target-evaluation",
  64. props: {
  65. target: {
  66. type: Object,
  67. default() {
  68. return {};
  69. },
  70. },
  71. sources: {
  72. type: Array,
  73. default() {
  74. return [];
  75. },
  76. },
  77. },
  78. data() {
  79. return {
  80. modalIsShow: false,
  81. dataList: [],
  82. selectedEvaluationIds: [],
  83. };
  84. },
  85. computed: {
  86. title() {
  87. return `${this.target.courseTargetName}平时成绩组成详情`;
  88. },
  89. },
  90. methods: {
  91. visibleChange() {
  92. this.dataList = this.target.evaluationList
  93. .slice(0, -1)
  94. .filter((item) => item.enable)
  95. .map((item) => {
  96. return { ...item };
  97. });
  98. this.selectedEvaluationIds = this.dataList.map(
  99. (item) => item.evaluationId
  100. );
  101. },
  102. cancel() {
  103. this.modalIsShow = false;
  104. },
  105. open() {
  106. this.modalIsShow = true;
  107. },
  108. selectChange() {
  109. const selectData = this.sources.filter((item) =>
  110. this.selectedEvaluationIds.includes(item.evaluationId)
  111. );
  112. const count = selectData.length;
  113. const weight = Math.floor(100 / count);
  114. const sData = 100 % count;
  115. this.dataList = selectData.map((item, index) => {
  116. return {
  117. ...item,
  118. weight: index === count - 1 ? weight + sData : weight,
  119. };
  120. });
  121. },
  122. async submit() {
  123. if (!this.dataList.length) {
  124. this.$message.error("请选择评价方式");
  125. return;
  126. }
  127. if (calcSum(this.dataList.map((item) => item.weight)) !== 100) {
  128. this.$message.error("权重综合不等于100%");
  129. return;
  130. }
  131. this.$emit("modified", this.dataList);
  132. this.cancel();
  133. },
  134. },
  135. };
  136. </script>