C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
2.7 KiB

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