unknown
2022-08-16 edd35a251b58b1fad17015deda92324f74458434
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,8 @@
    this.getUserInfo()
    this.getHistoryPoint()
    this.getNews()
    this.getCommitment()
    this.getLedgerType()
  },
  getNextEvaluationTime() {
@@ -73,11 +87,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 +109,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 +121,8 @@
            score: lastOne.totalPoint,
            rank: lastOne.rank,
            legalIndex: lastOne.level,
            illegalIndex: lastOne.level
            illegalIndex: lastOne.level,
            period: lastOne.period
          }
        })
      }
@@ -125,6 +153,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({
            promise: {
              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 +212,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 +234,7 @@
        break;
      case "3":
        //在线守法学习
        url = `/pages/learn/learn`
        break;
      case "4":
        //守法动态
@@ -168,14 +255,12 @@
              success: function (res) {
                console.log('打开文档成功')
              },
              fail (error) {
              fail(error) {
                console.log(error);
              }
            })
          }
        })
        break;
      case "5":
        break;
    }
    if (url != "") {