From 9f78f3f014a3423ea3fcab8f9f1056c57cd47fc8 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期五, 26 八月 2022 17:16:26 +0800
Subject: [PATCH] 2022.8.26

---
 pages/home/home.js |  143 +++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 123 insertions(+), 20 deletions(-)

diff --git a/pages/home/home.js b/pages/home/home.js
index d77d1db..f7c2d96 100644
--- a/pages/home/home.js
+++ b/pages/home/home.js
@@ -1,7 +1,10 @@
 // pages/home/home.js
 const userservice = require("../../service/userservice")
+const notificationservice = require("../../service/notificationservice")
 const assessmentService = require("../../service/assessmentservice")
 const lawservice = require("../../service/lawservice")
+const promiseservice = require("../../service/promiseservice")
+const ledgerservice = require("../../service/ledgerservice")
 const moment = require('../../utils/moment.min')
 const app = getApp()
 /**
@@ -13,10 +16,7 @@
    * 椤甸潰鐨勫垵濮嬫暟鎹�
    */
   data: {
-    notices: [{
-      notice: "鏈湀瀹堟硶鎵胯鑷祴鏅鸿瘎宸插紑鍚紝璇峰強鏃惰繘琛岃瘎浠�",
-      time: "2022/3/1"
-    }],
+    notices: [],
 
     dynamic: [{
       title: "浼佷笟钀ヤ笟鎵х収銆侀鍝佺粡钀ヨ鍙瘉涓㈠け璇ュ浣曡ˉ棰�",
@@ -34,9 +34,21 @@
       score: '--',
       rank: '--',
       legalIndex: '--',
-      illegalIndex: '--'
+      illegalIndex: '--',
+      period: ''
     },
-    period: ''
+    //鍙拌处瀹屾垚鎯呭喌
+    ledgerInfo: {
+      //蹇呭~椤规�绘暟
+      totalMust: 0,
+      //蹇呭~椤规彁浜ゆ暟
+      finishedMust: 0,
+    },
+    //鎵胯瀹屾垚鎯呭喌
+    promsieInfo: {
+      leftDays: 0
+    }
+
   },
 
   /**
@@ -57,6 +69,23 @@
     this.getUserInfo()
     this.getHistoryPoint()
     this.getNews()
+    this.getCommitment()
+    this.getLedgerType()
+  },
+
+  onShow(){
+    if (app.globalData.isLogin) {
+      
+    }
+  },
+
+  onPullDownRefresh(){
+    console.log('onPullDownRefresh');
+    wx.stopPullDownRefresh({
+      success: (res) => {},
+      fail: (res) => {},
+      complete: (res) => {},
+    })
   },
 
   getNextEvaluationTime() {
@@ -73,11 +102,21 @@
   },
 
   getNotice() {
-    this.setData({
-      notices: [{
-        notice: "鏈湀瀹堟硶鎵胯鑷祴鏅鸿瘎宸插紑鍚紝璇峰強鏃惰繘琛岃瘎浠�",
-        time: "2022/5/9"
-      }]
+    var that = this
+    notificationservice.getNotification(app.globalData.accessToken.userId, 1, {
+      success(res) {
+        let notices = []
+        res.forEach(r => {
+          notices.push({
+            notice: r.title,
+            time: moment(r.updateTime).format('YYYY/MM/DD'),
+            isRead: r.hasRead
+          })
+          that.setData({
+            notices
+          })
+        });
+      }
     })
   },
 
@@ -85,6 +124,9 @@
     var that = this
     assessmentService.getHistoryPoint(app.globalData.accessToken.userId, 1, {
       success(data) {
+        if (data.length == 0) {
+          return
+        }
         let lastOne = data[0]
         let year = lastOne.updateDate.substring(0, 4)
         let month = lastOne.updateDate.substring(5, 7)
@@ -94,7 +136,8 @@
             score: lastOne.totalPoint,
             rank: lastOne.rank,
             legalIndex: lastOne.level,
-            illegalIndex: lastOne.level
+            illegalIndex: lastOne.level,
+            period: lastOne.period
           }
         })
       }
@@ -104,7 +147,10 @@
   getNews() {
     var that = this
     let user = app.globalData.userInfo
-    lawservice.getLawRegulations(user.guid, 1, user.extension2, {
+    lawservice.getLawRegulations(user.guid, 1, {
+      sceneTypeId: user.extension2,
+      fileType: 1
+    }, {
       success(data) {
         let laws = []
         data.forEach(d => {
@@ -125,6 +171,57 @@
   },
 
   /**
+   * 鑾峰彇鎵胯鍘嗗彶璁板綍
+   */
+  getCommitment() {
+    var that = this
+    promiseservice.getCommitment(app.globalData.accessToken.userId, {
+      success(data) {
+        if (data.length > 0) {
+          let c = data[0]
+          let cTime = moment(c.cmCreateTime)
+          let leftDays = cTime.add(1, 'years').diff(moment(), 'days')
+          that.setData({
+            promsieInfo: {
+              leftDays: leftDays
+            }
+          })
+        }
+      }
+    })
+  },
+
+  getLedgerType() {
+    var that = this
+    var time = moment().format('YYYY-MM-DD')
+    ledgerservice.getLedgerSummary(app.globalData.accessToken.userId, app.globalData.userInfo.extension2, time, {
+      success(res) {
+        that.parseLedgerType(res)
+      }
+    })
+  },
+
+  parseLedgerType(subtypes) {
+    let monthInfo = {
+      totalMust: 0,
+      finishedMust: 0,
+    }
+    subtypes.forEach(s => {
+      //鏈堝害缁熻
+      if (s.needUpdate) {
+        monthInfo.totalMust++
+        if (s.upLoad) {
+          monthInfo.finishedMust++
+        }
+      }
+    });
+
+    monthInfo.percent = Math.round(monthInfo.finishedMust / monthInfo.totalMust * 100)
+
+    this.setData({monthInfo})
+  },
+
+  /**
    * 椤甸潰璺宠浆
    */
   goto: function (e) {
@@ -133,7 +230,17 @@
     switch (index) {
       case "0":
         //娴嬭瘎鍘嗗彶璁板綍
-        url = ""
+        url = `/pages/gradereport/gradereport?period=${this.data.historyPoint.period}`
+        break;
+      case "5":
+        wx.switchTab({
+          url: '/pages/module_ledger/ledgerhome/ledgerhome',
+        })
+        return;
+      case "6":
+        wx.switchTab({
+          url: '/pages/promise/promise',
+        })
         break;
       case "1":
         //宸ヤ綔鎻愰啋
@@ -145,9 +252,7 @@
         break;
       case "3":
         //鍦ㄧ嚎瀹堟硶瀛︿範
-        
-        url = `/pages/learn/learn`
-        
+        url = `/pages/module_learn/learn/learn`
         break;
       case "4":
         //瀹堟硶鍔ㄦ��
@@ -168,14 +273,12 @@
               success: function (res) {
                 console.log('鎵撳紑鏂囨。鎴愬姛')
               },
-              fail (error) {
+              fail(error) {
                 console.log(error);
               }
             })
           }
         })
-        break;
-      case "5":
         break;
     }
     if (url != "") {

--
Gitblit v1.9.3