C端小程序
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

273 Zeilen
7.3 KiB

  1. // pages/spellDetail/index.js
  2. const navigationBarHeight = (getApp().statusBarHeight + 44) + 'px';
  3. var config = require("../../../config/config.js");
  4. const Http = require("../../../utils/HttpBasics");
  5. const imgurl = require("../../../utils/imgurl");
  6. const { spellStatus } = require("../../../utils/spell");
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. navigationBarHeight,
  13. tuanzhang: imgurl.tuanzhang.url,
  14. spellBg: imgurl.spellBg.url,
  15. position: imgurl.position.url,
  16. close03: imgurl.close03.url,
  17. home: imgurl.wmhome.url,
  18. paramData: null,
  19. data: null,
  20. showErr: false,
  21. showAlert: false,
  22. remainingPoints:0
  23. },
  24. getUserInfo: function () {
  25. let that = this;
  26. // 获取用户信息
  27. Http.get({
  28. url: config.api.getScore,
  29. data: {}
  30. })
  31. .then(res => {
  32. console.log(res)
  33. that.setData({
  34. remainingPoints: Number(res.data.credit) - Number(that.data.data.creditPrice),
  35. userInfo:res.data
  36. })
  37. })
  38. },
  39. cannotPay(){
  40. wx.showToast({
  41. title: "您的积分不足",
  42. image: './../../../assets/images/fail.png',
  43. duration: 2000,
  44. mask: false
  45. });
  46. },
  47. gotoIndex() {
  48. wx.reLaunch({
  49. url: '/pages/index/index',
  50. })
  51. },
  52. gotoSearch() {
  53. wx.navigateTo({
  54. url: `/pages/spellGroup/spellGroup`,
  55. })
  56. },
  57. /**
  58. * 生命周期函数--监听页面加载
  59. */
  60. onLoad: function (options) {
  61. this.setData({
  62. paramData: options
  63. })
  64. this.getDetail(options.couponChannelId);
  65. // 关闭来自于左上角的分享
  66. wx.hideShareMenu()
  67. },
  68. /**
  69. * 发起支付
  70. */
  71. gotoPay() {
  72. var that = this;
  73. Http.get({
  74. url: config.api.checkPhoneStatus,
  75. data: {}
  76. })
  77. .then(res => {
  78. var data = {
  79. couponChannelId: "" + that.data.paramData.couponChannelId,
  80. couponId: "" + that.data.paramData.couponId
  81. }
  82. /**
  83. * orderSave 下单
  84. */
  85. return Http.post({
  86. url: config.api.orderSave,
  87. data: data
  88. });
  89. })
  90. .catch(err => {
  91. console.log(err);
  92. that.setData({
  93. showbutton: false,
  94. showbutton1: false
  95. })
  96. if (err.code == 2011) {
  97. wx.showToast({
  98. title: "商户信息没找到",
  99. image: './../../../assets/images/fail.png',
  100. duration: 2000,
  101. mask: false
  102. });
  103. } else if (err.code == 2013) {
  104. wx.showToast({
  105. title: "商户信息禁用",
  106. image: './../../../assets/images/fail.png',
  107. duration: 2000,
  108. mask: false
  109. });
  110. } else if (err.code == 3000) {
  111. wx.showToast({
  112. title: "库存不足",
  113. image: './../../../assets/images/fail.png',
  114. duration: 2000,
  115. mask: false
  116. });
  117. } else if (err.code == 3001) {
  118. wx.showToast({
  119. title: "您已超过限购",
  120. image: './../../../assets/images/fail.png',
  121. duration: 2000,
  122. mask: false
  123. });
  124. } else if (err.code == 3002) {
  125. wx.showToast({
  126. title: "订单失败",
  127. image: './../../../assets/images/fail.png',
  128. duration: 2000,
  129. mask: false
  130. });
  131. } else if (err.code == 3003) {
  132. wx.showToast({
  133. title: "订单不存在",
  134. image: './../../../assets/images/fail.png',
  135. duration: 2000,
  136. mask: false
  137. });
  138. } else if (err.code == 3004) {
  139. wx.showToast({
  140. title: "订单不存在",
  141. image: './../../../assets/images/fail.png',
  142. duration: 2000,
  143. mask: false
  144. });
  145. } else if (err.code == 4003) {
  146. wx.showToast({
  147. title: "卡券已作废",
  148. image: './../../../assets/images/fail.png',
  149. duration: 2000,
  150. mask: false
  151. });
  152. } else if (err.code == 3012) {
  153. wx.showModal({
  154. title: '提示',
  155. content: '您有未支付订单,请先进行支付',
  156. confirmText: "去支付",
  157. success: function (res) {
  158. console.log(res.confirm)
  159. if (res.confirm) {
  160. wx.navigateTo({
  161. url: '/pages/order/index/index?id=all',
  162. })
  163. }
  164. }
  165. })
  166. } else if (err.code == 11005) {
  167. /**
  168. * 将值传到用户手机号授权的页面
  169. *
  170. */
  171. wx.redirectTo({
  172. url: "/pages/getphoneInfo/index?couponChannelId=" +
  173. that.data.paramData.couponChannelId + "&couponId=" + that.data.paramData.couponId +"&path=jifen"
  174. });
  175. } else if (err.code == 11006) {
  176. // 用户手机已加密
  177. wx.redirectTo({
  178. url: "/pages/phoneinput/phoneinput?couponChannelId=" +
  179. that.data.paramData.couponChannelId + "&couponId=" + that.data.paramData.couponId + "&path=jifen"
  180. });
  181. } else {
  182. wx.showToast({
  183. title: err.message,
  184. icon: 'none',
  185. duration: 2000,
  186. mask: false
  187. });
  188. }
  189. })
  190. .then(res => {
  191. console.log(res)
  192. if (typeof (res) != "undefined") {
  193. let orderId = "" + res.data.id;
  194. that.setData({
  195. orderId: orderId
  196. });
  197. console.log(that.data.type)
  198. // 免费券
  199. that.payOrderUpdate(orderId, "0", 1, '',that);
  200. // that.payOrderUpdate(that.data.orderId, '', 1, '', that);
  201. if (that.data.cardType == 100) {
  202. wx.setStorage({
  203. key: 'couponNum2',
  204. data: "couponNum2"
  205. })
  206. } else if (that.data.data.type != "5") {
  207. wx.setStorage({
  208. key: 'couponNum',
  209. data: "couponNum"
  210. })
  211. }
  212. }
  213. })
  214. },
  215. /**
  216. * 支付订单更新
  217. */
  218. payOrderUpdate: (orderId, payOrderId, status, reason, _this) => {
  219. let that = this;
  220. // 支付成功
  221. Http.post({
  222. url: config.api.payOrderUpdate,
  223. data: {
  224. payOrderId: payOrderId,
  225. orderId: orderId,
  226. status: status,
  227. reason: reason
  228. }
  229. })
  230. .then(res => {
  231. wx.hideLoading()
  232. wx.navigateTo({
  233. url: '/pages/integralmall/payIntegcouponStatus/index?title=' + _this.data.data.title + '&coverImg=' + _this.data.data.coverImg + '&remainingPoints=' + _this.data.remainingPoints + '&type=' + _this.data.data.type,
  234. })
  235. })
  236. .catch(err => {
  237. console.log(err);
  238. if (err.code != 12002) {
  239. setTimeout(function () {
  240. _this.payOrderUpdate(orderId, payOrderId, status, reason, _this);
  241. }, 2000)
  242. }
  243. })
  244. },
  245. /**
  246. * 获取券详情信息
  247. */
  248. getDetail(couponChannelId) {
  249. let that = this;
  250. Http.get({
  251. url: config.api.couponDetail,
  252. data: {
  253. couponChannelId: couponChannelId
  254. }
  255. }).then(res => {
  256. wx.stopPullDownRefresh();
  257. that.getUserInfo()
  258. let data = res.data;
  259. that.setData({
  260. data
  261. });
  262. });
  263. },
  264. /**
  265. * 页面相关事件处理函数--监听用户下拉动作
  266. */
  267. onPullDownRefresh: function () {
  268. this.getDetail(this.data.paramData.couponChannelId);
  269. }
  270. })