文件
jw-beauty/miniprogram/pages/history/history.js
T
Guoguo aa4b215c8b feat(ui): redesign all miniprogram pages
- 全局样式改为粉色(#E6508C)/金色(#DCB982)/绿色(#52c41a)配色
- 所有非tab页使用自定义导航栏,带彩色头部+标题+副标题
- login页: 粉色头部+🌸图标+微信授权登录
- scan页: 粉色头部+虚线扫码框+手动输入按钮
- ble-connect页: 蓝牙提示+搜索中/已发现设备卡片
- bind-success页: 绿色头部+成功图标+7天试用提示卡
- wear-check页: 设备信息行+佩戴指引卡片
- index首页: 粉色设备卡片+开始护理/设备管理按钮
- treatment-setup页: 模式选择+面部地图选区域
- auto-scan页: 面部轮廓+扫描线动画+检测标签
- treating页: 蓝色头部+大倒计时+渐变进度条+放松提示
- treatment-done页: 绿色头部+统计卡片+已记录提示
- subscribe-prompt页: 普通/智能模式对比+试用提示+金色订阅按钮
- subscribe-plans页: 金色头部+服务卡片+月卡/年卡选择
- subscribe-success页: 绿色头部+订阅详情卡+金色按钮
- profile页: 渐变头部+用户行+订阅卡+菜单列表
- history页: 粉色统计行+模式标签记录列表
2026-04-22 21:40:55 +08:00

79 行
2.0 KiB
JavaScript

var http = require('../../utils/request')
var ble = require('../../services/ble')
Page({
data: {
records: [],
total: 0,
totalHours: 0,
monthCount: 0,
page: 1,
pageSize: 20,
loading: true,
loadingMore: false
},
onShow: function () {
this.loadRecords(true)
},
onPullDownRefresh: function () {
this.loadRecords(true).then(function () {
wx.stopPullDownRefresh()
})
},
onReachBottom: function () {
if (this.data.records.length < this.data.total) {
this.loadRecords(false)
}
},
loadRecords: function (refresh) {
var self = this
var page = refresh ? 1 : self.data.page + 1
if (refresh) {
self.setData({ loading: true })
} else {
self.setData({ loadingMore: true })
}
return http.get('/api/v1/treatment/history', {
page: page,
page_size: self.data.pageSize
}).then(function (data) {
var totalMs = 0
var now = new Date()
var monthStart = new Date(now.getFullYear(), now.getMonth(), 1)
var monthCount = 0
var records = (data.records || []).map(function (r) {
var durationMin = Math.floor((r.total_duration_ms || 0) / 60000)
totalMs += (r.total_duration_ms || 0)
r.duration_text = durationMin + '分钟'
r.region_names = ble.getRegionName(r.regions || 0).join('、')
r.wavelength_name = ble.getWavelengthName(r.wavelength || 2)
r.date_text = r.start_time ? r.start_time.slice(0, 10) : ''
if (r.start_time && new Date(r.start_time) >= monthStart) {
monthCount++
}
return r
})
self.setData({
records: refresh ? records : self.data.records.concat(records),
total: data.total || 0,
totalHours: Math.round(totalMs / 3600000),
monthCount: monthCount,
page: page,
loading: false,
loadingMore: false
})
}).catch(function () {
self.setData({ loading: false, loadingMore: false })
})
}
})