zhangdanlist.js 5.7 KB

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