From 48145f787eda81815f653ad21161a60e89b6a303 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期三, 13 十一月 2024 16:41:32 +0800
Subject: [PATCH] 2024.11.13

---
 pages/home/home.js |  367 +++++++++++++++++++++++++++++++--------------------
 1 files changed, 222 insertions(+), 145 deletions(-)

diff --git a/pages/home/home.js b/pages/home/home.js
index f7c2d96..4a2b497 100644
--- a/pages/home/home.js
+++ b/pages/home/home.js
@@ -1,44 +1,47 @@
 // 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()
+import $f from '../../service/baserequest';
+
+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();
 /**
  * 棣栭〉
  */
 Page({
-
   /**
    * 椤甸潰鐨勫垵濮嬫暟鎹�
    */
   data: {
-    notices: [],
+    icon1: $f.baseIconUrl + 'res/btn_bg_1.png',
+    icon2: $f.baseIconUrl + 'res/btn_bg_2.png',
+    icon3: $f.baseIconUrl + 'res/wm_assessment.png',
 
-    dynamic: [{
-      title: "浼佷笟钀ヤ笟鎵х収銆侀鍝佺粡钀ヨ鍙瘉涓㈠け璇ュ浣曡ˉ棰�",
-      time: "2022骞�4鏈�5鏃�",
-      views: 2012,
-      pic: "/res/icons/temp_pic_1.png"
-    }],
+    notices: [],
+    unReadNoiceCount: 0,
+
+    dynamic: [],
 
     nextEvaluationTime: '2022骞�6鏈�9鏃�',
     userRealName: '',
 
     //鍘嗗彶璇勫垎璇︽儏
+    assessmentCompleted: false,
     historyPoint: {
       time: '娴嬭瘎鍛ㄦ湡----骞�--鏈�',
       score: '--',
       rank: '--',
       legalIndex: '--',
       illegalIndex: '--',
-      period: ''
+      period: '',
     },
     //鍙拌处瀹屾垚鎯呭喌
-    ledgerInfo: {
+    ledgerCompleted: false,
+    monthInfo: {
       //蹇呭~椤规�绘暟
       totalMust: 0,
       //蹇呭~椤规彁浜ゆ暟
@@ -46,245 +49,319 @@
     },
     //鎵胯瀹屾垚鎯呭喌
     promsieInfo: {
-      leftDays: 0
-    }
-
+      leftDays: 0,
+    },
   },
 
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
    */
   onLoad: function (options) {
+    //鍒ゆ柇鐢ㄦ埛鏄惁涓洪娆$櫥褰曪紝鍐冲畾鏄惁寮哄埗淇敼榛樿瀵嗙爜
+    if (
+      app.globalData.userInfo.remark == null ||
+      app.globalData.userInfo.remark == ''
+    ) {
+      wx.navigateTo({
+        url: '/pages/mUser/pChangepw/pChangepw',
+      });
+    }
+
     wx.getStorage({
       key: 'accessToken',
-      success: (result) => {
+      success: result => {
         console.log(result.data);
       },
-      fail: (res) => {},
-      complete: (res) => {},
-    })
+      fail: res => {},
+      complete: res => {},
+    });
 
-    this.getNextEvaluationTime()
-    this.getNotice()
-    this.getUserInfo()
-    this.getHistoryPoint()
-    this.getNews()
-    this.getCommitment()
-    this.getLedgerType()
+    // this.getNextEvaluationTime();
+    // this.getNotice();
+    // this.getUnReadNoticeCount();
+    this.getUserInfo();
+    // this.getHistoryPoint();
+    // this.getNews();
+    // this.getCommitment();
+    // this.getLedgerType();
   },
 
-  onShow(){
+  onShow() {
     if (app.globalData.isLogin) {
-      
+      wx.startPullDownRefresh({
+        success: res => {},
+        fail: res => {},
+        complete: res => {},
+      });
     }
   },
 
-  onPullDownRefresh(){
-    console.log('onPullDownRefresh');
-    wx.stopPullDownRefresh({
-      success: (res) => {},
-      fail: (res) => {},
-      complete: (res) => {},
-    })
+  onPullDownRefresh() {
+    this.getNextEvaluationTime();
+    this.getNotice();
+    this.getUnReadNoticeCount();
+    this.getHistoryPoint();
+    this.getNews();
+    this.getCommitment();
+    this.getLedgerType();
   },
 
   getNextEvaluationTime() {
-    let now = moment().add(1, 'months')
+    let now = moment().add(1, 'months');
     this.setData({
-      nextEvaluationTime: now.format("YYYY骞碝M鏈�10鏃�")
-    })
+      nextEvaluationTime: now.format('YYYY骞碝M鏈�10鏃�'),
+    });
   },
 
   getUserInfo() {
     this.setData({
-      userRealName: app.globalData.userInfo.realname
-    })
+      userRealName: app.globalData.userInfo.realname,
+    });
   },
 
   getNotice() {
-    var that = this
+    var that = this;
     notificationservice.getNotification(app.globalData.accessToken.userId, 1, {
       success(res) {
-        let notices = []
+        let notices = [];
         res.forEach(r => {
           notices.push({
             notice: r.title,
             time: moment(r.updateTime).format('YYYY/MM/DD'),
-            isRead: r.hasRead
-          })
+            isRead: r.hasRead,
+          });
           that.setData({
-            notices
-          })
+            notices,
+          });
         });
-      }
-    })
+      },
+    });
+  },
+
+  getUnReadNoticeCount() {
+    var that = this;
+    notificationservice.getUnReadNoticeCount(
+      app.globalData.accessToken.userId,
+      {
+        success(res) {
+          that.setData({ unReadNoiceCount: res });
+        },
+      },
+    );
   },
 
   getHistoryPoint() {
-    var that = this
+    var that = this;
     assessmentService.getHistoryPoint(app.globalData.accessToken.userId, 1, {
       success(data) {
         if (data.length == 0) {
-          return
+          return;
         }
-        let lastOne = data[0]
-        let year = lastOne.updateDate.substring(0, 4)
-        let month = lastOne.updateDate.substring(5, 7)
+        let lastOne = data[0];
+        let year = lastOne.updateDate.substring(0, 4);
+        let month = lastOne.updateDate.substring(5, 7);
+        const now = moment();
+        if (now.year() == year && now.month() + 1 == month) {
+          that.setData({
+            assessmentCompleted: true,
+          });
+        }
         that.setData({
           historyPoint: {
-            time: `娴嬭瘎鍛ㄦ湡${year}骞�${month}鏈坄,
+            time: `鏈�鏂颁竴鏈� ${year}骞�${month}鏈坄,
             score: lastOne.totalPoint,
             rank: lastOne.rank,
             legalIndex: lastOne.level,
             illegalIndex: lastOne.level,
-            period: lastOne.period
-          }
-        })
-      }
-    })
+            period: lastOne.period,
+          },
+        });
+      },
+    });
   },
 
   getNews() {
-    var that = this
-    let user = app.globalData.userInfo
-    lawservice.getLawRegulations(user.guid, 1, {
-      sceneTypeId: user.extension2,
-      fileType: 1
-    }, {
-      success(data) {
-        let laws = []
-        data.forEach(d => {
-          laws.push({
-            title: d.lrResourcetitle,
-            time: d.lrPublishdate.substring(0, 10),
-            views: parseInt(Math.random() * 1000 + 10),
-            pic: d.lrPicurl,
-            url: d.lrBodyurl,
-            fileType: d.lrResourcefiletype,
-          })
-        });
-        that.setData({
-          dynamic: laws
-        })
-      }
-    })
+    var that = this;
+    let user = app.globalData.userInfo;
+    lawservice.getLawRegulations(
+      user.guid,
+      1,
+      {
+        sceneTypeId: user.extension2,
+        fileType: 1,
+      },
+      {
+        success(data) {
+          let laws = [];
+          data.forEach(d => {
+            laws.push({
+              title: d.lrResourcetitle,
+              time: d.lrPublishdate.substring(0, 10),
+              views: parseInt(Math.random() * 1000 + 10),
+              pic: d.lrPicurl,
+              url: d.lrBodyurl,
+              fileType: d.lrResourcefiletype,
+            });
+          });
+          that.setData({
+            dynamic: laws,
+          });
+        },
+      },
+    );
   },
 
   /**
    * 鑾峰彇鎵胯鍘嗗彶璁板綍
    */
   getCommitment() {
-    var that = this
+    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')
+          let c = data[0];
+          let cTime = moment(c.cmCreateTime);
+          let leftDays = cTime.add(1, 'years').diff(moment(), 'days');
           that.setData({
             promsieInfo: {
-              leftDays: leftDays
-            }
-          })
+              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)
-      }
-    })
+    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);
+        },
+        complete() {
+          wx.stopPullDownRefresh({
+            success: res => {},
+            fail: res => {},
+            complete: res => {},
+          });
+        },
+      },
+    );
   },
 
   parseLedgerType(subtypes) {
     let monthInfo = {
       totalMust: 0,
       finishedMust: 0,
-    }
+      totalSelf: 0,
+      finishedSelf: 0,
+    };
     subtypes.forEach(s => {
       //鏈堝害缁熻
       if (s.needUpdate) {
-        monthInfo.totalMust++
+        monthInfo.totalMust++;
+        //缁熻鑷贰鏌ョ被鍨嬬殑鍙拌处锛岀被鍒负-1锛堟殏瀹氾級
+        if (s.ledgerTypeId == -1) {
+          monthInfo.totalSelf++;
+        }
         if (s.upLoad) {
-          monthInfo.finishedMust++
+          monthInfo.finishedMust++;
+          if (s.ledgerTypeId == -1) {
+            monthInfo.finishedSelf++;
+          }
         }
       }
     });
 
-    monthInfo.percent = Math.round(monthInfo.finishedMust / monthInfo.totalMust * 100)
+    monthInfo.percent =
+      monthInfo.totalMust == 0
+        ? 0
+        : Math.round((monthInfo.finishedMust / monthInfo.totalMust) * 100);
+    monthInfo.percent2 =
+      monthInfo.totalSelf == 0
+        ? 0
+        : Math.round((monthInfo.finishedSelf / monthInfo.totalSelf) * 100);
 
-    this.setData({monthInfo})
+    this.setData({
+      monthInfo,
+      ledgerCompleted: monthInfo.percent >= 100 && monthInfo.percent2 >= 100,
+      // ledgerCompleted: true
+    });
   },
 
   /**
    * 椤甸潰璺宠浆
    */
   goto: function (e) {
-    var url = ""
-    var index = e.currentTarget.dataset.index
+    var url = '';
+    var index = e.currentTarget.dataset.index;
     switch (index) {
-      case "0":
+      case '0':
         //娴嬭瘎鍘嗗彶璁板綍
-        url = `/pages/gradereport/gradereport?period=${this.data.historyPoint.period}`
+        if (this.data.historyPoint.period == '') {
+          url = `/pages/mAssessment/grade/grade`;
+        } else {
+          url = `/pages/mAssessment/gradereport/gradereport?period=${this.data.historyPoint.period}`;
+        }
         break;
-      case "5":
+      case '5':
         wx.switchTab({
-          url: '/pages/module_ledger/ledgerhome/ledgerhome',
-        })
+          url: '/pages/mLedger/home/index',
+        });
         return;
-      case "6":
-        wx.switchTab({
-          url: '/pages/promise/promise',
-        })
-        break;
-      case "1":
+      case '6':
+        wx.navigateTo({
+          url: '/pages/mPromise/promisehome/promise',
+        });
+        return;
+      case '1':
         //宸ヤ綔鎻愰啋
-        url = "/pages/notice/notice"
+        url = '/pages/mNotice/notice/notice';
         break;
-      case "2":
+      case '2':
         //鏅鸿兘鍦ㄧ嚎鍜ㄨ
-        url = "/pages/module_consult/consulthome/consulthome"
+        url = '/pages/mConsult/consulthome/consulthome';
         break;
-      case "3":
+      case '3':
         //鍦ㄧ嚎瀹堟硶瀛︿範
-        url = `/pages/module_learn/learn/learn`
+        url = `/pages/mLearn/learn/learn`;
         break;
-      case "4":
+      case '4':
         //瀹堟硶鍔ㄦ��
         // url = "/pages/text/text"
-        let bodyUrl = e.currentTarget.dataset.url
-        let fileType = e.currentTarget.dataset.filetype
+        let bodyUrl = e.currentTarget.dataset.url;
+        let fileType = e.currentTarget.dataset.filetype;
         wx.showLoading({
-          title: ' 鏂囦欢涓嬭浇涓�',
+          title: ' 鍔犺浇涓�',
           mask: true,
-        })
+        });
         wx.downloadFile({
           url: bodyUrl,
           success: function (res) {
-            wx.hideLoading()
-            const filePath = res.tempFilePath
+            wx.hideLoading();
+            const filePath = res.tempFilePath;
             wx.openDocument({
               filePath: filePath,
               success: function (res) {
-                console.log('鎵撳紑鏂囨。鎴愬姛')
+                console.log('鎵撳紑鏂囨。鎴愬姛');
               },
               fail(error) {
                 console.log(error);
-              }
-            })
-          }
-        })
-        break;
+              },
+            });
+          },
+        });
+        return;
     }
-    if (url != "") {
+    if (url != '') {
       wx.navigateTo({
-        url: url
-      })
+        url: url,
+      });
     }
-  }
-})
\ No newline at end of file
+  },
+});

--
Gitblit v1.9.3