zhangdanlist.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. // 对账单列表按日期排序
  84. const sortedBills = apiReturnData.data.sort((a, b) => {
  85. return new Date(b.billDate) - new Date(a.billDate);
  86. });
  87. _this.setData({
  88. billList: sortedBills,
  89. });
  90. resolve(sortedBills);
  91. },
  92. fail(error) {
  93. wx.hideLoading();
  94. utils.simleInfo('获取账单失败,请稍后再试');
  95. reject(error);
  96. }
  97. });
  98. });
  99. },
  100. // 返回上一页
  101. goBack: function() {
  102. wx.navigateBack();
  103. },
  104. // 点击开发票按钮
  105. openInvoice: function(e) {
  106. const index = e.currentTarget.dataset.index;
  107. const bill = this.data.billList[index];
  108. wx.showToast({
  109. title: '开发票功能开发中',
  110. icon: 'none'
  111. });
  112. },
  113. // 切换到首页
  114. goToHome: function() {
  115. wx.switchTab({
  116. url: '/pages/homepage/homepage',
  117. });
  118. },
  119. // 切换到我的页面
  120. goToMine: function() {
  121. wx.switchTab({
  122. url: '/pages/mine/mine',
  123. });
  124. },
  125. navigateToHome() {
  126. wx.switchTab({
  127. url: '/pages/index/index'
  128. })
  129. },
  130. navigateToMine() {
  131. wx.switchTab({
  132. url: '/pages/mine/mine'
  133. })
  134. },
  135. // 跳转到账单详情页面
  136. goToBillDetail: function(e) {
  137. const bill = e.currentTarget.dataset.bill;
  138. wx.navigateTo({
  139. url: '/pages/zhangdanxiangqing/zdxiangqing?billInfo=' + JSON.stringify(bill)
  140. });
  141. },
  142. // 获取发票
  143. getInvoice: function(e) {
  144. wx.showToast({
  145. title: '暂不支持!',
  146. icon: 'none'
  147. });
  148. return;
  149. // 阻止事件冒泡,避免触发goToBillDetail
  150. e.stopPropagation();
  151. const bill = e.currentTarget.dataset.bill;
  152. wx.navigateTo({
  153. url: '/pages/invoice/invoice?billInfo=' + JSON.stringify(bill)
  154. });
  155. },
  156. // 生成近20年的年份数据
  157. generateYears: function() {
  158. const currentYear = new Date().getFullYear();
  159. let years = [];
  160. for (let i = 0; i < 20; i++) {
  161. years.push(String(currentYear - i));
  162. }
  163. this.setData({
  164. years: years,
  165. yearPickerValue: [0], // 默认选中当年
  166. selectedYear: String(currentYear) // 默认设置为当年
  167. });
  168. },
  169. // 显示年份选择器
  170. showYearPicker: function() {
  171. this.setData({
  172. showYearPicker: true
  173. });
  174. },
  175. // 隐藏年份选择器
  176. hideYearPicker: function() {
  177. this.setData({
  178. showYearPicker: false
  179. });
  180. },
  181. // 防止点击选择器内部时关闭选择器
  182. preventBubble: function() {
  183. return;
  184. },
  185. // 年份选择改变
  186. onYearChange: function(e) {
  187. const index = e.detail.value[0];
  188. this.setData({
  189. yearPickerValue: [index]
  190. });
  191. },
  192. // 确认年份选择
  193. confirmYearSelection: function() {
  194. const selectedIndex = this.data.yearPickerValue[0];
  195. const selectedYear = this.data.years[selectedIndex];
  196. this.setData({
  197. selectedYear: selectedYear,
  198. showYearPicker: false
  199. });
  200. // 根据选择的年份获取账单
  201. this.getBillListByYear();
  202. },
  203. // 根据年份获取账单
  204. getBillListByYear: function() {
  205. const { selectedYear } = this.data;
  206. const _this = this;
  207. wx.showLoading({
  208. title: '获取中...',
  209. mask: true,
  210. });
  211. wx.request({
  212. url: app.globalData.interfaceUrls.billList,
  213. method: 'POST',
  214. data: {
  215. accountNum: app.globalData.currentAccountInfo.usernumber,
  216. year: selectedYear
  217. },
  218. header: {
  219. 'content-type': 'application/json',
  220. 'token': app.globalData.userWxInfo.token,
  221. 'source': "wc",
  222. '!SAAS_LOGIN_TOKEN_!': app.globalData.currentAccountInfo.dsKey
  223. },
  224. success(res) {
  225. wx.hideLoading();
  226. let apiReturnData = res.data;
  227. // 对账单列表按日期排序
  228. const sortedBills = apiReturnData.data.sort((a, b) => {
  229. return new Date(b.billDate) - new Date(a.billDate);
  230. });
  231. _this.setData({
  232. billList: sortedBills,
  233. originalBillList: sortedBills
  234. });
  235. },
  236. fail(error) {
  237. wx.hideLoading();
  238. wx.showToast({
  239. title: '获取账单失败,请稍后再试',
  240. icon: 'none'
  241. });
  242. }
  243. });
  244. }
  245. })