抖音c端
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

311 rindas
8.4 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. }
  125. }).then(res => {
  126. if (res.data.tenantId) {
  127. that.setData({
  128. tenantId: res.data.tenantId
  129. })
  130. that.setRq()
  131. that.getCouponMerchant(res.data.couponId)
  132. }
  133. that.setData({
  134. couponorderstatus: res.data.couponOrderStatus,
  135. data: res.data,
  136. });
  137. that.setData({
  138. expiredTime: util.formatTime(that.data.data.expiredTime, "yyyy-MM-dd hh:mm:ss"),
  139. updateDate: util.formatTime(that.data.data.updateDate, "yyyy-MM-dd hh:mm:ss"),
  140. createDate: util.formatTime(that.data.data.createDate, "yyyy-MM-dd hh:mm:ss")
  141. });
  142. if (res.data.contentType != undefined && res.data.contentType == 1) {
  143. //获取图文展示详情html
  144. that.setData({
  145. contentType: res.data.contentType
  146. })
  147. that.getHtml(options.quancode);
  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. console.log(err, 'err');
  159. tt.showToast({
  160. title: err.message ? err.message : err.data,
  161. icon: 'none',
  162. duration: 2000,
  163. mask: false
  164. });
  165. })
  166. //
  167. //获得优惠券的详情
  168. let setInter = setInterval(function () {
  169. if (
  170. options.quancode &&
  171. that.data.couponorderstatus == 0
  172. ) {
  173. Http.get({
  174. url: config.api.couponOrderDetail,
  175. data: {
  176. couponOrderId: options.quancode
  177. }
  178. }).then(res => {
  179. console.log(res.data, '1233211234567');
  180. that.setData({
  181. couponorderstatus: res.data.couponOrderStatus,
  182. data: res.data,
  183. });
  184. if (res.data.tenantId) {
  185. that.setData({
  186. tenantId: res.data.tenantId
  187. })
  188. that.setRq()
  189. }
  190. console.log(that.data.tenantId, 'tenantId');
  191. that.setData({
  192. expiredTime: util.formatTime(that.data.data.expiredTime, "yyyy-MM-dd hh:mm:ss"),
  193. updateDate: util.formatTime(that.data.data.updateDate, "yyyy-MM-dd hh:mm:ss"),
  194. createDate: util.formatTime(that.data.data.createDate, "yyyy-MM-dd hh:mm:ss")
  195. });
  196. if (that.data.data.validStartDate && that.data.data.validEndDate) {
  197. that.setData({
  198. validStartDate: util.formatTime(that.data.data.validStartDate, "yyyy-MM-dd hh:mm:ss"),
  199. validEndDate: util.formatTime(that.data.data.validEndDate, "yyyy-MM-dd hh:mm:ss"),
  200. // pickStartDate: util.formatTime(res.data.pickStartDate, "yyyy-MM-dd hh:mm:ss"),
  201. // pickEndDate: util.formatTime(res.data.pickEndDate, "yyyy-MM-dd hh:mm:ss"),
  202. })
  203. }
  204. }).catch(err => {
  205. tt.showToast({
  206. title: err.message ? err.message : err.data,
  207. icon: 'none',
  208. duration: 2000,
  209. mask: false
  210. });
  211. })
  212. }
  213. }, 2000);
  214. that.setData({
  215. setInter: setInter
  216. })
  217. },
  218. setRq() {
  219. let _this = this
  220. _this.setData({
  221. showhieRq: false,
  222. })
  223. Http.get({ //获取动态二维码
  224. url: config.api.dynamicId,
  225. data: {
  226. couponOrderId: _this.data.code,
  227. couponTenantId: _this.data.tenantId || ''
  228. }
  229. }).then(res => {
  230. console.log(res, "res")
  231. _this.setData({
  232. dynamicRq: res.data.dynamicId,
  233. expiredSeconds: res.data.expiredSeconds,
  234. couponTenantId: res.data.couponTenantId
  235. })
  236. let url = JSON.stringify({
  237. END: "C",
  238. TYPE: "couponorder",
  239. ID: _this.data.dynamicRq,
  240. couponTenantId: _this.data.couponTenantId
  241. })
  242. if (res.data.expiredSeconds == 0) {
  243. } else {
  244. let inre = setInterval(() => {
  245. if (_this.data.expiredSeconds > 1) {
  246. _this.setData({
  247. expiredSeconds: _this.data.expiredSeconds - 1
  248. })
  249. console.log("有效", _this.data.expiredSeconds)
  250. } else {
  251. console.log("无效", _this.data.expiredSeconds)
  252. clearInterval(_this.data.templTiem)
  253. _this.setData({
  254. showhieRq: true
  255. })
  256. }
  257. }, 1000)
  258. _this.setData({
  259. templTiem: inre
  260. })
  261. }
  262. // util.qrcode("qrcode", url, 350, 350);
  263. _this.createQrCode(url, "qrcode", 210, 210);
  264. }).catch(err => {
  265. tt.showToast({
  266. title: err.message,
  267. icon: 'none',
  268. duration: 4000,
  269. mask: false
  270. });
  271. })
  272. },
  273. createQrCode: function (url, canvasId, cavW, cavH) {
  274. //调用插件中的draw方法,绘制二维码图片
  275. let that = this;
  276. QR.api.draw(url, canvasId, cavW, cavH, function (res) {
  277. that.setData({
  278. tempFilePath: res
  279. })
  280. });
  281. },
  282. onUnload: function () {
  283. let that = this;
  284. clearInterval(that.data.setInter);
  285. // clearInterval(that.data.templTiem);
  286. },
  287. onHide: function () {
  288. let that = this;
  289. clearInterval(that.data.setInter);
  290. // clearInterval(that.data.templTiem);
  291. },
  292. })