refundApply.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. const WXAPI = require('apifm-wxapi')
  2. Page({
  3. data: {
  4. orderId: 1,
  5. amount: 999.00,
  6. refundApplyDetail: undefined,
  7. type: 0,
  8. typeItems: [
  9. { name: '我要退款(无需退货)', value: '0', checked: true },
  10. { name: '我要退货退款', value: '1' },
  11. { name: '我要换货', value: '2' },
  12. ],
  13. logisticsStatus:0,
  14. logisticsStatusItems: [
  15. { name: '未收到货', value: '0', checked: true },
  16. { name: '已收到货', value: '1' }
  17. ],
  18. reasons: [
  19. "不喜欢/不想要",
  20. "空包裹",
  21. "未按约定时间发货",
  22. "快递/物流一直未送达",
  23. "货物破损已拒签",
  24. "退运费",
  25. "规格尺寸与商品页面描述不符",
  26. "功能/效果不符",
  27. "质量问题",
  28. "少件/漏发",
  29. "包装/商品破损",
  30. "发票问题",
  31. ],
  32. reasonIndex: 0,
  33. files: [],
  34. pics: []
  35. },
  36. onLoad: function (e) {
  37. this.setData({
  38. orderId: e.id,
  39. amount: e.amount
  40. });
  41. },
  42. onShow(){
  43. const _this = this
  44. WXAPI.refundApplyDetail(wx.getStorageSync('token'), _this.data.orderId).then(res => {
  45. if (res.code == 0) {
  46. _this.setData({
  47. refundApplyDetail: res.data[0] // baseInfo, pics
  48. })
  49. }
  50. })
  51. },
  52. refundApplyCancel(){
  53. const _this = this
  54. WXAPI.refundApplyCancel(wx.getStorageSync('token'), _this.data.orderId).then(res => {
  55. if (res.code == 0) {
  56. wx.navigateTo({
  57. url: "/pages/order-list/index"
  58. })
  59. }
  60. })
  61. },
  62. typeItemsChange: function (e) {
  63. const typeItems = this.data.typeItems;
  64. for (var i = 0, len = typeItems.length; i < len; ++i) {
  65. typeItems[i].checked = typeItems[i].value == e.detail.value;
  66. }
  67. this.setData({
  68. typeItems: typeItems,
  69. type: e.detail.value
  70. });
  71. },
  72. logisticsStatusItemsChange: function (e) {
  73. const logisticsStatusItems = this.data.logisticsStatusItems;
  74. for (var i = 0, len = logisticsStatusItems.length; i < len; ++i) {
  75. logisticsStatusItems[i].checked = logisticsStatusItems[i].value == e.detail.value;
  76. }
  77. this.setData({
  78. logisticsStatusItems: logisticsStatusItems,
  79. logisticsStatus: e.detail.value
  80. });
  81. },
  82. reasonChange: function (e) {
  83. this.setData({
  84. reasonIndex: e.detail.value
  85. })
  86. },
  87. chooseImage: function (e) {
  88. const that = this;
  89. wx.chooseImage({
  90. sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
  91. sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
  92. success: function (res) {
  93. // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
  94. that.setData({
  95. files: that.data.files.concat(res.tempFilePaths)
  96. });
  97. }
  98. })
  99. },
  100. previewImage: function (e) {
  101. const that = this;
  102. wx.previewImage({
  103. current: e.currentTarget.id, // 当前显示图片的http链接
  104. urls: that.data.files // 需要预览的图片http链接列表
  105. })
  106. },
  107. async uploadPics(){
  108. const _this = this;
  109. for (let i = 0; i< _this.data.files.length; i++) {
  110. const res = await WXAPI.uploadFile(wx.getStorageSync('token'), _this.data.files[i])
  111. if (res.code == 0) {
  112. _this.data.pics.push(res.data.url)
  113. }
  114. }
  115. },
  116. async bindSave (e) {
  117. // 提交保存
  118. const _this = this;
  119. // _this.data.orderId
  120. // _this.data.type
  121. // _this.data.logisticsStatus
  122. // _this.data.reasons[_this.data.reasonIndex]
  123. let amount = e.detail.value.amount;
  124. if (_this.data.type == 2) {
  125. amount = 0.00
  126. }
  127. let remark = e.detail.value.remark;
  128. if (!remark) {
  129. remark = ''
  130. }
  131. // 上传图片
  132. await _this.uploadPics()
  133. // _this.data.pics
  134. WXAPI.refundApply({
  135. token: wx.getStorageSync('token'),
  136. orderId: _this.data.orderId,
  137. type: _this.data.type,
  138. logisticsStatus: _this.data.logisticsStatus,
  139. reason: _this.data.reasons[_this.data.reasonIndex],
  140. amount,
  141. remark,
  142. pic: _this.data.pics.join()
  143. }).then(res => {
  144. if (res.code == 0) {
  145. wx.showModal({
  146. title: '成功',
  147. content: '提交成功,请耐心等待我们处理!',
  148. showCancel: false,
  149. confirmText: '我知道了',
  150. success(res) {
  151. wx.navigateTo({
  152. url: "/pages/order-list/index"
  153. })
  154. }
  155. })
  156. } else {
  157. wx.showModal({
  158. title: '失败',
  159. content: res.msg,
  160. showCancel: false,
  161. confirmText: '我知道了',
  162. success(res) {
  163. wx.navigateTo({
  164. url: "/pages/order-list/index"
  165. })
  166. }
  167. })
  168. }
  169. })
  170. }
  171. });