抖音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.

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