C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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