Browse Source

请假、补课、加课、调课数据对接,功能完善

zhangshuling 3 years ago
parent
commit
46a755c1ca

+ 219 - 19
pages/Components/classList/classList.js

@@ -1,7 +1,10 @@
 // pages/Components/classList/classList.js
+const app = getApp()
+const util = require("../../../utils/util")
+const urlDef = require("../../../utils/urls")
 Component({
-  lifetimes:{
-    attached:function(){
+  lifetimes: {
+    attached: function () {
       wx.getSystemInfo({
         success: (result) => {
           this.setData({
@@ -11,6 +14,19 @@ Component({
       })
     }
   },
+  pageLifetimes: {
+    show: function () {
+      let action = this.properties.action
+      this.setData({ action: action })
+      if ('1' == this.data.action) {
+        this.setData({ actionName: '补' })
+      } else if ('2' == this.data.action) {
+        this.setData({ actionName: '加' })
+      } else {
+        this.setData({ actionName: '调' })
+      }
+    }
+  },
   /**
    * 组件的属性列表
    */
@@ -19,20 +35,24 @@ Component({
       type: Boolean,
       value: false
     },
-    showTime:{ //是否显示上课时间
+    showTime: { //是否显示上课时间
       type: Boolean,
       value: true
     },
-    showFlag:{ //是否显示上课状态
+    showFlag: { //是否显示上课状态
       type: Boolean,
       value: true
     },
-    showBtn:{ //是否显示功能按钮
-      type:Boolean,
+    showBtn: { //是否显示功能按钮
+      type: Boolean,
+      value: false,
+    },
+    showRadio: { //是否显示单选按钮
+      type: Boolean,
       value: false,
     },
-    showRadio:{ //是否显示单选按钮
-      type:Boolean,
+    showLevel: {
+      type: Boolean,
       value: false,
     },
     date: {
@@ -41,6 +61,12 @@ Component({
     list: {
       type: Array,
       value: []
+    },
+    action: {
+      type: String
+    },
+    source: {
+      type: Object
     }
   },
 
@@ -49,21 +75,89 @@ Component({
    */
   data: {
     animation: null,
-    height:0,
+    height: 0,
     overflow: 'auto',
+    source: null,
+    target: null,
+    key: null,
+    action: null,
+    actionName: null
   },
 
   /**
    * 组件的方法列表
    */
   methods: {
-    toPages:function(e){
-      wx.navigateTo({
-        url: e.currentTarget.dataset.url,
+    toPages: function (e) {
+      let urls = urlDef.urls
+      let stu = wx.getStorageSync('student')
+      let item = null;
+      this.properties.list.map(h => {
+        if (item == null) {
+          if (h.items && h.items.length > 0) {
+            item = h.items.filter(o => o.id == e.currentTarget.dataset.id)[0]
+          }
+        }
       })
+      let action = e.currentTarget.dataset.action
+      if (action == '1' || action == '3' || action == '4') {
+        item.curDate = item.beginTime.substring(0, 10)
+        wx.navigateTo({
+          url: e.currentTarget.dataset.url + '?data=' + JSON.stringify({ source: item, action: (action ? action : 0), dayScope: 14 }),
+        })
+      } else if (action == '2') {
+        util.apiPost(urls.get_last_classes + '&q.studentId=' + stu.studentId + '&q.classesId=' + item.classesId).then(rs => {
+          if (rs == null) {
+            wx.showToast({
+              title: '未查询到排课数据',
+              icon: 'none'
+            })
+            return;
+          }
+          rs.curDate = rs.beginTime.substring(0, 10)
+          rs.classromeId = null; // 加课不用传 教室id
+          wx.navigateTo({
+            url: e.currentTarget.dataset.url + '?data=' + JSON.stringify({ source: rs, action: (action ? action : 0), dayScope: 14 }),
+          })
+        })
+      }
     },
-
-    showChoose:function(){
+    showChoose: function () {
+      // 判断是否选择了
+      let key = this.data.key
+      if (key == null || key == undefined) {
+        wx.showToast({
+          title: '请选择目标课程',
+          icon: 'none'
+        })
+        return;
+      }
+      let ks = key.split('#')
+      let action = this.data.action
+      this.properties.list.map(o => {
+        if (o.date == ks[0]) {
+          o.items.map(i => {
+            if (i.attendTeacherId == ks[1] && i.bt == ks[2]) {
+              let source = this.properties.source
+              if (source.curDate) {
+                source.date = source.curDate.substring(0, 10)
+                source.week = this.getWeek(source.date)
+              }
+              if (source.beginTime) {
+                source.bt = source.beginTime.substring(11, 16)
+              }
+              if (source.endTime) {
+                source.et = source.endTime.substring(11, 16)
+              }
+              if (i.newDate) {
+                i.date = i.newDate.substring(0, 10)
+                i.week = this.getWeek(i.date)
+              }
+              this.setData({ target: i, source: source, action: action })
+            }
+          })
+        }
+      })
       this.animation = wx.createAnimation({
         timingFunction: 'linear',
       })
@@ -71,11 +165,11 @@ Component({
       this.animation.translateY(bottom).step()
       this.setData({
         overflow: 'hidden',
-        animation:this.animation.export(),
+        animation: this.animation.export(),
         bottom
       })
     },
-    hideChoose:function(){
+    hideChoose: function () {
       this.animation = wx.createAnimation({
         timingFunction: 'linear',
       })
@@ -83,7 +177,7 @@ Component({
       this.animation.translateY(bottom).step()
       this.setData({
         overflow: 'auto',
-        animation:this.animation.export(),
+        animation: this.animation.export(),
       })
       setTimeout(() => {
         this.setData({
@@ -97,8 +191,114 @@ Component({
         url: '/pages/leaveRecord/leaveRecord',
       })
     },
-    radioChange:function(e){
-      console.log(JSON.stringify(e.detail.value))
+    radioChange: function (e) {
+      this.setData({ key: e.detail.value })
+    },
+    getWeek: function (d) {
+      return '星期' + '天一二三四五六'.charAt(new Date(d).getDay());
+    },
+    doSave: function () {
+      let that = this
+      wx.showModal({
+        title: '确认信息',
+        content: '确定要执行' + this.data.actionName + '课申请?',
+        showCancel: true,
+        cancelText: "否",
+        confirmText: "是",
+        success: function (res) {
+          if (res.cancel) {
+            that.hideChoose()
+          } else {
+            that.doRealSave()
+          }
+        }
+      })
     },
+    doRealSave: function () {
+      wx.showLoading({
+        title: '正在保存数据...',
+        mask: true
+      })
+
+      const urls = urlDef.urls;
+      let stu = wx.getStorageSync('student')
+      let data = {}
+      data.orgId = stu.orgId;
+      data.operator = stu.studentId
+      data.studentId = stu.studentId;
+      data.studentName = stu.name
+
+      if ('1' === this.data.action) {
+        data.leaveId = this.data.source.leaveId;
+        data.attenceStudentId = this.data.source.attenceStudentId;
+      } else {
+        data.attenceStudentId = this.data.source.studentId;
+      }
+      data.oldAttenceTeacherId = this.data.source.attenceTeacherId;
+      data.oldKindId = this.data.source.kindId;
+      data.attendTeacherId = this.data.target.attendTeacherId;
+      data.beginTime = this.data.target.newDate.substring(0, 10) + ' ' + this.data.target.beginTime + ':00';
+      data.endTime = this.data.target.newDate.substring(0, 10) + ' ' + this.data.target.endTime + ':00';
+      data.classesId = this.data.target.classesId;
+      data.courseName = this.data.target.courseName;
+      data.classesName = this.data.target.classesName;
+      data.name = this.data.target.classesName;
+
+      data.kindId = this.data.target.kindId;
+      data.teacherId = this.data.target.teacherId;
+      data.classRoomId = this.data.target.classroomId;
+
+      let saveURL = urls.classes_switch_save;
+      if ('1' === this.data.action) {
+        saveURL = urls.student_makeup;
+      }
+      if ('2' === this.data.action) {
+        data.classesId = this.data.source.classesId; // 原课程的classesId, 不然找不到当前学生的最后一节课
+        let gridList = [];
+        gridList.push(
+          {
+            personNum: this.data.target.personNum,
+            attendTeacherId: this.data.target.attendTeacherId,
+            teacherName: this.data.target.teacherName,
+            endDate: this.data.target.endDate,
+            classroomId: this.data.target.classroomId,
+            beginDate: this.data.target.beginDate,
+            classesId: this.data.target.classesId,
+            courseName: this.data.target.courseName,
+            teacherId: this.data.target.teacherId,
+            classesName: this.data.target.classesName,
+            beginTime: this.data.target.newDate.substring(0, 10) + ' ' + this.data.target.beginTime + ':00',
+            courseId: this.data.target.courseId,
+            kindId: this.data.target.kindId,
+            classRoomId: this.data.target.classroomId,
+            endTime: this.data.target.newDate.substring(0, 10) + ' ' + this.data.target.endTime + ':00'
+          }
+        );
+        data.gridList = gridList;
+        saveURL = urls.add_classes;
+      }
+      util.apiPost(saveURL, data, 'application/json').then((rs) => {
+        wx.hideLoading({})
+        this.hideChoose()
+        if (rs.message) {
+          wx.showToast({
+            title: this.data.actionName + '课失败,' + rs.message,
+            icon: 'none'
+          })
+          return;
+        } 
+        wx.showToast({
+          title: '您已' + this.data.actionName + '课成功!'
+        })
+        setTimeout(() => {
+          wx.navigateBack({
+            delta: 1, // 返回上一级页面。
+            success: function () {
+              console.log('成功!')
+            }
+          })
+        }, 1000)
+      })
+    }
   }
 })

+ 39 - 17
pages/Components/classList/classList.wxml

@@ -1,20 +1,24 @@
+
 <view class="class-container" style="height: {{height}}px;overflow-y: {{overflow}}">
-  <view class="class-view"  wx:for="{{list}}" wx:for-item="head">
-    <view class="class-date">{{head.date}} {{head.week}}</view>
+ <radio-group bindchange="radioChange">
+  <view class="class-view"  wx:for="{{list}}" wx:for-item="head" wx:key="index">
+    <view class="class-date" wx:if="{{head.date}}">{{head.date}} {{head.week}}</view>
     <view class="class-list">
-      <radio-group bindchange="radioChange">
         <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>
           <view class="class-time" wx:if="{{showTime}}">{{item.bt}} ~ {{item.et}}</view>
           <view class="get-box" wx:if="{{showRadio}}">
-            <radio value="{{index}}" checked="" color="#cc6031" />
+            <radio value="{{head.date}}#{{item.attendTeacherId}}#{{item.bt}}" checked="" color="#cc6031" />
           </view>
           <view class="class-detail-box">
             <view class="class-room">{{item.roomName}}</view>
             <view class="class-teacher">老师:{{item.teacherName}}</view>
           </view>
+         <view wx:if="{{showLevel}}">
+            <view class="class-teacher">等级:{{item.levelName ? item.levelName : '无'}}</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 == 2}}">已请假</span>
@@ -23,29 +27,47 @@
             <span wx:if="{{item.status == 5}}">补课</span>
           </view>
           <view class="class-btn-box" wx:if="{{showBtn}}">
-            <view class="add-btn class-btn" bindtap="toPages" data-url="/pages/targetList/targetList">申请加课</view>
+            <view class="add-btn class-btn" bindtap="toPages" data-url="/pages/targetList/targetList" data-id="{{item.id}}" data-action="{{action}}">申请{{actionName}}课</view>
           </view>
-
-          <view wx:if="{{showLeaveNum}}" class="last-leave-num" bindtap="getLeaveNumList">本课程请假余额 6 次</view>
+          <view class="class-btn-box" wx:if="{{item.leaveFlag}}">
+            <view class="add-btn class-btn" bindtap="toPages" data-url="/pages/leaveDetail/leaveDetail" data-id="{{item.id}}" data-action="{{action}}">请假</view>
+          </view>
+          <view class="class-btn-box" wx:if="{{item.transferFlag}}">
+            <view class="add-btn class-btn" bindtap="toPages" data-url="/pages/targetList/targetList" data-id="{{item.id}}" data-action="{{action}}">调课</view>
+          </view>
+          <view wx:if="{{showLeaveNum && (item.status == 0 || item.status == 2 || item.status == 4)}}" class="last-leave-num" bindtap="getLeaveNumList">本课程请假余额 {{item.leaveCount}} 次</view>
         </view>
-      </radio-group>
+     
     </view>
   </view>
-
+ </radio-group>
   <view class="choose-bg" wx:if="{{bottom == 0}}" bindtap="hideChoose"></view>
   <view class="class-choose" animation="{{animation}}" style="bottom:{{bottom}}rpx">
-    <view class="title">待补课程</view>
+
+  <view wx:if="{{action == '1' || action=='2' || action=='3'}}">
+    <view class="title">待{{actionName}}课程</view>
     <view class="choose-list">
-      <view class="choose-box" wx:for="{{2}}" wx:key="index">
-        <view class="choose-title">星期日,2021年01月01日</view>
-        <view class="choose-time">08:00 ~ 09:00</view>
-        <view class="choose-name">小鹏钢琴课</view>
-        <view class="choose-room">钢琴教室2</view>
-        <view class="choose-teacher">授课老师:张老师</view>
+      <view class="choose-box">
+        <view class="choose-title">{{source.week}}, {{source.date}}</view>
+        <view class="choose-time">{{source.bt}} ~ {{source.et}}</view>
+        <view class="choose-name">{{source.classesName}}</view>
+        <view class="choose-room">{{source.roomName}}</view>
+        <view class="choose-teacher">授课老师:{{source.teacherName}}</view>
+      </view>
+    </view>
+     <view class="title">目标课程</view>
+    <view class="choose-list">
+      <view class="choose-box">
+        <view class="choose-title">{{target.week}}, {{target.date}}</view>
+        <view class="choose-time">{{target.bt}} ~ {{target.et}}</view>
+        <view class="choose-name">{{target.classesName}}</view>
+        <view class="choose-room">{{target.roomName}}</view>
+        <view class="choose-teacher">授课老师:{{target.teacherName}}</view>
       </view>
     </view>
     <view class="choose-btn-view">
-      <view class="choose-btn" bindtap="hideChoose">确认补课</view>
+      <view class="choose-btn" bindtap="doSave">确认{{actionName}}课</view>
+    </view>
     </view>
   </view>
 

+ 2 - 3
pages/Components/classList/classList.wxss

@@ -1,6 +1,6 @@
 /* 课表列表 */
 .class-list{
-  padding-bottom: 150rpx
+  padding-bottom: 50rpx
 }
 .class-box{
   display: flex;
@@ -70,7 +70,6 @@
     text-align: center;
     font-size: 28rpx;
     border-radius: 50rpx;
-    margin-top: 30rpx;
 }
 
 /* end */
@@ -102,7 +101,7 @@
     line-height: 60rpx;
   }
   .choose-list{
-    height: 650rpx;
+    height: 320rpx;
     overflow-y: auto;
   }
   .choose-box{

+ 4 - 1
pages/Components/lessonsList/lessonsList.js

@@ -44,8 +44,11 @@ Component({
     toPages: function (e) {
       let item = this.properties.list.filter(o => o.id == e.currentTarget.dataset.id)[0]
       let action = e.currentTarget.dataset.action
+      if (action == 1) {
+        item.curDate = item.beginTime.substring(0, 10)
+      }
       wx.navigateTo({
-        url: e.currentTarget.dataset.url + '?data=' + JSON.stringify({ source: item, action: action ? action : 0 }),
+        url: e.currentTarget.dataset.url + '?data=' + JSON.stringify({ source: item, action: (action ? action : 0), dayScope: 14 }),
       })
     },
   }

+ 38 - 26
pages/addClass/addClass.js

@@ -1,15 +1,19 @@
 // pages/addClass/addClass.js
+const app = getApp()
+const util = require("../../utils/util")
+const urlDef = require("../../utils/urls")
 Page({
 
   /**
    * 页面的初始数据
    */
   data: {
-    list:[
-      {}
-    ],
     loading: '上拉加载',
+    list: [],
+    pageNum: 0,
+    hasNextPage: true,
     flag: 0,
+    data: []
   },
 
   getTip: function () {
@@ -42,7 +46,8 @@ Page({
    * 生命周期函数--监听页面显示
    */
   onShow: function () {
-
+    this.setData({ list: [], pageNum: 0 })
+    this.queryList()
   },
 
   /**
@@ -70,28 +75,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()
     }
   },
 
@@ -100,5 +87,30 @@ Page({
    */
   onShareAppMessage: function () {
 
+  },
+  queryList: function () {
+    const urls = urlDef.urls;
+    let stu = wx.getStorageSync('student');
+    if (stu) {
+      let params = { 'q.studentId': stu.studentId }
+      params.pageNum = this.data.pageNum
+      util.apiPost(urls.add_classes_list, params).then(rs => {
+        let list = rs.list;
+        list.map(o => {
+          if (o.beginTime) {
+            o.beginTime = o.beginTime.substring(11, 16)
+          }
+          if (o.endTime) {
+            o.endTime = o.endTime.substring(11, 16)
+          }
+        })
+        this.setData({
+          'hasNextPage': rs.hasNextPage,
+          'loading': rs.hasNextPage ? '下拉刷新' : '没有更多数据',
+          'list': this.data.list.concat(list)
+        })
+        this.setData({ data: [{ items: this.data.list }] })
+      })
+    }
   }
 })

+ 1 - 1
pages/addClass/addClass.wxml

@@ -5,7 +5,7 @@
   <!-- end -->
 
   <!-- 加课列表 -->
-  <classList showBtn="{{true}}" showFlag="{{false}}" showTime="{{false}}" list="{{list}}"></classList>
+  <classList showBtn="{{true}}" showFlag="{{false}}" showTime="{{false}}" list="{{data}}" action="2" showLevel="true"></classList>
   <!-- end -->
 
   <view class="loading">{{loading}}</view>

+ 83 - 2
pages/leave/leave.js

@@ -1,18 +1,65 @@
 // pages/leave/leave.js
+const app = getApp()
+const util = require("../../utils/util")
+const urlDef = require("../../utils/urls")
 Page({
 
   /**
    * 页面的初始数据
    */
   data: {
-
+    curStu: null,
+    aheadTime: 0,
+    eventList: [],
+    holidayList: [],
+    dateList: [],
+    date: null,
+    week: 0,
+    weekMap: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
+    leaveTime: 0,
+    leaveDay: 0,
+    curDate: null,
   },
 
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
-
+    const urls = urlDef.urls;
+    let stu = wx.getStorageSync('student');
+    if (stu) {
+      this.setData({ 'curStu': stu });
+
+      util.apiPost(urls.get_sys_params + '&q.orgId=' + stu.orgId + '&q.id=1000_2').then((rs) => {
+        if (rs && rs.length > 0) {
+          this.setData({ leaveTime: parseInt(rs[0].sysVal, 10) })
+        }
+      });
+      // this.leaveDay = 14; // 允许提前()天请假
+      util.apiPost(urls.get_sys_params + '&q.orgId=' + stu.orgId + '&q.id=1000_1').then((rs) => {
+        if (rs && rs.length > 0) {
+          this.setData({ leaveDay: parseInt(rs[0].sysVal, 10) })
+        }
+      });
+
+
+      util.apiPost(urls.get_sys_params, { 'q.orgId': stu.orgId, 'q.id': 'f8158acabeeb44ec9ff651aade6b295f' }).then((rs) => {
+        if (rs && rs.length > 0) {
+          // 将分钟转为毫秒
+          this.setData({ 'aheadTime': parseInt(rs[0].sysVal, 10) * 60 * 1000 })
+        }
+      });
+      util.apiPost(urls.leave_get_classes_info, { 'q.studentId': stu.studentId }).then((rs) => {
+        if (rs && rs.length > 0) {
+          this.setData({ 'eventList': rs })
+        }
+      });
+      util.apiPost(urls.get_holidays, { 'q.companyId': stu.orgId }).then((rs) => {
+        if (rs && rs.length > 0) {
+          this.setData({ 'holidayList': rs })
+        }
+      });
+    }
   },
 
   /**
@@ -62,5 +109,39 @@ Page({
    */
   onShareAppMessage: function () {
 
+  },
+  selectDate: function (v) {
+    this.setData({ curDate: v })
+    let vd = new Date(v);
+    let week = this.data.weekMap[vd.getDay()];
+    let list = this.data.eventList.filter(o => {
+      return o.attenceDate == v;
+    });
+    list.map(o => {
+      o.bt = o.beginTime.substring(0, 5);
+      o.et = o.endTime.substring(0, 5);
+      o.leaveFlag = this.canLeave(o)
+    })
+    this.setData({ 'date': v, 'week': week, 'dateList': [{ items: list, date: v, week: week }] });
+  },
+  callSelectDate: function (d) {
+    let v = d.detail.dateString;
+    this.selectDate(v);
+  },
+  canLeave(item) {
+    let timeCheck = (item.attenceDate > this.data.curDate); // 默认要大于当前时间,就是不能请当天的假
+    let dateCheck = (item.attenceDate > this.data.curDate); // 默认要大于当前时间,就是不能请当天的假
+    if (this.data.leaveTime > 0) { // 允许上课前()分钟请假
+      // 判断当前时间是否跟上课时间相差  leaveTime 分钟
+      let attenceTime = new Date(item.attenceDate + ' ' + item.beginTime)
+      timeCheck = Math.floor((attenceTime.getTime() - new Date().getTime()) / 60000) >= this.data.leaveTime;
+    }
+    if (this.data.leaveDay > 0) { // 允许提前()天请假
+      let attenceTime = new Date(item.attenceDate + ' 00:00:00')
+      const temDate = new Date();
+      temDate.setDate(temDate.getDate() + this.data.leaveDay);
+      dateCheck = (temDate >= attenceTime);
+    }
+    return (item.isAttend === 0 && item.leaveCount > 0 && timeCheck && dateCheck && (item.status === 0 || item.status === 4));
   }
 })

+ 2 - 2
pages/leave/leave.wxml

@@ -1,11 +1,11 @@
 <view class="container">
 
    <!-- 日历组件 -->
-   <calendar></calendar>
+  <calendar spot="{{eventList}}" bind:change="callSelectDate"></calendar>
   <!-- end -->
 
   <!-- 课表列表 -->
-  <classList showLeaveNum="true"></classList>
+  <classList date="{{date}}" list="{{dateList}}" showLeaveNum="true" action="4"></classList>
   <!-- end -->
 
 </view>

+ 116 - 11
pages/leaveDetail/leaveDetail.js

@@ -1,4 +1,7 @@
 // pages/leaveDetail/leaveDetail.js
+const app = getApp()
+const util = require("../../utils/util")
+const urlDef = require("../../utils/urls")
 Page({
 
   /**
@@ -6,21 +9,16 @@ Page({
    */
   data: {
     index: 0,
-    array:['事假','病假','其他'],
-    item:{
-      date: '2021-02-22',
-      time: '08:00',
-      title: 'haha钢琴',
-      teacher: '张老师',
-      num: '3'
-    }
+    array: ['事假', '病假', '其他'],
+    item: {},
+    content: ''
   },
 
-  getText:function(e){
-    console.log(e.detail.value)
+  getText: function (e) {
+    this.setData({ content: e.detail.value })
   },
 
-  bindPickerChange:function(e){
+  bindPickerChange: function (e) {
     const index = e.detail.value
     this.setData({
       index
@@ -31,6 +29,10 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
+    let o = JSON.parse(options.data)
+    let s = o.source
+    s.bt = s.beginTime.substring(0, 5)
+    this.setData({ item: s })
 
   },
 
@@ -81,5 +83,108 @@ Page({
    */
   onShareAppMessage: function () {
 
+  },
+  toSave: function () {
+    if (this.data.item.leaveCount <= 0) {
+      wx.showToast({
+        title: '该课程剩余请假次数不足,请联系前台!'
+      });
+      return;
+    }
+    const urls = urlDef.urls;
+    let stu = wx.getStorageSync('student')
+    util.apiPost(urls.get_params + '&q.orgId=' + stu.orgId + '&q.detailId=1000_1').then((rs) => {
+      let timeoutDay = 0;
+      if (rs && rs.length > 0) {
+        timeoutDay = parseInt(rs[0].sysVal, 10);
+      }
+      if (timeoutDay > 0) {// 计算本课程上课时间,跟当前时间相隔多少天,这个天不能超过 timeoutDay
+        let courseDate = new Date(this.data.item.attenceDate)
+        let now = new Date();
+        let day = Math.ceil((courseDate.getTime() - now.getTime()) / (1000 * 60 * 60 * 24));
+        if (day > timeoutDay) { // 超过请假范围了
+          wx.showToast({ title: '只能请' + timeoutDay + '天内的假' });
+          return;
+        }
+      }
+      let that = this
+      wx.showModal({
+        title: '确认信息',
+        content: '确定要执行请假申请?',
+        showCancel: true,
+        cancelText: "否",
+        confirmText: "是",
+        success: function (res) {
+          if (res.cancel) { } else {
+            that.doRealSave()
+          }
+        }
+      })
+    });
+
+
+  },
+  doRealSave: function () {
+
+    const urls = urlDef.urls;
+    let stu = wx.getStorageSync('student')
+    let today = util.curTime().substring(0, 10).replace(/\//g, '-')
+
+    let leaveReason = this.data.array[this.data.index];
+    if (this.data.index == 2) {
+      leaveReason = this.data.content
+    }
+    let attenceData = {
+      status: '1',
+      studentId: stu.studentId,
+      operator: stu.studentId,
+      orgId: stu.orgId,
+      leaveDate: today,
+      leaveReason: leaveReason,
+      goodList: [
+        {
+          beginTime: this.data.item.beginTime,
+          attenceStudentId: this.data.item.id,
+          attenceTeacherId: this.data.item.attenceTeacherId,
+          kindId: this.data.item.kindId,
+          status: this.data.item.status,
+          switchingId: this.data.item.switchingId
+        }
+      ]
+    };
+
+    util.apiPost(urls.student_leave, attenceData, 'application/json').then(rs => {
+      if (rs.message) {
+        wx.showToast({
+          title: '请假失败,' + rs.message,
+          icon: 'none'
+        })
+        return
+      }
+
+      wx.showModal({
+        title: '请假申请成功',
+        content: '需要立即预约补课吗?',
+        showCancel: true,
+        cancelText: "取消",
+        confirmText: "预约补课",
+        success: function (res) {
+          if (res.cancel) {
+            setTimeout(() => {
+              wx.navigateBack({
+                delta: 1, // 返回上一级页面。
+                success: function () {
+                  console.log('成功!')
+                }
+              })
+            }, 1000)
+          } else {
+            wx.redirectTo({
+              url: "/pages/lessons/lessons"
+            })
+          }
+        }
+      })
+    })
   }
 })

+ 6 - 6
pages/leaveDetail/leaveDetail.wxml

@@ -1,13 +1,13 @@
 <view class="container">
   <view class="view-box">
     <view class="title">请假日期</view>
-    <view class="value">{{item.date}}</view>
+    <view class="value">{{item.attenceDate}}</view>
     <view class="title">上课时间</view>
-    <view class="value">{{item.time}}</view>
+    <view class="value">{{item.bt}}</view>
     <view class="title">课程名称</view>
-    <view class="value">{{item.title}}</view>
+    <view class="value">{{item.classesName}}</view>
     <view class="title">授课老师</view>
-    <view class="value">{{item.teacher}}</view>
+    <view class="value">{{item.teacherName}}</view>
     <view class="title">请选择请假类型</view>
     <view class="value">
       <picker bindchange="bindPickerChange" value="{{index}}" range="{{array}}">
@@ -20,10 +20,10 @@
       <textarea bindinput="getText" placeholder="请输入请假原因" maxlength="200"></textarea>
     </view>
     <view class="title">本课程请假余额</view>
-    <view class="value red-view">{{item.num}}次</view>
+    <view class="value red-view">{{item.leaveCount}}次</view>
   </view>
 
-  <view class="submit-view">
+  <view class="submit-view" bindtap="toSave">
     提交
   </view>
  

+ 39 - 35
pages/leaveRecord/leaveRecord.js

@@ -1,20 +1,17 @@
 // pages/leaveRecord/leaveRecord.js
+const app = getApp()
+const util = require("../../utils/util")
+const urlDef = require("../../utils/urls")
 Page({
 
   /**
    * 页面的初始数据
    */
   data: {
-    loading:'上拉加载',
-    flag:0,
-    list:[
-      {},
-      {},
-      {},
-      {},
-      {},
-      {},
-    ],
+    loading: '上拉加载',
+    list: [],
+    pageNum: 0,
+    hasNextPage: true,
   },
 
   /**
@@ -35,7 +32,8 @@ Page({
    * 生命周期函数--监听页面显示
    */
   onShow: function () {
-
+    this.setData({ list: [] })
+    this.queryList()
   },
 
   /**
@@ -63,29 +61,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()
     }
   },
 
@@ -94,5 +73,30 @@ Page({
    */
   onShareAppMessage: function () {
 
-  }
+  },
+  queryList: function () {
+    const urls = urlDef.urls;
+    let stu = wx.getStorageSync('student');
+    if (stu) {
+      this.setData({ 'curStu': stu });
+      let params = {  'q.studentId': stu.studentId, 'q.orgId': stu.orgId }
+      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/leaveRecord/leaveRecord.wxml

@@ -1,6 +1,6 @@
 <view class="container">
   <!-- 补课记录列表 -->
-  <lessonsList id="lessonsList" list="{{list}}"></lessonsList>
+  <lessonsList id="lessonsList" list="{{list}}" action="1"></lessonsList>
   <!-- end -->
   <view class="loading">{{loading}}</view>
 </view>

+ 2 - 2
pages/schedule/schedule.js

@@ -25,7 +25,7 @@ Page({
     const urls = urlDef.urls;
     let stu = wx.getStorageSync('student');
     if (stu) {
-      this.setData('curStu', stu);
+      this.setData({'curStu': stu});
       util.apiPost(urls.get_sys_params, { 'q.orgId': stu.orgId, 'q.id': 'f8158acabeeb44ec9ff651aade6b295f' }).then((rs) => {
         if (rs && rs.length > 0) {
           // 将分钟转为毫秒
@@ -103,7 +103,7 @@ Page({
       o.bt = o.beginTime.substring(11, 16);
       o.et = o.endTime.substring(11, 16);
     })
-    this.setData({ 'date': v, 'week': week, 'dateList': list });
+    this.setData({ 'date': v, 'week': week, 'dateList': [{ items: list, date: v, week: week }] });
   },
   callSelectDate: function (d) {
     let v = d.detail.dateString;

+ 1 - 1
pages/schedule/schedule.wxml

@@ -5,7 +5,7 @@
   <!-- end -->
 
   <!-- 课表列表 -->
-   <classList date="{{date}}" list="{{dateList}}"></classList>
+   <classList date="{{date}}" list="{{dateList}}" showFlag="true" showTime="true"></classList>
   <!-- end -->
 
 </view>

+ 14 - 3
pages/targetList/targetList.js

@@ -10,6 +10,7 @@ Page({
   data: {
     source: null,
     target: null,
+    dayScope: 7,// 默认 7 天
     action: 0,
     list: [
     ],
@@ -19,7 +20,7 @@ Page({
     holidays: []
   },
 
-  showChoose:function(){
+  showChoose: function () {
     this.selectComponent("#classList").showChoose()
   },
 
@@ -27,19 +28,27 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
+    wx.showLoading({
+      title: '正在加载数据 ...',
+      mask: true
+    })
     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 _dayScope = o.dayScope
+    if (_dayScope) {
+      this.setData({ dayScope: _dayScope })
+    }
+    this.setData({ source: s, target: t, action: o.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 edd = new Date(now.setDate(now.getDate() + this.data.dayScope));
     let ed = util.formatTime(edd).substring(0, 10).replace(/\//g, '-')
     this.setData({ beginDate: bd, endDate: ed, list: [] });
 
@@ -210,6 +219,8 @@ Page({
           });
           classItem = data;
           this.setData({ list: classItem })
+
+          wx.hideLoading()
         }
 
       })

+ 1 - 1
pages/targetList/targetList.wxml

@@ -1,6 +1,6 @@
 <view class="container">
   <view class="classList">
-    <classList id="classList" showFlag="{{false}}" showRadio="{{true}}" list="{{list}}"></classList>
+    <classList id="classList" showFlag="{{false}}" showRadio="{{true}}" list="{{list}}" action="{{action}}" source="{{source}}"></classList>
   </view>
 
   <view class="submit-btn" bindtap="showChoose">确定</view>

+ 3 - 3
pages/task/task.js

@@ -35,7 +35,7 @@ Page({
     })
   },
 
-  getDates:function(e){
+  getDates: function (e) {
     this.setData({
       beginDate: e.detail[0],
       endDate: e.detail[1],
@@ -56,7 +56,7 @@ Page({
       let today = util.curTime().substring(0, 10).replace(/\//g, '-')
       this.setData({ 'beginDate': today.substring(0, 8) + '01', 'endDate': today })
     }
-    
+
   },
 
   /**
@@ -116,7 +116,7 @@ Page({
     const urls = urlDef.urls;
     let stu = wx.getStorageSync('student');
     if (stu) {
-      this.setData('curStu', stu);
+      this.setData({ 'curStu': stu });
       let params = { 'q.beginDate': this.data.beginDate, 'q.endDate': this.data.endDate, 'q.studentId': stu.studentId, 'q.status': this.data.status }
       params.pageNum = this.data.pageNum
       util.apiPost(urls.my_homework, params).then(rs => {

+ 61 - 26
pages/theClasses/theClasses.js

@@ -8,7 +8,6 @@ Page({
    * 页面的初始数据
    */
   data: {
-    curStu: null,
     aheadTime: 0,
     eventList: [],
     holidayList: [],
@@ -16,27 +15,31 @@ Page({
     date: null,
     week: 0,
     weekMap: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
-    tipList:[
+    tipList: [
       '1.每月仅有2次调课机会。如撤销,默认是为使用一次调整机会\r\n\r\n',
       '2.允许调课至原课程前后一周内。例如:今天11-30日,可调整到11.23到12.07之间的课程\r\n\r\n',
       '3.可提前7天进行调课\r\n\r\n',
       '4.调入后的课程,不可再调及请假'
-    ]
+    ],
+    transferDay: 0,
+    transferCount: 2,
+    monthCount: 0,
+    curDate: null,
   },
 
-  getTip:function(){
+  getTip: function () {
     var str = ''
-    for(var i in this.data.tipList){
-      str+= this.data.tipList[i]
+    for (var i in this.data.tipList) {
+      str += this.data.tipList[i]
     }
     wx.showModal({
-        title: '调课说明',
-         content: str,
-         showCancel: false,//是否显示取消按钮
-         cancelText:"否",//默认是“取消”
-         cancelColor:'#999999',//取消文字的颜色
-         confirmText:"我知道了",//默认是“确定”
-         confirmColor: 'skyblue',//确定文字的颜色
+      title: '调课说明',
+      content: str,
+      showCancel: false,//是否显示取消按钮
+      cancelText: "否",//默认是“取消”
+      cancelColor: '#999999',//取消文字的颜色
+      confirmText: "我知道了",//默认是“确定”
+      confirmColor: 'skyblue',//确定文字的颜色
     })
   },
 
@@ -47,7 +50,12 @@ Page({
     const urls = urlDef.urls;
     let stu = wx.getStorageSync('student');
     if (stu) {
-      this.setData('curStu', stu);
+      util.apiPost(urls.get_sys_params + '&q.orgId=' + stu.orgId + '&q.id=1000_8').then((rs) => {
+        if (rs && rs.length > 0) {
+          this.setData({ transferDay: parseInt(rs[0].sysVal, 10) })
+        }
+      });
+
       util.apiPost(urls.get_sys_params, { 'q.orgId': stu.orgId, 'q.id': 'f8158acabeeb44ec9ff651aade6b295f' }).then((rs) => {
         if (rs && rs.length > 0) {
           // 将分钟转为毫秒
@@ -115,22 +123,49 @@ Page({
   onShareAppMessage: function () {
 
   },
-  selectDate: function (d) {
-    console.log('selectDate ' + d)
-  },
-  callSelectDate: function (d) {
-    let v = d.detail.dateString;
+  selectDate: function (v) {
+    this.setData({ curDate: v })
     let vd = new Date(v);
     let week = this.data.weekMap[vd.getDay()];
-
-
     let list = this.data.eventList.filter(o => {
       return o.attenceDate == v;
     });
-    list.map(o => {
-      o.bt = o.beginTime.substring(11, 16);
-      o.et = o.endTime.substring(11, 16);
-    })
-    this.setData({ 'date': v, 'week': week, 'dateList': list });
+
+    let endDate = new Date(new Date().getTime() + 604800000)
+    if (this.data.transferDay > 0) {
+      const temDate = new Date();
+      temDate.setDate(temDate.getDate() + this.data.transferDay);
+      endDate = temDate;
+    }
+    let today = util.curTime().substring(0, 10).replace(/\//g, '-')
+    endDate = util.formatTime(endDate).substring(0, 10).replace(/\//g, '-')
+    let stu = wx.getStorageSync('student');
+    let urls = urlDef.urls;
+    util.apiPost(urls.get_attence_count + '&q.status=3&q.studentId=' + stu.studentId + '&q.month=' + v.substring(0, 7)).then((rs) => {
+      this.setData({ monthCount: rs })
+
+
+      list.map(o => {
+        o.bt = o.beginTime.substring(11, 16);
+        o.et = o.endTime.substring(11, 16);
+        if (o.status == 0 && o.isAttend == 0) {
+          if (this.data.monthCount >= this.data.transferCount) { // 本月内调过2次课的,不允许再调课
+            o.transferFlag = false;
+          } else {
+            // 晚于当前时间才能调课(当天都不行) 2周内
+            if (o.attenceDate > today && o.attenceDate <= endDate) {
+              o.transferFlag = true;
+            } else {
+              o.transferFlag = false;
+            }
+          }
+        }
+      })
+      this.setData({ 'date': v, 'week': week, 'dateList': [{ items: list, date: v, week: week }] });
+    }).catch(e => { });
+  },
+  callSelectDate: function (d) {
+    let v = d.detail.dateString;
+    this.selectDate(v);
   }
 })

+ 1 - 1
pages/theClasses/theClasses.wxml

@@ -9,7 +9,7 @@
 <!-- end -->
 
 <!-- 课表列表 -->
- <classList date="{{date}}" list="{{dateList}}"></classList>
+ <classList date="{{date}}" list="{{dateList}}" action="3"></classList>
 <!-- end -->
 
 </view>