lrf402788946 hace 4 años
padre
commit
dec61e85a8
Se han modificado 1 ficheros con 37 adiciones y 7 borrados
  1. 37 7
      src/views/plan/index.vue

+ 37 - 7
src/views/plan/index.vue

@@ -24,13 +24,12 @@
               </el-date-picker>
             </el-col>
           </el-row>
-          <data-table :fields="fields" :data="filterData()" :opera="opera" @apply="toApply">
+          <data-table :fields="fields" :data="filterData()" :opera="opera" @apply="toApply" @cancel="toCancel">
             <template #custom="{item, row}">
               <template v-if="item.prop === 'time'">
                 <el-row>
                   <el-col :span="24" v-for="(i, index) in row[item.prop]" :key="`${index}`">
                     <span v-if="index < 2"> {{ i }}</span>
-                    <!-- 暂时显示2段 -->
                   </el-col>
                 </el-row>
               </template>
@@ -71,7 +70,7 @@ export default {
   metaInfo: { title: '计划一览' },
   name: 'index',
   props: {},
-  components: { listFrame, dataTable },
+  components: { listFrame, dataTable }, //
   data: function() {
     var _this = this;
     return {
@@ -83,13 +82,19 @@ export default {
       opera: [
         {
           label: '申请授课',
-          icon: 'el-icon-document',
           method: 'apply',
           display: i => !_this.applyList.find(f => f.termid == i.termid && f.date == i.day && f.subid == i.subid),
         },
         {
-          label: '今日已申请',
-          display: i => _this.applyList.find(f => f.termid == i.termid && f.date == i.day && f.subid == i.subid),
+          label: '取消申请',
+          method: 'cancel',
+          type: 'danger',
+          display: i => _this.canCancel(i),
+        },
+        {
+          label: '已经申请(已过时限无法修改)',
+          type: 'danger',
+          display: i => _this.applyList.find(f => f.termid == i.termid && f.date == i.day && f.subid == i.subid) && !_this.canCancel(i),
         },
       ],
       fields: [
@@ -117,7 +122,7 @@ export default {
     ...subject({ getSubjectList: 'query' }),
     ...teacher({ getTeacher: 'fetch' }),
     ...mapActions(['query', 'delete', 'fetch']),
-    ...teaplan({ apply: 'create', applyFetch: 'query' }),
+    ...teaplan({ apply: 'create', applyFetch: 'query', cancelApply: 'delete' }),
     async getTeacherInfo() {
       const res = await this.getTeacher(this.user.userid);
       if (res.errcode == '0') this.$set(this, `teacher`, res.data);
@@ -177,6 +182,18 @@ export default {
         });
       } else this.teaApply(data);
     },
+    async toCancel({ data }) {
+      const { termid, subid, day } = data;
+      const r = this.applyList.find(f => f.termid == termid && f.date == day && f.subid == subid);
+      if (r) {
+        const res = await this.cancelApply(r._id);
+        if (this.$checkRes(res, '取消成功', res.errmsg || '取消失败')) {
+          this.searchApply();
+        }
+      } else {
+        this.$message.error('未找到申请的信息');
+      }
+    },
     async teaApply(data) {
       // 修改,老师报课没有限制
       let { termid, day: date, subid } = data;
@@ -236,6 +253,19 @@ export default {
         this.$set(this, `classTypeList`, res.data);
       }
     },
+    // 是否可以取消申请
+    canCancel(i) {
+      const r = this.applyList.find(f => f.termid == i.termid && f.date == i.day && f.subid == i.subid);
+      if (r) {
+        const { day } = i;
+        if (day) {
+          const today = moment().format('YYYY-MM-DD');
+          const sub = moment(day).diff(today, 'days');
+          if (sub > 5) return true;
+          else return false;
+        }
+      }
+    },
   },
   computed: {
     ...mapState(['user', 'defaultOption']),