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

225 line
6.4 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. validStatus:options.validStatus
  53. });
  54. if(options.couponorderstatus==0&&options.validStatus!=0){
  55. that.setRq()//动态二维码 //这个方法必须在拿到 options.quancode 后调用
  56. }
  57. //初始数据不能延时收到写一边
  58. Http.get({
  59. url: config.api.couponOrderDetail,
  60. data: {
  61. couponOrderId: options.quancode
  62. }
  63. }).then(res => {
  64. that.setData({
  65. couponorderstatus: res.data.couponOrderStatus,
  66. data: res.data,
  67. });
  68. that.setData({
  69. expiredTime: util.formatTime(that.data.data.expiredTime, "yyyy-MM-dd hh:mm:ss"),
  70. updateDate: util.formatTime(that.data.data.updateDate, "yyyy-MM-dd hh:mm:ss"),
  71. createDate: util.formatTime(that.data.data.createDate, "yyyy-MM-dd hh:mm:ss")
  72. });
  73. if (res.data.contentType != undefined && res.data.contentType == 1) {
  74. //获取图文展示详情html
  75. that.setData({
  76. contentType: res.data.contentType
  77. })
  78. that.getHtml(options.quancode);
  79. }
  80. if (that.data.data.validStartDate && that.data.data.validEndDate) {
  81. that.setData({
  82. validStartDate: util.formatTime(that.data.data.validStartDate, "yyyy-MM-dd hh:mm:ss"),
  83. validEndDate: util.formatTime(that.data.data.validEndDate, "yyyy-MM-dd hh:mm:ss"),
  84. // pickStartDate: util.formatTime(res.data.pickStartDate, "yyyy-MM-dd hh:mm:ss"),
  85. // pickEndDate: util.formatTime(res.data.pickEndDate, "yyyy-MM-dd hh:mm:ss"),
  86. })
  87. }
  88. }).catch(err => {
  89. tt.showToast({
  90. title: err.message?err.message:err.data,
  91. icon: 'none',
  92. duration: 2000,
  93. mask: false
  94. });
  95. })
  96. //
  97. //获得优惠券的详情
  98. let setInter = setInterval(function () {
  99. if (
  100. options.quancode &&
  101. that.data.couponorderstatus == 0
  102. ) {
  103. Http.get({
  104. url: config.api.couponOrderDetail,
  105. data: {
  106. couponOrderId: options.quancode
  107. }
  108. }).then(res => {
  109. that.setData({
  110. couponorderstatus: res.data.couponOrderStatus,
  111. data: res.data,
  112. });
  113. that.setData({
  114. expiredTime: util.formatTime(that.data.data.expiredTime, "yyyy-MM-dd hh:mm:ss"),
  115. updateDate: util.formatTime(that.data.data.updateDate, "yyyy-MM-dd hh:mm:ss"),
  116. createDate: util.formatTime(that.data.data.createDate, "yyyy-MM-dd hh:mm:ss")
  117. });
  118. if (that.data.data.validStartDate && that.data.data.validEndDate) {
  119. that.setData({
  120. validStartDate: util.formatTime(that.data.data.validStartDate, "yyyy-MM-dd hh:mm:ss"),
  121. validEndDate: util.formatTime(that.data.data.validEndDate, "yyyy-MM-dd hh:mm:ss"),
  122. // pickStartDate: util.formatTime(res.data.pickStartDate, "yyyy-MM-dd hh:mm:ss"),
  123. // pickEndDate: util.formatTime(res.data.pickEndDate, "yyyy-MM-dd hh:mm:ss"),
  124. })
  125. }
  126. }).catch(err => {
  127. tt.showToast({
  128. title: err.message?err.message:err.data,
  129. icon: 'none',
  130. duration: 2000,
  131. mask: false
  132. });
  133. })
  134. }
  135. }, 2000);
  136. that.setData({
  137. setInter:setInter
  138. })
  139. },
  140. setRq(){
  141. let _this = this
  142. _this.setData({
  143. showhieRq: false,
  144. })
  145. Http.get({//获取动态二维码
  146. url: config.api.dynamicId,
  147. data: {
  148. couponOrderId: _this.data.code
  149. }
  150. }).then(res => {
  151. console.log(res, "res")
  152. _this.setData({
  153. dynamicRq: res.data.dynamicId,
  154. expiredSeconds: res.data.expiredSeconds
  155. })
  156. let url = JSON.stringify({
  157. END: "C",
  158. TYPE: "couponorder",
  159. ID: _this.data.dynamicRq
  160. })
  161. if(res.data.expiredSeconds==0){
  162. }else{
  163. let inre = setInterval(()=>{
  164. if(_this.data.expiredSeconds>1){
  165. _this.setData({
  166. expiredSeconds: _this.data.expiredSeconds-1
  167. })
  168. console.log("有效",_this.data.expiredSeconds)
  169. }else{
  170. console.log("无效", _this.data.expiredSeconds)
  171. clearInterval(_this.data.templTiem)
  172. _this.setData({
  173. showhieRq:true
  174. })
  175. }
  176. },1000)
  177. _this.setData({
  178. templTiem:inre
  179. })
  180. }
  181. // util.qrcode("qrcode", url, 350, 350);
  182. _this.createQrCode(url, "qrcode", 210, 210);
  183. }).catch(err => {
  184. tt.showToast({
  185. title: err.message,
  186. icon: 'none',
  187. duration: 4000,
  188. mask: false
  189. });
  190. })
  191. },
  192. createQrCode: function (url, canvasId, cavW, cavH) {
  193. //调用插件中的draw方法,绘制二维码图片
  194. let that = this;
  195. QR.api.draw(url, canvasId, cavW, cavH, function (res) {
  196. that.setData({
  197. tempFilePath: res
  198. })
  199. });
  200. },
  201. onUnload: function () {
  202. let that = this;
  203. clearInterval(that.data.setInter);
  204. // clearInterval(that.data.templTiem);
  205. },
  206. onHide: function () {
  207. let that = this;
  208. clearInterval(that.data.setInter);
  209. // clearInterval(that.data.templTiem);
  210. },
  211. })