orders.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. var _request = require('../../../../utils/request.js')
  2. var rid
  3. Page({
  4. data: {
  5. tabLeft: '0%',
  6. type: '',
  7. page: 1,
  8. per_page: 10,
  9. list: [],
  10. more: true,
  11. tabChange: false
  12. },
  13. onLoad: function (options) {
  14. rid = options.type
  15. if (rid) {
  16. if (rid === 'unpay') {
  17. this.tabUnpay()
  18. } else if (rid === 'processing') {
  19. this.tabProcessing()
  20. } else if (rid === 'dispatch') {
  21. this.tabDispatch()
  22. } else if (rid === 'complete') {
  23. this.tabComplete()
  24. } else {
  25. this.getOrderList()
  26. }
  27. } else {
  28. this.getOrderList()
  29. }
  30. },
  31. onShow () {
  32. if (getApp().globalData.order) {
  33. this.typeList()
  34. getApp().globalData.order = false
  35. }
  36. // if (rid) {
  37. // if (rid === 'unpay') {
  38. // this.tabUnpay()
  39. // } else if (rid === 'processing') {
  40. // this.tabProcessing()
  41. // } else if (rid === 'dispatch') {
  42. // this.tabDispatch()
  43. // } else if (rid === 'complete') {
  44. // this.tabComplete()
  45. // } else {
  46. // this.getOrderList()
  47. // }
  48. // } else {
  49. // this.getOrderList()
  50. // }
  51. },
  52. tabAll: function () {
  53. if (this.data.type !== '') {
  54. this.setData({
  55. tabLeft: '0%',
  56. type: '',
  57. more: true,
  58. page: 1,
  59. tabChange: true
  60. })
  61. this.getOrderList()
  62. } else {
  63. }
  64. },
  65. tabUnpay: function () {
  66. if (this.data.type !== 'unpay') {
  67. this.setData({
  68. tabLeft: '20%',
  69. type: 'unpay',
  70. more: true,
  71. page: 1,
  72. tabChange: true
  73. })
  74. this.getOrderList()
  75. }
  76. },
  77. tabProcessing: function () {
  78. if (this.data.type !== 'processing') {
  79. this.setData({
  80. tabLeft: '40%',
  81. type: 'processing',
  82. more: true,
  83. page: 1,
  84. tabChange: true
  85. })
  86. this.getOrderList()
  87. }
  88. },
  89. tabDispatch: function () {
  90. if (this.data.type !== 'dispatch') {
  91. this.setData({
  92. tabLeft: '60%',
  93. type: 'dispatch',
  94. more: true,
  95. page: 1,
  96. tabChange: true
  97. })
  98. this.getOrderList()
  99. }
  100. },
  101. tabComplete: function () {
  102. if (this.data.type !== 'complete') {
  103. this.setData({
  104. tabLeft: '80%',
  105. type: 'complete',
  106. more: true,
  107. page: 1,
  108. tabChange: true
  109. })
  110. this.getOrderList()
  111. }
  112. },
  113. confirmPopup (val) {
  114. var that = this
  115. var id = val.currentTarget.dataset.val
  116. wx.showModal({
  117. title: '提示',
  118. content: '是否确认收货?',
  119. success: function(res) {
  120. if (res.confirm) {
  121. that.confirmOrder(id)
  122. } else if (res.cancel) {
  123. }
  124. }
  125. })
  126. },
  127. CancelPopup (val) {
  128. var that = this
  129. var id = val.currentTarget.dataset.val
  130. wx.showModal({
  131. title: '提示',
  132. content: '确定取消该订单?',
  133. success: function(res) {
  134. if (res.confirm) {
  135. that.CancelOrder(id)
  136. } else if (res.cancel) {
  137. }
  138. }
  139. })
  140. },
  141. confirmOrder: function (val) {
  142. var id = val
  143. var that = this
  144. var url = 'v1/order/' + id + '/confirm'
  145. var params = {
  146. }
  147. var success = function (res) {
  148. that.typeList()
  149. wx.showToast({
  150. title: '确认收货成功',
  151. icon: 'none',
  152. duration: 2000
  153. })
  154. }
  155. _request.$put(url, params, success)
  156. },
  157. CancelOrder: function (val) {
  158. var id = val
  159. var that = this
  160. var url = 'v1/order/' + id + '/cancel'
  161. var params = {
  162. }
  163. var success = function (res) {
  164. that.typeList()
  165. wx.showToast({
  166. title: '取消订单成功',
  167. icon: 'none',
  168. duration: 2000
  169. })
  170. }
  171. _request.$put(url, params, success)
  172. },
  173. getOrderList () {
  174. var that = this
  175. var url = 'v1/orders'
  176. var params = {
  177. status: this.data.type,
  178. page: this.data.page,
  179. per_page: this.data.per_page
  180. }
  181. var success = function (res) {
  182. if (that.data.tabChange) {
  183. that.setData({
  184. list: [],
  185. tabChange: false
  186. })
  187. }
  188. var result = that.data.list.concat(res.data.list || [])
  189. console.log('orderlist',result);
  190. that.setData({
  191. list: result
  192. })
  193. var listMore = res.data.list_count > that.data.list.length
  194. that.setData({
  195. more: listMore
  196. })
  197. }
  198. _request.$get(url, params, success)
  199. },
  200. onReachBottom: function () {
  201. if (this.data.more) {
  202. var page = this.data.page + 1
  203. this.setData({
  204. page: page
  205. })
  206. this.getOrderList()
  207. }
  208. },
  209. typeList: function () {
  210. this.setData({
  211. more: true,
  212. page: 1,
  213. tabChange: true
  214. })
  215. this.getOrderList()
  216. },
  217. onShareAppMessage: function (val) {
  218. return _request.share({
  219. sc: 'xcx_user_orders'
  220. })
  221. }
  222. })