From edd35a251b58b1fad17015deda92324f74458434 Mon Sep 17 00:00:00 2001
From: unknown <unknown@example.com>
Date: 星期三, 17 八月 2022 00:05:30 +0800
Subject: [PATCH] 台账模块、智能咨询模块

---
 pages/module_ledger/ledgerhome/ledgerhome.js |  183 +++++++++++++++++++++++++++++++++++++++------
 1 files changed, 158 insertions(+), 25 deletions(-)

diff --git a/pages/module_ledger/ledgerhome/ledgerhome.js b/pages/module_ledger/ledgerhome/ledgerhome.js
index 2cf573e..d72761e 100644
--- a/pages/module_ledger/ledgerhome/ledgerhome.js
+++ b/pages/module_ledger/ledgerhome/ledgerhome.js
@@ -9,14 +9,50 @@
    * 椤甸潰鐨勫垵濮嬫暟鎹�
    */
   data: {
-    deadline: '',
-    leftday:0 ,
+    thisMonth: '',
+    lastMonth: '',
 
+    //鎻愪氦鏈熼檺
+    deadline: '',
+    //鍓╀綑鎻愪氦澶╂暟
+    leftday: 0,
+
+    //鏈湀姹囨��
+    thisMonthInfo: {
+      //蹇呭~椤规�绘暟
+      totalMust: 0,
+      //蹇呭~椤规彁浜ゆ暟
+      finishedMust: 0,
+      //閫夊~椤规�绘暟
+      totalSelect: 0,
+      //閫夊~椤规彁浜ゆ暟
+      finishedSelect: 0,
+      //鎻愪氦鎯呭喌
+      status: '',
+      //瓒呮椂鎯呭喌
+      overtime: '',
+      //寤鸿
+      suggestion: ''
+    },
+    //涓婃湀姹囨��
+    lastMonthInfo: {
+      totalMust: 0,
+      finishedMust: 0,
+      totalSelect: 0,
+      finishedSelect: 0,
+      status: '',
+      overtime: '',
+      suggestion: ''
+    },
+
+    //閫夐」鍗$浉鍏�
     currentTab: 0,
     tabList: [],
     pageList: [],
+    pageheight: '300px',
 
-    pageheight: '300px'
+    //褰撳墠鏄剧ず鏈堜唤
+    showThisMonth: true,
   },
 
   //姣忔湀鍙拌处鎻愪氦鏈熼檺鏃�
@@ -26,14 +62,31 @@
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
    */
   onLoad(options) {
-    this.getLedgerType()
-
-    var deadline = moment().format(`MM-${this.DEADLINEDAY}`)
-    var leftday = this.DEADLINEDAY + 1 - moment().date()
+    let now = moment()
+    let deadline = now.format(`MM-${this.DEADLINEDAY}`)
+    let leftday = this.DEADLINEDAY + 1 - now.date()
+    let thisMonth = now.format('YYYY-MM')
+    let lastMonth = now.add(-1, 'M').format('YYYY-MM')
     this.setData({
-      deadline: deadline,
-      leftday: leftday
+      deadline,
+      leftday,
+      thisMonth,
+      lastMonth
     })
+
+    now = moment()
+    this.getLedgerType(now.format('YYYY-MM-DD'), r => {
+      this.setData({
+        tabList: r[0],
+        pageList: r[1],
+        thisMonthInfo: r[2]
+      })
+    }) //鏈湀
+    this.getLedgerType(now.add(-1, 'M').format('YYYY-MM-DD'), r => {
+      this.setData({
+        lastMonthInfo: r[2]
+      }, true)
+    }) //涓婃湀
   },
 
   /**
@@ -50,24 +103,43 @@
 
   },
 
-  getLedgerType () {
+  getLedgerType(time, success, lastMonth) {
     var that = this
-    var time = moment().format('YYYY-MM-DD')
+    // var time = moment().format('YYYY-MM-DD')
     ledgerservice.getLedgerSummary(app.globalData.accessToken.userId, app.globalData.userInfo.extension2, time, {
-      success (res) {
-        // console.log(res);
-        let r = that.parseLedgerType(res)
-        that.setData({
-          tabList: r[0],
-          pageList: r[1]
-        })
+      success(res) {
+        let r = that.parseLedgerType(res, lastMonth)
+        success(r)
       }
     })
   },
 
-  parseLedgerType (subtypes) {
-    var map = new Map()
+  parseLedgerType(subtypes, lastMonth) {
+    let monthInfo = {
+      totalMust: 0,
+      finishedMust: 0,
+      totalSelect: 0,
+      finishedSelect: 0,
+      status: '',
+      overtime: '',
+      suggestion: ''
+    }
+    let map = new Map()
     subtypes.forEach(s => {
+      //鏈堝害缁熻
+      if (s.needUpdate) {
+        monthInfo.totalMust++
+        if (s.upLoad) {
+          monthInfo.finishedMust++
+        }
+      } else {
+        monthInfo.totalSelect++
+        if (s.upLoad) {
+          monthInfo.finishedSelect++
+        }
+      }
+
+      //閫夐」鍗�
       if (s.upLoad) {
         s.tag = '/res/icons/round_check_fill.png'
       } else if (s.ledgerFinished) {
@@ -82,18 +154,56 @@
       }
       map.get(s.ledgerType).push(s)
     });
+
+    //
+    if (monthInfo.finishedMust == 0) {
+      monthInfo.status = '鏈彁浜�'
+      if (lastMonth) {
+        monthInfo.suggestion = '褰撴湡鍙拌处瀹屽叏鏈彁浜わ紝涓ラ噸褰卞搷璇勪及缁撴灉锛屽悗缁娉ㄦ剰'
+      } else {
+        monthInfo.suggestion = '璇峰敖蹇彁浜ゅ彴璐�'
+      }
+    } else if (monthInfo.finishedMust < monthInfo.totalMust) {
+      monthInfo.status = '閮ㄥ垎鎻愪氦'
+      if (lastMonth) {
+        monthInfo.suggestion = '褰撴湡鍙拌处閮ㄥ垎鏈彁浜わ紝浼氬奖鍝嶈瘎浼扮粨鏋滐紝鍚庣画璇峰敖閲忔彁浜ゆ墍鏈夊彴璐�'
+      } else {
+        monthInfo.suggestion = '褰撳墠宸叉彁浜ら儴鍒嗗彴璐︼紝璇疯ˉ鍏ㄥ墿浣欏彴璐�'
+      }
+    } else {
+      monthInfo.status = '宸叉彁浜�'
+      if (lastMonth) {
+        monthInfo.suggestion = '褰撴湡鍙拌处宸插叏閮ㄦ彁浜わ紝璇蜂繚鎸�'
+      } else {
+        monthInfo.suggestion = '鏈湡鍙拌处宸插叏閮ㄦ彁浜�'
+      }
+    }
+    monthInfo.overtime = moment().date() - this.DEADLINEDAY
+    monthInfo.percent = Math.round(monthInfo.finishedMust / monthInfo.totalMust * 100)
+
+    //閫夐」鍗�
     var t = []
     var p = []
-    for(let item of map){
+    for (let item of map) {
       console.log(item);
-      t.push(item[0])
+      let notUpload = 0
+      item[1].forEach(l => {
+        if (l.needUpdate && !l.upLoad) {
+          notUpload++
+        }
+      });
+      t.push({
+        name: item[0],
+        tag: notUpload,
+        total: item[1].length
+      })
       p.push(item[1])
     }
 
-    return [t, p]
+    return [t, p, monthInfo]
   },
 
-  gotoLedgerDetail (e) {
+  gotoLedgerDetail(e) {
     var i = e.currentTarget.dataset.index.split(',')
     var indexGroup = [parseInt(i[0]), parseInt(i[1])]
     var ledger = this.data.pageList[indexGroup[0]][indexGroup[1]]
@@ -123,12 +233,30 @@
     })
   },
 
+  gotoHistory(){
+    let tabList = this.data.tabList
+    wx.navigateTo({
+      url: '/pages/module_ledger/ledgerhistory/ledgerhistory',
+      success: (res) => {
+        // 閫氳繃 eventChannel 鍚戣鎵撳紑椤甸潰浼犻�佹暟鎹�
+        res.eventChannel.emit('acceptDataFromOpenerPage', {
+          tabList: tabList,
+        })
+      },
+    })
+  },
+
 
   //璁$畻swiper楂樺害鏂规硶锛堝湪鍒囨崲鐨勬椂鍊欒皟鐢級
   tabsHeight(element) {
     let that = this;
     let query = wx.createSelectorQuery(); //蹇呴』瑕佸厛鍒涘缓涓�涓煡璇�
     query.select(element).boundingClientRect(function (rect) {
+      // let pageheight = that.data.pageheight.split('px')[0]
+      // pageheight = parseInt(pageheight)
+      // if (rect > pa) {
+        
+      // }
       that.setData({
         pageheight: rect.height + 'px'
       });
@@ -143,7 +271,7 @@
         currentTab: e.target.dataset.current,
         navScrollLeft: e.target.dataset.current >= 3 ? ((e.target.dataset.current) * 60) : 0 //鍒ゆ柇褰撳墠閫変腑鐨勪釜鏁版槸鍚︽槸绗�5涓�
       })
-      that.tabsHeight('.page'+e.target.dataset.current);	//鏌ヨ鍝竴涓厓绱�
+      that.tabsHeight('.page' + e.target.dataset.current); //鏌ヨ鍝竴涓厓绱�
     }
   },
   bindChange: function (e) {
@@ -154,4 +282,9 @@
     });
     // that.tabsHeight('.page'+e.target.dataset.current);	//鏌ヨ鍝竴涓厓绱�
   },
+
+  changeMonth(){
+    let showThisMonth = !this.data.showThisMonth
+    this.setData({showThisMonth})
+  }
 })
\ No newline at end of file

--
Gitblit v1.9.3