jiaofeiList.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. const app = getApp();
  2. Page({
  3. data: {
  4. images: {
  5. background: '/static_file/background.png',
  6. water: '/static_file/water.png'
  7. },
  8. userInfo: {
  9. name: app.globalData.currentAccountInfo.username,
  10. id: app.globalData.currentAccountInfo.usernumber,
  11. address: app.globalData.currentAccountInfo.address
  12. },
  13. showKeyboard: false,
  14. selectedAmount: null,
  15. customAmount: '',
  16. inputFocus: false,
  17. address: '',
  18. paymentList: [],
  19. showYearPicker: false,
  20. years: [],
  21. yearPickerValue: [0],
  22. selectedYear: '',
  23. originalBillList: [], // 存储原始账单数据
  24. },
  25. onLoad: function(options) {
  26. // 确保图片资源正确加载
  27. this.setData({
  28. images: {
  29. background: '/static_file/background.png',
  30. water: '/static_file/water.png'
  31. },
  32. isInvoic: app.globalData.waterCompanys.filter(data=>data.id==app.globalData.currentAccountInfo.dsKey)[0].swCompanyInfo.supportonlineinvoice=="1"
  33. });
  34. // 生成近20年的年份数据
  35. this.generateYears();
  36. // 获取缴费记录列表
  37. this.getBillList().then(data => {
  38. this.setData({
  39. paymentList: data,
  40. originalBillList: data
  41. });
  42. });
  43. },
  44. // 添加日期格式化函数
  45. formatDateTime: function(dateString) {
  46. if (!dateString) return '';
  47. const date = new Date(dateString);
  48. const year = date.getFullYear();
  49. const month = (date.getMonth() + 1).toString().padStart(2, '0');
  50. const day = date.getDate().toString().padStart(2, '0');
  51. const hours = date.getHours().toString().padStart(2, '0');
  52. const minutes = date.getMinutes().toString().padStart(2, '0');
  53. return `${year}-${month}-${day} ${hours}:${minutes}`;
  54. },
  55. getBillList: function() {
  56. const _this = this;
  57. return new Promise((resolve, reject) => {
  58. wx.showLoading({
  59. title: '获取中...',
  60. mask: true,
  61. });
  62. wx.request({
  63. url: app.globalData.interfaceUrls.paymentList,
  64. method: 'POST',
  65. data: {
  66. accountNum: app.globalData.currentAccountInfo.usernumber,
  67. year: new Date().getFullYear()
  68. },
  69. header: {
  70. 'content-type': 'application/json',
  71. 'token': app.globalData.userWxInfo.token,
  72. 'source': "wc",
  73. '!SAAS_LOGIN_TOKEN_!': app.globalData.currentAccountInfo.dsKey
  74. },
  75. success(res) {
  76. wx.hideLoading();
  77. let apiReturnData = res.data;
  78. // 格式化日期
  79. if (apiReturnData.data && Array.isArray(apiReturnData.data)) {
  80. apiReturnData.data = apiReturnData.data.map(item => ({
  81. ...item,
  82. chargedate: _this.formatDateTime(item.chargedate)
  83. }));
  84. }
  85. _this.setData({
  86. paymentList: apiReturnData.data,
  87. });
  88. resolve(apiReturnData.data);
  89. },
  90. fail(error) {
  91. wx.hideLoading();
  92. utils.simleInfo('获取账单失败,请稍后再试');
  93. reject(error);
  94. }
  95. });
  96. });
  97. },
  98. // 返回上一页
  99. goBack: function() {
  100. wx.navigateBack();
  101. },
  102. // 切换到首页
  103. goToHome: function() {
  104. wx.switchTab({
  105. url: '/pages/homepage/homepage',
  106. });
  107. },
  108. // 切换到我的页面
  109. goToMine: function() {
  110. wx.switchTab({
  111. url: '/pages/mine/mine',
  112. });
  113. },
  114. navigateToHome() {
  115. wx.switchTab({
  116. url: '/pages/index/index'
  117. })
  118. },
  119. navigateToMine() {
  120. wx.switchTab({
  121. url: '/pages/mine/mine'
  122. })
  123. },
  124. // 跳转到账单详情页面
  125. goToDetail: function(e) {
  126. const billDetail = e.currentTarget.dataset.bill || {};
  127. // 使用JSON.stringify传递完整账单数据
  128. wx.navigateTo({
  129. url: `/pages/jiaofeixiangqing/jiaofeixiangqing?billInfo=${encodeURIComponent(JSON.stringify(billDetail))}`
  130. });
  131. },
  132. // 生成近20年的年份数据
  133. generateYears: function() {
  134. const currentYear = new Date().getFullYear();
  135. let years = ['全部']; // 添加"全部"选项
  136. for (let i = 0; i < 20; i++) {
  137. years.push(String(currentYear - i));
  138. }
  139. this.setData({
  140. years: years,
  141. yearPickerValue: [0] // 默认选中"全部"
  142. });
  143. },
  144. // 显示年份选择器
  145. showYearPicker: function() {
  146. this.setData({
  147. showYearPicker: true
  148. });
  149. },
  150. // 隐藏年份选择器
  151. hideYearPicker: function() {
  152. this.setData({
  153. showYearPicker: false
  154. });
  155. },
  156. // 防止点击选择器内部时关闭选择器
  157. preventBubble: function() {
  158. return;
  159. },
  160. // 年份选择改变
  161. onYearChange: function(e) {
  162. const index = e.detail.value[0];
  163. this.setData({
  164. yearPickerValue: [index]
  165. });
  166. },
  167. // 确认年份选择
  168. confirmYearSelection: function() {
  169. const selectedIndex = this.data.yearPickerValue[0];
  170. const selectedYear = this.data.years[selectedIndex];
  171. this.setData({
  172. selectedYear: selectedYear === '全部' ? '' : selectedYear,
  173. showYearPicker: false
  174. });
  175. // 根据选择的年份筛选账单
  176. this.filterBillsByYear();
  177. },
  178. // 修改年份筛选功能
  179. filterBillsByYear: function() {
  180. const { selectedYear, originalBillList } = this.data;
  181. if (!selectedYear) {
  182. // 重新获取所有数据
  183. this.getBillList();
  184. return;
  185. }
  186. // 通过接口重新获取指定年份的数据
  187. wx.showLoading({
  188. title: '获取中...',
  189. mask: true,
  190. });
  191. wx.request({
  192. url: app.globalData.interfaceUrls.paymentList,
  193. method: 'POST',
  194. data: {
  195. accountNum: app.globalData.currentAccountInfo.usernumber,
  196. year: selectedYear
  197. },
  198. header: {
  199. 'content-type': 'application/json',
  200. 'token': app.globalData.userWxInfo.token,
  201. 'source': "wc",
  202. '!SAAS_LOGIN_TOKEN_!': app.globalData.currentAccountInfo.dsKey
  203. },
  204. success: (res) => {
  205. wx.hideLoading();
  206. let apiReturnData = res.data;
  207. if (apiReturnData.data && Array.isArray(apiReturnData.data)) {
  208. apiReturnData.data = apiReturnData.data.map(item => ({
  209. ...item,
  210. chargedate: this.formatDateTime(item.chargedate)
  211. }));
  212. }
  213. this.setData({
  214. paymentList: apiReturnData.data
  215. });
  216. },
  217. fail: () => {
  218. wx.hideLoading();
  219. wx.showToast({
  220. title: '获取数据失败',
  221. icon: 'none'
  222. });
  223. }
  224. });
  225. }
  226. })