zhangdanlist.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. debugger
  82. wx.hideLoading();
  83. let apiReturnData = res.data;
  84. _this.setData({
  85. billList: apiReturnData.data,
  86. });
  87. resolve(apiReturnData.data);
  88. },
  89. fail(error) {
  90. wx.hideLoading();
  91. utils.simleInfo('获取账单失败,请稍后再试');
  92. reject(error);
  93. }
  94. });
  95. });
  96. },
  97. // 返回上一页
  98. goBack: function() {
  99. wx.navigateBack();
  100. },
  101. // 点击开发票按钮
  102. openInvoice: function(e) {
  103. const index = e.currentTarget.dataset.index;
  104. const bill = this.data.billList[index];
  105. wx.showToast({
  106. title: '开发票功能开发中',
  107. icon: 'none'
  108. });
  109. },
  110. // 切换到首页
  111. goToHome: function() {
  112. wx.switchTab({
  113. url: '/pages/homepage/homepage',
  114. });
  115. },
  116. // 切换到我的页面
  117. goToMine: function() {
  118. wx.switchTab({
  119. url: '/pages/mine/mine',
  120. });
  121. },
  122. navigateToHome() {
  123. wx.switchTab({
  124. url: '/pages/index/index'
  125. })
  126. },
  127. navigateToMine() {
  128. wx.switchTab({
  129. url: '/pages/mine/mine'
  130. })
  131. },
  132. // 跳转到账单详情页面
  133. goToBillDetail: function(e) {
  134. const bill = e.currentTarget.dataset.bill;
  135. wx.navigateTo({
  136. url: '/pages/zhangdanxiangqing/zdxiangqing?billInfo=' + JSON.stringify(bill)
  137. });
  138. },
  139. // 获取发票
  140. getInvoice: function(e) {
  141. wx.showToast({
  142. title: '暂不支持!',
  143. icon: 'none'
  144. });
  145. return;
  146. // 阻止事件冒泡,避免触发goToBillDetail
  147. e.stopPropagation();
  148. const bill = e.currentTarget.dataset.bill;
  149. wx.navigateTo({
  150. url: '/pages/invoice/invoice?billInfo=' + JSON.stringify(bill)
  151. });
  152. },
  153. // 生成近20年的年份数据
  154. generateYears: function() {
  155. const currentYear = new Date().getFullYear();
  156. let years = ['全部']; // 添加"全部"选项
  157. for (let i = 0; i < 20; i++) {
  158. years.push(String(currentYear - i));
  159. }
  160. this.setData({
  161. years: years,
  162. yearPickerValue: [0] // 默认选中"全部"
  163. });
  164. },
  165. // 显示年份选择器
  166. showYearPicker: function() {
  167. this.setData({
  168. showYearPicker: true
  169. });
  170. },
  171. // 隐藏年份选择器
  172. hideYearPicker: function() {
  173. this.setData({
  174. showYearPicker: false
  175. });
  176. },
  177. // 防止点击选择器内部时关闭选择器
  178. preventBubble: function() {
  179. return;
  180. },
  181. // 年份选择改变
  182. onYearChange: function(e) {
  183. const index = e.detail.value[0];
  184. this.setData({
  185. yearPickerValue: [index]
  186. });
  187. },
  188. // 确认年份选择
  189. confirmYearSelection: function() {
  190. const selectedIndex = this.data.yearPickerValue[0];
  191. const selectedYear = this.data.years[selectedIndex];
  192. this.setData({
  193. selectedYear: selectedYear === '全部' ? '' : selectedYear,
  194. showYearPicker: false
  195. });
  196. // 根据选择的年份筛选账单
  197. this.filterBillsByYear();
  198. },
  199. // 根据年份筛选账单
  200. filterBillsByYear: function() {
  201. const { selectedYear, originalBillList } = this.data;
  202. if (!selectedYear) {
  203. // 如果选择"全部",显示所有账单
  204. this.setData({
  205. billList: originalBillList
  206. });
  207. return;
  208. }
  209. // 根据年份筛选账单
  210. const filteredBills = originalBillList.filter(bill => {
  211. // 假设 billDate 格式为 "YYYY/MM/DD" 或 "YYYY-MM-DD"
  212. return bill.billDate.startsWith(selectedYear) || bill.billDate.startsWith(selectedYear + '-');
  213. });
  214. this.setData({
  215. billList: filteredBills
  216. });
  217. }
  218. })