C端小程序
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

304 řádky
8.2 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. submitAble:true,
  24. couponChannelDetail:null
  25. },
  26. getUserInfo: function () {
  27. let that = this;
  28. // 获取用户信息
  29. Http.get({
  30. url: config.api.getScore,
  31. data: {}
  32. })
  33. .then(res => {
  34. console.log(res)
  35. that.setData({
  36. remainingPoints: Number(res.data.credit) - Number(that.data.data.creditPrice),
  37. userInfo:res.data
  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. onShow:function(){
  60. this.setData({
  61. submitAble: true
  62. })
  63. },
  64. /**
  65. * 生命周期函数--监听页面加载
  66. */
  67. onLoad: function (options) {
  68. this.setData({
  69. paramData: options
  70. })
  71. this.getDetail(options.couponChannelId);
  72. // 关闭来自于左上角的分享
  73. wx.hideShareMenu()
  74. },
  75. /**
  76. * 发起支付
  77. */
  78. gotoPay() {
  79. var that = this;
  80. that.setData({
  81. submitAble: false
  82. })
  83. Http.get({
  84. url: config.api.checkPhoneStatus,
  85. data: {}
  86. })
  87. .then(res => {
  88. var data = {
  89. couponChannelId: "" + that.data.paramData.couponChannelId,
  90. couponId: "" + that.data.paramData.couponId
  91. }
  92. /**
  93. * orderSave 下单
  94. */
  95. return Http.post({
  96. url: config.api.orderSave,
  97. data: data
  98. });
  99. })
  100. .catch(err => {
  101. console.log(err);
  102. that.setData({
  103. submitAble: true
  104. })
  105. if (err.code == 2011) {
  106. wx.showToast({
  107. title: "商户信息没找到",
  108. image: './../../../assets/images/fail.png',
  109. duration: 2000,
  110. mask: false
  111. });
  112. } else if (err.code == 2013) {
  113. wx.showToast({
  114. title: "商户信息禁用",
  115. image: './../../../assets/images/fail.png',
  116. duration: 2000,
  117. mask: false
  118. });
  119. } else if (err.code == 3000) {
  120. wx.showToast({
  121. title: "库存不足",
  122. image: './../../../assets/images/fail.png',
  123. duration: 2000,
  124. mask: false
  125. });
  126. } else if (err.code == 3001) {
  127. wx.showToast({
  128. title: "您已超过限购",
  129. image: './../../../assets/images/fail.png',
  130. duration: 2000,
  131. mask: false
  132. });
  133. } else if (err.code == 3002) {
  134. wx.showToast({
  135. title: "订单失败",
  136. image: './../../../assets/images/fail.png',
  137. duration: 2000,
  138. mask: false
  139. });
  140. } else if (err.code == 3003) {
  141. wx.showToast({
  142. title: "订单不存在",
  143. image: './../../../assets/images/fail.png',
  144. duration: 2000,
  145. mask: false
  146. });
  147. } else if (err.code == 3004) {
  148. wx.showToast({
  149. title: "订单不存在",
  150. image: './../../../assets/images/fail.png',
  151. duration: 2000,
  152. mask: false
  153. });
  154. } else if (err.code == 4003) {
  155. wx.showToast({
  156. title: "卡券已作废",
  157. image: './../../../assets/images/fail.png',
  158. duration: 2000,
  159. mask: false
  160. });
  161. } else if (err.code == 3012) {
  162. wx.showModal({
  163. title: '提示',
  164. content: '您有未支付订单,请先进行支付',
  165. confirmText: "去支付",
  166. success: function (res) {
  167. console.log(res.confirm)
  168. if (res.confirm) {
  169. wx.navigateTo({
  170. url: '/pages/order/index/index?id=all',
  171. })
  172. }
  173. }
  174. })
  175. } else if (err.code == 11005) {
  176. /**
  177. * 将值传到用户手机号授权的页面
  178. *
  179. */
  180. wx.redirectTo({
  181. url: "/pages/getphoneInfo/index?couponChannelId=" +
  182. that.data.paramData.couponChannelId + "&couponId=" + that.data.paramData.couponId +"&path=jifen"
  183. });
  184. } else if (err.code == 11006) {
  185. // 用户手机已加密
  186. wx.redirectTo({
  187. url: "/pages/phoneinput/phoneinput?couponChannelId=" +
  188. that.data.paramData.couponChannelId + "&couponId=" + that.data.paramData.couponId + "&path=jifen"
  189. });
  190. } else {
  191. wx.showToast({
  192. title: err.message,
  193. icon: 'none',
  194. duration: 2000,
  195. mask: false
  196. });
  197. }
  198. })
  199. .then(res => {
  200. console.log(res)
  201. if (typeof (res) != "undefined") {
  202. let orderId = "" + res.data.mainOrderId;
  203. that.setData({
  204. orderId: orderId
  205. });
  206. console.log(that.data.type)
  207. // 免费券
  208. that.payOrderUpdate(orderId, "0", 1, '',that);
  209. // that.payOrderUpdate(that.data.orderId, '', 1, '', that);
  210. if (that.data.cardType == 100) {
  211. wx.setStorage({
  212. key: 'couponNum2',
  213. data: "couponNum2"
  214. })
  215. } else if (that.data.data.type != "5") {
  216. wx.setStorage({
  217. key: 'couponNum',
  218. data: "couponNum"
  219. })
  220. }
  221. }
  222. })
  223. },
  224. /**
  225. * 支付订单更新
  226. */
  227. payOrderUpdate: (orderId, payOrderId, status, reason, _this) => {
  228. let that = this;
  229. // 支付成功
  230. Http.post({
  231. url: config.api.payOrderUpdate,
  232. data: {
  233. payOrderId: payOrderId,
  234. composeOrderId: orderId,
  235. status: status,
  236. reason: reason
  237. }
  238. })
  239. .then(res => {
  240. wx.hideLoading()
  241. // 如果是停车券直接跳往停车页
  242. if (_this.couponChannelDetail.type == 51 ||_this.couponChannelDetail.type== 5) {
  243. wx.showModal({
  244. title: '兑换成功',
  245. cancelText: '我知道了',
  246. confirmText: '去使用',
  247. content: '即将前往停车页面',
  248. success(res) {
  249. if (res.confirm) {
  250. wx.switchTab({
  251. url: '/index/passCar'
  252. });
  253. }
  254. }
  255. })
  256. } else {
  257. wx.navigateTo({
  258. url: '/pages/integralmall/payIntegcouponStatus/index?title=' + _this.data.data.title + '&coverImg=' + _this.data.data.coverImg + '&remainingPoints=' + _this.data.remainingPoints + '&type=' + _this.data.data.type,
  259. })
  260. }
  261. })
  262. .catch(err => {
  263. if (err.code != 12002) {
  264. setTimeout(function () {
  265. _this.payOrderUpdate(orderId, payOrderId, status, reason, _this);
  266. }, 2000)
  267. }
  268. })
  269. },
  270. /**
  271. * 获取券详情信息
  272. */
  273. getDetail(couponChannelId) {
  274. let that = this;
  275. Http.get({
  276. url: config.api.couponDetail,
  277. data: {
  278. couponChannelId: couponChannelId
  279. }
  280. }).then(res => {
  281. that.couponChannelDetail=res.data
  282. console.log(that.couponChannelDetail.merchantVoList[0].merchantName,'that.couponChannelDetail');
  283. wx.stopPullDownRefresh();
  284. that.getUserInfo()
  285. let data = res.data;
  286. that.setData({
  287. data
  288. });
  289. });
  290. },
  291. /**
  292. * 页面相关事件处理函数--监听用户下拉动作
  293. */
  294. onPullDownRefresh: function () {
  295. this.getDetail(this.data.paramData.couponChannelId);
  296. this.setData({
  297. submitAble: true
  298. })
  299. },
  300. })