orderList.js 8.0 KB

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