C端小程序
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

300 linhas
7.5 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.creditPrice),
  33. userInfo:res.data,
  34. nickName: res.data.nickName,
  35. avatarUrl: res.data.avatarUrl
  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.showToast({
  154. title: "您有未支付订单",
  155. image: './../../../assets/images/fail.png',
  156. duration: 2000,
  157. mask: false
  158. });
  159. } else if (err.code == 11005) {
  160. /**
  161. * 将值传到用户手机号授权的页面
  162. *
  163. */
  164. wx.redirectTo({
  165. url: "/pages/getphoneInfo/index?couponChannelId=" +
  166. that.data.paramData.couponChannelId + "&couponId=" + that.data.paramData.couponId +"&path=jifen"
  167. });
  168. } else if (err.code == 11006) {
  169. // 用户手机已加密
  170. wx.redirectTo({
  171. url: "/pages/phoneinput/phoneinput?couponChannelId=" +
  172. that.data.paramData.couponChannelId + "&couponId=" + that.data.paramData.couponId + "&path=jifen"
  173. });
  174. } else {
  175. wx.showToast({
  176. title: err.message,
  177. icon: 'none',
  178. duration: 2000,
  179. mask: false
  180. });
  181. }
  182. })
  183. .then(res => {
  184. console.log(res)
  185. if (typeof (res) != "undefined") {
  186. let orderId = "" + res.data.id;
  187. that.setData({
  188. orderId: orderId
  189. });
  190. console.log(that.data.type)
  191. // 免费券
  192. that.payOrderUpdate(orderId, "0", 1, '',that);
  193. // that.payOrderUpdate(that.data.orderId, '', 1, '', that);
  194. if (that.data.cardType == 100) {
  195. wx.setStorage({
  196. key: 'couponNum2',
  197. data: "couponNum2"
  198. })
  199. } else if (that.data.data.type != "5") {
  200. wx.setStorage({
  201. key: 'couponNum',
  202. data: "couponNum"
  203. })
  204. }
  205. }
  206. })
  207. },
  208. /**
  209. * 支付订单更新
  210. */
  211. payOrderUpdate: (orderId, payOrderId, status, reason, _this) => {
  212. let that = this;
  213. // 支付成功
  214. Http.post({
  215. url: config.api.payOrderUpdate,
  216. data: {
  217. payOrderId: payOrderId,
  218. orderId: orderId,
  219. status: status,
  220. reason: reason
  221. }
  222. })
  223. .then(res => {
  224. wx.hideLoading()
  225. wx.navigateTo({
  226. url: '/pages/integralmall/payIntegcouponStatus/index?title=' + _this.data.data.title + '&coverImg=' + _this.data.data.coverImg + '&remainingPoints=' + _this.data.remainingPoints + '&type=' + _this.data.data.type,
  227. })
  228. })
  229. .catch(err => {
  230. console.log(err);
  231. if (err.code != 12002) {
  232. setTimeout(function () {
  233. _this.payOrderUpdate(orderId, payOrderId, status, reason, _this);
  234. }, 2000)
  235. }
  236. })
  237. },
  238. /**
  239. * 获取券详情信息
  240. */
  241. getDetail(couponChannelId) {
  242. let that = this;
  243. Http.get({
  244. url: config.api.couponDetail,
  245. data: {
  246. couponChannelId: couponChannelId
  247. }
  248. }).then(res => {
  249. wx.stopPullDownRefresh();
  250. that.getUserInfo()
  251. let data = res.data;
  252. that.setData({
  253. data
  254. });
  255. });
  256. },
  257. /**
  258. * 生命周期函数--监听页面初次渲染完成
  259. */
  260. onReady: function () {
  261. },
  262. /**
  263. * 生命周期函数--监听页面显示
  264. */
  265. onShow: function () {
  266. },
  267. /**
  268. * 生命周期函数--监听页面隐藏
  269. */
  270. onHide: function () {
  271. },
  272. /**
  273. * 生命周期函数--监听页面卸载
  274. */
  275. onUnload: function () {
  276. },
  277. /**
  278. * 页面相关事件处理函数--监听用户下拉动作
  279. */
  280. onPullDownRefresh: function () {
  281. this.getDetail(this.data.paramData.couponChannelId);
  282. },
  283. /**
  284. * 页面上拉触底事件的处理函数
  285. */
  286. onReachBottom: function () {
  287. }
  288. })