zhangshuling 3 rokov pred
rodič
commit
30e8ce40ea

+ 4 - 31
pages/Components/classList/classList.wxml

@@ -1,35 +1,9 @@
 <view class="class-container" style="height: {{height}}px;overflow-y: {{overflow}}">
-  <!-- <view class="class-view">
-    <view class="class-date">2021-02-22 星期一</view>
+  <view class="class-view"  wx:for="{{list}}" wx:for-item="head">
+    <view class="class-date">{{head.date}} {{head.week}}</view>
     <view class="class-list">
       <radio-group bindchange="radioChange">
-        <view class="class-box" wx:for="{{3}}" wx:key="index">
-
-          <view class="class-name" style="{{!showTime ? 'width: 700rpx;' : ''}}"><text
-              class="class-type">1v1</text>小鹏钢琴课</view>
-          <view class="class-time" wx:if="{{showTime}}">09:00 ~ 11:00</view>
-          <view class="get-box" wx:if="{{showRadio}}">
-            <radio value="{{index}}" checked="" color="#cc6031" />
-          </view>
-          <view class="class-detail-box">
-            <view class="class-room">钢琴教室01</view>
-            <view class="class-teacher">张老师</view>
-          </view>
-          <view class="class-flag" wx:if="{{showFlag}}">已上课</view>
-          <view class="class-btn-box" wx:if="{{showBtn}}">
-            <view class="add-btn class-btn" bindtap="toPages" data-url="/pages/targetList/targetList">申请加课</view>
-          </view>
-          <view wx:if="{{showLeaveNum}}" class="last-leave-num" bindtap="getLeaveNumList">本课程请假余额 6 次</view>
-        </view>
-      </radio-group>
-    </view>
-  </view> -->
-
-  <view class="class-view">
-    <view class="class-date">{{date}} {{week}}</view>
-    <view class="class-list">
-      <radio-group bindchange="radioChange">
-        <view class="class-box" wx:for="{{list}}" wx:key="index">
+        <view class="class-box" wx:for="{{head.items}}" wx:key="index">
           <view class="class-name" style="{{!showTime ? 'width: 700rpx;' : ''}}"><text
               class="class-type">{{item.kindId == 1 ? '1v1':'集体'}}</text>{{item.classesName}}
           </view>
@@ -42,8 +16,7 @@
             <view class="class-teacher">老师:{{item.teacherName}}</view>
           </view>
           <view class="class-flag" wx:if="{{showFlag}}">
-            <span
-              wx:if="{{item.status == 0 || item.status == 11 || item.status == 12 || item.status == 4}}">{{item.isAttend == 1 ?'已' : '待'}}上课</span>
+            <span wx:if="{{item.status == 0 || item.status == 11 || item.status == 12 || item.status == 4}}">{{item.isAttend == 1 ?'已' : '待'}}上课</span>
             <span wx:if="{{item.status == 2}}">已请假</span>
             <span wx:if="{{item.status == 3}}">已调出</span>
             <span wx:if="{{item.status == 11 || item.status == 12}}">加课</span>

+ 14 - 8
pages/Components/lessonsList/lessonsList.js

@@ -1,10 +1,10 @@
 // pages/Components/lessonsList/lessonsList.js
 Component({
   lifetimes: {
-    attached: function() {
+    attached: function () {
       // 在组件实例进入页面节点树时执行
     },
-    detached: function() {
+    detached: function () {
       // 在组件实例被从页面节点树移除时执行
     },
   },
@@ -12,17 +12,21 @@ Component({
    * 组件的属性列表
    */
   properties: {
-    list:{
+    list: {
       type: Array,
-      value:[]
+      value: []
     },
-    showBtn:{
+    showBtn: {
       type: Boolean,
       value: true,
     },
-    showDate:{
+    showDate: {
       type: Boolean,
       value: true,
+    },
+    action: {
+      type: String,
+      value: '0'
     }
   },
 
@@ -37,9 +41,11 @@ Component({
    * 组件的方法列表
    */
   methods: {
-    toPages:function(e){
+    toPages: function (e) {
+      let item = this.properties.list.filter(o => o.id == e.currentTarget.dataset.id)[0]
+      let action = e.currentTarget.dataset.action
       wx.navigateTo({
-        url: e.currentTarget.dataset.url,
+        url: e.currentTarget.dataset.url + '?data=' + JSON.stringify({ source: item, action: action ? action : 0 }),
       })
     },
   }

+ 10 - 11
pages/Components/lessonsList/lessonsList.wxml

@@ -1,19 +1,18 @@
 <view class="lessons-container">
   <view class="lessons-view">
     <view class="lessons-box" wx:for="{{list}}" wx:key="index">
-      <view class="lessons-type">1v1</view>
-      <view class="lessons-title">小鹏钢琴课</view>
-      <view wx:if="{{(index +1) % 2 == 0 && showBtn}}" class="{{(index +1) % 2 == 0 ? 'lessons-flag' : ''}}">未补课</view>
-      <view wx:if="{{(index +1) % 2 != 0 && showBtn}}" class="{{(index +1) % 2 != 0 ? 'lessons-flag-ed' : ''}}">已补课</view>
-      <view class="lessons-room">钢琴教室01</view>
-      <view class="lessons-teacher">授课老师:张老师</view>
+      <view class="lessons-type">{{item.kindId == '1' ? '1v1':'集体'}}</view>
+      <view class="lessons-title">{{item.classesName}}</view>
+      <view wx:if="{{action=='1'}}" class="{{item.makeupId == null ? 'lessons-flag' : 'lessons-flag-ed'}}">{{item.makeupId == null ? '未':'已'}}补课</view>
+      <view class="lessons-room"> {{item.roomName}}</view>
+      <view class="lessons-teacher">授课老师:{{item.teacherName}}</view>
       <view class="lessons-date-box">
-        <view class="lessons-beginDate">上课时间:2021-02-25 09:00</view>
-        <view class="lessons-endDate" wx:if="{{showDate}}">请假时间:2021-02-21 17:00</view>
+        <view class="lessons-beginDate">上课时间:{{item.beginTime}}</view>
+        <view class="lessons-endDate" wx:if="{{action=='1' || action=='2'}}">请假时间:{{item.createdDate}}</view>
       </view>
-      <view class="lessons-btn-box">
-        <view class="apply-btn" wx:if="{{(index +1) % 2 == 0 && showBtn}}" bindtap="toPages" data-url="/pages/targetList/targetList">申请补课</view>
-        <view class="more-btn" wx:elif="{{(index +1) % 2 != 0 && showBtn}}" bindtap="toPages" data-url="/pages/lessonsDetail/lessonsDetail">查看详情</view>
+      <view class="lessons-btn-box" wx:if="{{action == '1'}}">
+        <view class="apply-btn" wx:if="{{item.makeupId == null}}" bindtap="toPages" data-url="/pages/targetList/targetList" data-id="{{item.id}}" data-action="1">申请补课</view>
+        <view class="more-btn" wx:elif="{{item.makeupId != null}}" bindtap="toPages" data-url="/pages/lessonsDetail/lessonsDetail" data-id="{{item.id}}" >查看详情</view>
       </view>
     </view>
   </view>

+ 54 - 46
pages/lessons/lessons.js

@@ -1,4 +1,7 @@
 // pages/lessons/lessons.js
+const app = getApp()
+const util = require("../../utils/util")
+const urlDef = require("../../utils/urls")
 Page({
 
   /**
@@ -6,43 +9,40 @@ Page({
    */
   data: {
     switchTitle: ['待补课', '待上课'],
-    list: [{},
-      {},
-      {},
-      {},
-      {},
+    beginDate: null,
+    endDate: null,
+    status: '0',
+    list: [
     ],
     loading: '上拉加载',
     flag: 0,
+    pageNum: 0,
+    hasNextPage: true,
   },
 
   changeIndex: function (e) {
     if (e.detail == 0) {
-
+      this.setData({ status: '0' })
     } else {
-
+      this.setData({ status: '1' })
     }
     this.setData({
-      list: [{},
-        {},
-        {},
-        {},
-        {},
-      ],
+      list: [],
       loading: '上拉加载',
-      flag: 0,
+      pageNum: 0
     })
+    this.queryList()
   },
 
-  getTip:function(){
+  getTip: function () {
     wx.showModal({
-        title: '补课说明',
-         content: '1.针对请假的课程进行补课',
-         showCancel: false,//是否显示取消按钮
-         cancelText:"否",//默认是“取消”
-         cancelColor:'#999999',//取消文字的颜色
-         confirmText:"我知道了",//默认是“确定”
-         confirmColor: 'skyblue',//确定文字的颜色
+      title: '补课说明',
+      content: '1.针对请假的课程进行补课',
+      showCancel: false,//是否显示取消按钮
+      cancelText: "否",//默认是“取消”
+      cancelColor: '#999999',//取消文字的颜色
+      confirmText: "我知道了",//默认是“确定”
+      confirmColor: 'skyblue',//确定文字的颜色
     })
   },
 
@@ -50,7 +50,10 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
-
+    let now = new Date();
+    let ed = util.formatTime(now).substring(0, 10).replace(/\//g, '-')
+    let bd = ed.substring(0, 5) + '01-01'
+    this.setData({ beginDate: bd, endDate: ed });
   },
 
   /**
@@ -64,7 +67,8 @@ Page({
    * 生命周期函数--监听页面显示
    */
   onShow: function () {
-
+    this.setData({ list: [], pageNum: 0 })
+    this.queryList()
   },
 
   /**
@@ -92,28 +96,10 @@ Page({
    * 页面上拉触底事件的处理函数
    */
   onReachBottom: function () {
-    if (this.data.flag == 0) {
-      this.setData({
-        loading: '加载中',
-        flag: 1
-      })
-      setTimeout(() => {
-        this.setData({
-          list: [{},
-            {},
-            {},
-            {},
-            {},
-            {},
-            {},
-            {},
-            {},
-            {},
-          ],
-          loading: '没有更多数据',
-          flag: 2
-        })
-      }, 2000);
+    if (this.data.hasNextPage) {
+      let pn = this.data.pageNum
+      this.setData({ loading: '加载中', 'pageNum': ++pn })
+      this.queryList()
     }
   },
 
@@ -122,5 +108,27 @@ Page({
    */
   onShareAppMessage: function () {
 
+  },
+  queryList: function () {
+    const urls = urlDef.urls;
+    let stu = wx.getStorageSync('student')
+    let params = { 'q.studentId': stu.studentId, 'q.orgId': stu.orgId, 'q.status': this.data.status }
+    params.pageNum = this.data.pageNum
+    util.apiPost(urls.makeup_list, params).then(rs => {
+      let list = rs.list
+      list.map(o => {
+        if (o.beginTime) {
+          o.beginTime = o.beginTime.replace('T', ' ').substring(0, 16)
+        }
+        if (o.createdDate) {
+          o.createdDate = o.createdDate.replace('T', ' ').substring(0, 16)
+        }
+      })
+      this.setData({
+        'hasNextPage': rs.hasNextPage,
+        'loading': rs.hasNextPage ? '下拉刷新' : '没有更多数据',
+        'list': this.data.list.concat(list)
+      })
+    })
   }
 })

+ 1 - 1
pages/lessons/lessons.wxml

@@ -9,7 +9,7 @@
   <!-- end -->
 
   <!-- 补课、上课列表 -->
-  <lessonsList list="{{list}}"></lessonsList>
+  <lessonsList list="{{list}}" action="1"></lessonsList>
   <!-- end -->
 
   <view class="loading">{{loading}}</view>

+ 29 - 11
pages/lessonsDetail/lessonsDetail.js

@@ -1,27 +1,45 @@
 // pages/lessonsDetail/lessonsDetail.js
+const app = getApp()
+const util = require("../../utils/util")
+const urlDef = require("../../utils/urls")
 Page({
 
   /**
    * 页面的初始数据
    */
   data: {
-    lessonsList:[
-      {},
-      {},
-    ],
-    stayList:[
-      {},
-      {},
-      {},
-      {},
-    ]
+    source: null,
+    target: null,
+    lessonsList: [],
+    stayList: [],
   },
 
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
-
+    let o = JSON.parse(options.data)
+    let s = o.source
+    let t = o.target
+
+
+    if (t == null || t == undefined) {
+      const urls = urlDef.urls;
+      t = {}
+      this.setData({ lessonsList: [s], target: t })
+      util.apiPost(urls.makeup_detail + '&q.attenceStudentId=' + s.makeupId).then((rs) => {
+        t = rs[0]
+        if (t.beginTime) {
+          t.beginTime = t.beginTime.replace('T', ' ').substring(0, 16)
+        }
+        this.setData({ target: t, stayList: [t] })
+      });
+    } else {
+      if (t.beginTime) {
+        t.beginTime = t.beginTime.replace('T', ' ').substring(0, 16)
+      }
+      this.setData({ target: t, stayList: [t] })
+    }
   },
 
   /**

+ 3 - 3
pages/lessonsDetail/lessonsDetail.wxml

@@ -2,12 +2,12 @@
 
   <!-- 请假课程 -->
   <view class="title">请假课程</view>
-  <lessonsList showBtn="{{false}}" list="{{lessonsList}}"></lessonsList>
+  <lessonsList action="2" list="{{lessonsList}}"></lessonsList>
   <!-- end -->
 
   <!-- 呆上课程 -->
-  <view class="title">待上课程</view>
-  <lessonsList showBtn="{{false}}" showDate="{{false}}" list="{{stayList}}"></lessonsList>
+  <view class="title">{{target.isAttend == 1 ? '已补':'待上'}}课程</view>
+  <lessonsList  list="{{stayList}}"></lessonsList>
   <!-- end -->
 
 </view>

+ 252 - 7
pages/targetList/targetList.js

@@ -1,16 +1,22 @@
 // pages/targetList/targetList.js
+const app = getApp()
+const util = require("../../utils/util")
+const urlDef = require("../../utils/urls")
 Page({
 
   /**
    * 页面的初始数据
    */
   data: {
-    list:[
-      {},
-      {},
-      {},
-      {},
-    ]
+    source: null,
+    target: null,
+    action: 0,
+    list: [
+    ],
+    beginDate: null,
+    endDate: null,
+    teacherLeaveDates: [],
+    holidays: []
   },
 
   showChoose:function(){
@@ -21,7 +27,23 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
+    let o = JSON.parse(options.data)
+    let s = o.source
+    let t = o.target
+    if (t == null || t == undefined) {
+      t = {}
+    }
+    this.setData({ source: s, target: t, action: options.action })
 
+    let now = new Date();
+    // 从第2天开始,14天内的课程
+    let bdd = new Date(now.setDate(now.getDate() + 1));
+    let bd = util.formatTime(bdd).substring(0, 10).replace(/\//g, '-')
+    let edd = new Date(now.setDate(now.getDate() + 14));
+    let ed = util.formatTime(edd).substring(0, 10).replace(/\//g, '-')
+    this.setData({ beginDate: bd, endDate: ed, list: [] });
+
+    this.queryList()
   },
 
   /**
@@ -63,7 +85,6 @@ Page({
    * 页面上拉触底事件的处理函数
    */
   onReachBottom: function () {
-
   },
 
   /**
@@ -71,5 +92,229 @@ Page({
    */
   onShareAppMessage: function () {
 
+  },
+  queryList: function () {
+    const urls = urlDef.urls;
+    let stu = wx.getStorageSync('student')
+
+    // 先查询节假日数据,包含在节假日里面的所有课程,将不显示
+    util.apiPost(urls.get_holidays + '&q.companyId=' + stu.orgId).then((rs) => {
+      this.holidays = rs;
+      this.setData({ holidays: rs })
+      util.apiPost(urls.get_teacherLeave + '&q.orgId=' + stu.orgId).then((rs) => {
+        this.setData({ teacherLeaveDates: rs })
+        this.queryClassList()
+      });
+    });
+  },
+  queryClassList: function () {
+    const urls = urlDef.urls;
+    let stu = wx.getStorageSync('student')
+
+    let classItem = [];
+    let allWeekTask = {};
+    // 按星期分组
+    const dayTime = 86400000;
+    let tbd = new Date(this.data.beginDate);
+    let ted = new Date(this.data.endDate);
+    // 算出两个日期一共有多少天;
+    let days = Math.ceil((ted.getTime() - tbd.getTime()) / dayTime) + 1;
+    let weeks = Math.ceil(days / 7);
+    for (let i = 0; i < weeks; i++) {
+      let tempDate = new Date(this.data.beginDate);
+      tempDate.setDate(tempDate.getDate() + i * 7);
+      let weekTask = {};
+      weekTask.complete = false;
+      weekTask.beginDate = this.formateDate(tempDate);
+      tempDate.setDate(tempDate.getDate() + 6);
+      if (tempDate.getTime() > ted.getTime()) {
+        tempDate = ted;
+      }
+      weekTask.endDate = this.formateDate(tempDate);
+      weekTask.weekMap = this.initWeek(weekTask);
+      allWeekTask['week' + i] = weekTask;
+    }
+
+    for (let weekKey in allWeekTask) {
+      let weekTask = allWeekTask[weekKey];
+      // 查询
+      let item = this.data.source
+      let params = {
+        'q.courseId': item.courseId,
+        'q.classesId': item.classesId,
+        'q.beginDate': weekTask.beginDate,
+        'q.endDate': weekTask.endDate,
+        'q.classromeId': item.classRoomId,
+        'q.studentId': stu.studentId,
+        'q.oldTeacherId': item.teacherId,
+        'q.kindId': item.kindId,
+        'q.level': (item.level ? item.level : ''),
+        'q.orgId': stu.orgId
+      };
+      util.apiPost(urls.get_switch_course_list, params).then((rs) => {
+        weekTask.data = rs;
+        weekTask.complete = true;
+        weekTask.list = this.filterList(weekTask);
+
+        // 每次查询完,检查所有的请求执行完没有
+        let allTaskOver = true;
+        for (let wk in allWeekTask) {
+          if (allWeekTask[wk].complete) {
+          } else { // 只要有一个没执行完,就都没执行完
+            allTaskOver = false;
+            break;
+          }
+        }
+        if (allTaskOver) {
+          classItem = [];
+          for (let weekKey in allWeekTask) {
+            let weekTask = allWeekTask[weekKey];
+            classItem.push.apply(classItem, weekTask.list);
+          }
+          let data = [];
+          classItem.forEach(item => {
+            let day = item.newDate;
+            let o;
+            data.some(d => {
+              if (d.day === day) {
+                o = d;
+                return true;
+              }
+            });
+            if (!o) {
+              o = {};
+              o.day = day;
+              data.push(o);
+            }
+          });
+          // 按日期排序
+          data.sort((a, b) => {
+            return (parseInt(a.day.replace(/-/g, ''), 10) - parseInt(b.day.replace(/-/g, ''), 10));
+          });
+
+          data.forEach(item => {
+            let items = [];
+            classItem.forEach(i => {
+              if (i.newDate === item.day) {
+                i.bt = i.beginTime
+                i.et = i.endTime
+                items.push(i);
+              }
+            });
+            items.sort((a, b) => {
+              return (parseInt(a.beginTime.replace(/:/g, ''), 10) - parseInt(b.beginTime.replace(/:/g, ''), 10));
+            });
+            item.items = items;
+            item.date = item.day.substring(0, 10)
+            item.week = this.getWeek(item.date)
+          });
+          classItem = data;
+          this.setData({ list: classItem })
+        }
+
+      })
+    }
+  },
+  exceptHoliday: function (d) {
+    let result = true;
+    this.data.holidays.some(r => {
+      if (r.holidayDate === d) {
+        result = false;
+        return true;
+      }
+    });
+    return result;
+  },
+  exceptTeacheLeave: function (d) {
+    // 老师请假中的课程不显示
+    let result = true;
+    this.data.teacherLeaveDates.some(r => {
+      let leaveBeginTime = this.dateToNumber(r.beginTime);
+      let leaveEndTime = this.dateToNumber(r.endTime);
+      let beginTime = this.dateToNumber(d.newDate + d.beginTime);
+      let endTime = this.dateToNumber(d.newDate + d.endTime);
+      if (r.teacherId === d.teacherId && ((beginTime >= leaveBeginTime && beginTime <= leaveEndTime) || (endTime >= leaveBeginTime && endTime <= leaveEndTime))) {
+        result = false;
+        return true;
+      }
+    });
+    return result;
+  },
+  getDay: function (week, weekMap) {
+    let result = null;
+    weekMap.some(r => {
+      if (r.week === week) {
+        result = r.ymd;
+        return true;
+      }
+    });
+    return result;
+  },
+  formateDate: function (d) {
+    return d.getFullYear() + '-' + this.addZero(d.getMonth() + 1) + '-' + this.addZero(d.getDate());
+  },
+  dateToNumber: function (d) {
+    if (d) {
+      return parseInt(d.replace(/-/g, '').replace(/:/g, '').replace(/\s+/g, ''), 10);
+    } else {
+      return 0;
+    }
+  },
+  addZero: function (n) {
+    return (parseInt(n, 10) >= 10 ? '' : '0') + n;
+  },
+  initWeek: function (weekTask) {
+    let weekMap = [];
+    const bd = new Date(weekTask.beginDate);
+    const ed = new Date(weekTask.endDate);
+    while (bd.getTime() <= ed.getTime()) {
+      weekMap.push({ week: bd.getDay(), ymd: this.formateDate(bd) });
+      bd.setDate(bd.getDate() + 1);
+    }
+    return weekMap;
+  },
+  len: function (o) {
+    return (o == null || o === undefined) ? 0 : o.length;
+  },
+  filterList: function (weekTask) {
+    let items = [];
+    weekTask.data.forEach((it) => {
+      if (it.classes) {
+        it.classes.forEach(c => {
+          let item = c;
+          item.classesName = c.name;
+          item.address = c.address;
+          item.roomName = c.roomName;
+
+          let tempItems = [];
+          if (this.len(c.beginTime) > 0) {
+            let bt = c.beginTime.replace('T', ' ').substring(0, 16)
+            item.newDate = bt.substring(0.10)
+            item.beginTime = bt.substring(11);
+            item.endTime = this.addZero(it.endHours) + ':' + this.addZero(it.endMinutes);
+            tempItems.push(item);
+          } else { // 没有真实排课
+            item.beginTime = this.addZero(it.beginHours) + ':' + this.addZero(it.beginMinutes);
+            item.endTime = this.addZero(it.endHours) + ':' + this.addZero(it.endMinutes);
+            // 服务端返回的2345671 表示 周一到周日
+            // 此处是     1234567 表示 周一到周日
+            let d = this.getDay(it.week - 1, weekTask.weekMap);
+            if (d != null) {
+              item.newDate = d;
+              tempItems.push(item);
+            }
+          }
+          tempItems.forEach(item => {
+            if (item.classStatus === '1' && this.exceptHoliday(item.newDate) && this.exceptTeacheLeave(item)) { // 未满班的才允许调课 && 不在假节日中的课程
+              items.push(item);
+            }
+          });
+        });
+      }
+    });
+    return items;
+  },
+  getWeek: function (d) {
+    return '星期' + '天一二三四五六'.charAt(new Date(d).getDay());
   }
 })