invoice.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // pages/invoice/invoice.js
  2. const app = getApp();
  3. const now = new Date().getFullYear();
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. index: 0,
  10. years: [],
  11. curYear: now,
  12. tabIndex: 0,//0代表开发票 1代表我的发票
  13. InvoiceRecordInfo: [],//开票实收信息
  14. InvoiceInfo: [],//电子发票信息
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function (options) {
  20. this.setYears();
  21. if(options.index){
  22. this.setData({
  23. tabIndex:options.index
  24. })
  25. }
  26. this.getInvoiceRecordInfo(this.data.curYear);
  27. this.getInvoiceInfo(this.data.curYear)
  28. },
  29. setYears() {
  30. const years = [];
  31. for (let i = now; i >= 1990; i--) {
  32. years.push(`${i}年`);
  33. }
  34. this.setData({
  35. years
  36. })
  37. },
  38. previewImage(e){
  39. var current = e.currentTarget.dataset.imgurl;
  40. wx.previewImage({
  41. current: current,//当前显示图片的http链接,我这边是把图片转成了base64
  42. urls: [current] //需要预览的图片http链接列表
  43. })
  44. },
  45. bindPickerChange(e) {
  46. const year = this.data.years[e.detail.value].substr(0, 4);
  47. this.setData({
  48. index: e.detail.value,
  49. curYear: year
  50. })
  51. this.getInfo();
  52. },
  53. change(e) {
  54. this.setData({
  55. tabIndex: e.target.dataset.current
  56. })
  57. this.getInfo();
  58. },
  59. getInfo() {
  60. if (this.data.tabIndex == 0) {
  61. this.getInvoiceRecordInfo(this.data.curYear)
  62. } else {
  63. this.getInvoiceInfo(this.data.curYear)
  64. }
  65. },
  66. toInvoice(e) {
  67. wx.navigateTo({
  68. url: `/pages/invoice/pages/tickets/tickets?fee=` + e.currentTarget.dataset.fee+'&payseriesno=' + e.currentTarget.dataset.payseriesno
  69. })
  70. },
  71. toDetail(e){
  72. wx.navigateTo({
  73. url: `/pages/invoice/pages/detail/detail?invoiceId=` + e.currentTarget.dataset.invoiceid+'&invoiceState='+e.currentTarget.dataset.invoiceState
  74. })
  75. },
  76. toOtherPages(e){
  77. const {
  78. url
  79. } = e.target.dataset;
  80. wx.navigateTo({
  81. url: `/pages/invoice/pages/${url}/${url}`,
  82. })
  83. },
  84. // GET /invoice/getInvoiceRecordInfo 获取开票实收信息
  85. getInvoiceRecordInfo(year) {
  86. app.showLoading();
  87. app.$http.get('/invoice/getInvoiceRecordInfo', {
  88. year
  89. }).then(({ status, data = {} }) => {
  90. if (status == 0) {
  91. data.forEach(v => {
  92. v.fee = app.$util.numberFormat(v.fee, 2);
  93. })
  94. this.setData({
  95. InvoiceRecordInfo: data
  96. })
  97. }
  98. app.hideLoading();
  99. }).catch(() => {
  100. app.hideLoading();
  101. })
  102. },
  103. // GET /invoice/getInvoiceInfo 获取电子发票信息
  104. getInvoiceInfo(year) {
  105. app.showLoading();
  106. app.$http.get('/invoice/getInvoiceInfo', {
  107. year
  108. }).then(({ status, data = {} }) => {
  109. if (status == 0) {
  110. data.forEach(v => {
  111. v.totalPrintAmount = app.$util.numberFormat(v.totalPrintAmount, 2);
  112. v.imgUrl = v.imgUrl.split(',')[0]
  113. })
  114. this.setData({
  115. InvoiceInfo: data
  116. })
  117. }
  118. app.hideLoading();
  119. }).catch(() => {
  120. app.hideLoading();
  121. })
  122. },
  123. /**
  124. * 生命周期函数--监听页面初次渲染完成
  125. */
  126. onReady: function () {
  127. },
  128. /**
  129. * 生命周期函数--监听页面显示
  130. */
  131. onShow: function () {
  132. console.log(app.ticketsTabIndex);
  133. if(app.ticketsTabIndex != null && app.ticketsTabIndex != undefined) {
  134. this.setData({
  135. tabIndex: app.ticketsTabIndex
  136. })
  137. app.ticketsTabIndex = null;
  138. }
  139. },
  140. /**
  141. * 生命周期函数--监听页面隐藏
  142. */
  143. onHide: function () {
  144. },
  145. /**
  146. * 生命周期函数--监听页面卸载
  147. */
  148. onUnload: function () {
  149. },
  150. /**
  151. * 页面相关事件处理函数--监听用户下拉动作
  152. */
  153. onPullDownRefresh: function () {
  154. },
  155. /**
  156. * 页面上拉触底事件的处理函数
  157. */
  158. onReachBottom: function () {
  159. },
  160. /**
  161. * 用户点击右上角分享
  162. */
  163. onShareAppMessage: function () {
  164. }
  165. })