zhangdanlist.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. selectedYear: String(currentYear) // 默认设置为当年
  164. });
  165. },
  166. // 显示年份选择器
  167. showYearPicker: function() {
  168. this.setData({
  169. showYearPicker: true
  170. });
  171. },
  172. // 隐藏年份选择器
  173. hideYearPicker: function() {
  174. this.setData({
  175. showYearPicker: false
  176. });
  177. },
  178. // 防止点击选择器内部时关闭选择器
  179. preventBubble: function() {
  180. return;
  181. },
  182. // 年份选择改变
  183. onYearChange: function(e) {
  184. const index = e.detail.value[0];
  185. this.setData({
  186. yearPickerValue: [index]
  187. });
  188. },
  189. // 确认年份选择
  190. confirmYearSelection: function() {
  191. const selectedIndex = this.data.yearPickerValue[0];
  192. const selectedYear = this.data.years[selectedIndex];
  193. this.setData({
  194. selectedYear: selectedYear,
  195. showYearPicker: false
  196. });
  197. // 根据选择的年份获取账单
  198. this.getBillListByYear();
  199. },
  200. // 根据年份获取账单
  201. getBillListByYear: function() {
  202. const { selectedYear } = this.data;
  203. const _this = this;
  204. wx.showLoading({
  205. title: '获取中...',
  206. mask: true,
  207. });
  208. wx.request({
  209. url: app.globalData.interfaceUrls.billList,
  210. method: 'POST',
  211. data: {
  212. accountNum: app.globalData.currentAccountInfo.usernumber,
  213. year: selectedYear
  214. },
  215. header: {
  216. 'content-type': 'application/json',
  217. 'token': app.globalData.userWxInfo.token,
  218. 'source': "wc",
  219. '!SAAS_LOGIN_TOKEN_!': app.globalData.currentAccountInfo.dsKey
  220. },
  221. success(res) {
  222. wx.hideLoading();
  223. let apiReturnData = res.data;
  224. _this.setData({
  225. billList: apiReturnData.data,
  226. originalBillList: apiReturnData.data
  227. });
  228. },
  229. fail(error) {
  230. wx.hideLoading();
  231. wx.showToast({
  232. title: '获取账单失败,请稍后再试',
  233. icon: 'none'
  234. });
  235. }
  236. });
  237. }
  238. })