// pages/billMeterDetail/index.js
import { getRoundNumber } from "../../utils/index"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    data: {},
    headers: [
      { key: 'type', title: '' },
      { title: '尖',renderBody: (item) => { return item?.sharp } },
      { title: '峰',renderBody: (item) => { return item?.peak } },
      { title: '平',renderBody: (item) => { return item?.flat } },
      { title: '谷',renderBody: (item) => { return item?.valley } },
      { title: '深谷',renderBody: (item) => { return item?.deepValley } },
    ],
    list: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const data =  JSON.parse(options.data) || {}
    this.setData({
      data: data,
      list: [
        { type: "起码", sharp: data.startSharp, peak: data.startPeak, flat: data.startFlat, valley: data.startValley, deepValley: data.startDeepValley },
        { type: "止码", sharp: data.endSharp, peak: data.endPeak, flat: data.endFlat, valley: data.endValley, deepValley: data.endDeepValley },
        { type: "退补电量", sharp: data.refundSharp, peak: data.refundPeak, flat: data.refundFlat, valley: data.refundValley, deepValley: data.refundDeepValley },
        { type: "从表电量", sharp: getRoundNumber(data.nestSharp), peak: getRoundNumber(data.nestPeak), flat: getRoundNumber(data.nestFlat), valley: getRoundNumber(data.nestValley), deepValley: getRoundNumber(data.nestDeepValley) },
        { type: "电度电量", sharp: getRoundNumber(data?.critical?.amount), peak: getRoundNumber(data.peak?.amount), flat: getRoundNumber(data.flat?.amount), valley: getRoundNumber(data.valley?.amount), deepValley: getRoundNumber(data?.deepValley?.amount) },
        { type: "分时单价", sharp: data.critical?.price, peak: data.peak?.price, flat: data.flat?.price, valley: data.valley?.price , valley: data.valley?.price, deepValley: data.deepValley?.price},
        { type: "电费", sharp: getRoundNumber(data.chargeSharp), peak: getRoundNumber(data.chargePeak), flat: getRoundNumber(data.chargeFlat), valley: getRoundNumber(data.chargeValley), deepValley: getRoundNumber(data.chargeDeepValley) },
      ]
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})