|
- // pages/spellDetail/index.js
- var config = require("../../../config/config.js");
- const Http = require("../../../utils/HttpBasics");
- const imgurl = require("../../../utils/imgurl");
- const { spellStatus } = require("../../../utils/spell");
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- tuanzhang: imgurl.tuanzhang.url,
- spellBg: imgurl.spellBg.url,
- position: imgurl.position.url,
- close03: imgurl.close03.url,
- home: imgurl.wmhome.url,
- paramData: null,
- data: null,
- showErr: false,
- showAlert: false,
- remainingPoints:0
- },
- getUserInfo: function () {
- let that = this;
- // 获取用户信息
- Http.get({
- url: config.api.getScore,
- data: {}
- })
- .then(res => {
- console.log(res)
- that.setData({
- remainingPoints: Number(res.data.credit) - Number(that.data.data.salePriceStr),
- userInfo:res.data,
- nickName: res.data.nickName,
- avatarUrl: res.data.avatarUrl
- })
- })
- },
- gotoIndex() {
- wx.reLaunch({
- url: '/pages/index/index',
- })
- },
- gotoSearch() {
- wx.navigateTo({
- url: `/pages/spellGroup/spellGroup`,
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.setData({
- paramData: options
- })
- this.getDetail(options.couponChannelId);
-
- // 关闭来自于左上角的分享
- wx.hideShareMenu()
- },
- /**
- * 支付订单更新
- */
- payOrderUpdate: (orderId, payOrderId, status, reason, _this, orderGroupId) => {
- console.log(orderGroupId, 7777)
- let that = this;
- // 支付成功
- Http.post({
- url: config.api.payOrderUpdate,
- data: {
- payOrderId: payOrderId,
- orderId: orderId,
- status: status,
- reason: reason
- }
- })
- .then(res => {
- wx.hideLoading()
- if (res.data.orderStatus == 14) {
- _this.setData({
- showErr: true
- })
- return;
- }
- if (orderGroupId == undefined) {
- wx.navigateTo({
- url: '/pages/order/detail/index?orderId=' + res.data.id,
- })
- } else {
- _this.goToOrderGroup(orderId, res.data.orderGroupId, _this)
- }
- })
- .catch(err => {
- console.log(err);
- if (err.code != 12002) {
- setTimeout(function () {
- _this.payOrderUpdate(orderId, payOrderId, status, reason, _this, orderGroupId);
- }, 2000)
- }
- })
- },
- gotoPay() {
- let that = this;
- wx.showLoading({
- title: '支付创建中...',
- })
- Http.post({
- url: config.api.payOrderCreate,
- data: {
- orderId: that.data.paramData.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.paramData.orderId, payOrderId, 1, '', that, 0);
- if (res.errMsg == "requestPayment:ok") {
- setTimeout(function () {
- wx.hideLoading();
- }, 2000);
- }
- },
- fail: res => {
- /**
- * 支付失败,需要更新订单的状态
- */
- that.payOrderUpdate(that.data.paramData.orderId, payOrderId, 2, '', that, 0);
- that.setData({
- showbutton: false,
- canSpell: true,
- canBuyIf: true
- })
- return;
- },
- complete: res => { }
- });
- /// End payment --------
- })
- .catch(err => {
- that.setData({
- canSpell: true,
- canBuyIf: true
- })
- wx.showToast({
- title: err.message,
- icon: 'none',
- duration: 2000,
- mask: false
- });
- })
- },
- /**
- * 获取券详情信息
- */
- getDetail(couponChannelId) {
- let that = this;
- Http.get({
- url: config.api.couponDetail,
- data: {
- couponChannelId: couponChannelId
- }
- }).then(res => {
- wx.stopPullDownRefresh();
- that.getUserInfo()
- let data = res.data;
- that.setData({
- data
- });
- });
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- this.setData({
- showTime: true
- })
- },
-
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- this.setData({
- showTime: false
- })
- },
-
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- this.setData({
- showTime: false
- })
- },
-
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- this.getDetail(this.data.paramData);
- },
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
-
- }
- })
|