抖音小程序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.

217 lines
6.2 KiB

  1. const app = getApp();
  2. const navigationBarHeight = (getApp().statusBarHeight + 50) + "px";
  3. const Http = require("../../../utils/HttpBasics");
  4. const config = require("../../../config/config");
  5. const util = require("../../../utils/util");
  6. const QR = require("../../../utils/memberqrcode.js");
  7. Page({
  8. data: {
  9. navigationBarHeight,
  10. couponorderstatus:"",
  11. quancode:"",
  12. setInter:"",
  13. validStartDate:"",
  14. validEndDate:"",
  15. pickStartDate:"",
  16. pickEndDate:"",
  17. expiredTime:"",
  18. updateDate:"",
  19. createDate:"",
  20. code:"",
  21. data:{
  22. },
  23. showhieRq:false,
  24. dynamicRq:"",
  25. expiredSeconds:0,
  26. templTiem:"",
  27. curHtml:"",
  28. },
  29. getHtml(couponOrderId) {
  30. Http.get({
  31. url: config.api.couponHtmlDetailForPkg,
  32. data: {
  33. couponOrderId: couponOrderId
  34. }
  35. }).then(res => {
  36. console.log(res)
  37. if (res.code == 200 && res.data.html) {
  38. this.setData({
  39. curHtml: decodeURI(res.data.html)
  40. })
  41. // app.globalData.curHtml = this.data.curHtml;
  42. // console.log(app.globalData.curHtml)
  43. }
  44. })
  45. },
  46. onLoad: function (options) {
  47. let that = this;
  48. console.log(options);
  49. that.setData({
  50. code: options.quancode,
  51. couponorderstatus: options.couponorderstatus
  52. });
  53. that.setRq()//动态二维码 //这个方法必须在拿到 options.quancode 后调用
  54. //初始数据不能延时收到写一边
  55. Http.get({
  56. url: config.api.couponOrderDetail,
  57. data: {
  58. couponOrderId: options.quancode
  59. }
  60. }).then(res => {
  61. that.setData({
  62. couponorderstatus: res.data.couponOrderStatus,
  63. data: res.data,
  64. });
  65. that.setData({
  66. expiredTime: util.formatTime(that.data.data.expiredTime, "yyyy-MM-dd hh:mm:ss"),
  67. updateDate: util.formatTime(that.data.data.updateDate, "yyyy-MM-dd hh:mm:ss"),
  68. createDate: util.formatTime(that.data.data.createDate, "yyyy-MM-dd hh:mm:ss")
  69. });
  70. if (res.data.contentType != undefined && res.data.contentType == 1) {
  71. //获取图文展示详情html
  72. that.setData({
  73. contentType: res.data.contentType
  74. })
  75. that.getHtml(options.quancode);
  76. }
  77. if (that.data.data.validStartDate && that.data.data.validEndDate) {
  78. that.setData({
  79. validStartDate: util.formatTime(that.data.data.validStartDate, "yyyy-MM-dd hh:mm:ss"),
  80. validEndDate: util.formatTime(that.data.data.validEndDate, "yyyy-MM-dd hh:mm:ss"),
  81. // pickStartDate: util.formatTime(res.data.pickStartDate, "yyyy-MM-dd hh:mm:ss"),
  82. // pickEndDate: util.formatTime(res.data.pickEndDate, "yyyy-MM-dd hh:mm:ss"),
  83. })
  84. }
  85. }).catch(err => {
  86. tt.showToast({
  87. title: err.message?err.message:err.data,
  88. icon: 'none',
  89. duration: 2000,
  90. mask: false
  91. });
  92. })
  93. //
  94. //获得优惠券的详情
  95. let setInter = setInterval(function () {
  96. if (
  97. options.quancode &&
  98. that.data.couponorderstatus == 0
  99. ) {
  100. Http.get({
  101. url: config.api.couponOrderDetail,
  102. data: {
  103. couponOrderId: options.quancode
  104. }
  105. }).then(res => {
  106. that.setData({
  107. couponorderstatus: res.data.couponOrderStatus,
  108. data: res.data,
  109. });
  110. that.setData({
  111. expiredTime: util.formatTime(that.data.data.expiredTime, "yyyy-MM-dd hh:mm:ss"),
  112. updateDate: util.formatTime(that.data.data.updateDate, "yyyy-MM-dd hh:mm:ss"),
  113. createDate: util.formatTime(that.data.data.createDate, "yyyy-MM-dd hh:mm:ss")
  114. });
  115. if (that.data.data.validStartDate && that.data.data.validEndDate) {
  116. that.setData({
  117. validStartDate: util.formatTime(that.data.data.validStartDate, "yyyy-MM-dd hh:mm:ss"),
  118. validEndDate: util.formatTime(that.data.data.validEndDate, "yyyy-MM-dd hh:mm:ss"),
  119. // pickStartDate: util.formatTime(res.data.pickStartDate, "yyyy-MM-dd hh:mm:ss"),
  120. // pickEndDate: util.formatTime(res.data.pickEndDate, "yyyy-MM-dd hh:mm:ss"),
  121. })
  122. }
  123. }).catch(err => {
  124. tt.showToast({
  125. title: err.message?err.message:err.data,
  126. icon: 'none',
  127. duration: 2000,
  128. mask: false
  129. });
  130. })
  131. }
  132. }, 2000);
  133. that.setData({
  134. setInter:setInter
  135. })
  136. },
  137. setRq(){
  138. let _this = this
  139. _this.setData({
  140. showhieRq: false,
  141. })
  142. Http.get({//获取动态二维码
  143. url: config.api.dynamicId,
  144. data: {
  145. couponOrderId: _this.data.code
  146. }
  147. }).then(res => {
  148. console.log(res, "res")
  149. _this.setData({
  150. dynamicRq: res.data.dynamicId,
  151. expiredSeconds: res.data.expiredSeconds
  152. })
  153. let url = JSON.stringify({
  154. END: "C",
  155. TYPE: "couponorder",
  156. ID: _this.data.dynamicRq
  157. })
  158. let inre = setInterval(()=>{
  159. if(_this.data.expiredSeconds>1){
  160. _this.setData({
  161. expiredSeconds: _this.data.expiredSeconds-1
  162. })
  163. console.log("有效",_this.data.expiredSeconds)
  164. }else{
  165. console.log("无效", _this.data.expiredSeconds)
  166. clearInterval(_this.data.templTiem)
  167. _this.setData({
  168. showhieRq:true
  169. })
  170. }
  171. },1000)
  172. _this.setData({
  173. templTiem:inre
  174. })
  175. // util.qrcode("qrcode", url, 350, 350);
  176. _this.createQrCode(url, "qrcode", 210, 210);
  177. }).catch(err => {
  178. tt.showToast({
  179. title: err.message,
  180. icon: 'none',
  181. duration: 4000,
  182. mask: false
  183. });
  184. })
  185. },
  186. createQrCode: function (url, canvasId, cavW, cavH) {
  187. //调用插件中的draw方法,绘制二维码图片
  188. let that = this;
  189. QR.api.draw(url, canvasId, cavW, cavH, function (res) {
  190. that.setData({
  191. tempFilePath: res
  192. })
  193. });
  194. },
  195. onUnload: function () {
  196. let that = this;
  197. clearInterval(that.data.setInter);
  198. // clearInterval(that.data.templTiem);
  199. },
  200. onHide: function () {
  201. let that = this;
  202. clearInterval(that.data.setInter);
  203. // clearInterval(that.data.templTiem);
  204. },
  205. })