| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- const app = getApp()
- const api = require("../../../../../request/api.js");
- const http = require('../../../../../request/http');
- const utils = require('../../../../../utils/util.js');
- const storeKeys = require('../../../../../utils/storageKeys.js');
- Page({
- data: {
- isLoading: true,
- showSelectModal: false, //是否显示选择赠送方式弹窗
- showPhoneInputModal: false, //是否显示输入手机号弹窗
- showGiveSuccess: false, //是否显示赠送成功弹窗
- isConfirm: false, //是否提示确定手机号
- phoneValue: "", //手机号码
- orderId: "", //礼品卡订单id
- detail: {},
- effect_state: 1, //0 转赠中 1 生效中 2 失效
- },
- onLoad: function (options) {
- if (options) {
- this.data.orderId = options.orderId || "";
- }
- this.getOrderDetails()
- },
- onShow: function () {
- },
- //获取礼品卡订单详情
- getOrderDetails() {
- wx.showLoading({
- title: "加载中",
- mask: true
- });
- http.request({
- url: api.URL + "/api/order.RiceCardOrder/detail&order_id=" + this.data.orderId,
- token: utils.getStorageSync(storeKeys.TOKEN),
- method: 'GET',
- success: (res) => {
- wx.hideLoading();
- let orderDetail = res.data.data.detail || {};
- let detail = orderDetail.first_user_rice_card || {};
- let effect_state = detail.effect_state;
- if (effect_state == 2) {
- utils.toast("该卡已失效")
- setTimeout(() => {
- wx.switchTab({
- url: '/pages/tabBar/index/index'
- })
- }, 1500)
- return;
- }
- this.setData({
- detail,
- effect_state,
- isLoading: false
- });
- this.setData({
- detail,
- isLoading: false
- });
- },
- error: (res) => {}
- })
- },
- //监听手机号输入
- changePhoneValue(e) {
- this.setData({
- phoneValue: e.detail.value
- })
- },
- // 显示选择赠送方式弹窗
- showSelectModal() {
- this.setData({
- showSelectModal: true
- })
- },
- //关闭选择赠送方式弹窗
- hideSelectModal() {
- this.setData({
- showSelectModal: false
- })
- },
- //显示输入手机号弹窗
- showPhoneInputModal() {
- this.setData({
- showSelectModal: false,
- showPhoneInputModal: true,
- isConfirm: false,
- phoneValue: ""
- })
- },
- //关闭输入手机号弹窗
- hidePhoneInputModal() {
- this.setData({
- showPhoneInputModal: false
- })
- },
- //确定手机号输入完毕
- confirmPhone() {
- if (!this.data.phoneValue) {
- utils.toast("请输入手机号码")
- return;
- }
- let mobileReg = /^1[3|4|5|6|7|8|9][0-9]{9}$/; //手机号
- if (!mobileReg.test(this.data.phoneValue)) {
- utils.toast("请输入正确的手机号");
- return;
- }
- this.setData({
- isConfirm: true
- })
- },
- //确认正确
- confirmSubmit() {
- let data = {
- user_rice_card_id: this.data.detail.id, // 我的礼品卡id
- mobile: this.data.phoneValue
- }
- wx.showLoading({
- title: "加载中",
- mask: true
- });
- http.request({
- url: api.URL + "/api/card.UserRiceCard/smsshareto",
- token: utils.getStorageSync(storeKeys.TOKEN),
- method: 'POST',
- data,
- success: (res) => {
- wx.hideLoading();
- utils.toast(res.data.message);
- this.getOrderDetails();
- this.setData({
- showPhoneInputModal: false,
- showGiveSuccess: true,
- effect_state: 0
- })
- },
- error: (res) => {}
- })
- },
- // 赠送成功好的
- fide() {
- wx.navigateBack({
- delta: 1
- })
- this.setData({
- showGiveSuccess: false
- })
- },
- // 回到首页
- goHome: utils.throttle(function (e) {
- wx.switchTab({
- url: '/pages/tabBar/index/index'
- })
- }),
- goToMyCard: utils.throttle(function (e) {
- wx.redirectTo({
- url: '/pages/index/pages/riceCard/myRiceCard/myRiceCard'
- })
- }),
- navigateBack: utils.throttle(function (e) {
- wx.navigateBack({
- delta: 1
- })
- }),
- //分享给好友
- onShareAppMessage: function (res) {
- console.log(res)
- if (res.from === 'button') {
- let riceShareImage = this.data.detail.image_text || app.globalData.riceShareImage;
- let userInfo = utils.getStorageSync(storeKeys.USERINFO) || {}
- let userId = userInfo.user_id || '';
- const promise = new Promise(resolve => {
- wx.showLoading({
- title: "加载中"
- });
- http.request({
- url: api.URL + '/api/card.UserRiceCard/shareto?user_rice_card_id=' + this.data.detail.id,
- method: 'GET',
- token: utils.getStorageSync(storeKeys.TOKEN),
- success: (res) => {
- if (res.data.status == 200) {
- wx.hideLoading();
- this.setData({
- showSelectModal: false
- })
- let sign = res.data.data.sign;
- this.getOrderDetails();
- resolve({
- title: '您收到一份来自好友的礼物!',
- imageUrl: riceShareImage,
- path: "pages/index/pages/riceCard/receiveCard/receiveCard?sign=" + sign + "&giveUserId=" + userId
- })
- }
- },
- error: (res) => {
- wx.hideLoading();
- utils.toast(res.data.message);
- }
- })
- })
- return promise
- } else {
- return {
- title: app.globalData.shareTitle,
- imageUrl: app.globalData.shareImage,
- path: app.globalData.sharePath,
- }
- }
- }
- })
|