cardPaySuccess.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. const app = getApp()
  2. const api = require("../../../../../request/api.js");
  3. const http = require('../../../../../request/http');
  4. const utils = require('../../../../../utils/util.js');
  5. const storeKeys = require('../../../../../utils/storageKeys.js');
  6. Page({
  7. data: {
  8. isLoading: true,
  9. showSelectModal: false, //是否显示选择赠送方式弹窗
  10. showPhoneInputModal: false, //是否显示输入手机号弹窗
  11. showGiveSuccess: false, //是否显示赠送成功弹窗
  12. isConfirm: false, //是否提示确定手机号
  13. phoneValue: "", //手机号码
  14. orderId: "", //礼品卡订单id
  15. detail: {},
  16. effect_state: 1, //0 转赠中 1 生效中 2 失效
  17. },
  18. onLoad: function (options) {
  19. if (options) {
  20. this.data.orderId = options.orderId || "";
  21. }
  22. this.getOrderDetails()
  23. },
  24. onShow: function () {
  25. },
  26. //获取礼品卡订单详情
  27. getOrderDetails() {
  28. wx.showLoading({
  29. title: "加载中",
  30. mask: true
  31. });
  32. http.request({
  33. url: api.URL + "/api/order.RiceCardOrder/detail&order_id=" + this.data.orderId,
  34. token: utils.getStorageSync(storeKeys.TOKEN),
  35. method: 'GET',
  36. success: (res) => {
  37. wx.hideLoading();
  38. let orderDetail = res.data.data.detail || {};
  39. let detail = orderDetail.first_user_rice_card || {};
  40. let effect_state = detail.effect_state;
  41. if (effect_state == 2) {
  42. utils.toast("该卡已失效")
  43. setTimeout(() => {
  44. wx.switchTab({
  45. url: '/pages/tabBar/index/index'
  46. })
  47. }, 1500)
  48. return;
  49. }
  50. this.setData({
  51. detail,
  52. effect_state,
  53. isLoading: false
  54. });
  55. this.setData({
  56. detail,
  57. isLoading: false
  58. });
  59. },
  60. error: (res) => {}
  61. })
  62. },
  63. //监听手机号输入
  64. changePhoneValue(e) {
  65. this.setData({
  66. phoneValue: e.detail.value
  67. })
  68. },
  69. // 显示选择赠送方式弹窗
  70. showSelectModal() {
  71. this.setData({
  72. showSelectModal: true
  73. })
  74. },
  75. //关闭选择赠送方式弹窗
  76. hideSelectModal() {
  77. this.setData({
  78. showSelectModal: false
  79. })
  80. },
  81. //显示输入手机号弹窗
  82. showPhoneInputModal() {
  83. this.setData({
  84. showSelectModal: false,
  85. showPhoneInputModal: true,
  86. isConfirm: false,
  87. phoneValue: ""
  88. })
  89. },
  90. //关闭输入手机号弹窗
  91. hidePhoneInputModal() {
  92. this.setData({
  93. showPhoneInputModal: false
  94. })
  95. },
  96. //确定手机号输入完毕
  97. confirmPhone() {
  98. if (!this.data.phoneValue) {
  99. utils.toast("请输入手机号码")
  100. return;
  101. }
  102. let mobileReg = /^1[3|4|5|6|7|8|9][0-9]{9}$/; //手机号
  103. if (!mobileReg.test(this.data.phoneValue)) {
  104. utils.toast("请输入正确的手机号");
  105. return;
  106. }
  107. this.setData({
  108. isConfirm: true
  109. })
  110. },
  111. //确认正确
  112. confirmSubmit() {
  113. let data = {
  114. user_rice_card_id: this.data.detail.id, // 我的礼品卡id
  115. mobile: this.data.phoneValue
  116. }
  117. wx.showLoading({
  118. title: "加载中",
  119. mask: true
  120. });
  121. http.request({
  122. url: api.URL + "/api/card.UserRiceCard/smsshareto",
  123. token: utils.getStorageSync(storeKeys.TOKEN),
  124. method: 'POST',
  125. data,
  126. success: (res) => {
  127. wx.hideLoading();
  128. utils.toast(res.data.message);
  129. this.getOrderDetails();
  130. this.setData({
  131. showPhoneInputModal: false,
  132. showGiveSuccess: true,
  133. effect_state: 0
  134. })
  135. },
  136. error: (res) => {}
  137. })
  138. },
  139. // 赠送成功好的
  140. fide() {
  141. wx.navigateBack({
  142. delta: 1
  143. })
  144. this.setData({
  145. showGiveSuccess: false
  146. })
  147. },
  148. // 回到首页
  149. goHome: utils.throttle(function (e) {
  150. wx.switchTab({
  151. url: '/pages/tabBar/index/index'
  152. })
  153. }),
  154. goToMyCard: utils.throttle(function (e) {
  155. wx.redirectTo({
  156. url: '/pages/index/pages/riceCard/myRiceCard/myRiceCard'
  157. })
  158. }),
  159. navigateBack: utils.throttle(function (e) {
  160. wx.navigateBack({
  161. delta: 1
  162. })
  163. }),
  164. //分享给好友
  165. onShareAppMessage: function (res) {
  166. console.log(res)
  167. if (res.from === 'button') {
  168. let riceShareImage = this.data.detail.image_text || app.globalData.riceShareImage;
  169. let userInfo = utils.getStorageSync(storeKeys.USERINFO) || {}
  170. let userId = userInfo.user_id || '';
  171. const promise = new Promise(resolve => {
  172. wx.showLoading({
  173. title: "加载中"
  174. });
  175. http.request({
  176. url: api.URL + '/api/card.UserRiceCard/shareto?user_rice_card_id=' + this.data.detail.id,
  177. method: 'GET',
  178. token: utils.getStorageSync(storeKeys.TOKEN),
  179. success: (res) => {
  180. if (res.data.status == 200) {
  181. wx.hideLoading();
  182. this.setData({
  183. showSelectModal: false
  184. })
  185. let sign = res.data.data.sign;
  186. this.getOrderDetails();
  187. resolve({
  188. title: '您收到一份来自好友的礼物!',
  189. imageUrl: riceShareImage,
  190. path: "pages/index/pages/riceCard/receiveCard/receiveCard?sign=" + sign + "&giveUserId=" + userId
  191. })
  192. }
  193. },
  194. error: (res) => {
  195. wx.hideLoading();
  196. utils.toast(res.data.message);
  197. }
  198. })
  199. })
  200. return promise
  201. } else {
  202. return {
  203. title: app.globalData.shareTitle,
  204. imageUrl: app.globalData.shareImage,
  205. path: app.globalData.sharePath,
  206. }
  207. }
  208. }
  209. })