lrf402788946 4 år sedan
förälder
incheckning
effa437f4e

+ 3 - 3
src/views/class/newClass/daily.vue

@@ -2,7 +2,7 @@
   <div id="daily">
     <van-notice-bar color="#1989fa" background="#ecf9ff" left-icon="info-o" text="点击查看每天的评分" />
     <van-cell v-for="(stu, index) in data" :key="index" :title="stu.name" :value="getScore(stu.id)" @click="searchDailyList(stu)" />
-    <van-dialog v-model="show" :show-confirm-button="user.job.includes(limitJob)" :show-cancel-button="user.job.includes(limitJob)" @confirm="toSave">
+    <van-dialog v-model="show" :show-confirm-button="user.job.includes(limitJob)" show-cancel-button @confirm="toSave">
       <template #title>
         <van-row style="padding:15px 0;" type="flex" justify="center">
           <van-col span="8">{{ form.name }}</van-col>
@@ -12,7 +12,7 @@
         </van-row>
       </template>
       <van-notice-bar v-if="user.job.includes(limitJob)" color="#1989fa" background="#ecf9ff" left-icon="info-o" text="学委可以添加/修改平时分数" />
-      <template v-if="user.job === '班长'">
+      <template v-if="user.job.includes(limitJob)">
         <van-field v-for="(i, index) in dailyList" :key="index" v-model="i.score" colon type="number" :label="i.date" placeholder="请输入平时分数" border />
       </template>
       <template v-else>
@@ -37,7 +37,7 @@ export default {
   data: function() {
     return {
       show: false,
-      limitJob: '班长',
+      limitJob: '学委',
       form: {},
       dailyList: [],
     };

+ 77 - 249
src/views/user/dati.vue

@@ -6,9 +6,8 @@
           <NavBar v-show="navShow" :title="title" :isleftarrow="isleftarrow"> </NavBar>
         </el-col>
         <el-col :span="24" class="main">
-          <el-col :span="24" class="leaveBtn"> </el-col>
-          <el-col :span="24" class="leaveList">
-            <datiList :datilist="datilist" :form="form" :answer="answer" @submit="onsave"></datiList>
+          <el-col :span="24" class="leaveList" v-if="task.id">
+            <task :task="task" :answer="answer" @submit="onsave"></task>
           </el-col>
         </el-col>
       </el-col>
@@ -18,9 +17,10 @@
 
 <script>
 import NavBar from '@/layout/common/topInfo.vue';
-import datiList from '@/layout/user/datiList.vue';
+import task from './homework/task.vue';
 import { mapState, createNamespacedHelpers, mapGetters } from 'vuex';
 const { mapActions: mapTask } = createNamespacedHelpers('task');
+const { mapActions: util } = createNamespacedHelpers('util');
 const { mapActions: mapTaskUploadtask } = createNamespacedHelpers('uploadtask');
 
 export default {
@@ -28,20 +28,18 @@ export default {
   props: {},
   components: {
     NavBar, //头部导航
-    datiList,
+    task,
   },
   data: () => ({
     loading: true,
-    datilist: {},
+    task: {},
     show: false,
     navShow: true,
     title: '',
     isleftarrow: '',
     answer: [],
-    form: {},
     taskid: '',
-    resdata: '',
-    valid: '',
+    taskAnswer: null,
   }),
   mounted() {
     this.title = this.$route.meta.title;
@@ -56,271 +54,101 @@ export default {
   created() {
     this.search();
   },
-
-  computed: {
-    ...mapState(['user']),
-    name() {
-      return this.$route.query.name;
-    },
-    id() {
-      return this.$route.query.id;
-    },
-    lessonid() {
-      return this.$route.query.lessonid;
-    },
-  },
   methods: {
+    ...util({ modelFetch: 'fetch' }),
     ...mapTask({ list: 'query', add: 'create', fet: 'fetch', updates: 'update' }),
     ...mapTaskUploadtask({ Uploadtasklist: 'query', Uploadtaskadd: 'create', Uploadtaskfet: 'fetch', Uploadtaskupdates: 'update' }),
 
     //查询作业
     async search() {
-      // console.log(this.name);s
-      const res = await this.list();
-      var tilist = res.data.filter(item => item.code === this.id);
-      let result = tilist[0];
-      // console.log(result.id);
-      this.$set(this, `taskid`, result.id);
-      // console.log(result.question);
-
+      const res = await this.list({ code: this.id });
+      if (res.total <= 0) {
+        this.$toast({ message: '没有找到该科目的在线作业', icon: 'fail' });
+        return;
+      }
+      var midlist = res.data.filter(item => item.code === this.id && item.status == '1');
+      let result = _.head(midlist);
+      if (!result) return;
       result.question = result.question.map(i => {
         if (i.type == 1) {
           i.answers = [];
         } else {
           i.answers = '';
         }
-        // console.log(i.answers);
-        // console.log(i);
 
         return i;
       });
       let num = _.cloneDeep(result);
-      console.log(num);
-      console.log(result.question);
-
-      this.$set(this, `datilist`, result);
-
-      //   this.$set(this, `datilist`, num);
-
-      let stuid = this.user.userid;
-      let lessonid = this.lessonid;
-
-      let ress = await this.Uploadtasklist({ lessonid });
-
-      console.log(ress.data);
-
-      this.$set(this, `resdata`, ress.data);
-      //回显
-      for (const val of ress.data) {
-        let less = val.answers;
-        console.log(val.id);
-        this.$set(this, `valid`, val.id);
-        console.log(less);
-        result.question.map(i => {
-          if (i.type == 1) {
-            val.answers.map(m => {
-              if (i._id == m.questionid) {
-                // 将string类型还原
-                i.answers = JSON.parse(m.answer);
-                return m;
-              }
-            });
-          } else {
-            less.map(n => {
-              if (i._id == n.questionid) {
-                i.answers = n.answer;
-                return n;
-              }
-            });
-          }
-          return i;
-          console.log(result.question);
-        });
+      this.$set(this, `task`, result);
+      //获取答过的作业
+      let taskAnswer = await this.modelFetch({ model: 'uploadtask', studentid: this.user.userid, taskid: this.task.id });
+      if (!taskAnswer.data) return;
+      this.$set(this, `taskAnswer`, taskAnswer.data);
+      let { answers } = this.taskAnswer;
+      let task = _.cloneDeep(this.task);
+      let { question } = task;
+      for (const quest of question) {
+        let ans = answers.find(f => f.questionid == quest._id);
+        if (!ans) continue;
+        let { answer } = ans;
+        if (quest.type == '1') {
+          // 多选题,需要转回array
+          quest.answers = JSON.parse(answer);
+        } else quest.answers = answer;
       }
+      this.$set(this.task, `question`, question);
       this.loading = false;
     },
 
     async onsave() {
-      let answerss = {
-        termid: this.user.termid,
-        batchid: this.user.batchid,
-        classid: this.user.classid,
-        lessonid: this.lessonid,
-        id: this.valid,
-        studentid: this.user.userid,
-        taskid: this.taskid,
-      };
-      let answers = {};
-      let data = this.datilist.question;
-
-      var answer = data.map(i => {
-        answers.questionid = i._id;
-        answers.answer = JSON.stringify(i.answers);
-        if (i.type == 1) {
-          return {
-            answer: JSON.stringify(i.answers),
-            questionid: i._id,
-          };
-        } else {
-          return {
-            answer: i.answers,
-            questionid: i._id,
-          };
-        }
-      });
-
-      //上传
-      let dati = this.resdata;
-      console.log(dati);
-
-      if (dati.length) {
-        let task = this.datilist;
-        let newsc = [];
-        task.question.map(n => {
-          if (n.type == 1) {
-            // a b array类型
-            let a = n.answer.split(';');
-            let b = n.answers;
-
-            let c = new Set(a);
-            let d = new Set(b);
-
-            let differenceABSet = new Set([...d].filter(x => !c.has(x)));
-            console.log(differenceABSet);
-
-            var sc = this.datilist.question.map(a => {
-              if (n._id == a._id) {
-                if (differenceABSet.size === 0) {
-                  return {
-                    // 转换成string
-                    // answer: JSON.stringify(n.answers),
-
-                    answer: JSON.stringify(n.answers),
-                    questionid: n._id,
-                    questionscore: n.score,
-                  };
-                } else {
-                  return {
-                    // 转换成string
-                    // answer: JSON.stringify(n.answers),
-
-                    answer: JSON.stringify(n.answers),
-                    questionid: n._id,
-                    questionscore: 0,
-                  };
-                }
-              }
-            });
-          } else {
-            var sc = this.datilist.question.map(a => {
-              if (n._id == a._id) {
-                if (n.answers === n.answer) {
-                  return {
-                    answer: n.answers,
-                    questionid: n._id,
-                    questionscore: n.score,
-                  };
-                } else {
-                  return {
-                    answer: n.answers,
-                    questionid: n._id,
-                    questionscore: 0,
-                  };
-                }
-              }
-            });
-          }
-
-          newsc = [...sc, ...newsc];
-
-          var arr = newsc.filter(item => item);
-          answerss.answers = arr;
-        });
-        console.log(answerss.answers);
-        let sum = '';
-        answerss.answers.forEach(item => {
-          sum = Number(sum) + Number(item.questionscore);
-        });
-        console.log(sum);
-        answerss.score = sum;
-        let res = await this.Uploadtaskupdates(answerss);
-      } else {
-        //作业
-        let task = this.datilist;
-        let newsc = [];
-        task.question.map(n => {
-          console.log(n._id);
-
-          if (n.type == 1) {
-            // a b array类型
-            let a = n.answer.split(';');
-            let b = n.answers;
-
-            let c = new Set(a);
-            let d = new Set(b);
-
-            let differenceABSet = new Set([...d].filter(x => !c.has(x)));
-
-            var sc = this.datilist.question.map(a => {
-              if (n._id == a._id) {
-                if (differenceABSet.size === 0) {
-                  console.log(n.answers);
-
-                  return {
-                    // 转换成string
-                    // answer: JSON.stringify(n.answers),
-
-                    answer: JSON.stringify(n.answers),
-                    questionid: n._id,
-                    questionscore: n.score,
-                  };
-                } else {
-                  return {
-                    // 转换成string
-                    // answer: JSON.stringify(n.answers),
-
-                    answer: JSON.stringify(n.answers),
-                    questionid: n._id,
-                    questionscore: 0,
-                  };
-                }
-              }
-            });
-          } else {
-            console.log(this.datilist.question);
-            var sc = this.datilist.question.map(a => {
-              if (n._id == a._id) {
-                if (n.answers === n.answer) {
-                  return {
-                    answer: n.answers,
-                    questionid: n._id,
-                    questionscore: n.score,
-                  };
-                } else {
-                  return {
-                    answer: n.answers,
-                    questionid: n._id,
-                    questionscore: 0,
-                  };
-                }
-              }
-            });
-          }
-
-          newsc = [...sc, ...newsc];
-
-          console.log(newsc);
-          var arr = newsc.filter(item => item);
-          answerss.answers = arr;
-          console.log(answerss);
-        });
-        console.log(answerss);
-
-        let res = await this.Uploadtaskadd(answerss);
+      let task = _.cloneDeep(this.task);
+      let obj = {};
+      console.log(this.taskAnswer);
+      if (!this.taskAnswer) {
+        obj = {
+          termid: this.user.termid,
+          batchid: this.user.batchid,
+          classid: this.user.classid,
+          lessonid: this.lessonid,
+          lessonname: this.task.name,
+          studentid: this.user.userid,
+          taskid: this.taks.id,
+        };
+      } else obj = _.cloneDeep(this.taskAnswer);
+
+      let studanswer = [];
+      let { question } = task;
+      for (const quest of question) {
+        const { topic, answers, _id: questionid } = quest;
+        let obj = { topic, questionid };
+        if (_.isString(answers)) obj.answer = answers;
+        else obj.answer = JSON.stringify(answers);
+        studanswer.push(obj);
+      }
+      obj.answers = studanswer;
+      console.log(obj);
+      if (!obj.id) {
+        let res = await this.Uploadtaskadd(obj);
         if (this.$checkRes(res, '作业提交成功', res.errmsg || '作业提交失败')) window.history.go(-1);
+      } else {
+        let res = await this.Uploadtaskupdates(obj);
+        if (this.$checkRes(res, '作业修改成功', res.errmsg || '作业修改失败')) window.history.go(-1);
       }
     },
   },
+
+  computed: {
+    ...mapState(['user']),
+    name() {
+      return this.$route.query.name;
+    },
+    id() {
+      return this.$route.query.id;
+    },
+    lessonid() {
+      return this.$route.query.lessonid;
+    },
+  },
 };
 </script>
 

+ 10 - 7
src/views/user/homework.vue

@@ -21,13 +21,14 @@
 <script>
 import NavBar from '@/layout/common/topInfo.vue';
 import footInfo from '@/layout/common/footInfo.vue';
-import workList from '@/layout/user/workList.vue';
+import workList from './homework/workList.vue';
 import { mapState, createNamespacedHelpers, mapGetters } from 'vuex';
 const { mapActions: mapClass } = createNamespacedHelpers('classes');
 const { mapActions: mapLesson } = createNamespacedHelpers('lesson');
 const { mapActions: mapTask } = createNamespacedHelpers('task');
 const { mapActions: mapSubject } = createNamespacedHelpers('subject');
 const { mapActions: uploadtask } = createNamespacedHelpers('uploadtask');
+const { mapActions: util } = createNamespacedHelpers('util');
 
 export default {
   name: 'homework',
@@ -61,6 +62,7 @@ export default {
     ...mapState(['user']),
   },
   methods: {
+    ...util({ modelFetch: 'fetch' }),
     ...uploadtask({ getUploadTask: 'query' }),
     ...mapTask({ list: 'query', add: 'create', fet: 'fetch', updates: 'update' }),
     ...mapClass({ classinfo: 'fetch', classquery: 'query' }),
@@ -100,14 +102,15 @@ export default {
     async getUpload() {
       let list = _.cloneDeep(this.workLists);
       for (let i of list) {
-        let res = await this.getUploadTask({ studentid: this.user.userid, lessonid: i._id });
+        let res = await this.modelFetch({ model: 'uploadtask', studentid: this.user.userid, lessonid: i._id });
         if (this.$checkRes(res)) {
           let r = res.data;
-          if (r.length > 0) {
-            let head = _.head(r);
-            i.have = true;
-            if (head.score) i.score = head.score;
-          } else i.have = false;
+          if (r) {
+            const { answers, picrul, score } = r;
+            if (score) i.score = score;
+            if (answers && answers.length > 0) i.onlinetask = true;
+            if (picrul) i.pictask = true;
+          }
         }
       }
       this.$set(this, `workLists`, list);

+ 6 - 7
src/layout/user/datiList.vue

@@ -2,23 +2,23 @@
   <div id="index">
     <el-row>
       <el-col :span="24" class="style">
-        <el-form ref="form" :model="form">
+        <el-form ref="form">
           <el-col :span="24" class="topTitle">
-            {{ datilist.name }}
+            {{ task.name }}
           </el-col>
-          <el-col :span="24" v-for="(item, index) in datilist.question" :key="index">
+          <el-col :span="24" v-for="(item, index) in task.question" :key="index">
             <el-form-item>
               <span slot="label">{{ index + 1 }} . {{ item.topic }}</span>
             </el-form-item>
             <template v-if="item.type === '0'">
               <el-col :span="24" v-for="(items, index) in item.option" :key="index">
-                <el-radio v-model="item.answers" :label="items.number">{{ items.opname }}</el-radio>
+                <el-radio v-model="item.answers" :label="`${items.number}:${items.opname}`">{{ items.opname }}</el-radio>
               </el-col>
             </template>
             <template v-else-if="item.type === '1'">
               <el-checkbox-group v-model="item.answers">
                 <el-col :span="24" v-for="(items, index) in item.option" :key="index">
-                  <el-checkbox :label="items.number">{{ items.opname }}</el-checkbox>
+                  <el-checkbox :label="`${items.number}:${items.opname}`">{{ items.opname }}</el-checkbox>
                 </el-col>
               </el-checkbox-group>
             </template>
@@ -47,8 +47,7 @@ import _ from 'lodash';
 export default {
   name: 'index',
   props: {
-    form: null,
-    datilist: null,
+    task: null,
     answer: null,
   },
   components: {},

+ 18 - 9
src/layout/user/workList.vue

@@ -3,17 +3,26 @@
     <el-row>
       <el-col :span="24" class="info">
         <el-col :span="24" class="list" v-for="(item, index) in workLists" :key="index">
-          <el-col :span="24" class="time">
-            <el-col :span="item.score ? 14 : 18">科目:{{ item.subname }}</el-col>
-            <el-col :span="4">{{ item.score }}</el-col>
-            <el-col :span="6" class="anniu" v-if="!item.have">
-              <el-button type="primary" size="small" @click="clickBtn(item.subname, item.subid, item._id)">在线作答</el-button>
-              <el-button type="primary" size="small" @click="clickzy(item.subid, item.subname, item._id)">上传作业</el-button>
+          <el-row type="flex" justify="space-around" align="middle">
+            <el-col :span="15" class="time">
+              <el-col :span="item.score ? 20 : 24">科目:{{ item.subname }}</el-col>
+              <el-col :span="4">{{ item.score }}</el-col>
             </el-col>
-            <el-col :span="6" class="anniu" v-else>
-              已提交作业
+            <el-col :span="6" class="anniu">
+              <el-row>
+                <el-col :span="24" style="padding: 5px 0;">
+                  <el-button type="primary" size="mini" @click="clickBtn(item.subname, item.subid, item._id)">
+                    {{ item.onlinetask ? '修改在线作业' : '在线作答' }}
+                  </el-button>
+                </el-col>
+                <el-col :span="24" style="padding: 5px 0;">
+                  <el-button type="primary" size="mini" @click="clickzy(item.subid, item.subname, item._id)">
+                    {{ item.pictask ? '修改上传作业' : '上传作业' }}
+                  </el-button>
+                </el-col>
+              </el-row>
             </el-col>
-          </el-col>
+          </el-row>
         </el-col>
       </el-col>
     </el-row>