抖音c端
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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