riku
2024-08-14 f2a0ea849099f49a3d2a9c7e5c44d033df22468f
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
import { fetchAssessmentDetail } from '../../../services/enterprise/fetchAssessment';
import { fetchSceneAuthen } from '../../../services/enterprise/fetchAuthentication';
import { fetchCreditInfo } from '../../../services/enterprise/fetchCreditCode';
import { fetchLedgerSummary } from '../../../services/enterprise/fetchLedger';
import { fetchCommitmentStat } from '../../../services/enterprise/fetchPromise';
import { fetchRiskInfo } from '../../../services/enterprise/fetchRisk';
import { useLoading } from '../../../behaviors/loading';
import { toTime, toPeriod } from '../../../utils/period';
import { openDoc } from '../../../utils/file';
import { getLedgerStat } from '../../../model/ledger/ledgerStat';
import { getLedgerIsUploaded } from '../../../model/ledger/ledgerSummary';
 
Page({
  behaviors: [useLoading],
  data: {
    // 当前展示的周期
    period: '',
    monthValue: '',
    // 企业用户信息
    enterprise: {},
    // 企业认证情况
    authenInfo: [],
    // 合规风险信息
    riskInfo: {},
    // 自巡查信息
    selfCheckInfo: {},
    // 台账信息
    ledgerInfo: {},
    // 自测自评
    historyPoint: {},
    // 守法承诺
    promsieInfo: {},
    // 环信码
    creditInfo: {},
  },
 
  onLoad(options) {
    this.getOpenerEventChannel().on('acceptEnterpriseData', data => {
      this.setData({ ...data });
      this.init();
      this._startLoad();
    });
  },
 
  init() {
    if (!this.data.period) {
      const period = toPeriod();
      const monthValue = toTime(period).format('YYYY-MM');
      this.setData({ period, monthValue });
    } else {
      const monthValue = toTime(this.data.period).format('YYYY-MM');
      this.setData({ monthValue });
    }
  },
 
  _fetchData(page) {
    let { id: userId, sceneTypeId: sceneType } = this.data.enterprise;
    let { period } = this.data;
    let time = toTime(period).format('YYYY-MM-DD');
 
    let f1 = fetchAssessmentDetail({ userId, period }).then(res => {
      this.setData({ historyPoint: res.data });
    });
    let f2 = fetchLedgerSummary({ userId, sceneType, time }).then(res => {
      // 自巡查和台账的提交百分比
      const stat = getLedgerStat(res.data, time);
      // 自巡查和台账的具体提交内容
      const detail = getLedgerIsUploaded(res.data);
      this.setData({
        selfCheckInfo: {
          stat: {
            total: stat.totalSelf,
            finished: stat.finishedSelf,
            percent: stat.percent2,
          },
          detail: detail.selfCheckInfo,
        },
        ledgerInfo: {
          stat: {
            total: stat.totalMust,
            finished: stat.finishedMust,
            percent: stat.percent,
          },
          detail: detail.ledgerInfo,
        },
      });
    });
    let f3 = fetchCommitmentStat({ userId }).then(res => {
      this.setData({ promsieInfo: res.data });
    });
    let f4 = fetchCreditInfo({ userId, period }).then(res => {
      this.setData({ creditInfo: res.data });
    });
    let f5 = fetchRiskInfo({ userId, period: time }).then(res => {
      this.setData({ riskInfo: res.data });
    });
    let f6 = fetchSceneAuthen({ userId }).then(res => {
      this.setData({ authenInfo: res.data });
    });
 
    return Promise.all([f1, f2, f3, f4, f5, f6]);
  },
 
  onTimePickerConfirm(e) {
    const { timeText, timeValue } = e.detail;
    const period = toPeriod(timeValue);
    const monthValue = toTime(period).format('YYYY-MM');
    this.setData({ period, monthValue });
    this._startLoad();
  },
 
  navToAssessment() {
    if (this.data.historyPoint.time) {
      wx.navigateTo({
        // url: `/pages/enterprise/assessment/history/index?userId=${this.data.enterprise.id}`,
        url: `/pages/enterprise/assessment/form/index?userId=${this.data.enterprise.id}&period=${this.data.period}`,
      });
    }
  },
 
  navToAssessmentReport() {
    if (this.data.historyPoint.time) {
      wx.navigateTo({
        url: `/pages/enterprise/assessment/detail/index?userId=${this.data.enterprise.id}&period=${this.data.period}`,
      });
    }
  },
 
  navToLedger(e) {
    const { mode } = e.currentTarget.dataset;
    wx.navigateTo({
      url: `/pages/enterprise/ledger/history/index?userId=${this.data.enterprise.id}&sceneTypeId=${this.data.enterprise.sceneTypeId}&time=${this.data.monthValue}&mode=${mode}`,
    });
  },
 
  navToPromise() {
    // wx.navigateTo({
    //   url: `/pages/enterprise/promise/history/index?userId=${this.data.enterprise.id}`,
    // });
 
    const p = this.data.promsieInfo;
    if (!p.picPath) return;
    if (p.picPath.length > 0) {
      wx.navigateTo({
        url: '/pages/enterprise/promise/detail/index',
        success: function (res) {
          // 通过 eventChannel 向被打开页面传送数据
          res.eventChannel.emit('acceptPromiseData', {
            promise: {
              picPath: p.picPath,
              pdfPath: p.pdfPath,
            },
          });
        },
      });
    } else if (p.pdfPath.length > 0) {
      openDoc(p.pdfPath);
    }
  },
 
  navToEcCode(e) {
    const id = e.detail;
    wx.navigateTo({
      url: `/pages/enterprise/ec-code/index?userId=${id}`,
    });
  },
});