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.

317 lines
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. 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. composeOrderId: 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(res.data.singleOrder.id, res.data.mainOrderId, _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. composeOrderType: that.data.paramData.composeOrderType,
  188. }
  189. })
  190. .then(res => {
  191. var payOrderId = "" + res.data.payOrderId;
  192. wx.hideLoading();
  193. wx.requestPayment({
  194. timeStamp: res.data.timeStamp,
  195. nonceStr: res.data.nonceStr,
  196. package: res.data.package,
  197. signType: (res.data.signType) ? res.data.signType : "MD5",
  198. paySign: res.data.paySign,
  199. success: res => {
  200. wx.showLoading({
  201. title: '订单正在处理中...',
  202. })
  203. setTimeout(function() {
  204. wx.hideLoading()
  205. }, 5000)
  206. that.payOrderUpdate(that.data.paramData.orderId, payOrderId, 1, '', that, 0);
  207. if (res.errMsg == "requestPayment:ok") {
  208. setTimeout(function() {
  209. wx.hideLoading();
  210. }, 2000);
  211. }
  212. },
  213. fail: res => {
  214. /**
  215. * 支付失败,需要更新订单的状态
  216. */
  217. that.payOrderUpdate(that.data.paramData.orderId, payOrderId, 2, '', that, 0);
  218. that.setData({
  219. showbutton: false,
  220. canSpell: true,
  221. canBuyIf: true,
  222. disabled: false
  223. })
  224. return;
  225. },
  226. complete: res => {}
  227. });
  228. /// End payment --------
  229. })
  230. .catch(err => {
  231. that.setData({
  232. canSpell: true,
  233. canBuyIf: true,
  234. disabled: false
  235. })
  236. wx.showToast({
  237. title: err.message,
  238. icon: 'none',
  239. duration: 2000,
  240. mask: false
  241. });
  242. })
  243. },
  244. /**
  245. * 去使用
  246. */
  247. gotoUse() {
  248. wx.navigateTo({
  249. url: `/pages/couponorder/index/index`
  250. });
  251. },
  252. /**
  253. * 拼团状态字段转换
  254. */
  255. changeSatus(status) {
  256. console.log(spellStatus, 8888888)
  257. return spellStatus.filter(item => item.value == status)[0].name;
  258. },
  259. //跳转拼团列表
  260. gotoSpellList() {
  261. wx.navigateTo({
  262. url: '/pages/spellGroup/spellGroup',
  263. })
  264. },
  265. /**
  266. * 获取券详情信息
  267. */
  268. getDetail() {
  269. let that = this;
  270. Http.get({
  271. url: config.api.couponDetail,
  272. data: {
  273. couponChannelId: this.data.paramData.couponChannelId
  274. }
  275. }).then(res => {
  276. wx.stopPullDownRefresh();
  277. let data = res.data;
  278. that.setData({
  279. data
  280. });
  281. });
  282. },
  283. /**
  284. * 生命周期函数--监听页面显示
  285. */
  286. onShow: function() {
  287. this.setData({
  288. showTime: true
  289. })
  290. },
  291. /**
  292. * 生命周期函数--监听页面隐藏
  293. */
  294. onHide: function() {
  295. this.setData({
  296. showTime: false
  297. })
  298. },
  299. /**
  300. * 生命周期函数--监听页面卸载
  301. */
  302. onUnload: function() {
  303. this.setData({
  304. showTime: false
  305. })
  306. },
  307. /**
  308. * 页面相关事件处理函数--监听用户下拉动作
  309. */
  310. onPullDownRefresh: function() {
  311. this.getDetail(this.data.paramData);
  312. },
  313. })