C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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