|
- 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: {
- fenxiangUrl:imgurl.fenxiang.url,
- clockUrl:imgurl.clock.url,
- teljpgUrl:imgurl.teljpg.url,
- closedUrl:imgurl.closed.url,
- quesGouUrl:imgurl.ques_gou.url,
- headbgUrl:imgurl.headbg.url,
- quesBgUrl:imgurl.ques_bg.url,
- data: {
- title: null
- },
- showPage:false,
- questions1: null,
- questions2: null,
- carList: [],
- couponChannelId: null,
- couponId: null,
- orderId: "",
- hour: null,
- minute: "",
- tempFilePaths: null,
- userInfo: {},
- hasUserInfo: false,
- canIUse: wx.canIUse('button.open-type.getUserInfo'),
- id: null,
- result: [],
- end_time: null,
- checked:false,
- clock: "已经截止",
- 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
- },
- phone: function (e) {
- let that = this;
- wx.makePhoneCall({
- phoneNumber: e.target.dataset.merchantlinkphone
- });
- },
- onLoad(options) {
- let that = this;
- wx.showLoading({
- title: "加载中..."
- });
- var parmer = {
- url: config.api.cardpayList,
- data: {
- cardId: options.cardId,
- pageNum:1,
- pageSize:10
- }
- };
- Http.get(parmer)
- .then(res => {
- if(res.code==200){
- that.setData({
- showPage:true
- })
- }
- if (res.data.endTime) {
- that.countdown(res.data.endTime);
- //当前时间与优惠券下架时间做计算
- 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)
- });
- }
- }
- wx.hideLoading();
- that.setData({
- data: res.data
- });
-
- 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"),
- });
- } else {
- that.setData({
- validDays: res.data.validDays
- });
- }
- }).catch(err => {
- wx.showToast({
- title: err.message,
- icon: 'none',
- duration: 2000,
- mask: false
- });
- })
- },
- /**
- * 支付订单更新
- */
- payOrderUpdate: (orderId, payOrderId, status, reason, type, _this) => {
- let that = this;
- // 支付成功
- Http.post({
- url: config.api.payOrderUpdate,
- data: {
- payOrderId: payOrderId,
- orderId: orderId,
- status: status,
- reason: reason
- }
- })
- .then(res => {
- wx.hideLoading()
- // 有价券
- if (!type&&type!='free') {
- wx.navigateTo({
- url: `/pages/order/detail/index?orderId=${
- orderId
- }`
- });
- }else if(type=='free'){
- wx.navigateTo({
- url: `/pages/order/detail/index?orderId=${
- orderId
- }`
- });
- }
- })
- .catch(err => {
- console.log(err);
- if (!type) {
- setTimeout(function () {
- _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this);
- }, 2000)
- }
- })
- },
- /**
- * 发起支付
- */
- orderFunc(flag) {
- var that = this;
- // wx.showLoading({
- // title: "加载中..."
- // });
- Http.post({
- url: config.api.checkPhoneStatus,
- data: {}
- })
- .then(res => {
- var data = {
- couponChannelId: "" + that.data.couponChannelId,
- couponId: "" + that.data.couponId
- };
- if (that.data.couponChannelId == null) {
- var data = {
- couponId: "" + that.data.couponId
- };
- }
- /**
- * orderSave 下单
- */
- return Http.post({
- url: config.api.orderSave,
- data: data
- });
- })
- .catch(err => {
- if (err.code == "2011") {
- wx.showToast({
- title: "商户信息没找到",
- image:imgurl.fail.url,
- duration: 2000,
- mask: false
- });
- } else if (err.code == "2013") {
- wx.showToast({
- title: "商户信息禁用",
- image:imgurl.fail.url,
- duration: 2000,
- mask: false
- });
- } else if (err.code == "3000") {
- wx.showToast({
- title: "库存不足",
- image:imgurl.fail.url,
- duration: 2000,
- mask: false
- });
- } else if (err.code == "3001") {
- wx.showToast({
- title: "领取达到上限",
- image:imgurl.fail.url,
- duration: 2000,
- mask: false
- });
- } else if (err.code == "3002") {
- wx.showToast({
- title: "订单失败",
- image:imgurl.fail.url,
- duration: 2000,
- mask: false
- });
- } else if (err.code == "3003") {
- wx.showToast({
- title: "订单不存在",
- image:imgurl.fail.url,
- duration: 2000,
- mask: false
- });
- } else if (err.code == "3004") {
- wx.showToast({
- title: "订单不存在",
- image:imgurl.fail.url,
- duration: 2000,
- mask: false
- });
- } else if (err.code == "4003") {
- wx.showToast({
- title: "卡券已作废",
- image:imgurl.fail.url,
- duration: 2000,
- mask: false
- });
- } else if (err.code == 11005) {
- /**
- * 将值传到用户手机号授权的页面
- *
- */
- wx.redirectTo({
- url: "/pages/getphoneInfo/index?couponChannelId=" +
- that.data.couponChannelId +
- "&couponId=" +
- that.data.couponId
- });
- } else if (err.code == 11006) {
- // 用户手机已加密
- wx.redirectTo({
- url: "/pages/phoneinput/phoneinput?couponChannelId=" +
- that.data.couponChannelId +
- "&couponId=" +
- that.data.couponId
- });
- } else {
- wx.showToast({
- title: err.message,
- icon: 'none',
- duration: 2000,
- mask: false
- });
- }
- })
- .then(res => {
- if (typeof (res) != "undefined") {
- let orderId = "" + res.data.id;
- that.setData({
- orderId: orderId
- });
- if (res.data.payment > 0) {
- // 支付金额不为0
- /**
- * 支付订单创建
- */
- Http.post({
- url: config.api.payOrderCreate,
- data: {
- orderId: orderId
- }
- }).then(res => {
- var payOrderId = "" + res.data.payOrderId;
- wx.hideLoading();
- wx.requestPayment({
- timeStamp: res.data.timeStamp,
- nonceStr: res.data.nonceStr,
- package: res.data.package,
- signType: (res.data.signType) ? res.data.signType : "MD5",
- paySign: res.data.paySign,
- success: res => {
- wx.showLoading({
- title: '订单正在处理中...',
- })
- setTimeout(function(){
- wx.hideLoading()
- },5000)
- that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that);
- if (res.errMsg == "requestPayment:ok") {
- setTimeout(function () {
- wx.hideLoading();
- }, 2000);
- /**
- * 用户支付成功以后跳转到券包列表
- */
- wx.setStorage({
- key: 'couponNum',
- data: "couponNum",
- })
- }
- },
- fail: res => {
- /**
- * 支付失败,需要更新订单的状态
- */
- that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that);
- that.setData({
- showbutton: false
- })
- return;
- },
- complete: res => {}
- });
- /// End payment --------
- })
- .catch(err => {
- wx.showToast({
- title: err.message,
- icon: 'none',
- duration: 2000,
- mask: false
- });
- })
- } else {
- // 免费券
- that.payOrderUpdate(orderId, "0", 1, '', 'free');
- wx.setStorage({
- key: 'couponNum',
- data: "couponNum"
- })
- }
- }
- })
- .catch(err => {
- wx.showToast({
- title: err.message,
- icon: 'none',
- duration: 2000,
- mask: false
- });
- })
- },
- onShow(){
- this.setData({
- showbutton:false
- })
- },
- onShareAppMessage: function (options) {
- var that = this;
- var shareObj = {
- title: that.data.data.title,
- path: `/pages/index/index?couponChannelId=${that.data.couponChannelId}&couponId=${that.data.couponId}`,
- success: function (res) {
- if (res.errMsg == 'shareAppMessage:ok') {}
- },
- fail: function (error) {
- if (res.errMsg == 'shareAppMessage:fail cancel') {} else if (res.errMsg == 'shareAppMessage:fail') {}
- }
- };
- // 来自页面内的按钮的转发
- if (options.from == 'button') {
- var eData = options.target.dataset.id;
- var couponId = options.target.dataset.couponid;
- shareObj.path = `/pages/index/index?couponChannelId=${eData}&couponId=${couponId}`;
- }
- // 返回shareObj
- return shareObj;
- },
-
- });
|