// pages/grade/grade.js const assessmentService = require("../../service/assessmentservice") const moment = require('../../utils/moment.min') const app = getApp() Page({ /** * 页面的初始数据 */ data: { // { // title1: '在线监测设备', // sub1: [{ // title2: '设备', // group: 0, // sub2: [{ // content: '设备未安装', // score: '-10', // select: false // }, // { // content: '设备私自拆除', // score: '-10', // select: false // }, // { // content: '设备未运行', // score: '-10', // select: false // }, { // content: '设备未运维', // score: '-10', // select: false // } // ] // }, { // title2: '数据', // group: 1, // sub2: [{ // content: '数据未超标', // score: '-10', // select: false // }, // { // content: '数据部分超标', // score: '-10', // select: false // }, // { // content: '数据大量超标', // score: '-10', // select: false // }, { // content: '数据严重超标', // score: '-10', // select: false // } // ] // }], // } evaluations: [] }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.getScoreHistory() }, /** * 获取本期的评估规则及记录 */ getScoreHistory() { var that = this let now = moment() //根据当前时间获取评估周期YYYY/M-M this.period = `${now.year()}/${now.month()+1}-${now.month()+1}` assessmentService.getScore(app.globalData.accessToken.userId, this.period, { success(data) { that.setData({ evaluations: data }) } }) }, choose: function (e) { var index = e.currentTarget.dataset.index var group = e.currentTarget.dataset.group var evaluations = this.data.evaluations for (let i = 0; i < evaluations.length; i++) { const e1 = evaluations[i]; var found = false for (let y = 0; y < e1.sub1.length; y++) { const e2 = e1.sub1[y]; if (e2.group == group) { e2.sub2.forEach(s2 => { s2.select = false }); e2.sub2[index].select = true found = true break } } if (found) { break } } this.setData({ evaluations: evaluations }) }, onSubmit: function () { var itemList = [] var evaluations = this.data.evaluations for (let i = 0; i < evaluations.length; i++) { const e1 = evaluations[i]; for (let y = 0; y < e1.sub1.length; y++) { const e2 = e1.sub1[y]; for (let t = 0; t < e2.sub2.length; t++) { const s2 = e2.sub2[t]; if (s2.select) { itemList.push({ first: s2.id, second: s2.score + '' }) } } } } if (itemList.length == 0) { wx.showToast({ title: '请至少选择一项进行评估', icon: 'none', }) } else { this.setData({ itemList: itemList, showDialog: true, startCalculate: false }) } }, upload: function () { var that = this this.setData({ showDialog: false, showDialog2: true, startCalculate: true, loadingOverText: '' }) this.loadingText("计算总分中", function () { that.setData({ loadingOverText: ['计算总分完成'] }) that.loadingText('等级评估中', function () { that.setData({ loadingOverText: ['计算总分完成', '等级评估完成'] }) var h = that.loadingText('生成综合测评报告', function () { that.setData({ loadingText: '', loadingOverText: ['计算总分完成', '等级评估完成', '综合测评报告生成失败'] }) }, 25) assessmentService.uploadScore(app.globalData.accessToken.userId, that.period, that.data.itemList, { success(data) { clearInterval(h) that.setData({ startCalculate: false, loadingText: '', loadingOverText: ['计算总分完成', '等级评估完成', '综合测评报告生成'] }) } }) }) }) }, gotoReport() { this.setData({ showDialog2: false, }) wx.redirectTo({ url: '/pages/gradereport/gradereport' }) }, goBack() { this.setData({ showDialog2: false, }) wx.navigateBack({ delta: 1, }) }, loadingText(text, onDone, max) { var i = 0 if (max == undefined) { max = 5 } var h = setInterval(() => { if (i > max) { clearInterval(h) onDone() } else { var points = '' var n = i % 3 for (let t = 0; t < n + 1; t++) { points += '.' } this.setData({ loadingText: text + points }) i++ } }, 200); return h }, })