foodOrder.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. productIdAndNum : cartList,
  69. storeId: self.data.shopId,
  70. mobile: self.data.mobile
  71. }
  72. const rs = await orderApi.createFoodOrder(data)
  73. let orderId = rs.orderId;
  74. wx.requestPayment({
  75. timeStamp: rs.timeStamp,
  76. nonceStr: rs.nonceStr,
  77. package: rs.package,
  78. signType: rs.signType,
  79. paySign: rs.paySign,
  80. success (res) {
  81. setTimeout(()=>{
  82. wx.navigateTo({
  83. url: '../order/order?id=' + orderId,
  84. })
  85. },2000)
  86. },
  87. fail (res) {
  88. wx.navigateTo({
  89. url: '../order/order?id=' + orderId,
  90. })
  91. }
  92. })
  93. },
  94. goMenu(){
  95. wx.navigateBack({
  96. delta: 1
  97. })
  98. }
  99. })