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.

316 linhas
7.3 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. let app = getApp();
  7. const {
  8. spellStatus
  9. } = require("../../../utils/spell");
  10. Page({
  11. /**
  12. * 页面的初始数据
  13. */
  14. data: {
  15. navigationBarHeight,
  16. blueImg: imgurl.blue.url,
  17. tuanzhang: imgurl.tuanzhang.url,
  18. spellBg: imgurl.spellBg.url,
  19. position: imgurl.position.url,
  20. close03: imgurl.close03.url,
  21. home: imgurl.wmhome.url,
  22. orderGroupFail: imgurl.orderGroupFail.url,
  23. paramData: null,
  24. data: null,
  25. clock: "00",
  26. day: "0",
  27. hour: "00",
  28. min: "00",
  29. sec: "00",
  30. spellStatusList: spellStatus,
  31. isMyself: false,
  32. showErr: false,
  33. showAlert: false,
  34. disabled: false
  35. },
  36. gotoAgain() {
  37. let data = this.data.data;
  38. wx.navigateTo({
  39. url: `/pages/spellGroup/mySpellGroup/index?couponId=${data.couponId}&couponChannelId=${data.couponChannelId}`,
  40. })
  41. },
  42. getUserInfo: function() {
  43. let that = this;
  44. // 获取用户信息
  45. Http.get({
  46. url: config.api.getScore,
  47. data: {}
  48. })
  49. .then(res => {
  50. console.log(res)
  51. that.setData({
  52. nickName: res.data.nickName,
  53. avatarUrl: res.data.avatarUrl
  54. })
  55. })
  56. },
  57. gotoIndex() {
  58. wx.reLaunch({
  59. url: '/pages/index/index',
  60. })
  61. },
  62. gotoSearch() {
  63. wx.navigateTo({
  64. url: `/pages/spellGroup/spellGroup`,
  65. })
  66. },
  67. /**
  68. * 生命周期函数--监听页面加载
  69. */
  70. onLoad: function(options) {
  71. Http.get({
  72. url: config.api.checkUserStatus,
  73. data: {
  74. token: app.globalData.token
  75. }
  76. }).then(res => {
  77. Http.get({
  78. url: config.api.checkPhoneStatus,
  79. data: {}
  80. }).then(res => {
  81. this.setData({
  82. paramData: options
  83. })
  84. this.getUserInfo();
  85. if (options.orderGroupId) {
  86. if (options.orderId && options.couponId) {
  87. this.getDetail(options);
  88. }
  89. }
  90. // 关闭来自于左上角的分享
  91. wx.hideShareMenu()
  92. }).catch(res => {
  93. wx.redirectTo({
  94. url: `/pages/getphoneInfo/index`
  95. });
  96. })
  97. }).catch(res => {
  98. wx.redirectTo({
  99. url: `/pages/getuserinfo/index`
  100. })
  101. })
  102. },
  103. /**
  104. * 去拼团
  105. */
  106. goToOrderGroup(orderId, orderGroupId, _this) {
  107. console.log(22222222)
  108. let that = this;
  109. // 支付成功
  110. Http.post({
  111. url: config.api.toOrderGroup,
  112. data: {
  113. id: orderGroupId,
  114. orderId,
  115. couponId: _this.data.data.couponId
  116. }
  117. })
  118. .then(res => {
  119. wx.redirectTo({
  120. url: `/pages/spellDetail/index?orderId=${orderId}&couponId=${_this.data.paramData.couponId}&orderGroupId=${res.data.orderGroupId}&couponChannelId=${_this.data.paramData.couponChannelId}`
  121. });
  122. })
  123. .catch(err => {
  124. console.log(err);
  125. })
  126. // return;
  127. },
  128. /**
  129. * 支付订单更新
  130. */
  131. payOrderUpdate: (orderId, payOrderId, status, reason, _this, orderGroupId) => {
  132. console.log(orderGroupId, 7777)
  133. let that = _this;
  134. // 支付成功
  135. Http.post({
  136. url: config.api.payOrderUpdate,
  137. data: {
  138. payOrderId: payOrderId,
  139. orderId: orderId,
  140. status: status,
  141. reason: reason
  142. }
  143. })
  144. .then(res => {
  145. wx.hideLoading()
  146. that.setData({
  147. disabled: false
  148. })
  149. if (res.data.orderStatus == 14) {
  150. _this.setData({
  151. showErr: true
  152. })
  153. return;
  154. }
  155. if (orderGroupId == undefined) {
  156. wx.navigateTo({
  157. url: '/pages/order/detail/index?orderId=' + res.data.id,
  158. })
  159. } else {
  160. _this.goToOrderGroup(orderId, res.data.orderGroupId, _this)
  161. }
  162. })
  163. .catch(err => {
  164. console.log(err);
  165. that.setData({
  166. disabled: false
  167. })
  168. if (err.code != 12002) {
  169. setTimeout(function() {
  170. _this.payOrderUpdate(orderId, payOrderId, status, reason, _this, orderGroupId);
  171. }, 2000)
  172. }
  173. })
  174. },
  175. gotoPay() {
  176. let that = this;
  177. wx.showLoading({
  178. title: '支付创建中...',
  179. })
  180. that.setData({
  181. disabled: true
  182. })
  183. Http.post({
  184. url: config.api.payOrderCreate,
  185. data: {
  186. orderId: that.data.paramData.orderId
  187. }
  188. })
  189. .then(res => {
  190. var payOrderId = "" + res.data.payOrderId;
  191. wx.hideLoading();
  192. wx.requestPayment({
  193. timeStamp: res.data.timeStamp,
  194. nonceStr: res.data.nonceStr,
  195. package: res.data.package,
  196. signType: (res.data.signType) ? res.data.signType : "MD5",
  197. paySign: res.data.paySign,
  198. success: res => {
  199. wx.showLoading({
  200. title: '订单正在处理中...',
  201. })
  202. setTimeout(function() {
  203. wx.hideLoading()
  204. }, 5000)
  205. that.payOrderUpdate(that.data.paramData.orderId, payOrderId, 1, '', that, 0);
  206. if (res.errMsg == "requestPayment:ok") {
  207. setTimeout(function() {
  208. wx.hideLoading();
  209. }, 2000);
  210. }
  211. },
  212. fail: res => {
  213. /**
  214. * 支付失败,需要更新订单的状态
  215. */
  216. that.payOrderUpdate(that.data.paramData.orderId, payOrderId, 2, '', that, 0);
  217. that.setData({
  218. showbutton: false,
  219. canSpell: true,
  220. canBuyIf: true,
  221. disabled: false
  222. })
  223. return;
  224. },
  225. complete: res => {}
  226. });
  227. /// End payment --------
  228. })
  229. .catch(err => {
  230. that.setData({
  231. canSpell: true,
  232. canBuyIf: true,
  233. disabled: false
  234. })
  235. wx.showToast({
  236. title: err.message,
  237. icon: 'none',
  238. duration: 2000,
  239. mask: false
  240. });
  241. })
  242. },
  243. /**
  244. * 去使用
  245. */
  246. gotoUse() {
  247. wx.navigateTo({
  248. url: `/pages/couponorder/index/index`
  249. });
  250. },
  251. /**
  252. * 拼团状态字段转换
  253. */
  254. changeSatus(status) {
  255. console.log(spellStatus, 8888888)
  256. return spellStatus.filter(item => item.value == status)[0].name;
  257. },
  258. //跳转拼团列表
  259. gotoSpellList() {
  260. wx.navigateTo({
  261. url: '/pages/spellGroup/spellGroup',
  262. })
  263. },
  264. /**
  265. * 获取券详情信息
  266. */
  267. getDetail() {
  268. let that = this;
  269. Http.get({
  270. url: config.api.couponDetail,
  271. data: {
  272. couponChannelId: this.data.paramData.couponChannelId
  273. }
  274. }).then(res => {
  275. wx.stopPullDownRefresh();
  276. let data = res.data;
  277. that.setData({
  278. data
  279. });
  280. });
  281. },
  282. /**
  283. * 生命周期函数--监听页面显示
  284. */
  285. onShow: function() {
  286. this.setData({
  287. showTime: true
  288. })
  289. },
  290. /**
  291. * 生命周期函数--监听页面隐藏
  292. */
  293. onHide: function() {
  294. this.setData({
  295. showTime: false
  296. })
  297. },
  298. /**
  299. * 生命周期函数--监听页面卸载
  300. */
  301. onUnload: function() {
  302. this.setData({
  303. showTime: false
  304. })
  305. },
  306. /**
  307. * 页面相关事件处理函数--监听用户下拉动作
  308. */
  309. onPullDownRefresh: function() {
  310. this.getDetail(this.data.paramData);
  311. },
  312. })