|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720 |
- const navigationBarHeight = (getApp().statusBarHeight + 50) + 'px'
- var config = require("../../config/config.js");
- var app = getApp();
- const Http = require("../../utils/HttpBasics");
- const util = require("../../utils/util");
- const imgurl = require("../../utils/imgurl");
- Page({
- data: {
- isGetUser: true,//判断是否授权抖音
- mouldType: 0,
- navigationBarHeight,
- homeSelectedO: imgurl.homeSelectedO.url,
- isshowposter: false, //是否显示分享弹框
- fenxiang: imgurl.fenxiang1.url,
- fenxiangUrl: imgurl.fenxiang.url,
- clockUrl: imgurl.clock.url,
- yushouUrl: imgurl.yushou.url,
- teljpgUrl: imgurl.teljpg.url,
- closedUrl: imgurl.closed.url,
- quesGouUrl: imgurl.ques_gou.url,
- headbgUrl: imgurl.headbg.url,
- quesBgUrl: imgurl.ques_bg.url,
- close02: imgurl.close02.url,
- share01: imgurl.share01.url,
- fail: imgurl.fail.url,
- wmhome: imgurl.wmhome.url,
- swiperCurrent: 0,
- detailPicture: [],
- coverPicture: [],
- couponList: [],
- data: {
- title: null
- },
- showPage: false,
- questions1: null,
- questions2: null,
- carList: [],
- couponChannelId: null,
- orderId: "",
- hour: null,
- day: null,
- month: null,
- year: null,
- minute: "",
- tempFilePaths: null,
- userInfo: {},
- hasUserInfo: false,
- id: null,
- result: [],
- end_time: null,
- checked: false,
- questionnaire: {},
- questionId: null,
- widthScreen: null,
- moveData: null,
- rotateData: null,
- alphaData: null,
- scaleData: null,
- skewData: null,
- matrixData: null,
- opacity: 0,
- queueData: null,
- zIndex: 11,
- display: "none",
- showbutton: false,
- cardData: null,
- showCardOffer: false,
- isSamePeople: true,
- statusText: '',
- isReceived: false,
- receivedDisabled: false,
- clock: "结束",
- day: "00",
- hour: "00",
- min: "00",
- sec: "00",
- clock02: "00",
- day02: "00",
- hour02: "00",
- min02: "00",
- sec02: "00",
- countdown: "",
- showbutton1: false,
- limitCondition: "",
- minLimit: 0,
- maxLimit: 0,
- dispressEndDate: false,
- barTitle: "",
- activityStatus: "",
- //图文混排
- curHtml: '',
- contentType: 0,
- page: 1,//查询商户优惠券page
- idList: [],
- showBox: false,//手机号授权框
- },
-
- /**
- * 显示分享弹框
- */
- showshare: function () {
- this.setData({
- isshowposter: true,
- })
- },
-
- setPhone(paramData) {//子组件调用这个方法说明手机号已经授权成功
- this.setData({
- showBox: paramData.detail,
- })
- tt.showToast({
- title: '授权成功', // 内容
- icon: 'none', // 图标
- success: (res) => {
-
- },
- fail: (res) => {
-
- },
- });
- },
- setBox(paramData) {
- this.setData({
- showBox: paramData.detail
- })
- tt.showToast({
- title: '取消授权', // 内容
- icon: 'none', // 图标
- success: (res) => {
-
- },
- fail: (res) => {
-
- },
- });
- },
- /**
- * 隐藏分享弹框
- */
- hidemodal: function () {
- this.setData({
- isshowposter: false,
- })
- },
- /**
- * 显示分享海报
- */
- /* showPoster: function() {
- //跳转到海报生成页
- console.log(this.data.canIUse)
-
- // return;
- tt.navigateTo({
- url: `/pages/canvas/index?couponChannelId=${this.data.data.id}`
- })
- }, */
- showPoster: function () {
- //跳转到海报生成页
- let that = this;
- Http.get({
- url: config.api.checkUserStatus,
- data: {
- token: app.globalData.token
- }
- }).then(res => {
- tt.navigateTo({
- url: `/pages/canvas/index?couponChannelId=${that.data.data.id}`
- })
- }).catch(err => {
- console.log(err)
- if (err.code == 11004) {
- // 用户昵称未授权
- tt.redirectTo({
- url: `/pages/getuserinfo/index?couponChannelId=${that.data.data.id}&fromflag=poster`
- })
- }
- })
-
- },
- swiperChange: function (e) {
- this.setData({
- swiperCurrent: e.detail.current
- });
- },
- gohome(e) {
- console.log(e.currentTarget.dataset.id, "123")
- tt.navigateTo({
- url: `/pages/fillIndent/fillIndent?couponChannelId=${e.currentTarget.dataset.couponchannelid}&couponId=${e.currentTarget.dataset.couponid}&shippingtype=${e.currentTarget.dataset.shippingtype}`,
- })
- },
-
- gochild(e) {
- let id = e.currentTarget.dataset.id
- tt.navigateTo({
- url: `/pages/coupon/childDetail/childDetail?couponIds=${id}`,
- })
- },
- //获取当前登录用户信息
- getUserInfo: function () {
- let that = this;
- // 获取用户信息
- Http.get({
- url: config.api.getScore,
- data: {}
- })
- .then(res => {
- console.log(res)
- that.getQueryCardStatus()
- if (that.data.cardData.cuserId != res.data.id) {
- console.log(2222, 6666)
- that.setData({
- isSamePeople: false
- })
- }
- })
- },
- //获取卡转赠状态
- getQueryCardStatus() {
- let that = this;
- let param = {
- id: this.data.cardData.couponOrderId,
- cUserId: this.data.cardData.cuserId,
- updateDate: util.formatTime(Number(that.data.cardData.updateDate), "yyyy-MM-dd hh:mm:ss")
- }
- Http.get({
- url: config.api.queryCardStatus,
- data: param
- })
- .then(res => {
- console.log(res, 333333333333)
- })
- .catch(err => {
- that.setData({
- isReceived: true,
- statusText: err.message
- })
- })
- },
- receiveCard() {
- let that = this;
- let param = {
- id: this.data.cardData.couponOrderId,
- cUserId: this.data.cardData.cuserId,
- updateDate: util.formatTime(Number(this.data.cardData.updateDate), "yyyy-MM-dd hh:mm:ss")
- }
-
- this.setData({
- receivedDisabled: true
- })
- Http.post({
- url: config.api.cardAccept,
- data: param
- })
- .then(res => {
- tt.showToast({
- title: '领取成功!',
- icon: 'none',
- duration: 2000,
- mask: false
- });
- tt.reLaunch({
- url: '/pages/complete/index?couponOrderId=' + this.data.cardData.couponOrderId,
- })
- })
- .catch(err => {
- tt.showToast({
- title: err.message,
- icon: 'none',
- duration: 2000,
- mask: false
- });
- that.setData({
- receivedDisabled: false
- })
- })
- },
- closeAlert() {
- this.setData({
- showCardOffer: false
- })
- },
- goback: function () {
- tt.reLaunch({
- url: '/index/index',
- })
- },
- /**
- * 点击提交问题单选
- */
- formSubmit: function (e) {
- console.log(e);
- let that = this;
- /**
- * 多选
- */
- if (e.currentTarget.dataset.flags == 'multi') {
- if (that.data.anwserId.length == 0) {
- var answserIs = null
- } else {
- var answserIs = that.data.anwserId.join(",");
- }
- } else if (e.currentTarget.dataset.flags == 'single') {
- var answserIs = e.detail.value;
- }
- console.log(answserIs)
- console.log(e.currentTarget.dataset.questionid)
- Http.post({
- url: config.api.answerQuestion,
- data: {
- answer: answserIs,
- questionId: e.currentTarget.dataset.questionid
- }
- })
- .then(res => {
- that.closeQuestion();
- })
- .catch(err => {
- tt.showToast({
- title: err.message,
- icon: 'none',
- duration: 2000,
- mask: false
- });
- })
- },
- /**
- * 多选
- */
- checkboxChange: function (e) {
- console.log(e)
- this.setData({
- anwserId: e.detail.value
- })
- },
-
- closeQuestion: function () {
- let that = this;
- that.setData({
- display: "none",
- zIndex: 11,
- opacity: 0
- })
- setTimeout(function () {
- that.orderFunc();
- }, 500)
- },
- ifGetUser() {
- Http.get({
- url: config.api.checkUserStatus,
- data: {
- token: app.globalData.token
- }
- }).then(res => {
- }).catch(err => {
- if (err.code == 11004) {
- this.setData({
- isGetUser: false
- })
- }
- })
- },
-
- setIntervalTime(end_time) {
- let that = this;
- var EndTime = end_time;
- var NowTime = new Date().getTime();
- var total_micro_second = EndTime - NowTime || [];
- // 渲染倒计时时钟
- let obj = that.dateformat(total_micro_second);
- if (total_micro_second > 0) {
- that.setData({
- clock: obj,
- day: obj.a1,
- hour: obj.b1,
- min: obj.c1,
- sec: obj.d1,
- })
- } else {
- that.setData({
- clock: "00",
- day: "00",
- hour: "00",
- min: "00",
- sec: "00",
- })
- //如果倒计时结束,需要重新查询一下券的状态
- // 给getDetail一个标识
- that.getDetail(that.data.id, 'endclock');
- }
- total_micro_second -= 1000;
- },
- countdown: function (end_time) {
- let that = this;
- that.setIntervalTime(end_time);
- that.data.setInterval = setInterval(function () {
- that.setIntervalTime(end_time);
- }, 1000)
- },
- // 时间格式化输出,如11:03 25:19 每1s都会调用一次
- dateformat(micro_second) {
- // 总秒数
- var second = Math.floor(micro_second / 1000);
- // 天数
- var day = Math.floor(second / 3600 / 24) < 10 ? "0" + Math.floor(second / 3600 / 24) : Math.floor(second / 3600 / 24);
- // 小时
- var hr = Math.floor(second / 3600 % 24) < 10 ? "0" + Math.floor(second / 3600 % 24) : Math.floor(second / 3600 % 24);
- // 分钟
- var min = Math.floor(second / 60 % 60) < 10 ? "0" + Math.floor(second / 60 % 60) : Math.floor(second / 60 % 60);
- // 秒
- var sec = Math.floor(second % 60) < 10 ? "0" + Math.floor(second % 60) : Math.floor(second % 60);
-
- // return day + "天" + hr + "小时" + min + "分钟" + sec + "秒";
- return {
- a1: day,
- b1: hr,
- c1: min,
- d1: sec
- }
- },
- /**
- * 获取用户信息
- */
- onLoad(options) {
- console.log(options);
-
- this.setData({
- mouldType: app.globalData.mouldType,
- })
- let that = this;
- if (options.g) {
- app.globalData.havePlayEd1 = true;
- }
- tt.showLoading({
- title: "加载中..."
- });
- that.setData({
- onshow: false
- })
- if (options && (options.id || options.couponIds)) {
- that.getDetail(options.id, 'notendclock');
-
- }
-
- that.setData({
- couponChannelId: options.id,
- });
-
- },
- getHtml(couponChannelId) {
- Http.get({
- url: config.api.couponHtmlDetail,
- data: {
- couponChannelId: couponChannelId
- }
- }).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)
- }
- })
- },
- getDetail: function (couponChannelId, flag) {
- let that = this;
- var parmer = {
- url: config.api.getSnapshot,
- data: {orderId:couponChannelId}
- };
- Http.get(parmer)
- .then(res => {
-
- //aaa
- if (res.data.contentType != undefined && res.data.contentType == 1) {
- //获取图文展示详情html
- this.setData({
- contentType: res.data.contentType
- })
- this.getHtml(couponChannelId);
- }
- that.setData({
- couponId: res.data.couponId
- })
- that.setData({
- showPage: true
- })
- if (res && res.data && res.data.detailPicture) {
- that.setData({
- detailPicture: JSON.parse(res.data.detailPicture)
- })
- }
- if (res && res.data && res.data.coverPicture) {
- that.setData({
- coverPicture: JSON.parse(res.data.coverPicture)
- })
- }
- if (res && res.data && res.data.conditions) {
- that.setData({
- limitCondition: JSON.parse(res.data.conditions).type
- })
- if (JSON.parse(res.data.conditions).type == 2 && (JSON.parse(res.data.conditions).min || JSON.parse(res.data.conditions).min == 0)) {
- that.setData({
- minLimit: JSON.parse(res.data.conditions).min
- })
- }
- if (JSON.parse(res.data.conditions).type == 2 && (JSON.parse(res.data.conditions).max) || JSON.parse(res.data.conditions).max == 0) {
- that.setData({
- maxLimit: JSON.parse(res.data.conditions).max
- })
- }
- }
- /**
- * 将优惠券优惠卡的详情的BarTitle
- * 设置成券的名称
- */
- // tt.setNavigationBarTitle({
- // title: res.data.title
- // })
- that.setData({
- barTitle: res.data.title
- })
- var EndTime = res.data.validStartDate;
- var NowTime = new Date().getTime();
-
- /**
- * activityStatus==0 活动未开始
- * activityStatus==1 活动已开始
- * flag == endclock 说明倒计时已经结束
- */
- if (res.data.endTime && res.data.beginTime) {
- that.setData({
- begin_time: res.data.beginTime,
- end_time: res.data.endTime,
- activityStatus: res.data.activityStatus ? res.data.activityStatus : ''
- })
- if (res.data.activityStatus == 0 && flag != 'endclock') {
- that.countdown(res.data.beginTime);
- } else if (res.data.activityStatus != 0 && flag != 'endclock') {
- that.countdown(res.data.endTime);
- } else {
- clearInterval(that.data.setInterval)
- }
- if (res.data.activityStatus == 0) {
- var beginTime = util.formatTime(res.data.beginTime, "yyyy-MM-dd hh:mm:ss");
- if (util.timechuo(beginTime).indexOf('-') == 0) {
- that.setData({
- beginTime: "活动已结束",
- });
- } else {
- that.setData({
- beginTime: util.timechuo(beginTime)
- });
- }
- } else {
- var endTime = util.formatTime(res.data.endTime, "yyyy-MM-dd hh:mm:ss");
- if (util.timechuo(endTime).indexOf('-') == 0) {
- that.setData({
- endtime: "活动已结束",
- });
- } else {
- that.setData({
- endtime: util.timechuo(endTime)
- });
- }
- }
- }
- tt.hideLoading();
- that.setData({
- data: res.data,
- merchantVoList: res.data.merchantVoList
- });
- if (res.data.type == 10) {
- that.setData({
- salePriceStr: res.data.salePriceStr,
- pickEndDate: util.formatTime(res.data.pickEndDate, "yyyy-MM-dd"),
- pickStartDate: util.formatTime(res.data.pickStartDate, "yyyy-MM-dd"),
- priceStr: res.data.priceStr,
- tailPriceStr: res.data.tailPriceStr,
- origPriceStr: res.data.origPriceStr
- })
- }
- if (res.data.validType == 1) {
- that.setData({
- validStartDate: util.formatTime(res.data.validStartDate, "yyyy-MM-dd"),
- validEndDate: util.formatTime(res.data.validEndDate, "yyyy-MM-dd"),
- pickStartDate: util.formatTime(res.data.pickStartDate, "yyyy-MM-dd"),
- pickEndDate: util.formatTime(res.data.pickEndDate, "yyyy-MM-dd"),
- });
- } else {
- if (res.data.validDays) {
- that.setData({
- validDays: res.data.validDays
- });
- }
- }
-
-
- if(res.data.itemGroup){
- let tempObj = that.data.data
- tempObj.itemGroup = JSON.parse(tempObj.itemGroup)
- that.setData({
- data:tempObj
- })
- console.log(that.data.data,"data");
- }
-
-
- if (res.data.productAttrs && res.data.skuAttrs) {
- let tempObj = that.data.data
- tempObj.productAttrs = JSON.parse(tempObj.productAttrs)
- tempObj.skuAttrs = JSON.parse(tempObj.skuAttrs)
- tempObj.productAttrs.map(item => {
-
- if (item.key == "appointment") {
- let tempAppoinObj = JSON.parse(item.data)
- if (tempAppoinObj.need_appointment) {
- let subscribeSing = "";
- if (tempAppoinObj.ahead_time_type == 1) {
- subscribeSing = `需提前${tempAppoinObj.ahead_day_num}天致电商家预约`
- } else if (tempAppoinObj.ahead_time_type == 2) {
- subscribeSing = `需提前${tempAppoinObj.ahead_hour_num}小时致电商家预约`
- } else if (tempAppoinObj.ahead_time_type == 3) {
- subscribeSing = `需提前${tempAppoinObj.ahead_minute_num}分钟致电商家预约`
- }
- tempObj.subscribeSing = subscribeSing
- }
-
- }
-
-
- if (item.key == "Notification") {
- if (item.data != '') {
- tempObj.curLsit = JSON.parse(item.data)
- }
- }
- if (item.key == "bring_out_meal") {
- tempObj.besides = item.data
- }
- if (item.key == "free_pack") {
- tempObj.pack = item.data
- }
-
- if (item.key == "superimposed_discounts") {
- tempObj.superimposed_discounts = item.data
- }
- if (item.key == "private_room") {
- tempObj.private_room = item.data
- }
- if (item.key == "rec_person_num_max") {
- tempObj.rec_person_num_max = item.data
- }
-
-
- if (item.key == 'Description') {
- tempObj.Description = JSON.parse(item.data)
- }
- if (item.key == "can_no_use_date") {
- tempObj.can_no_use_date = JSON.parse(item.data)
- }
- })
-
- tempObj.skuAttrs.map(item => {
- if (item.key == "commodity") {
- if (item.data != '') {
- tempObj.itemGroup = JSON.parse(item.data)
- }
- }
- })
- this.setData({
- data: tempObj
- })
- }
- }).catch(err => {
- tt.showToast({
- title: err.message,
- icon: 'none',
- duration: 2000,
- mask: false
- });
- })
- },
-
-
-
- onShow() {
- this.ifGetUser()//判断是否授权抖音
- this.setData({
- mouldType: app.globalData.mouldType,
- showbutton: false,
- showbutton1: false
- })
- if (this.data.end_time && this.data.activityStatus != 0) {
- this.countdown(this.data.end_time)
- } else if (this.data.begin_time && this.data.activityStatus == 0) {
- this.countdown(this.data.begin_time)
- }
- },
- onUnload: function () {
- let that = this;
- clearInterval(that.data.setInterval)
- },
- onHide: function () {
- let that = this;
- clearInterval(that.data.setInterval)
- },
- // 下拉刷新
- onPullDownRefresh: function () {
- this.getDetail(this.data.couponChannelId);
- tt.stopPullDownRefresh()
- },
- onReachBottom: function () {
- this.setData({
- page: this.data.page + 1
- })
-
-
- }
- });
|