record.js 2.3 KB

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