paySuccess.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. // pages/paySuccess/paySuccess.js
  2. import { get, post } from '../../utils/http'
  3. import { $wuxCountDown } from '../../components/dist/index'
  4. import { PROJECT_TYPE } from '../../utils/global'
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. orderId: 0,
  11. orderData: {},
  12. isMember: -1,
  13. source: '', //订单类型,project项目订单,product升级产品订单,goods美妆产品订单,默认project
  14. orderType: '', // 接口返回的订单类型
  15. recommendList: [],
  16. productList: [],
  17. seconds: 0, // 倒计时秒数
  18. countdownStr: '', // 倒计时字符串
  19. takeOutTime: '', // 取货截止时间
  20. tips: {
  21. show_tips: 0,
  22. project: ['您的预约单已生效,请准时到店体验'],
  23. product: ['您的预约单已生效,请准时到店体验'],
  24. goods: ['您的预约单已生效', '请于_TIME_OUT_之前']
  25. },
  26. mainOrderId: -1, // 主订单ID
  27. selectProductData: null // 选中的新人推荐项目升级产品
  28. },
  29. /**
  30. * 生命周期函数--监听页面加载
  31. */
  32. onLoad: function (options) {
  33. let that = this
  34. this.setData(
  35. {
  36. orderId: options.order_id,
  37. source: options.source || 'project',
  38. isMember:
  39. getApp().globalData.userInfo && getApp().globalData.userInfo.is_vip
  40. ? getApp().globalData.userInfo.is_vip
  41. : 0
  42. },
  43. () => {
  44. if(options.source === 'secondaryCard'){
  45. this.setData({
  46. orderType: options.source
  47. })
  48. return
  49. }
  50. that.getOrderSuccess(options.order_id)
  51. }
  52. )
  53. },
  54. /**
  55. * 生命周期函数--监听页面初次渲染完成
  56. */
  57. onReady: function () {},
  58. /**
  59. * 生命周期函数--监听页面显示
  60. */
  61. onShow: function () {},
  62. /**
  63. * 生命周期函数--监听页面隐藏
  64. */
  65. onHide: function () {},
  66. /**
  67. * 生命周期函数--监听页面卸载
  68. */
  69. onUnload: function () {
  70. if (this.c1) this.c1.stop()
  71. },
  72. /**
  73. * 页面相关事件处理函数--监听用户下拉动作
  74. */
  75. onPullDownRefresh: function () {},
  76. /**
  77. * 页面上拉触底事件的处理函数
  78. */
  79. onReachBottom: function () {},
  80. /**
  81. * 用户点击右上角分享
  82. */
  83. onShareAppMessage: function () {},
  84. /**
  85. * 获取订单信息
  86. * @param {*} order_id
  87. */
  88. getOrderSuccess(order_id) {
  89. let that = this
  90. let { source } = this.data
  91. if (source == 'product_with_project_order') {
  92. source = 'product'
  93. }
  94. get(
  95. 'api/order/success',
  96. {
  97. order_id,
  98. order_type: source
  99. },
  100. (res) => {
  101. let orderData = res.data
  102. this.setData(
  103. {
  104. orderData: orderData,
  105. productList: orderData.product_list,
  106. recommendList: orderData.recommend_list,
  107. takeOutTime: orderData.take_out_time,
  108. seconds: orderData.seconds,
  109. orderType: orderData.type,
  110. mainOrderId: orderData.main_order_id
  111. },
  112. () => {
  113. that.c1 = new $wuxCountDown({
  114. date: +new Date() + orderData.seconds * 1000,
  115. render(date) {
  116. const hours = this.leadingZeros(date.hours, 2)
  117. const min = this.leadingZeros(date.min, 2)
  118. const sec = this.leadingZeros(date.sec, 2)
  119. that.setData({ countdownStr: `${hours}:${min}:${sec}` })
  120. },
  121. onEnd() {
  122. that.c1.stop()
  123. // that.getOrderDetail(that.data.orderId)
  124. }
  125. })
  126. }
  127. )
  128. console.log(res)
  129. }
  130. )
  131. },
  132. /**
  133. * 跳转订单详情
  134. */
  135. gotoOrderDetail() {
  136. let { orderType, orderId, mainOrderId } = this.data
  137. let _orderId = mainOrderId ? mainOrderId : orderId
  138. let url = `/pages/orderDetail/orderDetail?source=${orderType}&id=${_orderId}`
  139. if (['goods', 'cardgoods'].indexOf(orderType) > -1) {
  140. url = `/pages/goods/orderDetail/orderDetail?source=${orderType}&id=${_orderId}`
  141. }
  142. if(['secondaryCard'].indexOf(orderType) > -1){
  143. url = `/subPackages/pages/cardBag/cardBag`
  144. }
  145. wx.navigateTo({
  146. url: url
  147. })
  148. },
  149. /**
  150. * 跳转首页
  151. */
  152. gotoHome() {
  153. wx.switchTab({
  154. url: '/pages/home/home'
  155. })
  156. },
  157. /**
  158. * 跳转至项目耗材详情页
  159. */
  160. gotoProductDetail(e) {
  161. let item = e.currentTarget.dataset.item
  162. wx.navigateTo({
  163. url: `/pages/projectDetail/projectDetail?source=product&project_id=${item.product_id}`
  164. })
  165. },
  166. /**
  167. * 跳转至推荐详情页
  168. */
  169. gotoRecommendDetail(e) {
  170. let { source } = this.data
  171. let item = e.currentTarget.dataset.item
  172. if (source == 'product_with_project_order') {
  173. source = 'product'
  174. }
  175. wx.navigateTo({
  176. url: `/pages/projectDetail/projectDetail?source=${source}&project_id=${item.id}`
  177. })
  178. },
  179. /**
  180. * 勾选了新人推荐产品
  181. */
  182. selectProjectProduct(e) {
  183. let { selectProductData } = this.data
  184. let item = e.currentTarget.dataset.item
  185. if (selectProductData && selectProductData.product_id == item.product_id) {
  186. this.setData({ selectProductData: null })
  187. return
  188. }
  189. this.setData({ selectProductData: item })
  190. },
  191. /**
  192. * 选中新人福利推荐的项目升级产品
  193. */
  194. addProductOrder() {
  195. let { selectProductData } = this.data
  196. if (!selectProductData) {
  197. wx.showToast({
  198. title: '请先选择升级产品',
  199. icon: 'none'
  200. })
  201. return
  202. }
  203. let source = 'product'
  204. let sourceType = PROJECT_TYPE[source]
  205. get(
  206. 'api/product/info',
  207. {
  208. store_id: wx.getStorageSync('store_id'),
  209. product_id: selectProductData.product_id,
  210. type: sourceType
  211. },
  212. (res) => {
  213. // 正常应该直接传入selectProductData,但是接口参数不齐,所以调用一次详情接口
  214. wx.navigateTo({
  215. url: `/pages/reserveProduct/reserveProduct?source=${source}&productData=${encodeURIComponent(
  216. JSON.stringify(res.data)
  217. )}`
  218. })
  219. }
  220. )
  221. }
  222. })