C端小程序
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

108 líneas
2.6 KiB

  1. let util = require("../../utils/util");
  2. let Http = require("../../utils/HttpBasics");
  3. let config = require("../../config/config.js");
  4. Page({
  5. data: {
  6. code: "",
  7. //存储计时器
  8. setInter: ""
  9. },
  10. onLoad: function(options) {
  11. let that = this;
  12. setTimeout(function () {
  13. wx.setScreenBrightness({
  14. value: 0.7,
  15. })
  16. }, 200),
  17. util.barcode("barcode", options.quancode, 500, 100);
  18. util.qrcode("qrcode", options.quancode, 350, 350);
  19. that.setData({
  20. sight: options.sight,
  21. code: options.quancode,
  22. title: options.title,
  23. subtitle: options.subtitle,
  24. remark: options.remark,
  25. couponorderstatus: options.couponorderstatus
  26. });
  27. console.log(options.couponorderstatus);
  28. console.log("我是状态");
  29. /**
  30. * 如果没有核销
  31. */
  32. that.data.setInter = setInterval(function() {
  33. if (that.data.couponorderstatus == 0) {
  34. Http.get({
  35. url: config.api.getStatus,
  36. data: {
  37. couponOrderId: options.quancode
  38. }
  39. }).then(res => {
  40. console.log(res);
  41. that.setData({
  42. couponorderstatus: res.data.CouponOrderStatus
  43. });
  44. if (res.data.CouponOrderStatus == 1) {
  45. /**
  46. * 动态改变上一级页面的核销状态
  47. */
  48. var pages = getCurrentPages();
  49. var prevPage = pages[pages.length - 2]; //上一个页面
  50. //直接调用上一个页面的setData()方法,把数据存到上一个页面中去
  51. prevPage.setData({
  52. mystatus: res.data.CouponOrderStatus
  53. });
  54. }
  55. })
  56. .catch(err => {
  57. wx.showToast({
  58. title: err.errMsg,
  59. icon: 'none',
  60. duration: 2000,
  61. mask: false
  62. });
  63. })
  64. }
  65. }, 2000);
  66. if (that.data.couponorderstatus == 1) {
  67. /**
  68. * 如果已经核销
  69. * 不需要循环
  70. */
  71. Http.get({
  72. url: config.api.getStatus,
  73. data: {
  74. couponOrderId: options.quancode
  75. }
  76. }).then(res => {
  77. console.log(res);
  78. that.setData({
  79. couponorderstatus: res.data.CouponOrderStatus
  80. });
  81. })
  82. .catch(err => {
  83. wx.showToast({
  84. title: err.errMsg,
  85. icon: 'none',
  86. duration: 2000,
  87. mask: false
  88. });
  89. })
  90. }
  91. /**
  92. * couponorderstatus
  93. * 0 没有核销
  94. * 1 已经核销成功
  95. */
  96. },
  97. onUnload: function() {
  98. let that = this;
  99. clearInterval(that.data.setInter);
  100. wx.setScreenBrightness({
  101. value: that.data.sight,
  102. })
  103. }
  104. });