zhangdanlist.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. selectedYear: String(currentYear) // 默认设置为当年
  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,
  194. showYearPicker: false
  195. });
  196. // 根据选择的年份获取账单
  197. this.getBillListByYear();
  198. },
  199. // 根据年份获取账单
  200. getBillListByYear: function() {
  201. const { selectedYear } = this.data;
  202. const _this = this;
  203. wx.showLoading({
  204. title: '获取中...',
  205. mask: true,
  206. });
  207. wx.request({
  208. url: app.globalData.interfaceUrls.billList,
  209. method: 'POST',
  210. data: {
  211. accountNum: app.globalData.currentAccountInfo.usernumber,
  212. year: selectedYear
  213. },
  214. header: {
  215. 'content-type': 'application/json',
  216. 'token': app.globalData.userWxInfo.token,
  217. 'source': "wc",
  218. '!SAAS_LOGIN_TOKEN_!': app.globalData.currentAccountInfo.dsKey
  219. },
  220. success(res) {
  221. wx.hideLoading();
  222. let apiReturnData = res.data;
  223. _this.setData({
  224. billList: apiReturnData.data,
  225. originalBillList: apiReturnData.data
  226. });
  227. },
  228. fail(error) {
  229. wx.hideLoading();
  230. wx.showToast({
  231. title: '获取账单失败,请稍后再试',
  232. icon: 'none'
  233. });
  234. }
  235. });
  236. }
  237. })