orders.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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: '16.6%',
  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: '33.2%',
  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: '49.8%',
  97. type: 'dispatch',
  98. more: true,
  99. page: 1,
  100. tabChange: true
  101. })
  102. this.getOrderList()
  103. }
  104. },
  105. tabComment: function () {
  106. if (this.data.type !== 'waitcommen') {
  107. this.setData({
  108. tabLeft: '66.4%',
  109. type: 'waitcommen',
  110. more: true,
  111. page: 1,
  112. tabChange: true
  113. })
  114. this.getOrderList()
  115. }
  116. },
  117. tabComplete: function () {
  118. if (this.data.type !== 'complete') {
  119. this.setData({
  120. tabLeft: '83%',
  121. type: 'complete',
  122. more: true,
  123. page: 1,
  124. tabChange: true
  125. })
  126. this.getOrderList()
  127. }
  128. },
  129. confirmPopup (val) {
  130. var that = this
  131. var id = val.currentTarget.dataset.val
  132. wx.showModal({
  133. title: '提示',
  134. content: '是否确认收货?',
  135. success: function(res) {
  136. if (res.confirm) {
  137. that.confirmOrder(id)
  138. } else if (res.cancel) {
  139. }
  140. }
  141. })
  142. },
  143. CancelPopup (val) {
  144. var that = this
  145. var id = val.currentTarget.dataset.val
  146. wx.showModal({
  147. title: '提示',
  148. content: '确定取消该订单?',
  149. success: function(res) {
  150. if (res.confirm) {
  151. that.CancelOrder(id)
  152. } else if (res.cancel) {
  153. }
  154. }
  155. })
  156. },
  157. confirmOrder: function (val) {
  158. var id = val
  159. var that = this
  160. var url = 'v1/order/' + id + '/confirm'
  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. CancelOrder: function (val) {
  174. var id = val
  175. var that = this
  176. var url = 'v1/order/' + id + '/cancel'
  177. var params = {
  178. }
  179. var success = function (res) {
  180. that.typeList()
  181. wx.showToast({
  182. title: '取消订单成功',
  183. icon: 'none',
  184. duration: 2000
  185. })
  186. }
  187. _request.$put(url, params, success)
  188. },
  189. getOrderList () {
  190. var that = this
  191. var url = 'v1/orders'
  192. var params = {
  193. status: this.data.type,
  194. page: this.data.page,
  195. per_page: this.data.per_page
  196. }
  197. var success = function (res) {
  198. if (that.data.tabChange) {
  199. that.setData({
  200. list: [],
  201. tabChange: false
  202. })
  203. }
  204. var result = that.data.list.concat(res.data.list || [])
  205. console.log('orderlist',result);
  206. that.setData({
  207. list: result
  208. })
  209. var listMore = res.data.list_count > that.data.list.length
  210. that.setData({
  211. more: listMore
  212. })
  213. }
  214. _request.$get(url, params, success)
  215. },
  216. onReachBottom: function () {
  217. if (this.data.more) {
  218. var page = this.data.page + 1
  219. this.setData({
  220. page: page
  221. })
  222. this.getOrderList()
  223. }
  224. },
  225. typeList: function () {
  226. this.setData({
  227. more: true,
  228. page: 1,
  229. tabChange: true
  230. })
  231. this.getOrderList()
  232. },
  233. onShareAppMessage: function (val) {
  234. return _request.share({
  235. sc: 'xcx_user_orders'
  236. })
  237. },
  238. toCommend:function(e){
  239. let that = this;
  240. let id = e.currentTarget.dataset.id;
  241. let pid = e.currentTarget.dataset.pid;
  242. wx.navigateTo({
  243. url:'../comment/comment?id='+id+'&pid='+pid
  244. })
  245. }
  246. })