orders.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. },
  37. tabAll: function () {
  38. if (this.data.type !== '') {
  39. this.setData({
  40. tabLeft: '0%',
  41. type: '',
  42. more: true,
  43. page: 1,
  44. tabChange: true
  45. })
  46. this.getOrderList()
  47. } else {
  48. }
  49. },
  50. tabUnpay: function () {
  51. if (this.data.type !== 'unpay') {
  52. this.setData({
  53. tabLeft: '20%',
  54. type: 'unpay',
  55. more: true,
  56. page: 1,
  57. tabChange: true
  58. })
  59. this.getOrderList()
  60. }
  61. },
  62. tabProcessing: function () {
  63. if (this.data.type !== 'processing') {
  64. this.setData({
  65. tabLeft: '40%',
  66. type: 'processing',
  67. more: true,
  68. page: 1,
  69. tabChange: true
  70. })
  71. this.getOrderList()
  72. }
  73. },
  74. tabDispatch: function () {
  75. if (this.data.type !== 'dispatch') {
  76. this.setData({
  77. tabLeft: '60%',
  78. type: 'dispatch',
  79. more: true,
  80. page: 1,
  81. tabChange: true
  82. })
  83. this.getOrderList()
  84. }
  85. },
  86. tabComplete: function () {
  87. if (this.data.type !== 'complete') {
  88. this.setData({
  89. tabLeft: '80%',
  90. type: 'complete',
  91. more: true,
  92. page: 1,
  93. tabChange: true
  94. })
  95. this.getOrderList()
  96. }
  97. },
  98. confirmPopup (val) {
  99. var that = this
  100. var id = val.currentTarget.dataset.val
  101. wx.showModal({
  102. title: '提示',
  103. content: '是否确认收货?',
  104. success: function(res) {
  105. if (res.confirm) {
  106. that.confirmOrder(id)
  107. } else if (res.cancel) {
  108. }
  109. }
  110. })
  111. },
  112. CancelPopup (val) {
  113. var that = this
  114. var id = val.currentTarget.dataset.val
  115. wx.showModal({
  116. title: '提示',
  117. content: '确定取消该订单?',
  118. success: function(res) {
  119. if (res.confirm) {
  120. that.CancelOrder(id)
  121. } else if (res.cancel) {
  122. }
  123. }
  124. })
  125. },
  126. confirmOrder: function (val) {
  127. var id = val
  128. var that = this
  129. var url = 'v1/order/' + id + '/confirm'
  130. var params = {
  131. }
  132. var success = function (res) {
  133. that.typeList()
  134. wx.showToast({
  135. title: '确认收货成功',
  136. icon: 'none',
  137. duration: 2000
  138. })
  139. }
  140. _request.$put(url, params, success)
  141. },
  142. CancelOrder: function (val) {
  143. var id = val
  144. var that = this
  145. var url = 'v1/order/' + id + '/cancel'
  146. var params = {
  147. }
  148. var success = function (res) {
  149. that.typeList()
  150. wx.showToast({
  151. title: '取消订单成功',
  152. icon: 'none',
  153. duration: 2000
  154. })
  155. }
  156. _request.$put(url, params, success)
  157. },
  158. getOrderList () {
  159. var that = this
  160. var url = 'v1/orders'
  161. var params = {
  162. status: this.data.type,
  163. page: this.data.page,
  164. per_page: this.data.per_page
  165. }
  166. var success = function (res) {
  167. if (that.data.tabChange) {
  168. that.setData({
  169. list: [],
  170. tabChange: false
  171. })
  172. }
  173. var result = that.data.list.concat(res.data.list || [])
  174. that.setData({
  175. list: result
  176. })
  177. var listMore = res.data.list_count > that.data.list.length
  178. that.setData({
  179. more: listMore
  180. })
  181. }
  182. _request.$get(url, params, success)
  183. },
  184. onReachBottom: function () {
  185. if (this.data.more) {
  186. var page = this.data.page + 1
  187. this.setData({
  188. page: page
  189. })
  190. this.getOrderList()
  191. }
  192. },
  193. typeList: function () {
  194. this.setData({
  195. more: true,
  196. page: 1,
  197. tabChange: true
  198. })
  199. this.getOrderList()
  200. },
  201. onShareAppMessage: function (val) {
  202. return _request.share({
  203. sc: 'xcx_user_orders'
  204. })
  205. }
  206. })