history.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // pages/payment/history/history.js
  2. const moment = require('../../../utils/moment');
  3. const app = getApp();
  4. const now = new Date().getFullYear();
  5. const tabIndex = new Date().getMonth();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. index: 0,
  12. years: [],
  13. curYear: now,
  14. months: [],
  15. activeTab: tabIndex,
  16. curMonth: tabIndex + 1,
  17. history: {},
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function (options) {
  23. this.setYears();
  24. },
  25. setYears() {
  26. const years = [];
  27. for (let i = now; i >= 1990; i--) {
  28. years.push(`${i}年`);
  29. }
  30. this.setData({
  31. years
  32. })
  33. this.setMonths();
  34. },
  35. setMonths(val) {
  36. let months = [];
  37. for (let i = 1; i <= 12; i++) {
  38. months.push({
  39. title: `${i}月`,
  40. id: i
  41. });
  42. }
  43. this.setData({
  44. months,
  45. history: {}
  46. })
  47. this.getHisitoryBillDetail(this.data.curYear, this.data.curMonth);
  48. },
  49. bindPickerChange(e) {
  50. const year = this.data.years[e.detail.value].substr(0, 4);
  51. this.setData({
  52. index: e.detail.value,
  53. curYear: year
  54. })
  55. this.setMonths(year);
  56. },
  57. onTabClick(e) {
  58. const index = e.detail.index
  59. this.setData({
  60. activeTab: index,
  61. curMonth: this.data.months[index].id
  62. })
  63. },
  64. onChange(e) {
  65. const index = e.detail.index;
  66. this.setData({
  67. activeTab: index,
  68. curMonth: this.data.months[index].id
  69. })
  70. this.getHisitoryBillDetail(this.data.curYear, this.data.curMonth);
  71. },
  72. getHisitoryBillDetail(year, month) {
  73. wx.showNavigationBarLoading();
  74. app.$http.get('/user/getHisitoryBillDetail', {
  75. year,
  76. month
  77. }).then(({
  78. status,
  79. data = []
  80. }) => {
  81. wx.hideNavigationBarLoading();
  82. if (status == 0) {
  83. data.forEach(v => {
  84. v.reading = app.$util.numberFormat(v.reading, 1);
  85. v.payamount = app.$util.numberFormat(v.payamount, 1);
  86. v.receivefee = app.$util.numberFormat(v.receivefee, 2);
  87. v.debt = app.$util.numberFormat(v.debt, 2);
  88. v.debt = app.$util.numberFormat(v.debt, 2);
  89. v.recorddate = v.recorddate ? moment(v.recorddate).format('YYYY.MM.DD') : '-';
  90. v.lastrecorddate = v.lastrecorddate ? moment(v.lastrecorddate).format('YYYY.MM.DD') : '-';
  91. Object.keys(v.feelist).forEach(k => {
  92. v.feelist[k] = app.$util.numberFormat(v.feelist[k], 2);
  93. })
  94. })
  95. this.setData({
  96. [`history.${this.data.activeTab}`]: data
  97. })
  98. }
  99. }).catch(() => {
  100. wx.hideNavigationBarLoading();
  101. })
  102. },
  103. })