jiaofeiList.js 6.6 KB

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