riku
2025-04-27 f46786f11c5c08ead7501a82e5a71430ad69b782
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
import { fetchEnterpriseCount } from '../../services/enterprise/fetchEnterprise';
import { fetchCreditCodeCount } from '../../services/enterprise/fetchCreditCode';
import { fetchRiskCount } from '../../services/enterprise/fetchRisk';
 
/**
 * 线上监管相关信息获取逻辑
 */
export const useSupervision = Behavior({
  data: {
    supervisionLoading: false,
    enterpriseCountRes: [],
    riskPeriod: '',
    riskRes: [],
    creditPeriod: '',
    creditRes: [],
    // 取消网络请求标志
    cancelFetch: [],
  },
  lifetimes: {
    attached: function () {},
  },
  methods: {
    /**
     * 线上监管统计信息
     */
    fetchSupervision(page) {
      const { provinceName, cityName, districtName, townName, sceneTypeValue } = this.data;
      const params = { provinceName, cityName, districtName, townName, sceneTypes: sceneTypeValue };
      this._fetchSupervision(page, params);
    },
 
    _fetchSupervision(page, params) {
      // 取消正在进行中的上一次请求
      let { cancelFetch } = this.data;
      if (cancelFetch.length > 0) {
        cancelFetch[0] = true;
        cancelFetch = [];
      }
      let abort = false;
      cancelFetch.push(abort);
      this.setData({ cancelFetch });
      this.setData({ supervisionLoading: true });
      // 企业数量
      const f1 = fetchEnterpriseCount({
        data: params,
      }).then(res => {
        if (!abort) {
          this.setData({
            enterpriseCountRes: res.data,
          });
        }
      });
      // 综合风险
      const f2 = fetchRiskCount({
        data: params,
      }).then(res => {
        if (!abort) {
          this.setData({
            riskPeriod: res.data.period,
            riskRes: res.data.count,
          });
        }
      });
      // 环信码
      const f3 = fetchCreditCodeCount({
        data: params,
      }).then(res => {
        if (!abort) {
          this.setData({
            creditPeriod: res.data.period,
            creditRes: res.data.count,
          });
        }
      });
 
      Promise.all([f1, f2, f3]).finally(() => {
        setTimeout(() => {
          this.setData({ supervisionLoading: false });
        }, 500);
      });
    },
 
    navToEnterprise() {},
 
    // 跳转合规风险界面
    navToRisk(e) {
      const { index } = e.detail;
      const { riskPeriod } = this.data;
      let url = '/pages/supervision/risk/index';
      url += this._navParams();
      url += `&period=${riskPeriod}`;
      url += `&riskType=${index}`;
      wx.navigateTo({
        url: url,
      });
    },
 
    // 跳转环信码界面
    navToEcCode(e) {
      const { index } = e.detail;
      const { creditPeriod } = this.data;
      let url = '/pages/supervision/ec-code/index';
      url += this._navParams();
      url += `&period=${creditPeriod}`;
      url += `&ecCodeType=${index}`;
      wx.navigateTo({
        url: url,
      });
    },
 
    _navParams() {
      const { provinceName, cityName, districtName, townName, sceneTypeValue, locationValue } =
        this.data;
      let url = `?sceneType=${sceneTypeValue[0]}`;
      if (provinceName) url += `&province=${provinceName}`;
      if (cityName) url += `&city=${cityName}`;
      if (districtName) url += `&district=${districtName}`;
      if (townName) url += `&town=${townName}`;
      if (locationValue) url += `&locationValue=${locationValue}`;
      return url;
    },
  },
});