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

315 lines
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. },
  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. getCouponMerchant(couponChannelId) { //获取适用门店
  62. Http.get({
  63. url: config.api.couponMerchant,
  64. data: {
  65. couponChannelId: couponChannelId
  66. }
  67. }).then(res => {
  68. const keys = Object.keys(res.data)
  69. const mallList = []
  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: true
  77. }
  78. mallList.push(obj)
  79. })
  80. this.setData({
  81. mallList: mallList
  82. })
  83. // if (res.data && res.data.length) {
  84. // let merchantVoList = res.data
  85. // let idList = []
  86. // merchantVoList.map(item => {
  87. // idList.push(item.id)
  88. // })
  89. // this.setData({
  90. // idList: idList
  91. // })
  92. // this.getCouponList(idList) //获取推荐列表
  93. // }
  94. // this.setData({
  95. // merchantVoList: res.data
  96. // })
  97. })
  98. },
  99. getHtml(couponOrderId) {
  100. Http.get({
  101. url: config.api.couponHtmlDetailForPkg,
  102. data: {
  103. couponOrderId: couponOrderId
  104. }
  105. }).then(res => {
  106. console.log(res)
  107. if (res.code == 200 && res.data.html) {
  108. this.setData({
  109. curHtml: decodeURI(res.data.html)
  110. })
  111. // app.globalData.curHtml = this.data.curHtml;
  112. // console.log(app.globalData.curHtml)
  113. }
  114. })
  115. },
  116. onLoad: function (options) {
  117. let that = this;
  118. console.log(options);
  119. that.setData({
  120. code: options.quancode,
  121. codeS: options.quancode.slice(0, 4) + `******` + options.quancode.slice(14),
  122. couponorderstatus: options.couponorderstatus,
  123. validStatus: options.validStatus
  124. });
  125. if (options.couponorderstatus == 0 && options.validStatus != 0) {
  126. that.setRq() //动态二维码 //这个方法必须在拿到 options.quancode 后调用
  127. }
  128. //初始数据不能延时收到写一边
  129. Http.get({
  130. url: config.api.couponOrderDetail,
  131. data: {
  132. couponOrderId: options.quancode
  133. }
  134. }).then(res => {
  135. if (res.data.tenantId) {
  136. that.setData({
  137. tenantId: res.data.tenantId
  138. })
  139. that.setRq()
  140. }
  141. that.setData({
  142. couponorderstatus: res.data.couponOrderStatus,
  143. data: res.data,
  144. });
  145. that.setData({
  146. expiredTime: util.formatTime(that.data.data.expiredTime, "yyyy-MM-dd hh:mm:ss"),
  147. updateDate: util.formatTime(that.data.data.updateDate, "yyyy-MM-dd hh:mm:ss"),
  148. createDate: util.formatTime(that.data.data.createDate, "yyyy-MM-dd hh:mm:ss")
  149. });
  150. if (res.data.contentType != undefined && res.data.contentType == 1) {
  151. //获取图文展示详情html
  152. that.setData({
  153. contentType: res.data.contentType
  154. })
  155. that.getHtml(options.quancode);
  156. }
  157. if (that.data.data.validStartDate && that.data.data.validEndDate) {
  158. that.setData({
  159. validStartDate: util.formatTime(that.data.data.validStartDate, "yyyy-MM-dd hh:mm:ss"),
  160. validEndDate: util.formatTime(that.data.data.validEndDate, "yyyy-MM-dd hh:mm:ss"),
  161. // pickStartDate: util.formatTime(res.data.pickStartDate, "yyyy-MM-dd hh:mm:ss"),
  162. // pickEndDate: util.formatTime(res.data.pickEndDate, "yyyy-MM-dd hh:mm:ss"),
  163. })
  164. }
  165. }).catch(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. }
  185. }).then(res => {
  186. console.log(res.data, '1233211234567');
  187. that.setData({
  188. couponorderstatus: res.data.couponOrderStatus,
  189. data: res.data,
  190. });
  191. if (res.data.tenantId) {
  192. that.setData({
  193. tenantId: res.data.tenantId
  194. })
  195. that.setRq()
  196. }
  197. console.log(that.data.tenantId, 'tenantId');
  198. that.setData({
  199. expiredTime: util.formatTime(that.data.data.expiredTime, "yyyy-MM-dd hh:mm:ss"),
  200. updateDate: util.formatTime(that.data.data.updateDate, "yyyy-MM-dd hh:mm:ss"),
  201. createDate: util.formatTime(that.data.data.createDate, "yyyy-MM-dd hh:mm:ss")
  202. });
  203. if (that.data.data.validStartDate && that.data.data.validEndDate) {
  204. that.setData({
  205. validStartDate: util.formatTime(that.data.data.validStartDate, "yyyy-MM-dd hh:mm:ss"),
  206. validEndDate: util.formatTime(that.data.data.validEndDate, "yyyy-MM-dd hh:mm:ss"),
  207. // pickStartDate: util.formatTime(res.data.pickStartDate, "yyyy-MM-dd hh:mm:ss"),
  208. // pickEndDate: util.formatTime(res.data.pickEndDate, "yyyy-MM-dd hh:mm:ss"),
  209. })
  210. }
  211. }).catch(err => {
  212. tt.showToast({
  213. title: err.message ? err.message : err.data,
  214. icon: 'none',
  215. duration: 2000,
  216. mask: false
  217. });
  218. })
  219. }
  220. }, 2000);
  221. that.setData({
  222. setInter: setInter
  223. })
  224. },
  225. setRq() {
  226. let _this = this
  227. _this.setData({
  228. showhieRq: false,
  229. })
  230. Http.get({ //获取动态二维码
  231. url: config.api.dynamicId,
  232. data: {
  233. couponOrderId: _this.data.code,
  234. couponTenantId: _this.data.tenantId || ''
  235. }
  236. }).then(res => {
  237. console.log(res, "res")
  238. _this.setData({
  239. dynamicRq: res.data.dynamicId,
  240. expiredSeconds: res.data.expiredSeconds,
  241. couponTenantId: res.data.couponTenantId
  242. })
  243. let url = JSON.stringify({
  244. END: "C",
  245. TYPE: "couponorder",
  246. ID: _this.data.dynamicRq,
  247. couponTenantId: _this.data.couponTenantId
  248. })
  249. if (res.data.expiredSeconds == 0) {
  250. } else {
  251. let inre = setInterval(() => {
  252. if (_this.data.expiredSeconds > 1) {
  253. _this.setData({
  254. expiredSeconds: _this.data.expiredSeconds - 1
  255. })
  256. console.log("有效", _this.data.expiredSeconds)
  257. } else {
  258. console.log("无效", _this.data.expiredSeconds)
  259. clearInterval(_this.data.templTiem)
  260. _this.setData({
  261. showhieRq: true
  262. })
  263. }
  264. }, 1000)
  265. _this.setData({
  266. templTiem: inre
  267. })
  268. }
  269. // util.qrcode("qrcode", url, 350, 350);
  270. _this.createQrCode(url, "qrcode", 210, 210);
  271. }).catch(err => {
  272. tt.showToast({
  273. title: err.message,
  274. icon: 'none',
  275. duration: 4000,
  276. mask: false
  277. });
  278. })
  279. },
  280. createQrCode: function (url, canvasId, cavW, cavH) {
  281. //调用插件中的draw方法,绘制二维码图片
  282. let that = this;
  283. QR.api.draw(url, canvasId, cavW, cavH, function (res) {
  284. that.setData({
  285. tempFilePath: res
  286. })
  287. });
  288. },
  289. onUnload: function () {
  290. let that = this;
  291. clearInterval(that.data.setInter);
  292. // clearInterval(that.data.templTiem);
  293. },
  294. onHide: function () {
  295. let that = this;
  296. clearInterval(that.data.setInter);
  297. // clearInterval(that.data.templTiem);
  298. },
  299. })