index.js 4.0 KB

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