riku
2022-08-05 45b2c022e27dda53ee4e5266fbdbdf1ac3aa4c65
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// pages/home/home.js
const userservice = require("../../service/userservice")
const assessmentService = require("../../service/assessmentservice")
const lawservice = require("../../service/lawservice")
const moment = require('../../utils/moment.min')
const app = getApp()
/**
 * 首页
 */
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    notices: [{
      notice: "本月守法承诺自测智评已开启,请及时进行评价",
      time: "2022/3/1"
    }],
 
    dynamic: [{
      title: "企业营业执照、食品经营许可证丢失该如何补领",
      time: "2022年4月5日",
      views: 2012,
      pic: "/res/icons/temp_pic_1.png"
    }],
 
    nextEvaluationTime: '2022年6月9日',
    userRealName: '',
 
    //历史评分详情
    historyPoint: {
      time: '测评周期----年--月',
      score: '--',
      rank: '--',
      legalIndex: '--',
      illegalIndex: '--'
    },
    period: ''
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.getStorage({
      key: 'accessToken',
      success: (result) => {
        console.log(result.data);
      },
      fail: (res) => {},
      complete: (res) => {},
    })
 
    this.getNextEvaluationTime()
    this.getNotice()
    this.getUserInfo()
    this.getHistoryPoint()
    this.getNews()
  },
 
  getNextEvaluationTime() {
    let now = moment().add(1, 'months')
    this.setData({
      nextEvaluationTime: now.format("YYYY年MM月10日")
    })
  },
 
  getUserInfo() {
    this.setData({
      userRealName: app.globalData.userInfo.realname
    })
  },
 
  getNotice() {
    this.setData({
      notices: [{
        notice: "本月守法承诺自测智评已开启,请及时进行评价",
        time: "2022/5/9"
      }]
    })
  },
 
  getHistoryPoint() {
    var that = this
    assessmentService.getHistoryPoint(app.globalData.accessToken.userId, 1, {
      success(data) {
        let lastOne = data[0]
        let year = lastOne.updateDate.substring(0, 4)
        let month = lastOne.updateDate.substring(5, 7)
        that.setData({
          historyPoint: {
            time: `测评周期${year}年${month}月`,
            score: lastOne.totalPoint,
            rank: lastOne.rank,
            legalIndex: lastOne.level,
            illegalIndex: lastOne.level
          }
        })
      }
    })
  },
 
  getNews() {
    var that = this
    let user = app.globalData.userInfo
    lawservice.getLawRegulations(user.guid, 1, user.extension2, {
      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
        })
      }
    })
  },
 
  /**
   * 页面跳转
   */
  goto: function (e) {
    var url = ""
    var index = e.currentTarget.dataset.index
    switch (index) {
      case "0":
        //测评历史记录
        url = ""
        break;
      case "1":
        //工作提醒
        url = "/pages/notice/notice"
        break;
      case "2":
        //智能在线咨询
        url = ""
        return;
      case "3":
        //在线守法学习
        
        url = `/pages/learn/learn`
        
        break;
      case "4":
        //守法动态
        // url = "/pages/text/text"
        let bodyUrl = e.currentTarget.dataset.url
        let fileType = e.currentTarget.dataset.filetype
        wx.downloadFile({
          // 示例 url,并非真实存在
          url: bodyUrl,
          success: function (res) {
            const filePath = res.tempFilePath
            var t = filePath.split('.')[filePath.split('.').length - 1]
            wx.openDocument({
              filePath: filePath,
              success: function (res) {
                console.log('打开文档成功')
              },
              fail (error) {
                console.log(error);
              }
            })
          }
        })
        break;
      case "5":
        break;
    }
    if (url != "") {
      wx.navigateTo({
        url: url
      })
    }
  }
})