riku
2024-11-12 befd1f21839939b54254bd316bbd158b136fcd15
pages/inspection/ranking/index.js
@@ -1,19 +1,22 @@
import dayjs from 'dayjs';
import { useLoading } from '../../../behaviors/loading';
import { useProblemChangeList } from "./problem-change-list.js";
import { useStatistic } from "./statistic.js";
import { useSortOptions } from "./sort-options.js";
import { fetchSceneProSummary } from '../../../services/inspection/fetchScene';
import { fetchProblemsStatistic } from '../../../services/inspection/fetchInspection';
import { _getParamsArea } from '../param-util.js';
Page({
  behaviors: [useLoading],
  behaviors: [useLoading, useProblemChangeList, useStatistic, useSortOptions],
  data: {
    summaryList: [],
    sort: '',
    sortBy: 'pro',
    statistic: {
      proNum: 0,
      changeNum: 0,
    },
    // summaryList: [],
    // sort: '',
    // sortBy: 'pro',
    // statistic: {
    //   proNum: 0,
    //   changeNum: 0,
    // },
  },
  onLoad(options) {
@@ -39,51 +42,51 @@
  },
  _fetchData(page) {
    const f1 = this.fetchSceneProSummary(page);
    const f2 = this.fetchProblems(page);
    const params = _getParamsArea(this.data);
    const f1 = this.fetchSceneProSummary(params, page);
    const f2 = this.fetchProblems(params, page);
    return Promise.all([f1, f2]).then(res => {
      // 返回请求f1的分页信息
      return res[0];
    });
  },
  fetchSceneProSummary(page) {
    const params = _getParamsArea(this.data);
    const { sortBy } = this.data;
    return fetchSceneProSummary({ area: params, sortBy, page }).then(res => {
      if (res.success) {
        this.setData({
          summaryList: page == 1 ? res.data : this.data.summaryList.concat(res.data),
        });
      } else {
        this.setData({
          summaryList: [],
        });
      }
      return res.head;
    });
  },
  // fetchSceneProSummary(params, page) {
  //   const params = _getParamsArea(this.data);
  //   return fetchSceneProSummary({ area: params, page }).then(res => {
  //     if (res.success) {
  //       this.setData({
  //         summaryList: page == 1 ? res.data : this.data.summaryList.concat(res.data),
  //       });
  //     } else {
  //       this.setData({
  //         summaryList: [],
  //       });
  //     }
  //     return res.head;
  //   });
  // },
  fetchProblems(page) {
    const params = _getParamsArea(this.data);
    return fetchProblemsStatistic(params).then(res => {
      let proNum = 0,
        changeNum = 0,
        changePer = 0;
      res.data.forEach(r => {
        proNum += r.count;
        changeNum += r.changeCount;
      });
      if (proNum > 0) {
        changePer = Math.round((changeNum / proNum) * 1000) / 10;
        changePer += '%';
      }
      this.setData({
        statistic: { proNum, changeNum, changePer },
      });
      return res.head;
    });
  },
  // fetchProblems(params, page) {
  //   const params = _getParamsArea(this.data);
  //   return fetchProblemsStatistic(params).then(res => {
  //     let proNum = 0,
  //       changeNum = 0,
  //       changePer = 0;
  //     res.data.forEach(r => {
  //       proNum += r.count;
  //       changeNum += r.changeCount;
  //     });
  //     if (proNum > 0) {
  //       changePer = Math.round((changeNum / proNum) * 1000) / 10;
  //       changePer += '%';
  //     }
  //     this.setData({
  //       statistic: { proNum, changeNum, changePer },
  //     });
  //     return res.head;
  //   });
  // },
  onTimePickerConfirm(e) {
    const { timeValue } = e.detail;
@@ -124,29 +127,17 @@
    this._startLoad();
  },
  // 问题数排序更改
  onProNumSortChange(e) {
    const { sorts } = e.detail;
    this.setData({
      sort: sorts,
    });
    this._startLoad();
  },
  // 整改率排序更改
  onChangePerSortChange(e) {},
  navToDetail(e) {
    const { index } = e.currentTarget.dataset;
    const summary = this.data.summaryList[index];
    wx.navigateTo({
      url: '/pages/inspection/detail/index',
      success: result => {
        result.eventChannel.emit('acceptInspectionDetailData', {
          scene: summary.scene,
          time: this.data.time,
        });
      },
    });
  },
  // navToDetail(e) {
  //   const { index } = e.currentTarget.dataset;
  //   const summary = this.data.summaryList[index];
  //   wx.navigateTo({
  //     url: '/pages/inspection/detail/index',
  //     success: result => {
  //       result.eventChannel.emit('acceptInspectionDetailData', {
  //         scene: summary.scene,
  //         time: this.data.time,
  //       });
  //     },
  //   });
  // },
});