jiaofeiList.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. wx.hideLoading();
  91. let apiReturnData = res.data;
  92. // 格式化日期
  93. if (apiReturnData.data && Array.isArray(apiReturnData.data)) {
  94. apiReturnData.data = apiReturnData.data.map(item => ({
  95. ...item,
  96. chargedate: _this.formatDateTime(item.chargedate)
  97. }));
  98. }
  99. _this.setData({
  100. paymentList: apiReturnData.data,
  101. });
  102. resolve(apiReturnData.data);
  103. },
  104. fail(error) {
  105. wx.hideLoading();
  106. utils.simleInfo('获取账单失败,请稍后再试');
  107. reject(error);
  108. }
  109. });
  110. });
  111. },
  112. // 返回上一页
  113. goBack: function() {
  114. wx.navigateBack();
  115. },
  116. // 切换到首页
  117. goToHome: function() {
  118. wx.switchTab({
  119. url: '/pages/homepage/homepage',
  120. });
  121. },
  122. // 切换到我的页面
  123. goToMine: function() {
  124. wx.switchTab({
  125. url: '/pages/mine/mine',
  126. });
  127. },
  128. navigateToHome() {
  129. wx.switchTab({
  130. url: '/pages/index/index'
  131. })
  132. },
  133. navigateToMine() {
  134. wx.switchTab({
  135. url: '/pages/mine/mine'
  136. })
  137. },
  138. // 跳转到账单详情页面
  139. goToDetail: function(e) {
  140. const billDetail = e.currentTarget.dataset.bill || {};
  141. // 使用JSON.stringify传递完整账单数据
  142. wx.navigateTo({
  143. url: `/pages/jiaofeixiangqing/jiaofeixiangqing?billInfo=${encodeURIComponent(JSON.stringify(billDetail))}`
  144. });
  145. },
  146. // 生成近20年的年份数据
  147. generateYears: function() {
  148. const currentYear = new Date().getFullYear();
  149. let years = [];
  150. for (let i = 0; i < 20; i++) {
  151. years.push(String(currentYear - i));
  152. }
  153. this.setData({
  154. years: years,
  155. yearPickerValue: [0], // 默认选中当年
  156. selectedYear: String(currentYear) // 默认设置为当年
  157. });
  158. },
  159. // 显示年份选择器
  160. showYearPicker: function() {
  161. this.setData({
  162. showYearPicker: true
  163. });
  164. },
  165. // 隐藏年份选择器
  166. hideYearPicker: function() {
  167. this.setData({
  168. showYearPicker: false
  169. });
  170. },
  171. // 防止点击选择器内部时关闭选择器
  172. preventBubble: function() {
  173. return;
  174. },
  175. // 年份选择改变
  176. onYearChange: function(e) {
  177. const index = e.detail.value[0];
  178. this.setData({
  179. yearPickerValue: [index]
  180. });
  181. },
  182. // 确认年份选择
  183. confirmYearSelection: function() {
  184. const selectedIndex = this.data.yearPickerValue[0];
  185. const selectedYear = this.data.years[selectedIndex];
  186. this.setData({
  187. selectedYear: selectedYear,
  188. showYearPicker: false
  189. });
  190. // 根据选择的年份筛选账单
  191. this.filterBillsByYear();
  192. },
  193. // 修改年份筛选功能
  194. filterBillsByYear: function() {
  195. const { selectedYear } = this.data;
  196. // 通过接口重新获取指定年份的数据
  197. wx.showLoading({
  198. title: '获取中...',
  199. mask: true,
  200. });
  201. wx.request({
  202. url: app.globalData.interfaceUrls.paymentList,
  203. method: 'POST',
  204. data: {
  205. accountNum: app.globalData.currentAccountInfo.usernumber,
  206. year: selectedYear
  207. },
  208. header: {
  209. 'content-type': 'application/json',
  210. 'token': app.globalData.userWxInfo.token,
  211. 'source': "wc",
  212. '!SAAS_LOGIN_TOKEN_!': app.globalData.currentAccountInfo.dsKey
  213. },
  214. success: (res) => {
  215. wx.hideLoading();
  216. let apiReturnData = res.data;
  217. if (apiReturnData.data && Array.isArray(apiReturnData.data)) {
  218. apiReturnData.data = apiReturnData.data.map(item => ({
  219. ...item,
  220. chargedate: this.formatDateTime(item.chargedate)
  221. }));
  222. }
  223. this.setData({
  224. paymentList: apiReturnData.data
  225. });
  226. },
  227. fail: () => {
  228. wx.hideLoading();
  229. wx.showToast({
  230. title: '获取数据失败',
  231. icon: 'none'
  232. });
  233. }
  234. });
  235. }
  236. })