index.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import {
  2. createAndroidOrder,
  3. payQrCode,
  4. pollingOrder
  5. } from '~/api/global'
  6. let polling
  7. Component({
  8. properties: {
  9. },
  10. data: {
  11. qrCode: '',
  12. product: {}
  13. },
  14. lifetimes: {
  15. attached() {
  16. /* this.selectComponent("#popUp").showModal()
  17. this.getTabBar().setData({
  18. show: false
  19. }) */
  20. },
  21. },
  22. methods: {
  23. async open(product) {
  24. let orderId = await createAndroidOrder({
  25. productId: product.id
  26. })
  27. let qrCode = await payQrCode({
  28. orderId,
  29. productId: product.id,
  30. channel: wx.getStorageSync('channelCode')
  31. })
  32. this.getTabBar().setData({
  33. show: false
  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. this.getTabBar().setData({
  50. show: true
  51. })
  52. clearInterval(polling)
  53. },
  54. close() {
  55. this.selectComponent("#popUp").hideModal()
  56. this.getTabBar().setData({
  57. show: true
  58. })
  59. }
  60. }
  61. })