|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- const app = getApp();
- const navigationBarHeight = (getApp().statusBarHeight + 50) + "px";
- const Http = require("../../../utils/HttpBasics");
- const config = require("../../../config/config");
- const util = require("../../../utils/util");
- const QR = require("../../../utils/memberqrcode.js");
- Page({
- data: {
- showIdFalg: false,
- navigationBarHeight,
- couponorderstatus: "",
- quancode: "",
- setInter: "",
- validStartDate: "",
- validEndDate: "",
- pickStartDate: "",
- pickEndDate: "",
- expiredTime: "",
- updateDate: "",
- createDate: "",
- code: "",
- data: {
-
- },
- showhieRq: false,
- dynamicRq: "",
- expiredSeconds: 0,
- couponTenantId: '',
- templTiem: "",
- curHtml: "",
- tenantId: '',
- mallList: '',
- mallTenantId: ""
- },
- showId() {
- let this_ = this;
- if (!this_.data.showIdFalg) {
- tt.showModal({
- // title: "查看券码",
- content: "是否查看完整券码",
- success(res) {
- if (res.confirm) {
- console.log("confirm, continued");
- this_.setData({
- showIdFalg: true
- })
- } else if (res.cancel) {
- //取消
- console.log("cancel, cold");
- } else {
- // what happend?
- }
- },
- fail(err) {
- console.log(`showModal 调用失败`, err);
- },
- });
- } else {
- this.setData({
- showIdFalg: false
- })
- }
-
- },
-
- //获取适用门店
- getCouponMerchant(couponId) {
- Http.get({
- url: `/wxCoupon/couponMerchantByCouponId?couponId=${couponId}&mallTenantId=${this.data.mallTenantId || ''}`,
- }).then(res => {
- const keys = Object.keys(res.data)
- const mallList = []
- let i = 0
- keys.forEach(item => {
- const arr = item.split('|')
- const obj = {
- tenantId: arr[0],
- mallName: arr[1],
- merchantVoList: res.data[item],
- expand: false
- }
- if (i == 0) {
- obj.expand = true
- }
- mallList.push(obj)
- i++
- })
- this.setData({
- mallList: mallList
- })
- }).catch(err => {
-
- })
- },
-
- getHtml(couponOrderId) {
- Http.get({
- url: config.api.couponHtmlDetailForPkg,
- data: {
- couponOrderId: couponOrderId
- }
- }).then(res => {
- console.log(res)
- if (res.code == 200 && res.data.html) {
- this.setData({
- curHtml: decodeURI(res.data.html)
- })
- // app.globalData.curHtml = this.data.curHtml;
- // console.log(app.globalData.curHtml)
- }
- })
- },
-
- onLoad: function (options) {
- let that = this;
- console.log(options);
- that.setData({
- code: options.quancode,
- codeS: options.quancode.slice(0, 4) + `******` + options.quancode.slice(14),
- couponorderstatus: options.couponorderstatus,
- validStatus: options.validStatus
- });
-
- if (options.couponorderstatus == 0 && options.validStatus != 0) {
- that.setRq() //动态二维码 //这个方法必须在拿到 options.quancode 后调用
- }
-
- if (options.mallTenantId) {
- that.setData({
- mallTenantId: options.mallTenantId
- })
- }
-
- //初始数据不能延时收到写一边
- Http.get({
- url: config.api.couponOrderDetail,
- data: {
- couponOrderId: options.quancode,
- mallTenantId: options.mallTenantId
- }
- }).then(res => {
- if (res.data.tenantId) {
- that.setData({
- tenantId: res.data.tenantId
- })
- that.setRq()
- that.getCouponMerchant(res.data.couponId)
- }
- that.setData({
- couponorderstatus: res.data.couponOrderStatus,
- data: res.data,
- });
-
- that.setData({
- expiredTime: util.formatTime(that.data.data.expiredTime, "yyyy-MM-dd hh:mm:ss"),
- updateDate: util.formatTime(that.data.data.updateDate, "yyyy-MM-dd hh:mm:ss"),
- createDate: util.formatTime(that.data.data.createDate, "yyyy-MM-dd hh:mm:ss")
- });
- if (res.data.contentType != undefined && res.data.contentType == 1) {
- //获取图文展示详情html
- that.setData({
- contentType: res.data.contentType
- })
- that.getHtml(options.quancode);
- }
- if (that.data.data.validStartDate && that.data.data.validEndDate) {
- that.setData({
- validStartDate: util.formatTime(that.data.data.validStartDate, "yyyy-MM-dd hh:mm:ss"),
- validEndDate: util.formatTime(that.data.data.validEndDate, "yyyy-MM-dd hh:mm:ss"),
- // pickStartDate: util.formatTime(res.data.pickStartDate, "yyyy-MM-dd hh:mm:ss"),
- // pickEndDate: util.formatTime(res.data.pickEndDate, "yyyy-MM-dd hh:mm:ss"),
- })
- }
-
- }).catch(err => {
- console.log(err, 'err');
- tt.showToast({
- title: err.message ? err.message : err.data,
- icon: 'none',
- duration: 2000,
- mask: false
- });
- })
- //
-
-
-
-
- //获得优惠券的详情
- let setInter = setInterval(function () {
- if (
- options.quancode &&
- that.data.couponorderstatus == 0
- ) {
-
- Http.get({
- url: config.api.couponOrderDetail,
- data: {
- couponOrderId: options.quancode,
- mallTenantId: options.mallTenantId
- }
- }).then(res => {
- console.log(res.data, '1233211234567');
- that.setData({
- couponorderstatus: res.data.couponOrderStatus,
- data: res.data,
- });
- if (res.data.tenantId) {
- that.setData({
- tenantId: res.data.tenantId
- })
- that.setRq()
- }
- console.log(that.data.tenantId, 'tenantId');
- that.setData({
- expiredTime: util.formatTime(that.data.data.expiredTime, "yyyy-MM-dd hh:mm:ss"),
- updateDate: util.formatTime(that.data.data.updateDate, "yyyy-MM-dd hh:mm:ss"),
- createDate: util.formatTime(that.data.data.createDate, "yyyy-MM-dd hh:mm:ss")
- });
- if (that.data.data.validStartDate && that.data.data.validEndDate) {
- that.setData({
- validStartDate: util.formatTime(that.data.data.validStartDate, "yyyy-MM-dd hh:mm:ss"),
- validEndDate: util.formatTime(that.data.data.validEndDate, "yyyy-MM-dd hh:mm:ss"),
- // pickStartDate: util.formatTime(res.data.pickStartDate, "yyyy-MM-dd hh:mm:ss"),
- // pickEndDate: util.formatTime(res.data.pickEndDate, "yyyy-MM-dd hh:mm:ss"),
- })
- }
-
- }).catch(err => {
- tt.showToast({
- title: err.message ? err.message : err.data,
- icon: 'none',
- duration: 2000,
- mask: false
- });
- })
- }
- }, 2000);
- that.setData({
- setInter: setInter
- })
- },
- setRq() {
- let _this = this
- _this.setData({
- showhieRq: false,
- })
- Http.get({ //获取动态二维码
- url: config.api.dynamicId,
- data: {
- couponOrderId: _this.data.code,
- couponTenantId: _this.data.tenantId || ''
- }
- }).then(res => {
- console.log(res, "res")
- _this.setData({
- dynamicRq: res.data.dynamicId,
- expiredSeconds: res.data.expiredSeconds,
- couponTenantId: res.data.couponTenantId
- })
-
- let url = JSON.stringify({
- END: "C",
- TYPE: "couponorder",
- ID: _this.data.dynamicRq,
- couponTenantId: _this.data.couponTenantId
- })
- if (res.data.expiredSeconds == 0) {
-
- } else {
- let inre = setInterval(() => {
- if (_this.data.expiredSeconds > 1) {
- _this.setData({
- expiredSeconds: _this.data.expiredSeconds - 1
- })
- console.log("有效", _this.data.expiredSeconds)
- } else {
- console.log("无效", _this.data.expiredSeconds)
- clearInterval(_this.data.templTiem)
- _this.setData({
- showhieRq: true
- })
- }
- }, 1000)
- _this.setData({
- templTiem: inre
- })
- }
- // util.qrcode("qrcode", url, 350, 350);
- _this.createQrCode(url, "qrcode", 210, 210);
- }).catch(err => {
- tt.showToast({
- title: err.message,
- icon: 'none',
- duration: 4000,
- mask: false
- });
- })
- },
-
- createQrCode: function (url, canvasId, cavW, cavH) {
- //调用插件中的draw方法,绘制二维码图片
- let that = this;
- QR.api.draw(url, canvasId, cavW, cavH, function (res) {
- that.setData({
- tempFilePath: res
- })
- });
- },
- onUnload: function () {
- let that = this;
- clearInterval(that.data.setInter);
- // clearInterval(that.data.templTiem);
- },
- onHide: function () {
- let that = this;
- clearInterval(that.data.setInter);
- // clearInterval(that.data.templTiem);
- },
- })
|