foodOrder.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. const app = getApp()
  2. import {
  3. default as productApi
  4. } from "../../api/product"
  5. import {
  6. default as storeApi
  7. } from "../../api/store"
  8. import {
  9. default as orderApi
  10. } from "../../api/order"
  11. Page({
  12. data: {
  13. is_confirms:true,
  14. cartList:[],
  15. totalNum:0,
  16. totalPrice:0.00,
  17. },
  18. onShow:function(){
  19. this.setData({
  20. is_confirms:true
  21. })
  22. },
  23. // 获取购物车
  24. getCart: async function(){
  25. let self = this;
  26. let data = {
  27. tableId: this.data.tableId,
  28. storeId: this.data.storeId
  29. }
  30. const rs = await productApi.getCart(data)
  31. self.setData({
  32. cartId:rs.id,
  33. cartList:rs.list,
  34. totalNum:rs.totalNum,
  35. totalPrice:rs.totalPrice
  36. })
  37. },
  38. onLoad : async function (options) {
  39. this.setData({
  40. tableId:options.tableId,
  41. storeId:options.storeId,
  42. })
  43. const rs = await storeApi.getStoreById(options.storeId)
  44. this.setData({
  45. storeInfo: rs.info
  46. })
  47. this.getCart();
  48. wx.showLoading({
  49. title: 'loading',
  50. mask:true
  51. });
  52. },
  53. showMoreHandle:function(){
  54. this.setData({
  55. showMore:!this.data.showMore
  56. })
  57. },
  58. confirms:async function(){
  59. wx.showLoading({
  60. title: 'loading',
  61. mask:true
  62. });
  63. this.setData({
  64. is_confirms:false
  65. })
  66. let self = this;
  67. let data = {
  68. cartId : self.data.cartId,
  69. tableId : self.data.tableId
  70. }
  71. const rs = await orderApi.createFoodOrder(data)
  72. let orderId = rs.orderId;
  73. wx.requestPayment({
  74. timeStamp: rs.timeStamp,
  75. nonceStr: rs.nonceStr,
  76. package: rs.package,
  77. signType: rs.signType,
  78. paySign: rs.paySign,
  79. success (res) {
  80. setTimeout(()=>{
  81. wx.reLaunch({
  82. url: '../order/order?id=' + orderId,
  83. })
  84. },2000)
  85. },
  86. fail (res) {
  87. wx.reLaunch({
  88. url: '../order/order?id=' + orderId,
  89. })
  90. }
  91. })
  92. },
  93. goMenu(){
  94. wx.navigateBack({
  95. delta: 1
  96. })
  97. }
  98. })