orderList.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. var http = require('../../utils/http.js');
  2. var config = require('../../utils/config.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. statusObject: {
  9. 0: '待支付',
  10. 20: '订单已接单',
  11. 30: '订单待配送',
  12. 40: '订单配送中',
  13. 50: '订单取消待审核',
  14. 60: '订单已取消',
  15. 70: '订单已送达',
  16. 80: '订单已完成'
  17. },
  18. list: [],
  19. current: 1,
  20. pages: 0,
  21. sts: 0,
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad: function (options) {
  27. if (options.sts) {
  28. this.setData({
  29. sts: options.sts
  30. });
  31. }
  32. this.loadOrderData(this.data.sts, 1);
  33. },
  34. /**
  35. * 生命周期函数--监听页面显示
  36. */
  37. onShow: function () {},
  38. /**
  39. * 加载订单数据
  40. */
  41. loadOrderData: function (sts, current) {
  42. var ths = this;
  43. wx.showLoading();
  44. //加载订单列表
  45. var params = {
  46. url: "/p/myOrder/myOrder",
  47. method: "GET",
  48. data: {
  49. current: current,
  50. size: 10,
  51. status: sts,
  52. },
  53. callBack: function (res) {
  54. // console.log(res);
  55. let img=''
  56. res.records.forEach(orderItem => {
  57. orderItem.totalCounts = 0
  58. if (orderItem.returnMoneySts == null) {
  59. orderItem.returnMoneySts = 0
  60. }
  61. orderItem.orderItemDtos.forEach(prod => {
  62. img=prod.pic.split(',')
  63. prod.pic=img[0]
  64. orderItem.totalCounts += prod.prodCount
  65. })
  66. })
  67. var list = [];
  68. if (res.current == 1) {
  69. list = res.records;
  70. } else {
  71. list = ths.data.list;
  72. Array.prototype.push.apply(list, res.records);
  73. }
  74. ths.setData({
  75. list: list,
  76. pages: res.pages,
  77. current: res.current,
  78. });
  79. wx.hideLoading();
  80. }
  81. };
  82. http.request(params);
  83. },
  84. /**
  85. * 状态点击事件
  86. */
  87. onStsTap: function (e) {
  88. var sts = e.currentTarget.dataset.sts;
  89. this.setData({
  90. sts: sts
  91. });
  92. this.loadOrderData(sts, 1);
  93. },
  94. /**
  95. * 生命周期函数--监听页面初次渲染完成
  96. */
  97. onReady: function () {
  98. },
  99. /**
  100. * 生命周期函数--监听页面隐藏
  101. */
  102. onHide: function () {
  103. },
  104. /**
  105. * 生命周期函数--监听页面卸载
  106. */
  107. onUnload: function () {
  108. },
  109. /**
  110. * 页面相关事件处理函数--监听用户下拉动作
  111. */
  112. onPullDownRefresh: function () {
  113. },
  114. /**
  115. * 页面上拉触底事件的处理函数
  116. */
  117. onReachBottom: function () {
  118. if (this.data.current < this.data.pages) {
  119. this.loadOrderData(this.data.sts, this.data.current + 1);
  120. }
  121. },
  122. /**
  123. * 用户点击右上角分享
  124. */
  125. onShareAppMessage: function () {
  126. },
  127. /**
  128. * 跳转店铺首页
  129. */
  130. toShopIndex: function (e) {
  131. wx.navigateTo({
  132. url: '/pages/shopPage/shopPage?shopId=' + e.currentTarget.dataset.shopid
  133. })
  134. },
  135. /**
  136. * 查看物流
  137. */
  138. toDeliveryPage: function (e) {
  139. let lat=e.currentTarget.dataset.lat
  140. let long=e.currentTarget.dataset.lon
  141. wx.navigateTo({
  142. url: '/pages/MaterialFlowInfo/MaterialFlowInfo?orderNumber=' + e.currentTarget.dataset.ordernum+'&lat='+lat+'&long='+long
  143. })
  144. },
  145. /**
  146. * 取消订单
  147. */
  148. onCancelOrder: function (e) {
  149. var ordernum = e.currentTarget.dataset.ordernum;
  150. var ths = this;
  151. wx.showModal({
  152. title: '',
  153. content: '要取消此订单?',
  154. confirmColor: "#3e62ad",
  155. cancelColor: "#3e62ad",
  156. cancelText: '否',
  157. confirmText: '是',
  158. success(res) {
  159. if (res.confirm) {
  160. wx.showLoading({
  161. mask: true
  162. });
  163. var params = {
  164. url: "/p/myOrder/cancel/" + ordernum,
  165. method: "PUT",
  166. data: {},
  167. callBack: function (res) {
  168. //console.log(res);
  169. ths.loadOrderData(ths.data.sts, 1);
  170. wx.hideLoading();
  171. }
  172. };
  173. http.request(params);
  174. } else if (res.cancel) {
  175. //console.log('用户点击取消')
  176. }
  177. }
  178. })
  179. },
  180. /**
  181. * 待发货取消订单
  182. * @param {*} e
  183. */
  184. onRefundOrder: function (e) {
  185. var params = {
  186. url: '/p/orderRefund/getIsDistribution',
  187. method: 'GET',
  188. data: {
  189. orderNumber: e.currentTarget.dataset.ordernum
  190. },
  191. callBack: res => {
  192. if (res == true) {
  193. wx.showToast({
  194. title: '商品已在配送中,无法取消',
  195. icon: 'none'
  196. })
  197. } else {
  198. wx.navigateTo({
  199. url: '/pages/order-detail/order-detail?orderNum=' + e.currentTarget.dataset.ordernum,
  200. })
  201. }
  202. }
  203. }
  204. http.request(params);
  205. },
  206. /**
  207. * 付款
  208. */
  209. onPayAgain: function (e) {
  210. wx.showLoading({
  211. mask: true
  212. });
  213. var orderType = e.currentTarget.dataset.ordertype;
  214. var params = {
  215. url: "/p/order/pay",
  216. method: "POST",
  217. data: {
  218. orderType: orderType ? orderType : 0,
  219. payType: 1,
  220. orderNumbers: e.currentTarget.dataset.ordernum
  221. },
  222. callBack: res => {
  223. //console.log(res);
  224. wx.hideLoading();
  225. wx.requestPayment({
  226. timeStamp: res.timeStamp,
  227. nonceStr: res.nonceStr,
  228. package: res.package,
  229. signType: res.signType,
  230. paySign: res.paySign,
  231. success: function () {
  232. wx.navigateTo({
  233. url: '/pages/pay-result/pay-result?sts=1&orderNumbers=' + e.currentTarget.dataset.ordernum,
  234. })
  235. },
  236. fail: function (err) {
  237. //console.log("支付失败");
  238. }
  239. })
  240. }
  241. };
  242. http.request(params);
  243. },
  244. /**
  245. * 查看订单详情
  246. */
  247. toOrderDetailPage: function (e) {
  248. wx.navigateTo({
  249. url: '/pages/order-detail/order-detail?orderNum=' + e.currentTarget.dataset.ordernum,
  250. })
  251. },
  252. /**
  253. * 确认收货
  254. */
  255. onConfirmReceive: function (e) {
  256. var ths = this;
  257. wx.showModal({
  258. title: '',
  259. content: '我已收到货?',
  260. confirmColor: "#FF941A",
  261. success(res) {
  262. if (res.confirm) {
  263. wx.showLoading({
  264. mask: true
  265. });
  266. var params = {
  267. url: "/p/myOrder/receipt/" + e.currentTarget.dataset.ordernum,
  268. method: "PUT",
  269. data: {},
  270. callBack: function (res) {
  271. //console.log(res);
  272. ths.loadOrderData(ths.data.sts, 1);
  273. wx.hideLoading();
  274. }
  275. };
  276. http.request(params);
  277. } else if (res.cancel) {
  278. //console.log('用户点击取消')
  279. }
  280. }
  281. })
  282. },
  283. //删除已完成||已取消的订单
  284. delOrderList: function (e) {
  285. var ths = this
  286. wx.showModal({
  287. title: '',
  288. content: '确定要删除此订单吗?',
  289. confirmColor: "#FF941A",
  290. success(res) {
  291. if (res.confirm) {
  292. var ordernum = e.currentTarget.dataset.ordernum;
  293. wx.showLoading();
  294. var params = {
  295. url: "/p/myOrder/" + ordernum,
  296. method: "DELETE",
  297. data: {},
  298. callBack: function (res) {
  299. ths.loadOrderData(ths.data.sts, 1);
  300. wx.hideLoading();
  301. }
  302. }
  303. http.request(params);
  304. } else if (res.cancel) {
  305. console.log('用户点击取消')
  306. }
  307. }
  308. })
  309. },
  310. /**
  311. * 跳转评价页面
  312. */
  313. onComment: function (e) {
  314. var info = e.currentTarget.dataset.info;
  315. wx.setStorageSync("orderItemInfo", info);
  316. wx.navigateTo({
  317. url: '/pages/prodComm/prodComm',
  318. })
  319. }
  320. })