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

312 lines
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. }
  179. }).then(res => {
  180. console.log(res.data, '1233211234567');
  181. that.setData({
  182. couponorderstatus: res.data.couponOrderStatus,
  183. data: res.data,
  184. });
  185. if (res.data.tenantId) {
  186. that.setData({
  187. tenantId: res.data.tenantId
  188. })
  189. that.setRq()
  190. }
  191. console.log(that.data.tenantId, 'tenantId');
  192. that.setData({
  193. expiredTime: util.formatTime(that.data.data.expiredTime, "yyyy-MM-dd hh:mm:ss"),
  194. updateDate: util.formatTime(that.data.data.updateDate, "yyyy-MM-dd hh:mm:ss"),
  195. createDate: util.formatTime(that.data.data.createDate, "yyyy-MM-dd hh:mm:ss")
  196. });
  197. if (that.data.data.validStartDate && that.data.data.validEndDate) {
  198. that.setData({
  199. validStartDate: util.formatTime(that.data.data.validStartDate, "yyyy-MM-dd hh:mm:ss"),
  200. validEndDate: util.formatTime(that.data.data.validEndDate, "yyyy-MM-dd hh:mm:ss"),
  201. // pickStartDate: util.formatTime(res.data.pickStartDate, "yyyy-MM-dd hh:mm:ss"),
  202. // pickEndDate: util.formatTime(res.data.pickEndDate, "yyyy-MM-dd hh:mm:ss"),
  203. })
  204. }
  205. }).catch(err => {
  206. tt.showToast({
  207. title: err.message ? err.message : err.data,
  208. icon: 'none',
  209. duration: 2000,
  210. mask: false
  211. });
  212. })
  213. }
  214. }, 2000);
  215. that.setData({
  216. setInter: setInter
  217. })
  218. },
  219. setRq() {
  220. let _this = this
  221. _this.setData({
  222. showhieRq: false,
  223. })
  224. Http.get({ //获取动态二维码
  225. url: config.api.dynamicId,
  226. data: {
  227. couponOrderId: _this.data.code,
  228. couponTenantId: _this.data.tenantId || ''
  229. }
  230. }).then(res => {
  231. console.log(res, "res")
  232. _this.setData({
  233. dynamicRq: res.data.dynamicId,
  234. expiredSeconds: res.data.expiredSeconds,
  235. couponTenantId: res.data.couponTenantId
  236. })
  237. let url = JSON.stringify({
  238. END: "C",
  239. TYPE: "couponorder",
  240. ID: _this.data.dynamicRq,
  241. couponTenantId: _this.data.couponTenantId
  242. })
  243. if (res.data.expiredSeconds == 0) {
  244. } else {
  245. let inre = setInterval(() => {
  246. if (_this.data.expiredSeconds > 1) {
  247. _this.setData({
  248. expiredSeconds: _this.data.expiredSeconds - 1
  249. })
  250. console.log("有效", _this.data.expiredSeconds)
  251. } else {
  252. console.log("无效", _this.data.expiredSeconds)
  253. clearInterval(_this.data.templTiem)
  254. _this.setData({
  255. showhieRq: true
  256. })
  257. }
  258. }, 1000)
  259. _this.setData({
  260. templTiem: inre
  261. })
  262. }
  263. // util.qrcode("qrcode", url, 350, 350);
  264. _this.createQrCode(url, "qrcode", 210, 210);
  265. }).catch(err => {
  266. tt.showToast({
  267. title: err.message,
  268. icon: 'none',
  269. duration: 4000,
  270. mask: false
  271. });
  272. })
  273. },
  274. createQrCode: function (url, canvasId, cavW, cavH) {
  275. //调用插件中的draw方法,绘制二维码图片
  276. let that = this;
  277. QR.api.draw(url, canvasId, cavW, cavH, function (res) {
  278. that.setData({
  279. tempFilePath: res
  280. })
  281. });
  282. },
  283. onUnload: function () {
  284. let that = this;
  285. clearInterval(that.data.setInter);
  286. // clearInterval(that.data.templTiem);
  287. },
  288. onHide: function () {
  289. let that = this;
  290. clearInterval(that.data.setInter);
  291. // clearInterval(that.data.templTiem);
  292. },
  293. })