order-detail.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. // pages/order-detail/order-detail.js
  2. var http = require('../../utils/http.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. orderItemDtos: [],
  9. remarks: "",
  10. actualTotal: 0,
  11. userAddrDto: null,
  12. orderNumber: "",
  13. createTime: "",
  14. status: 0,
  15. productTotalAmount: '',
  16. transfee: '',
  17. reduceAmount: '',
  18. prodid: '',
  19. orderType: 0,
  20. shopName: '', //店铺名称
  21. canRefund: false, // 能否退款
  22. canAllRefund: false, // 能否整单退款
  23. isLastProd: false, //最后一款商品
  24. irrevocable: false, //不可撤销
  25. sum: [], //本单已申请单个退款的商品数组
  26. orderScore: 0, // 整单使用积分
  27. orderNumSend:''
  28. },
  29. //跳转商品详情页
  30. toProdPage: function(e) {
  31. var prodid = e.currentTarget.dataset.prodid;
  32. if(this.data.orderType==3){
  33. console.log('积分商品')
  34. wx.navigateTo({
  35. url: '/pages/convertProdDet/convertProdDet?prodid=' + prodid,
  36. })
  37. }else{
  38. wx.navigateTo({
  39. url: '/pages/prod/prod?prodid=' + prodid,
  40. })
  41. }
  42. },
  43. /**
  44. * 是否最后一个商品在执行单个商品退款事件
  45. */
  46. applyLastProdRefund: function() {
  47. if(this.data.status==2) { //待发货状态下
  48. // 遍历商品list
  49. if(this.data.orderItemDtos.length > 1) { //如果商品列表长度大于1
  50. let sum = []
  51. this.data.orderItemDtos.forEach((el,index) => {
  52. if (el.refundSn) { //如果拥有退款单号
  53. sum.push(el)
  54. this.setData({
  55. sum
  56. })
  57. }
  58. })
  59. console.log(this.data.sum)
  60. if(this.data.sum.length == this.data.orderItemDtos.length-1) {
  61. // 如果拥有退款单号的item等于商品列表数据长度-1,那么点击的这件商品就是最后意见商品
  62. this.setData({
  63. isLastProd: true
  64. })
  65. }else if(this.data.sum.length == this.data.orderItemDtos.length) {
  66. // 如果拥有退款单号的item等于商品列表数据长度,那么不可撤销申请
  67. this.setData({
  68. irrevocable: true //不可撤销
  69. })
  70. }
  71. }
  72. console.log('isLastProd:',this.data.isLastProd)
  73. console.log('irrevocable:',this.data.irrevocable)
  74. }
  75. },
  76. /**
  77. * 申请退款
  78. */
  79. applyRefund: function(e) {
  80. var refundType = e.currentTarget.dataset.refundtype // 退款类型 1整单 2单个物品
  81. var status = this.data.status
  82. this.loadOrderDetail(this.data.orderNumber) //请求订单详情数据
  83. if (e.currentTarget.dataset.refundtype == 1) { //整单退款
  84. var item = {}
  85. item.orderNumber = this.data.orderNumber;
  86. item.actualTotal = this.data.actualTotal;
  87. item.transfee = this.data.transfee;
  88. item.status = this.data.status; //订单状态
  89. item.orderItemDtos = this.data.orderItemDtos;
  90. item.orderScore = this.data.orderScore, // 整单积分
  91. //拿到存储在本地的订单项数据
  92. wx.setStorageSync("refundItem", item);
  93. // console.log('订单详情页获取到的整单退item:',item)
  94. } else if(e.currentTarget.dataset.refundtype == 2) { //单个商品退款
  95. this.applyLastProdRefund() //是否最后一个商品执行单个商品退款
  96. console.log('isLastProd:',this.data.isLastProd)
  97. // 将数据存储到本地
  98. var item = e.currentTarget.dataset.item;
  99. if(this.data.orderItemDtos.length == 1) {
  100. item.addTransfee = true
  101. }else {
  102. item.addTransfee = false
  103. }
  104. item.orderNumber = this.data.orderNumber;
  105. item.transfee = this.data.transfee;
  106. item.status = this.data.status; //订单状态
  107. item.isLastProd = this.data.isLastProd?this.data.isLastProd:undefined //是否最后一款商品
  108. //拿到存储在本地的订单项数据
  109. wx.setStorageSync("refundItem", item);
  110. console.log(item)
  111. console.log(item.actualTotal)
  112. }
  113. /**
  114. * 判断跳转页面(根据订单是否已发货)
  115. */
  116. var type = e.currentTarget.dataset.type;
  117. if (status == 2) { //待发货,直接跳转到申请页,不需要选择退货方式
  118. wx.redirectTo({ //通过wx.redirectTo实现跳转(关闭当前页面,跳转到应用内某个页面)
  119. url: '/pages/applyRefund/applyRefund?type=' + type + '&refundType=' + refundType,
  120. })
  121. } else { //已发货,跳转到选择退货方式页
  122. wx.redirectTo({
  123. url: '/pages/chooseRefundWay/chooseRefundWay?refundType=' + refundType
  124. })
  125. }
  126. },
  127. /**
  128. * 查看退款
  129. */
  130. viewRefund: function(e) {
  131. var refundSn = e.currentTarget.dataset.refundsn;
  132. this.applyLastProdRefund() //是否最后一个商品执行单个商品退款
  133. console.log(this.data.irrevocable)
  134. wx.navigateTo({
  135. url: '/pages/DetailsOfRefund/DetailsOfRefund?refundSn=' + refundSn + '&irrevocable=' + this.data.irrevocable+'&userAddrDto='+JSON.stringify(this.data.userAddrDto) +'&orderNumber=' + this.data.orderNumSend
  136. })
  137. },
  138. /**
  139. * 生命周期函数--监听页面加载
  140. */
  141. onLoad: function(options) {
  142. this.setData({
  143. orderNumSend:options.orderNum
  144. })
  145. this.loadOrderDetail(options.orderNum);
  146. },
  147. /**
  148. * 加载订单数据
  149. */
  150. loadOrderDetail: function(orderNum) {
  151. var ths = this;
  152. wx.showLoading();
  153. //加载订单详情
  154. var params = {
  155. url: "/p/myOrder/orderDetail",
  156. method: "GET",
  157. data: {
  158. orderNumber: orderNum
  159. },
  160. callBack: function(res) {
  161. let img=''
  162. res.orderItemDtos.forEach(e=>{
  163. img=e.pic.split(',')
  164. e.pic=img[0]
  165. })
  166. ths.setData({
  167. orderNumber: orderNum,
  168. actualTotal: res.actualTotal, //实际支付总额(商品总额+运费)
  169. userAddrDto: res.userAddrDto,
  170. remarks: res.remarks,
  171. orderItemDtos: res.orderItemDtos,
  172. createTime: res.createTime,
  173. status: res.status,
  174. productTotalAmount: res.total, //所有商品总额
  175. transfee: res.transfee, //运费
  176. reduceAmount: res.reduceAmount,
  177. orderType: res.orderType,
  178. shopName: res.shopName,
  179. canRefund: res.canRefund,
  180. canAllRefund: res.canAllRefund,
  181. orderScore: res.orderScore, // 整单使用积分
  182. });
  183. wx.hideLoading();
  184. }
  185. };
  186. http.request(params);
  187. },
  188. /**
  189. * 生命周期函数--监听页面初次渲染完成
  190. */
  191. onReady: function() {
  192. },
  193. /**
  194. * 生命周期函数--监听页面显示
  195. */
  196. onShow: function() {
  197. },
  198. /**
  199. * 生命周期函数--监听页面隐藏
  200. */
  201. onHide: function() {
  202. },
  203. /**
  204. * 生命周期函数--监听页面卸载
  205. */
  206. onUnload: function() {
  207. },
  208. /**
  209. * 页面相关事件处理函数--监听用户下拉动作
  210. */
  211. onPullDownRefresh: function() {
  212. },
  213. /**
  214. * 页面上拉触底事件的处理函数
  215. */
  216. onReachBottom: function() {
  217. },
  218. /**
  219. * 用户点击右上角分享
  220. */
  221. onShareAppMessage: function() {
  222. },
  223. toGroupDetails: function(e) {
  224. wx.navigateTo({
  225. url: '/pages/spellGroupDetails/spellGroupDetails?orderNumber=' + e.currentTarget.dataset.ordernumber,
  226. })
  227. },
  228. // 一键复制事件
  229. copyBtn: function(e) {
  230. var ths = this;
  231. wx.setClipboardData({
  232. //准备复制的数据
  233. data: ths.data.orderNumber,
  234. success: function(res) {
  235. wx.showToast({
  236. title: '复制成功',
  237. });
  238. }
  239. })
  240. },
  241. })