抖音c端
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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