paymentSuccessed.js 5.41 KB
import config from '../../common/config';
import { GET, POST } from '../../common/request';
import { jumpByUrl } from '../../common/urlRoute';
import {
  logEvent,
  YB_SHARE_RESULT_L,
} from '../../common/analytics.js'

Page({
  data: {
    showModalStatus: false ,


    adUrl: "./images/disclosure-arrow_h@2x.png",
    pay_successIcon: "./images/pay_success@2x.png",
    productImage: "./images/suibianguangguang@2x.png",
    detailText: "给你发链接退款的都是诈骗!谨防假冒客服诈骗!",
    closeImage: "./images/close-ic@3x.png",
    bindTipsIcon: "./images/bindTipsIcon@2x.png",

    price: "0.00",
    orderCode: '',
    hasSuc: false,


    token: '',
    activityName: '',
    activityIcon: '',
    activityBanner: '',
    activityUrl: '',
  },

  onShareAppMessage: function (res) {
    this.hideAlert();
    let param = {
      FROM: res.from,
      SHARE_RESUIL: 0,
      TITLE: '我在有货给你发红包啦,专属好礼送不停!',
      PATH: '/pages/envelopesActivity/envelopesActivity?token=' + this.data.token,
    }

    return {
      path: param.PATH,
      imageUrl: 'https://cdn.yoho.cn/20171218/fenxianghongbao.png',
      title: param.TITLE,
      success: function (res) {
        param.SHARE_RESUIL = 1
        logEvent(YB_SHARE_RESULT_L, param);
      },
      fail: function (res) {
        param.SHARE_RESUIL = 2
        logEvent(YB_SHARE_RESULT_L, param);
      }
    }
  },

  onLoad: function (options) {

    let hasSuc = options.hasSuc;
    let orderCode = options.orderCode;
    let price = options.price;

    this.setData({
      hasSuc,
      orderCode,
      price,
    });

    if (hasSuc){
      this.fetchBanner();
      this.loadEnvelopesData();
    }else {
      wx.showModal({
        content: '支付失败!\r\n是否尝试二次支付?',
        showCancel: true,
        cancelText: "取消",
        confirmText: "继续支付",
        success: function (res) {
          if (res.confirm) {
            //支付
          }else {
            //取消
          }
        }
      })
    }
  },
  

  //随便逛逛
  suibianTapped: function(e) {
    // console.log("随便逛逛");

    wx.switchTab({
      url: '/pages/index/index'
    })
  },

  //查看订单
  detailTapped: function (e) {

    let order_code = this.data.orderCode;

    wx.navigateTo({
      url: "../orders/orderDetail/orderDetail?order_code=" + order_code + '&page_name=' + 'paymentSuccessed' + '&page_param=' + ''
    });

  },


  //获取红包信息
  loadEnvelopesData: function () {
    let app = getApp();
    let that = this;
    let param = {
      // method: 'app.activity.payActivityProfile',
      // uid: '500029682',//app.getUid(),
      // orderCode: '1701060848',//this.data.orderCode,
      // debug: 'XYZ',

      method: 'app.activity.payActivityProfile',
      uid: app.getUid(),
      orderCode: this.data.orderCode,
      
    };

    // that.showAlert();

    GET(config.constants.API_HOST, param)
      .then(function (data) {
        if (data && data.code == 200) {
          let {
            token,
            activityName,
            activityIcon,
          } = data.data;
          // console.log(data);
          that.setData({
            token,
            activityName,
            activityIcon,
          });

          // that.showAlert();
        } else {
        }
      })
      .catch(function (error) {
      });
  },

  //获取banner
  fetchBanner: function () {
    let that = this;
    let content_code = 'f76a79f28ddfdcb0613e5e79a52ad733';
    let fromPage = 'orderDetail';

    let param = {
      content_code,
      fromPage,
    };
    // console.log(param);

    GET(config.constants.API_HOST + '/operations/api/v5/resource/get', param)
      .then(json => {
        let activityBanner = '';
        let activityUrl = '';
        if (json.code == 200) {
          let list = json.data;
          if (list && list.length > 0) {
            let imageData = list[0].data.list[0];
            let imageHeight = list[0].data.imageHeight;
            let imageWidth = list[0].data.imageWidth;
            activityBanner = imageData.src.replace(/{width}/g, imageWidth).replace(/{height}/g, imageHeight).replace('{mode}', 2);
            activityUrl = imageData.url;
          }

          that.setData({
            activityBanner,
            activityUrl,
          });
        }
      })
      .catch(error => {
        // console.log(error);
      });
  },


/*********************alert*************************/

  showAlert: function (e) {  
    this.alertAction(true)
  },

  hideAlert: function (e) {
    this.alertAction(false)
  },

  alertAction: function (currentStatu){  

    var animation = wx.createAnimation({ 
      duration: 200,  //动画时长  
      timingFunction: "linear", //线性  
      delay: 0  //0则不延迟  
    });  
    this.animation = animation;  
    animation.opacity(0).rotateX(-100).step();  
    this.setData({ 
      animationData: animation.export() 
    }) 
       
    setTimeout(function () { 
      animation.opacity(1).rotateX(0).step();  
      this.setData({ 
        animationData: animation  
      }) 
         
      //关闭  
      if (!currentStatu) { 
        this.setData( 
          { 
            showModalStatus: false 
          } 
        );  
      } 
    }.bind(this), 200) 
     
    // 显示  
    if (currentStatu) { 
      this.setData( 
        { 
          showModalStatus: true, 
        } 
      );  
    } 
  } 
/*********************end*************************/

})