zhangdanlist.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. billList: [],
  19. // 是否可以开票
  20. isInvoic:false,
  21. showYearPicker: false,
  22. years: [],
  23. yearPickerValue: [0],
  24. selectedYear: '',
  25. originalBillList: [], // 存储原始账单数据
  26. },
  27. onLoad: function(options) {
  28. // 确保图片资源正确加载
  29. this.setData({
  30. images: {
  31. background: '/static_file/background.png',
  32. water: '/static_file/water.png'
  33. },
  34. isInvoic: app.globalData.waterCompanys.filter(data=>data.id==app.globalData.currentAccountInfo.dsKey)[0].swCompanyInfo.supportonlineinvoice=="1"
  35. });
  36. // 生成近20年的年份数据
  37. this.generateYears();
  38. // 获取账单列表
  39. this.getBillList().then(data => {
  40. this.setData({
  41. billList: data,
  42. originalBillList: data
  43. });
  44. });
  45. },
  46. getBillList: function() {
  47. const _this = this;
  48. return new Promise((resolve, reject) => {
  49. wx.showLoading({
  50. title: '获取中...',
  51. mask: true,
  52. });
  53. wx.request({
  54. url: app.globalData.interfaceUrls.billList,
  55. method: 'POST',
  56. data: {
  57. accountNum: app.globalData.currentAccountInfo.usernumber,
  58. year: new Date().getFullYear()
  59. },
  60. header: {
  61. 'content-type': 'application/json',
  62. 'token': app.globalData.userWxInfo.token,
  63. 'source': "wc",
  64. '!SAAS_LOGIN_TOKEN_!': app.globalData.currentAccountInfo.dsKey
  65. },
  66. success(res) {
  67. wx.hideLoading();
  68. let apiReturnData = res.data;
  69. _this.setData({
  70. billList: apiReturnData.data,
  71. });
  72. resolve(apiReturnData.data);
  73. },
  74. fail(error) {
  75. wx.hideLoading();
  76. utils.simleInfo('获取账单失败,请稍后再试');
  77. reject(error);
  78. }
  79. });
  80. });
  81. },
  82. // 返回上一页
  83. goBack: function() {
  84. wx.navigateBack();
  85. },
  86. // 点击开发票按钮
  87. openInvoice: function(e) {
  88. const index = e.currentTarget.dataset.index;
  89. const bill = this.data.billList[index];
  90. wx.showToast({
  91. title: '开发票功能开发中',
  92. icon: 'none'
  93. });
  94. },
  95. // 切换到首页
  96. goToHome: function() {
  97. wx.switchTab({
  98. url: '/pages/homepage/homepage',
  99. });
  100. },
  101. // 切换到我的页面
  102. goToMine: function() {
  103. wx.switchTab({
  104. url: '/pages/mine/mine',
  105. });
  106. },
  107. navigateToHome() {
  108. wx.switchTab({
  109. url: '/pages/index/index'
  110. })
  111. },
  112. navigateToMine() {
  113. wx.switchTab({
  114. url: '/pages/mine/mine'
  115. })
  116. },
  117. // 跳转到账单详情页面
  118. goToBillDetail: function(e) {
  119. const bill = e.currentTarget.dataset.bill;
  120. wx.navigateTo({
  121. url: '/pages/zhangdanxiangqing/zdxiangqing?billInfo=' + JSON.stringify(bill)
  122. });
  123. },
  124. // 获取发票
  125. getInvoice: function(e) {
  126. wx.showToast({
  127. title: '暂不支持!',
  128. icon: 'none'
  129. });
  130. return;
  131. // 阻止事件冒泡,避免触发goToBillDetail
  132. e.stopPropagation();
  133. const bill = e.currentTarget.dataset.bill;
  134. wx.navigateTo({
  135. url: '/pages/invoice/invoice?billInfo=' + JSON.stringify(bill)
  136. });
  137. },
  138. // 生成近20年的年份数据
  139. generateYears: function() {
  140. const currentYear = new Date().getFullYear();
  141. let years = ['全部']; // 添加"全部"选项
  142. for (let i = 0; i < 20; i++) {
  143. years.push(String(currentYear - i));
  144. }
  145. this.setData({
  146. years: years,
  147. yearPickerValue: [0] // 默认选中"全部"
  148. });
  149. },
  150. // 显示年份选择器
  151. showYearPicker: function() {
  152. this.setData({
  153. showYearPicker: true
  154. });
  155. },
  156. // 隐藏年份选择器
  157. hideYearPicker: function() {
  158. this.setData({
  159. showYearPicker: false
  160. });
  161. },
  162. // 防止点击选择器内部时关闭选择器
  163. preventBubble: function() {
  164. return;
  165. },
  166. // 年份选择改变
  167. onYearChange: function(e) {
  168. const index = e.detail.value[0];
  169. this.setData({
  170. yearPickerValue: [index]
  171. });
  172. },
  173. // 确认年份选择
  174. confirmYearSelection: function() {
  175. const selectedIndex = this.data.yearPickerValue[0];
  176. const selectedYear = this.data.years[selectedIndex];
  177. this.setData({
  178. selectedYear: selectedYear === '全部' ? '' : selectedYear,
  179. showYearPicker: false
  180. });
  181. // 根据选择的年份筛选账单
  182. this.filterBillsByYear();
  183. },
  184. // 根据年份筛选账单
  185. filterBillsByYear: function() {
  186. const { selectedYear, originalBillList } = this.data;
  187. if (!selectedYear) {
  188. // 如果选择"全部",显示所有账单
  189. this.setData({
  190. billList: originalBillList
  191. });
  192. return;
  193. }
  194. // 根据年份筛选账单
  195. const filteredBills = originalBillList.filter(bill => {
  196. // 假设 billDate 格式为 "YYYY/MM/DD" 或 "YYYY-MM-DD"
  197. return bill.billDate.startsWith(selectedYear) || bill.billDate.startsWith(selectedYear + '-');
  198. });
  199. this.setData({
  200. billList: filteredBills
  201. });
  202. }
  203. })