index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. const Parse = getApp().Parse
  2. const dateF = require('../../../../../utils/date')
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. id: null,
  9. foodorder: null,
  10. time: null,
  11. show: false
  12. },
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad: function (options) {
  17. this.setData({
  18. activeColor:getApp().globalData.activeColor || '#229293'
  19. })
  20. let id = options.id
  21. console.log(id);
  22. this.setData({ id: id })
  23. console.log(this.data.id);
  24. this.foodorder()
  25. },
  26. async foodorder() {
  27. let FoodOrder = new Parse.Query("FoodOrder")
  28. FoodOrder.include("store")
  29. FoodOrder.include("table")
  30. FoodOrder.include("foods")
  31. let foodorder = await FoodOrder.get(this.data.id)
  32. console.log(foodorder.toJSON());
  33. let time = dateF.formatTime("YYYY-mm-dd HH:MM:SS", foodorder.toJSON().createdAt)
  34. this.setData({
  35. foodorder: foodorder.toJSON(),
  36. time: time
  37. })
  38. },
  39. submit() {
  40. let userLogin = wx.getStorageSync("userLogin");
  41. if (userLogin == "") {
  42. login.loginNow();
  43. return;
  44. }
  45. this.setData({
  46. show: true
  47. })
  48. },
  49. async acceptResult(e) {
  50. let { activeOrder } = this.data
  51. let that = this
  52. let {
  53. params,
  54. no
  55. } = e.detail;
  56. that.setData({
  57. show: false
  58. })
  59. try {
  60. if (params == "ok") {
  61. // activeOrder.set("status", 200)
  62. // activeOrder.set("isPay", true)
  63. await that.getorder()
  64. // await activeOrder.save()
  65. wx.showToast({
  66. title: '购买成功',
  67. icon: 'none',
  68. image: '',
  69. duration: 1500,
  70. mask: false,
  71. });
  72. wx.navigateBack({
  73. delta: 1,
  74. })
  75. } else {
  76. wx.showToast({
  77. title: '支付失败,取消订单',
  78. icon: 'none',
  79. image: '',
  80. duration: 1500,
  81. mask: false,
  82. });
  83. }
  84. } catch (error) {
  85. console.log(error)
  86. wx.showToast({
  87. title: "支付失败",
  88. icon: "error",
  89. duration: 1500,
  90. });
  91. wx.hideLoading()
  92. }
  93. },
  94. async getorder() {
  95. let FoodOrder = new Parse.Query("FoodOrder")
  96. let foodorder = await FoodOrder.get(this.data.id)
  97. foodorder.set("state", "200")
  98. foodorder.save().then(res => {
  99. console.log(res)
  100. })
  101. },
  102. /**
  103. * 生命周期函数--监听页面初次渲染完成
  104. */
  105. onReady: function () {
  106. },
  107. /**
  108. * 生命周期函数--监听页面显示
  109. */
  110. onShow: function () {
  111. },
  112. /**
  113. * 生命周期函数--监听页面隐藏
  114. */
  115. onHide: function () {
  116. },
  117. /**
  118. * 生命周期函数--监听页面卸载
  119. */
  120. onUnload: function () {
  121. },
  122. /**
  123. * 页面相关事件处理函数--监听用户下拉动作
  124. */
  125. onPullDownRefresh: function () {
  126. },
  127. /**
  128. * 页面上拉触底事件的处理函数
  129. */
  130. onReachBottom: function () {
  131. },
  132. /**
  133. * 用户点击右上角分享
  134. */
  135. onShareAppMessage: function () {
  136. }
  137. })