index.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. const app = getApp();
  2. const CONFIG = require('../../config.js')
  3. const WXAPI = require('apifm-wxapi')
  4. import wxbarcode from 'wxbarcode'
  5. Page({
  6. data:{
  7. orderId:0,
  8. goodsList:[]
  9. },
  10. onLoad:function(e){
  11. // e.id = 478785
  12. var orderId = e.id;
  13. this.data.orderId = orderId;
  14. this.setData({
  15. orderId: orderId
  16. });
  17. },
  18. onShow : function () {
  19. var that = this;
  20. WXAPI.orderDetail(wx.getStorageSync('token'), that.data.orderId).then(function (res) {
  21. if (res.code != 0) {
  22. wx.showModal({
  23. title: '错误',
  24. content: res.msg,
  25. showCancel: false
  26. })
  27. return;
  28. }
  29. // 绘制核销码
  30. if (res.data.orderInfo.hxNumber && res.data.orderInfo.status > 0) {
  31. wxbarcode.qrcode('qrcode', res.data.orderInfo.hxNumber, 650, 650);
  32. }
  33. // 子快递单信息
  34. if (res.data.orderLogisticsShippers) {
  35. res.data.orderLogisticsShippers.forEach(ele => {
  36. if (ele.traces) {
  37. ele.tracesArray = JSON.parse (ele.traces)
  38. if (ele.tracesArray && ele.tracesArray.length > 0) {
  39. ele.tracesLast = ele.tracesArray[ele.tracesArray.length - 1].AcceptStation + '\n' + ele.tracesArray[ele.tracesArray.length - 1].AcceptTime
  40. }
  41. }
  42. })
  43. }
  44. that.setData({
  45. orderDetail: res.data
  46. });
  47. })
  48. },
  49. wuliuDetailsTap:function(e){
  50. var orderId = e.currentTarget.dataset.id;
  51. wx.navigateTo({
  52. url: "/pages/wuliu/index?id=" + orderId
  53. })
  54. },
  55. confirmBtnTap:function(e){
  56. let that = this;
  57. let orderId = this.data.orderId;
  58. wx.showModal({
  59. title: '确认您已收到商品?',
  60. content: '',
  61. success: function(res) {
  62. if (res.confirm) {
  63. WXAPI.orderDelivery(wx.getStorageSync('token'), orderId).then(function (res) {
  64. if (res.code == 0) {
  65. that.onShow();
  66. }
  67. })
  68. }
  69. }
  70. })
  71. },
  72. async submitReputation(e) {
  73. let that = this;
  74. let postJsonString = {};
  75. postJsonString.token = wx.getStorageSync('token');
  76. postJsonString.orderId = this.data.orderId;
  77. let reputations = [];
  78. let i = 0;
  79. while (e.detail.value["orderGoodsId" + i]) {
  80. let orderGoodsId = e.detail.value["orderGoodsId" + i];
  81. let goodReputation = e.detail.value["goodReputation" + i];
  82. let goodReputationRemark = e.detail.value["goodReputationRemark" + i];
  83. if (!goodReputation) {
  84. goodReputation = 0
  85. } else if(goodReputation <= 1) {
  86. goodReputation = 0
  87. } else if(goodReputation <= 4) {
  88. goodReputation = 1
  89. } else {
  90. goodReputation = 2
  91. }
  92. let reputations_json = {};
  93. reputations_json.id = orderGoodsId;
  94. reputations_json.reputation = goodReputation;
  95. reputations_json.remark = goodReputationRemark;
  96. if (this.data.picsList && this.data.picsList[i] && this.data.picsList[i].length > 0) {
  97. reputations_json.pics = []
  98. for (let index = 0; index < this.data.picsList[i].length; index++) {
  99. const pic = this.data.picsList[i][index];
  100. const res = await WXAPI.uploadFile(wx.getStorageSync('token'), pic.url)
  101. if (res.code == 0) {
  102. reputations_json.pics.push(res.data.url)
  103. }
  104. }
  105. }
  106. reputations.push(reputations_json);
  107. i++;
  108. }
  109. postJsonString.reputations = reputations;
  110. WXAPI.orderReputation({
  111. postJsonString: JSON.stringify(postJsonString)
  112. }).then(function (res) {
  113. if (res.code == 0) {
  114. that.onShow();
  115. }
  116. })
  117. },
  118. afterPicRead(e) {
  119. const idx = e.currentTarget.dataset.idx
  120. let picsList = this.data.picsList
  121. if (!picsList) {
  122. picsList = []
  123. for (let index = 0; index < this.data.orderDetail.goods.length; index++) {
  124. picsList[index] = []
  125. }
  126. }
  127. picsList[idx] = picsList[idx].concat(e.detail.file)
  128. this.setData({
  129. picsList
  130. })
  131. },
  132. afterPicDel(e) {
  133. const idx = e.currentTarget.dataset.idx
  134. let picsList = this.data.picsList
  135. picsList[idx].splice(e.detail.index, 1)
  136. this.setData({
  137. picsList
  138. })
  139. }
  140. })