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.

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