orders.js 4.9 KB

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