|
- // pages/spellGroup/mySpellGroup/index.js
- var config = require("../../../config/config.js");
- const Http = require("../../../utils/HttpBasics");
- const imgurl = require("../../../utils/imgurl");
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- teljpgUrl: imgurl.teljpg.url,
- couponChannelId:'',
- couponId:'',
- data:[],
- spellData:null,
- canSpell:true,
- canBuyIf:true
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.setData({
- couponChannelId: options.couponChannelId,
- couponId: options.couponId
- })
- this.getDetail(options.couponChannelId);
- this.getOneSpell(options.couponId)
- },
- /**
- * 拨打电话
- */
- phone: function (e) {
- let that = this;
- wx.makePhoneCall({
- phoneNumber: e.target.dataset.merchantlinkphone
- });
- },
- /**
- * 直接购买
- */
- gotoBuy(){
- console.log(22222)
- this.setData({
- canBuyIf: false
- })
- },
- /**
- * 发起拼团
- */
- gotoSpell(){
- console.log(111111111)
- this.setData({
- canSpell:false
- })
- this.orderFunc()
- },
- /**
- * 获取一个拼团信息
- */
- getOneSpell(couponId){
- let that = this;
- Http.get({
- url: config.api.queryRemainOne,
- data: {
- couponId: couponId
- }
- }).then(res => {
- if(res.data){
- that.setData({
- spellData: res.data
- });
- }
- });
- },
- /**
- * 获取券详情信息
- */
- getDetail(couponChannelId){
- let that = this;
- Http.get({
- url: config.api.couponDetail,
- data: {
- couponChannelId: couponChannelId
- }
- }).then(res => {
- let data = res.data;
- data.price = (data.price / 100).toFixed(2)
- data.salePrice = (data.salePrice / 100).toFixed(2)
- that.setData({
- data
- });
- });
- },
- /**
- * 发起支付
- */
- orderFunc(discount) {
- var that = this;
- Http.post({
- url: config.api.checkPhoneStatus,
- data: {}
- })
- .then(res => {
- /**
- * orderSave 下单
- */
- debugger
- // return Http.post({
- // url: config.api.orderSave,
- // data: data
- // });
- })
- .catch(err => {
- console.log(err);
- that.setData({
- showbutton: false,
- showbutton1: false
- })
- if (err.code == 2011) {
- wx.showToast({
- title: "商户信息没找到",
- image: './../../../assets/images/fail.png',
- duration: 2000,
- mask: false
- });
- } else if (err.code == 2013) {
- wx.showToast({
- title: "商户信息禁用",
- image: './../../../assets/images/fail.png',
- duration: 2000,
- mask: false
- });
- } else if (err.code == 3000) {
- wx.showToast({
- title: "库存不足",
- image: './../../../assets/images/fail.png',
- duration: 2000,
- mask: false
- });
- } else if (err.code == 3001) {
- wx.showToast({
- title: "超过限购条件",
- image: './../../../assets/images/fail.png',
- duration: 2000,
- mask: false
- });
- } else if (err.code == 3002) {
- wx.showToast({
- title: "订单失败",
- image: './../../../assets/images/fail.png',
- duration: 2000,
- mask: false
- });
- } else if (err.code == 3003) {
- wx.showToast({
- title: "订单不存在",
- image: './../../../assets/images/fail.png',
- duration: 2000,
- mask: false
- });
- } else if (err.code == 3004) {
- wx.showToast({
- title: "订单不存在",
- image: './../../../assets/images/fail.png',
- duration: 2000,
- mask: false
- });
- } else if (err.code == 4003) {
- wx.showToast({
- title: "卡券已作废",
- image: './../../../assets/images/fail.png',
- duration: 2000,
- mask: false
- });
- } else if (err.code == 11005) {
- /**
- * 将值传到用户手机号授权的页面
- *
- */
- wx.redirectTo({
- url: "/pages/getphoneInfo/index?path=spell&couponChannelId=" +
- that.data.couponChannelId + '&couponId=' + that.data.couponId
- });
- } else if (err.code == 11006) {
- // 用户手机已加密
- wx.redirectTo({
- url: "/pages/phoneinput/phoneinput?path=spell&couponChannelId=" +
- that.data.couponChannelId + '&couponId=' + that.data.couponId
- });
- } else {
- wx.showToast({
- title: err.message,
- icon: 'none',
- duration: 2000,
- mask: false
- });
- }
- })
- .then(res => {
- console.log(res)
- if (discount != 'discount') {
- 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);
- /**
- * 用户支付成功以后跳转到券包列表
- */
- if (that.data.cardType == 100) {
- wx.setStorage({
- key: 'couponNum2',
- data: "couponNum2"
- })
- } else if (that.data.data.type != 5) {
- 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 {
- console.log(that.data.type)
- // 免费券
- that.payOrderUpdate(orderId, "0", 1, '', 'free');
- if (that.data.cardType == 100) {
- wx.setStorage({
- key: 'couponNum2',
- data: "couponNum2"
- })
- } else if (that.data.data.type != "5") {
- wx.setStorage({
- key: 'couponNum',
- data: "couponNum"
- })
- }
- }
- }
- } else {
- if (res) {
- wx.navigateTo({
- url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${res.data.id}`,
- })
- }
- }
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- this.setData({
- canSpell:true,
- canBuyIf:true
- })
- },
-
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
-
- },
-
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
-
- },
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
-
- }
- })
|