index.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import {
  2. createAndroidOrder,
  3. payQrCode,
  4. pollingOrder
  5. } from '~/api/global'
  6. let polling
  7. Component({
  8. data: {
  9. qrCode: '',
  10. product: {}
  11. },
  12. lifetimes: {
  13. attached() {
  14. /* this.selectComponent("#popUp").showModal()
  15. this.getTabBar().setData({
  16. show: false
  17. }) */
  18. },
  19. },
  20. methods: {
  21. async open(product) {
  22. let orderId = await createAndroidOrder({
  23. productId: product.id
  24. })
  25. let qrCode = await payQrCode({
  26. orderId,
  27. productId: product.id,
  28. channel: wx.getStorageSync('channelCode')
  29. })
  30. if (typeof this.getTabBar === 'function' && this.getTabBar()) {
  31. this.getTabBar().setData({
  32. show: false
  33. })
  34. }
  35. this.setData({
  36. product,
  37. qrCode
  38. })
  39. this.selectComponent("#popUp").showModal()
  40. polling = setInterval(async () => {
  41. let res = await pollingOrder(orderId)
  42. if (res.payStatus == 'SUCCESS') {
  43. this.triggerEvent('paySuccess')
  44. this.close()
  45. }
  46. }, 2000);
  47. },
  48. closeEvent() {
  49. if (typeof this.getTabBar === 'function' && this.getTabBar()) {
  50. this.getTabBar().setData({
  51. show: true
  52. })
  53. }
  54. clearInterval(polling)
  55. },
  56. close() {
  57. this.selectComponent("#popUp").hideModal()
  58. clearInterval(polling)
  59. if (typeof this.getTabBar === 'function' && this.getTabBar()) {
  60. this.getTabBar().setData({
  61. show: true
  62. })
  63. }
  64. }
  65. }
  66. })