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

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