order.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../config/api.js');
  3. import play from '../../../utils/pay.js'
  4. Page({
  5. data:{
  6. orderList: [],
  7. page: 1,
  8. size: 10,
  9. loadmoreText: '正在加载更多数据',
  10. nomoreText: '全部加载完成',
  11. nomore: false,
  12. totalPages: 1,
  13. activeIdx:-1,
  14. header:[
  15. {
  16. icon: 'ct1',
  17. name: '全部订单',
  18. id: -1
  19. },
  20. {
  21. icon: 'ct2',
  22. name: '待付款',
  23. id: 0
  24. },
  25. {
  26. icon: 'ct3',
  27. name: '待发货',
  28. id: 201
  29. },
  30. {
  31. icon: 'ct4',
  32. name: '待收货',
  33. id: 300
  34. },
  35. {
  36. icon: 'ct5',
  37. name: '已完成',
  38. id: 301
  39. }
  40. ]
  41. },
  42. async quita(ev) {
  43. if (this.quiting) return;
  44. let text = ['预订中', '预订审核', '预订成功', '预订失败', '取消预订', '已用餐', '支付超时', '已失效']
  45. this.quiting = true
  46. let data = ev.target.dataset.itemdata
  47. if (data.status === 3 || data.status === 4 || data.status === 5 || data.status === 6 || data.status === 7) {
  48. this.quiting = false
  49. return wx.navigateTo({
  50. url: '/pages/scene/scene?scene='+data.canteen.sceneNum+'&id='+data.canteen.id+'&deskId='+data.deskId,
  51. })
  52. } else if (data.status === 0) {
  53. try {
  54. await play(data.id)
  55. let res1 = await util.request(api.OrderQuery, { orderId: data.id})
  56. wx.showToast({
  57. icon: 'success',
  58. title: res1.errmsg
  59. })
  60. this.refresh()
  61. getApp().callOrderBuyCbs({deskId: data.deskId})
  62. } catch (e) {
  63. wx.showToast({
  64. icon: 'none',
  65. title: '付款失败',
  66. })
  67. }
  68. this.quiting = false
  69. return
  70. }
  71. let that = this
  72. wx.showActionSheet({
  73. alertText: '是否取消预订座位',
  74. itemColor: '#FA5151',
  75. itemList: ['确定'],
  76. success (res) {
  77. util.request(api.OrderCancel, {orderId: ev.target.dataset.orderid})
  78. .then(res => {
  79. if (res.code === 0) {
  80. util.request(api.refundQuery, {orderId: ev.target.dataset.orderid})
  81. .then(res => {
  82. if (res.code === 0) {
  83. wx.showToast({
  84. title: '取消预订成功',
  85. icon: 'none',
  86. duration: 2000
  87. })
  88. that.setData({
  89. orderList: [],
  90. page: 1
  91. })
  92. that.getOrderList();
  93. } else {
  94. wx.showToast({
  95. icon: 'none',
  96. title: res.msg,
  97. })
  98. }
  99. this.quiting = false
  100. })
  101. } else {
  102. wx.showToast({
  103. icon: 'none',
  104. title: res.msg,
  105. })
  106. this.quiting = false
  107. }
  108. })
  109. },
  110. fail (res) {
  111. this.quiting = false
  112. console.log(res.errMsg)
  113. }
  114. })
  115. },
  116. onLoad:function(options){
  117. getApp().checkNetStatu();
  118. let {id} = options
  119. this.setData({
  120. activeIdx: -1
  121. })
  122. // 页面初始化 options为页面跳转所带来的参数
  123. // 页面显示
  124. },
  125. refresh: function(){
  126. wx.showLoading({
  127. title: '加载中...',
  128. success: function () {
  129. }
  130. });
  131. this.setData({
  132. orderList: [],
  133. page: 1
  134. })
  135. this.getOrderList();
  136. },
  137. onPullDownRefresh() {
  138. this.refresh()
  139. getApp().onPullDownRefresh()
  140. },
  141. /**
  142. * 页面上拉触底事件的处理函数
  143. */
  144. onReachBottom: function () {
  145. this.getOrderList()
  146. },
  147. tabHeader:function(e){
  148. let {id} = e.currentTarget.dataset
  149. this.setData({
  150. activeIdx: id
  151. })
  152. this.refresh()
  153. },
  154. getOrderList(id){
  155. let that = this;
  156. this.setData({loadding: true})
  157. util.request(api.OrderList, { pageNum: that.data.page, pageSize: that.data.size}, 'GET').then(function (res) {
  158. let text = ['预订中', '预订审核', '预订成功', '预订失败', '取消预订', '已用餐', '支付超时', '已失效']
  159. if (res.code === 0) {
  160. let list = res.data.list.map(item => {
  161. let order = item.order
  162. order.reserveTime = order.reserveTime.substr(0,16)
  163. order.canteen = item.canteen
  164. order.order_status_text = text[Number(order.status)]
  165. order.reserveUserPhone = order.reserveUserPhone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
  166. return order
  167. })
  168. that.setData({
  169. orderList: that.data.orderList.concat(list),
  170. page: res.data.curPage + 1,
  171. totalPages: res.data.totalPageNum
  172. });
  173. that.setData({loadding: false})
  174. wx.hideLoading();
  175. if (res.data.list.length <= 0) {
  176. that.setData({
  177. nomore: true
  178. })
  179. return;
  180. }
  181. }
  182. });
  183. },
  184. gotoLogti: function(e){
  185. let {no,id} = e.currentTarget.dataset
  186. wx.navigateTo({
  187. url: '/pages/logistics/index?no=' + no + '&id=' + id
  188. })
  189. },
  190. payOrder(event){
  191. let that = this;
  192. let orderIndex = event.currentTarget.dataset.orderIndex;
  193. let order = that.data.orderList[orderIndex];
  194. wx.redirectTo({
  195. url: '/pages/pay/pay?orderId=' + order.id + '&actualPrice=' + order.actual_price,
  196. })
  197. },
  198. onReady:function(){
  199. // 页面渲染完成
  200. },
  201. onShow:function(){
  202. this.refresh()
  203. },
  204. onHide:function(){
  205. // 页面隐藏
  206. },
  207. onUnload:function(){
  208. // 页面关闭
  209. }
  210. })