orderList.js 8.1 KB

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