C端小程序
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

232 rader
5.3 KiB

  1. // pages/spellDetail/index.js
  2. var config = require("../../../config/config.js");
  3. const Http = require("../../../utils/HttpBasics");
  4. const imgurl = require("../../../utils/imgurl");
  5. const { spellStatus } = require("../../../utils/spell");
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. tuanzhang: imgurl.tuanzhang.url,
  12. spellBg: imgurl.spellBg.url,
  13. position: imgurl.position.url,
  14. close03: imgurl.close03.url,
  15. home: imgurl.wmhome.url,
  16. paramData: null,
  17. data: null,
  18. showErr: false,
  19. showAlert: false,
  20. remainingPoints:0
  21. },
  22. getUserInfo: function () {
  23. let that = this;
  24. // 获取用户信息
  25. Http.get({
  26. url: config.api.getScore,
  27. data: {}
  28. })
  29. .then(res => {
  30. console.log(res)
  31. that.setData({
  32. remainingPoints: Number(res.data.credit) - Number(that.data.data.salePriceStr),
  33. userInfo:res.data,
  34. nickName: res.data.nickName,
  35. avatarUrl: res.data.avatarUrl
  36. })
  37. })
  38. },
  39. gotoIndex() {
  40. wx.reLaunch({
  41. url: '/pages/index/index',
  42. })
  43. },
  44. gotoSearch() {
  45. wx.navigateTo({
  46. url: `/pages/spellGroup/spellGroup`,
  47. })
  48. },
  49. /**
  50. * 生命周期函数--监听页面加载
  51. */
  52. onLoad: function (options) {
  53. this.setData({
  54. paramData: options
  55. })
  56. this.getDetail(options.couponChannelId);
  57. // 关闭来自于左上角的分享
  58. wx.hideShareMenu()
  59. },
  60. /**
  61. * 支付订单更新
  62. */
  63. payOrderUpdate: (orderId, payOrderId, status, reason, _this, orderGroupId) => {
  64. console.log(orderGroupId, 7777)
  65. let that = this;
  66. // 支付成功
  67. Http.post({
  68. url: config.api.payOrderUpdate,
  69. data: {
  70. payOrderId: payOrderId,
  71. orderId: orderId,
  72. status: status,
  73. reason: reason
  74. }
  75. })
  76. .then(res => {
  77. wx.hideLoading()
  78. if (res.data.orderStatus == 14) {
  79. _this.setData({
  80. showErr: true
  81. })
  82. return;
  83. }
  84. if (orderGroupId == undefined) {
  85. wx.navigateTo({
  86. url: '/pages/order/detail/index?orderId=' + res.data.id,
  87. })
  88. } else {
  89. _this.goToOrderGroup(orderId, res.data.orderGroupId, _this)
  90. }
  91. })
  92. .catch(err => {
  93. console.log(err);
  94. if (err.code != 12002) {
  95. setTimeout(function () {
  96. _this.payOrderUpdate(orderId, payOrderId, status, reason, _this, orderGroupId);
  97. }, 2000)
  98. }
  99. })
  100. },
  101. gotoPay() {
  102. let that = this;
  103. wx.showLoading({
  104. title: '支付创建中...',
  105. })
  106. Http.post({
  107. url: config.api.payOrderCreate,
  108. data: {
  109. orderId: that.data.paramData.orderId
  110. }
  111. })
  112. .then(res => {
  113. var payOrderId = "" + res.data.payOrderId;
  114. wx.hideLoading();
  115. wx.requestPayment({
  116. timeStamp: res.data.timeStamp,
  117. nonceStr: res.data.nonceStr,
  118. package: res.data.package,
  119. signType: (res.data.signType) ? res.data.signType : "MD5",
  120. paySign: res.data.paySign,
  121. success: res => {
  122. wx.showLoading({
  123. title: '订单正在处理中...',
  124. })
  125. setTimeout(function () {
  126. wx.hideLoading()
  127. }, 5000)
  128. that.payOrderUpdate(that.data.paramData.orderId, payOrderId, 1, '', that, 0);
  129. if (res.errMsg == "requestPayment:ok") {
  130. setTimeout(function () {
  131. wx.hideLoading();
  132. }, 2000);
  133. }
  134. },
  135. fail: res => {
  136. /**
  137. * 支付失败,需要更新订单的状态
  138. */
  139. that.payOrderUpdate(that.data.paramData.orderId, payOrderId, 2, '', that, 0);
  140. that.setData({
  141. showbutton: false,
  142. canSpell: true,
  143. canBuyIf: true
  144. })
  145. return;
  146. },
  147. complete: res => { }
  148. });
  149. /// End payment --------
  150. })
  151. .catch(err => {
  152. that.setData({
  153. canSpell: true,
  154. canBuyIf: true
  155. })
  156. wx.showToast({
  157. title: err.message,
  158. icon: 'none',
  159. duration: 2000,
  160. mask: false
  161. });
  162. })
  163. },
  164. /**
  165. * 获取券详情信息
  166. */
  167. getDetail(couponChannelId) {
  168. let that = this;
  169. Http.get({
  170. url: config.api.couponDetail,
  171. data: {
  172. couponChannelId: couponChannelId
  173. }
  174. }).then(res => {
  175. wx.stopPullDownRefresh();
  176. that.getUserInfo()
  177. let data = res.data;
  178. that.setData({
  179. data
  180. });
  181. });
  182. },
  183. /**
  184. * 生命周期函数--监听页面初次渲染完成
  185. */
  186. onReady: function () {
  187. },
  188. /**
  189. * 生命周期函数--监听页面显示
  190. */
  191. onShow: function () {
  192. this.setData({
  193. showTime: true
  194. })
  195. },
  196. /**
  197. * 生命周期函数--监听页面隐藏
  198. */
  199. onHide: function () {
  200. this.setData({
  201. showTime: false
  202. })
  203. },
  204. /**
  205. * 生命周期函数--监听页面卸载
  206. */
  207. onUnload: function () {
  208. this.setData({
  209. showTime: false
  210. })
  211. },
  212. /**
  213. * 页面相关事件处理函数--监听用户下拉动作
  214. */
  215. onPullDownRefresh: function () {
  216. this.getDetail(this.data.paramData);
  217. },
  218. /**
  219. * 页面上拉触底事件的处理函数
  220. */
  221. onReachBottom: function () {
  222. }
  223. })