index.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. const Parse = getApp().Parse;
  2. const company = getApp().globalData.company
  3. let navigationBarHeight = getApp().globalData.statusBarHeight + 44;
  4. const dateF = require('../../../../utils/date');
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. active: 0,
  11. list: [],
  12. totalPrice: 0,
  13. stickytop: navigationBarHeight,
  14. },
  15. async acceptResult(e) {
  16. let { activeOrder } = this.data
  17. let that = this
  18. let {
  19. params,
  20. no
  21. } = e.detail;
  22. that.setData({
  23. showPayment: false
  24. })
  25. try {
  26. if (params == "ok") {
  27. // activeOrder.set("status", 200)
  28. // activeOrder.set("isPay", true)
  29. await that.getorder()
  30. // await activeOrder.save()
  31. wx.showToast({
  32. title: '支付成功',
  33. icon: 'none',
  34. duration: 1500,
  35. mask: false,
  36. });
  37. wx.navigateBack({
  38. delta: 1,
  39. })
  40. } else {
  41. wx.showToast({
  42. title: '支付失败,取消订单',
  43. icon: 'none',
  44. duration: 1500,
  45. mask: false,
  46. });
  47. }
  48. } catch (error) {
  49. console.log(error)
  50. wx.showToast({
  51. title: "支付失败",
  52. icon: "error",
  53. duration: 1500,
  54. });
  55. wx.hideLoading()
  56. }
  57. },
  58. async getorder() {
  59. let id = this.data.id
  60. console.log(id);
  61. let shopOrder
  62. let ShopOrder = new Parse.Query("FoodOrder")
  63. shopOrder = await ShopOrder.get(id)
  64. shopOrder.set("state", "400")
  65. shopOrder.save().then(res => {
  66. console.log(res)
  67. })
  68. },
  69. onChange(event) {
  70. let active = event.detail.name
  71. this.setData({
  72. active: active
  73. })
  74. console.log(active);
  75. this.getFoodOrder()
  76. },
  77. storepackage(e) {
  78. let userLogin = wx.getStorageSync("userLogin");
  79. if (userLogin == "") {
  80. login.loginNow();
  81. return;
  82. }
  83. let totalPrice = e.currentTarget.dataset.item.totalPrice
  84. let id = e.currentTarget.dataset.item.objectId
  85. console.log(totalPrice);
  86. this.setData({
  87. show: true,
  88. totalPrice: totalPrice,
  89. id: id
  90. })
  91. },
  92. //删除
  93. delOrder(e) {
  94. console.log(e);
  95. let {
  96. index
  97. } = e.currentTarget.dataset
  98. let {
  99. list
  100. } = this.data
  101. let _this = this
  102. wx.showModal({
  103. title: '',
  104. content: '你确定删除该订单吗?',
  105. showCancel: true,
  106. cancelText: '取消',
  107. cancelColor: '#000000',
  108. confirmText: '确定',
  109. confirmColor: '#3CC51F',
  110. success: async(result) => {
  111. if (result.confirm) {
  112. await this.upDel(list[index].objectId)
  113. list.splice(index, 1)
  114. _this.setData({
  115. list
  116. })
  117. wx.showToast({
  118. title: '已取消',
  119. icon: 'none',
  120. image: '',
  121. duration: 1500,
  122. });
  123. }
  124. },
  125. fail: () => {},
  126. complete: () => {}
  127. });
  128. },
  129. async upDel(id) {
  130. let FoodOrder = new Parse.Query('FoodOrder')
  131. let order = await FoodOrder.get(id)
  132. if (order && order.id) {
  133. console.log(order);
  134. await order.destroy()
  135. }
  136. },
  137. foodevaluation(e) {
  138. let id = e.currentTarget.dataset.item.objectId
  139. console.log(id);
  140. wx.navigateTo({
  141. url: '/nova-tourism/pages/my/order-details/foodevaluation/index?id=' + id
  142. });
  143. },
  144. foodpay(e) {
  145. let id = e.currentTarget.dataset.item.objectId
  146. console.log(id);
  147. wx.navigateTo({
  148. url: '/nova-tourism/pages/my/order-details/food-pay/index?id=' + id
  149. });
  150. },
  151. refund(e) {
  152. let id = e.currentTarget.dataset.item.objectId
  153. console.log(id);
  154. wx.navigateTo({
  155. url: '/nova-tourism/pages/my/refund/reply-refund/index?id=' + id
  156. });
  157. },
  158. async getFoodOrder() {
  159. let FoodOrder = new Parse.Query('FoodOrder')
  160. FoodOrder.equalTo('company', company)
  161. FoodOrder.equalTo('user', Parse.User.current().id)
  162. if (this.data.active == 1) {
  163. FoodOrder.equalTo('state', "100")
  164. }
  165. // if (this.data.active == 2) {
  166. // FoodOrder.equalTo('status', "200")
  167. // }
  168. if (this.data.active == 2) {
  169. console.log(this.data.active)
  170. FoodOrder.equalTo('state', "400")
  171. }
  172. FoodOrder.include('foods')
  173. FoodOrder.include('table')
  174. let foodOrder = await FoodOrder.find()
  175. let listJSON = []
  176. if (foodOrder && foodOrder.length > 0) {
  177. foodOrder.forEach(c => {
  178. let order = c.toJSON()
  179. order.Time = dateF.formatTime('YYYY-mm-dd HH:MM:SS', order.createdAt);
  180. listJSON.push(order)
  181. })
  182. }
  183. this.setData({
  184. list: listJSON
  185. })
  186. console.log(this.data.list);
  187. },
  188. /**
  189. * 生命周期函数--监听页面加载
  190. */
  191. onLoad: function(options) {
  192. this.getFoodOrder()
  193. },
  194. /**
  195. * 生命周期函数--监听页面初次渲染完成
  196. */
  197. onReady: function() {
  198. },
  199. /**
  200. * 生命周期函数--监听页面显示
  201. */
  202. onShow: function() {
  203. },
  204. /**
  205. * 生命周期函数--监听页面隐藏
  206. */
  207. onHide: function() {
  208. },
  209. /**
  210. * 生命周期函数--监听页面卸载
  211. */
  212. onUnload: function() {
  213. },
  214. /**
  215. * 页面相关事件处理函数--监听用户下拉动作
  216. */
  217. onPullDownRefresh: function() {
  218. },
  219. /**
  220. * 页面上拉触底事件的处理函数
  221. */
  222. onReachBottom: function() {
  223. },
  224. /**
  225. * 用户点击右上角分享
  226. */
  227. onShareAppMessage: function() {
  228. }
  229. })