抖音小程序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.

283 line
7.4 KiB

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