Silent il y a 6 ans
Parent
commit
69634627f8

+ 24 - 0
app/Http/Controllers/WeChat/ApiController.php

xqd xqd
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\WeChat;
 
 use App\Models\CheckCard;
 use App\Models\Content;
+use App\Models\Leave;
 use App\Models\Setting;
 use App\Models\Student;
 use App\Models\StudentCourse;
@@ -235,4 +236,27 @@ class ApiController extends Controller
         }
         return $res;
     }
+
+    public function applyLeave(Request $request)
+    {
+        if(empty($request->input('student_id')) || empty($student = Student::find($request->input('student_id')))) {
+            return response()->json(['status' => 'fail', 'info' => '找不到学员']);
+        }
+        $student_course = StudentCourse::where('student_id', $student->id)->first();
+        if(empty($course)) {
+            return response()->json(['status' => 'fail', 'info' => '暂无课程']);
+        }
+        $res = Leave::create([
+            'student_id' => $student->id,
+            'course_id' => $student_course->course_id,
+            'student_course_id' => $student_course->id,
+            'date' => $request->input('date'),
+            'days' => $request->input('days'),
+            'remark' => $request->input('remark')
+        ]);
+        if(!$res) {
+            return response()->json(['status' => 'fail', 'info' => '保存失败']);
+        }
+        return response()->json(['status' => 'success', 'info' => '请假成功']);
+    }
 }

+ 2 - 1
routes/wechat.php

xqd
@@ -8,4 +8,5 @@ Route::get('endCheckCard', 'ApiController@endCheckCard');
 Route::get('getShareInfo', 'ApiController@getShareInfo');
 Route::get('getMoreVideos', 'ApiController@getMoreVideos');
 Route::get('getCourseInfo', 'ApiController@getCourseInfo');
-Route::get('getMyLearnInfo', 'ApiController@getMyLearnInfo');
+Route::get('getMyLearnInfo', 'ApiController@getMyLearnInfo');
+Route::get('applyLeave', 'ApiController@applyLeave');

+ 37 - 8
wechat/pages/apply-leave/apply-leave.js

xqd
@@ -1,22 +1,51 @@
 
 var app = getApp()
+var api = require('../../utils/api.js');
 Page({
-  
-  onLoad: function () {
-    console.log('onLoad')
-  },
   data: {
-    date: '2018/6/23',
+    date: '',
     typeEnum: [
-      '长假60天', '长假60天', '长假60天'
+      '短假1天', '长假7天'
     ],
     selectedType: 0
   },
+  onLoad: function () {
+    let date = this.getNowFormatDate();
+    this.setData({
+      date: date
+    })
+  },
+  getNowFormatDate() {
+    var date = new Date();
+    var seperator1 = "-";
+    var year = date.getFullYear();
+    var month = date.getMonth() + 1;
+    var strDate = date.getDate();
+    if(month >= 1 && month <= 9) {
+      month = "0" + month;
+    }
+        if (strDate >= 0 && strDate <= 9) {
+      strDate = "0" + strDate;
+    }
+        var currentdate = year + seperator1 + month + seperator1 + strDate;
+    return currentdate;
+  },
   bindDateChange: function(e) {
     console.log('picker发送选择改变,携带值为', e.detail.value)
     this.setData({
-      date: e.detail.value.replace(/-/g, '/')
+      date: e.detail.value
+    })
+  },
+  formSubmit: function (e) {
+    let value = e.detail.value
+    wx.request({
+      url: api.applyLeaveUrl,
+      method: 'GET',
+      data: {
+        'student_id': wx.getStorageSync('pt_student').id,
+        'date': value.date,
+        'type': value.type
+      }
     })
-
   }
 })

+ 26 - 33
wechat/pages/apply-leave/apply-leave.wxml

xqd
@@ -1,34 +1,27 @@
-<view>
-  <zan-cell-group>
-    <zan-cell title="请假日期" is-link>
-      <picker
-        slot="footer"
-        mode="date"
-        value="{{date}}"
-        bindchange="bindDateChange"
-      >
-        {{date}}
-      </picker>
-    </zan-cell>
-    <zan-cell title="请假类型" is-link>
-      <picker
-        slot="footer"
-        mode="selector"
-        range="{{typeEnum}}"
-        value="{{selectedType}}"
-      >
-      {{typeEnum[selectedType]}}
-      </picker>
-    </zan-cell>
-    <zan-cell title="说明">
-      <view class="section">
-        <textarea placeholder="请输入请假说明"  auto-height />
-      </view>
-    </zan-cell>
-  </zan-cell-group>
-  <zan-cell></zan-cell>
+<form bindsubmit="formSubmit">
+  <view>
+    <zan-cell-group>
+      <zan-cell title="请假日期" is-link>
+        <picker slot="footer" mode="date" value="{{date}}" bindchange="bindDateChange" name='date'>
+          {{date}}
+        </picker>
+      </zan-cell>
+      <zan-cell title="请假类型" is-link>
+        <picker slot="footer" mode="selector" range="{{typeEnum}}" value="{{selectedType}}" name='type'>
+          {{typeEnum[selectedType]}}
+        </picker>
+      </zan-cell>
+      <zan-cell title="说明">
+        <view class="section">
+          <textarea placeholder="请输入请假说明" auto-height name='info'/>
+        </view>
+      </zan-cell>
+    </zan-cell-group>
     <zan-cell></zan-cell>
-    <zan-button-group>
-      <zan-button type="primary" bindtap="onSubmit">提交</zan-button>
-    </zan-button-group>
-</view>
+    <zan-cell></zan-cell>
+    <!-- <zan-button-group>
+       <zan-button type="primary" btnclick="onSubmit">提交</zan-button>
+    </zan-button-group> -->
+    <button formType="submit" type='primary' class='submit-btn'>提交</button>
+  </view>
+</form>

+ 3 - 0
wechat/pages/apply-leave/apply-leave.wxss

xqd
@@ -0,0 +1,3 @@
+.submit-btn {
+  margin: 3px 3px
+}

+ 3 - 1
wechat/pages/index/index.js

xqd
@@ -33,7 +33,9 @@ Page({
       }
     })
     var pt_student = wx.getStorageSync('pt_student')
-
+    let ok = 1;
+    let tmp = ok == 1 ? '2' : '3';
+    console.log(tmp)
     wx.request({
       url: api.getShareInfoUrl,
       method: 'GET',

+ 3 - 3
wechat/pages/my-log/my-log.wxml

xqd
@@ -6,8 +6,8 @@
     show-more-days="true"
   />
   <zan-cell-group>
-    <zan-cell title="本月积累学习时长" value="8小时56分"> </zan-cell>
-    <zan-cell title="总学习时间" value="131小时28分"> </zan-cell>
-    <zan-cell title="总打卡天数" value="16天"> </zan-cell>
+    <zan-cell title="本月积累学习时长" value="{{ thisMonthLearnTime }}"> </zan-cell>
+    <zan-cell title="总学习时间" value="{{ totalLearnTime }}"> </zan-cell>
+    <zan-cell title="总打卡天数" value="{{ checkCardDays }}"> </zan-cell>
   </zan-cell-group>
 </view>

+ 1 - 0
wechat/utils/api.js

xqd
@@ -11,4 +11,5 @@ module.exports = {
   getMoreVideosUrl: headUrl + 'getMoreVideos',
   getCourseInfoUrl: headUrl + 'getCourseInfo',
   getMyLearnInfoUrl: headUrl + 'getMyLearnInfo',
+  applyLeaveUrl: headUrl + 'applyLeave',
 }