foodOrder.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. },
  16. onShow:function(){
  17. this.setData({
  18. is_confirms:true
  19. })
  20. },
  21. // 获取购物车
  22. getCart: async function(){
  23. let self = this;
  24. let data = {
  25. tableId: this.data.tableId,
  26. storeId: this.data.storeId
  27. }
  28. const rs = await productApi.getCart(data)
  29. self.setData({
  30. cartId:rs.id,
  31. cartList:rs.list
  32. })
  33. },
  34. onLoad : async function (options) {
  35. this.setData({
  36. tableId:options.tableId,
  37. storeId:options.storeId,
  38. })
  39. const rs = await storeApi.getStoreById(options.storeId)
  40. this.setData({
  41. storeInfo: rs.info
  42. })
  43. this.getCart();
  44. wx.showLoading({
  45. title: 'loading',
  46. mask:true
  47. });
  48. },
  49. showMoreHandle:function(){
  50. this.setData({
  51. showMore:!this.data.showMore
  52. })
  53. },
  54. confirms:async function(){
  55. wx.showLoading({
  56. title: 'loading',
  57. mask:true
  58. });
  59. this.setData({
  60. is_confirms:false
  61. })
  62. let self = this;
  63. let data = {
  64. productIdAndNum : cartList,
  65. storeId: self.data.shopId,
  66. mobile: self.data.mobile
  67. }
  68. const rs = await orderApi.createFoodOrder(data)
  69. let orderId = rs.orderId;
  70. wx.requestPayment({
  71. timeStamp: rs.timeStamp,
  72. nonceStr: rs.nonceStr,
  73. package: rs.package,
  74. signType: rs.signType,
  75. paySign: rs.paySign,
  76. success (res) {
  77. setTimeout(()=>{
  78. wx.navigateTo({
  79. url: '../order/order?id=' + orderId,
  80. })
  81. },2000)
  82. },
  83. fail (res) {
  84. wx.navigateTo({
  85. url: '../order/order?id=' + orderId,
  86. })
  87. }
  88. })
  89. },
  90. goMenu(){
  91. wx.navigateBack({
  92. delta: 1
  93. })
  94. }
  95. })