index.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import { queryWrUserReceiptInfo } from "../../../../services/api/common/index"
  2. import { setWrUserReceiptInfo, userid } from "../../../../services/utils"
  3. import { hideLoading, showLoading } from "../../../../utils/message/index"
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. /// 底部安全区域
  10. safeBottom: getApp().globalData.safeBottom,
  11. /// 是否空数据
  12. isEmpty: true,
  13. /// 数据信息
  14. infos: <Array<GuangZuan.WrUserReceiptInfo>>[],
  15. /// 是否从我的页面过来
  16. isMine: 'true'
  17. },
  18. /**
  19. * 返回上层视图
  20. */
  21. backToParent() {
  22. /// 返回上层视图
  23. wx.navigateBack()
  24. },
  25. /**
  26. * 按钮点击响应事件
  27. */
  28. onButtonPressed(e: any) {
  29. const id = e.currentTarget.id
  30. switch (id) {
  31. case "new": /// 新增
  32. wx.navigateTo({
  33. url: "/mMine/pages/invoice/operate/index"
  34. })
  35. break;
  36. default: /// 修改
  37. if (this.data.isMine === 'true') {
  38. wx.navigateTo({
  39. url: "/mMine/pages/invoice/operate/index?id="+JSON.stringify(this.data.infos[e.currentTarget.id])
  40. })
  41. } else {
  42. setWrUserReceiptInfo(this.data.infos[Number(id)])
  43. wx.navigateBack()
  44. }
  45. break;
  46. }
  47. },
  48. /// 查询用户发票信息
  49. queryWrUserReceiptInfo() {
  50. /// showLoading
  51. showLoading(()=>{
  52. /// 发送查询请求
  53. queryWrUserReceiptInfo({
  54. data: {
  55. userid: userid()
  56. },
  57. success: (res) => {
  58. /// 加载失败
  59. if (res.code != 200) {
  60. hideLoading(()=>{}, '数据加载失败,原因:'+res.msg)
  61. return
  62. }
  63. /// 数据信息
  64. hideLoading(()=>{
  65. this.setData({
  66. infos: res.data,
  67. isEmpty: res.data.length === 0
  68. })
  69. })
  70. },
  71. fail: (emsg) => {
  72. hideLoading(()=>{}, emsg)
  73. },
  74. complete: () => {
  75. /// 结束下拉刷新
  76. wx.stopPullDownRefresh()
  77. }
  78. })
  79. })
  80. },
  81. /**
  82. * 生命周期函数--监听页面加载
  83. */
  84. onLoad(options: any) {
  85. this.setData({ isMine: options.isMine })
  86. },
  87. /**
  88. * 生命周期函数--监听页面初次渲染完成
  89. */
  90. onReady() {
  91. },
  92. /**
  93. * 生命周期函数--监听页面显示
  94. */
  95. onShow() {
  96. /// 查询用户发票信息
  97. this.queryWrUserReceiptInfo()
  98. },
  99. /**
  100. * 生命周期函数--监听页面隐藏
  101. */
  102. onHide() {
  103. },
  104. /**
  105. * 生命周期函数--监听页面卸载
  106. */
  107. onUnload() {
  108. },
  109. /**
  110. * 页面相关事件处理函数--监听用户下拉动作
  111. */
  112. onPullDownRefresh() {
  113. /// 查询用户发票信息
  114. this.queryWrUserReceiptInfo()
  115. },
  116. /**
  117. * 页面上拉触底事件的处理函数
  118. */
  119. onReachBottom() {
  120. },
  121. /**
  122. * 用户点击右上角分享
  123. */
  124. onShareAppMessage() {
  125. }
  126. })