抖音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.

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