lesson.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <div id="index">
  3. <el-row>
  4. <el-col :span="24" class="style">
  5. <el-col :span="24" class="top">
  6. <NavBar v-show="navShow" :title="title" :isleftarrow="isleftarrow"> </NavBar>
  7. </el-col>
  8. <el-col :span="24" class="main">
  9. <el-col :span="24" class="lessonList" v-for="(item, index) in lessonList" :key="index">
  10. <el-col :span="16" class="name">
  11. {{ item.subname }}
  12. </el-col>
  13. <el-col :span="8" class="btn">
  14. <el-button type="primary" size="mini" @click="scoreBtn(item)">小组科目打分</el-button>
  15. </el-col>
  16. <el-col :span="24" class="other">
  17. <span>科目教师:{{ item.teaname }}</span>
  18. <span>科目时间:{{ item.date }}</span>
  19. </el-col>
  20. </el-col>
  21. </el-col>
  22. </el-col>
  23. </el-row>
  24. <van-dialog v-model="show" title="小组分" :showConfirmButton="false" :showCancelButton="true">
  25. <van-form>
  26. <van-field v-model="form.score" name="小组分" label="小组分" placeholder="请输入小组分" />
  27. <div style="margin: 16px;">
  28. <van-button round block type="info" @click="onSubmit">
  29. 提交
  30. </van-button>
  31. </div>
  32. </van-form>
  33. </van-dialog>
  34. </div>
  35. </template>
  36. <script>
  37. import NavBar from '@/layout/common/topInfo.vue';
  38. import { mapState, createNamespacedHelpers } from 'vuex';
  39. const { mapActions: lesson } = createNamespacedHelpers('lesson');
  40. const { mapActions: util } = createNamespacedHelpers('util');
  41. const { mapActions: groupscore } = createNamespacedHelpers('groupscore');
  42. export default {
  43. name: 'index',
  44. props: {},
  45. components: {
  46. NavBar,
  47. },
  48. data: function() {
  49. return {
  50. title: '',
  51. isleftarrow: '',
  52. navShow: true,
  53. lessonList: [],
  54. show: false,
  55. form: {},
  56. };
  57. },
  58. created() {
  59. this.search();
  60. },
  61. methods: {
  62. ...lesson({ lessionInfo: 'fetch', lessionList: 'query' }),
  63. ...util({ modelFetch: 'fetch' }),
  64. ...groupscore({ groupscoreQuery: 'query', groupscoreUpdate: 'update', groupscoreCreate: 'create' }),
  65. async search() {
  66. let classid = this.user.classid;
  67. const lesson = await this.modelFetch({ model: 'lesson', classid });
  68. let lessons = _.get(lesson.data, 'lessons', []);
  69. // lesson排序,只去时间最早的作为作业的上传lessonid,需要和学生作业列表处相同处理
  70. let r = lessons.filter(f => f.subid);
  71. r = r.map(r => {
  72. let time = r.time.split('-');
  73. r.start = `${r.date} ${time[0]}`;
  74. return r;
  75. });
  76. r = Object.values(_.groupBy(r, 'subid'));
  77. r = r.map(a => {
  78. let na = _.orderBy(a, ['start'], ['asc']);
  79. return _.head(na);
  80. });
  81. console.log(r);
  82. this.$set(this, `lessonList`, r);
  83. },
  84. // 打开小组分
  85. async scoreBtn(item) {
  86. let res = await this.groupscoreQuery({ classid: this.user.classid, subid: item.subid, groupid: this.$route.query.id });
  87. if (res.total > 0) {
  88. this.$set(this, `form`, res.data[0]);
  89. } else {
  90. let data = {
  91. classid: this.user.classid,
  92. subid: item.subid,
  93. date: item.date,
  94. groupid: this.$route.query.id,
  95. score: 0,
  96. };
  97. this.$set(this, `form`, data);
  98. }
  99. this.show = true;
  100. },
  101. // 保存小组分
  102. async onSubmit() {
  103. let data = this.form;
  104. if (data.id) {
  105. const res = await this.groupscoreUpdate(data);
  106. if (res.errcode === 0) {
  107. this.$notify({
  108. message: '修改小组打分成功',
  109. type: 'success',
  110. });
  111. this.show = false;
  112. } else {
  113. this.$notify({
  114. message: res.errmsg,
  115. type: 'danger',
  116. });
  117. }
  118. } else {
  119. const res = await this.groupscoreCreate(data);
  120. if (res.errcode === 0) {
  121. this.$notify({
  122. message: '小组打分成功',
  123. type: 'success',
  124. });
  125. this.show = false;
  126. } else {
  127. this.$notify({
  128. message: res.errmsg,
  129. type: 'danger',
  130. });
  131. }
  132. }
  133. },
  134. },
  135. computed: {
  136. ...mapState(['user']),
  137. },
  138. mounted() {
  139. this.title = this.$route.meta.title;
  140. this.isleftarrow = this.$route.meta.isleftarrow;
  141. },
  142. watch: {
  143. $route(to, from) {
  144. this.title = to.meta.title;
  145. this.isleftarrow = to.meta.isleftarrow;
  146. },
  147. },
  148. };
  149. </script>
  150. <style lang="less" scoped>
  151. .style {
  152. width: 100%;
  153. min-height: 667px;
  154. position: relative;
  155. background-color: #f9fafc;
  156. }
  157. .top {
  158. height: 46px;
  159. overflow: hidden;
  160. }
  161. .main {
  162. min-height: 570px;
  163. .lessonList {
  164. border-bottom: 1px dashed #ccc;
  165. padding: 10px 5px;
  166. margin: 0 10px;
  167. background: #fff;
  168. width: 95%;
  169. .name {
  170. padding: 5px 0;
  171. }
  172. .btn {
  173. padding: 5px 0;
  174. text-align: center;
  175. }
  176. .other {
  177. padding: 5px 0 0 0;
  178. span {
  179. display: inline-block;
  180. width: 50%;
  181. }
  182. }
  183. }
  184. }
  185. p {
  186. padding: 0;
  187. margin: 0;
  188. }
  189. </style>