order.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. var _request = require('../../../../utils/request.js')
  2. var rid
  3. Page({
  4. data: {
  5. order: {},
  6. express: '',
  7. total:0,
  8. },
  9. onLoad: function (options) {
  10. rid = options.id
  11. this.getRadish()
  12. },
  13. onShow: function () {
  14. this.getRadish()
  15. },
  16. getRadish () {
  17. var that = this
  18. var url = 'v1/order/' + rid
  19. var params = {
  20. }
  21. var success = function (res) {
  22. var data = res.data
  23. console.log('orderdata',data);
  24. var total = 0;
  25. for(var i in data.product_list){
  26. total = total + (data.product_list[i].price * data.product_list[i].order_count)
  27. }
  28. that.setData({
  29. order: data,
  30. total:total
  31. })
  32. that.formatOrder()
  33. }
  34. _request.$get(url, params, success)
  35. },
  36. confirmPopup () {
  37. var that = this
  38. wx.showModal({
  39. title: '提示',
  40. content: '是否确认收货?',
  41. success: function(res) {
  42. if (res.confirm) {
  43. that.confirmOrder()
  44. } else if (res.cancel) {
  45. }
  46. }
  47. })
  48. },
  49. CancelPopup () {
  50. var that = this
  51. wx.showModal({
  52. title: '提示',
  53. content: '确定取消该订单?',
  54. success: function(res) {
  55. if (res.confirm) {
  56. that.CancelOrder()
  57. } else if (res.cancel) {
  58. }
  59. }
  60. })
  61. },
  62. confirmOrder: function () {
  63. var id = this.data.order.order_id
  64. var that = this
  65. var url = 'v1/order/' + id + '/confirm'
  66. var params = {
  67. }
  68. var success = function (res) {
  69. getApp().globalData.order = true
  70. wx.navigateBack()
  71. }
  72. _request.$put(url, params, success)
  73. },
  74. CancelOrder: function () {
  75. var id = this.data.order.order_id
  76. var that = this
  77. var url = 'v1/order/' + id + '/cancel'
  78. var params = {
  79. }
  80. var success = function (res) {
  81. getApp().globalData.order = true
  82. wx.navigateBack()
  83. }
  84. _request.$put(url, params, success)
  85. },
  86. formatOrder: function () {
  87. var id = this.data.order.express_order_no
  88. var result = ''
  89. for (var i = 0; i < id.length; i++) {
  90. if (i%4 === 0 && i !== 0) {
  91. result = result + ' '
  92. }
  93. result = result + id[i]
  94. }
  95. this.setData({
  96. express: result
  97. })
  98. },
  99. copeOrder: function () {
  100. var that = this
  101. var id = this.data.order.express_order_no
  102. wx.setClipboardData({
  103. data: id,
  104. success: function(res) {
  105. wx.showToast({
  106. title: '已成功复制到剪贴板',
  107. icon: 'none',
  108. duration: 2000
  109. })
  110. }
  111. })
  112. },
  113. onShareAppMessage: function (val) {
  114. return _request.share({
  115. sc: 'xcx_user_order'
  116. })
  117. },
  118. copy:function(e){
  119. var code = e.currentTarget.dataset.copy;
  120. wx.setClipboardData({
  121. data: code,
  122. success: function (res) {
  123. wx.showToast({
  124. title: '已复制订单号',
  125. });
  126. },
  127. fail:function(res){
  128. wx.showToast({
  129. title: '复制失败',
  130. });
  131. }
  132. })
  133. }
  134. })