aftersale.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../config/api.js');
  3. Page({
  4. data: {
  5. orderId: 0,
  6. orderInfo: {},
  7. orderGoods: [],
  8. aftersale: {
  9. pictures: []
  10. },
  11. columns: ['未收货退款', '不退货退款', '退货退款'],
  12. contentLength: 0,
  13. fileList: []
  14. },
  15. onLoad: function (options) {
  16. // 页面初始化 options为页面跳转所带来的参数
  17. this.setData({
  18. orderId: options.id
  19. });
  20. this.getOrderDetail();
  21. },
  22. getOrderDetail: function () {
  23. wx.showLoading({
  24. title: '加载中',
  25. });
  26. setTimeout(function () {
  27. wx.hideLoading()
  28. }, 2000);
  29. let that = this;
  30. util.request(api.OrderDetail, {
  31. orderId: that.data.orderId
  32. }).then(function (res) {
  33. if (res.errno === 0) {
  34. console.log(res.data);
  35. that.setData({
  36. orderInfo: res.data.orderInfo,
  37. orderGoods: res.data.orderGoods,
  38. 'aftersale.orderId': that.data.orderId,
  39. 'aftersale.amount': res.data.orderInfo.actualPrice - res.data.orderInfo.freightPrice
  40. });
  41. }
  42. wx.hideLoading();
  43. });
  44. },
  45. deleteImage (event) {
  46. const { fileList = [] } = this.data;
  47. fileList.splice(event.detail.index, 1)
  48. this.setData({
  49. fileList: fileList
  50. })
  51. },
  52. afterRead(event) {
  53. const { file } = event.detail
  54. let that = this
  55. const uploadTask = wx.uploadFile({
  56. url: api.StorageUpload,
  57. filePath: file.path,
  58. name: 'file',
  59. success: function (res) {
  60. var _res = JSON.parse(res.data);
  61. if (_res.errno === 0) {
  62. var url = _res.data.url
  63. that.data.aftersale.pictures.push(url)
  64. const { fileList = [] } = that.data;
  65. fileList.push({ ...file, url: url });
  66. that.setData({
  67. fileList: fileList
  68. })
  69. }
  70. },
  71. fail: function (e) {
  72. wx.showModal({
  73. title: '错误',
  74. content: '上传失败',
  75. showCancel: false
  76. })
  77. },
  78. })
  79. },
  80. previewImage: function (e) {
  81. wx.previewImage({
  82. current: e.currentTarget.id, // 当前显示图片的http链接
  83. urls: this.data.files // 需要预览的图片http链接列表
  84. })
  85. },
  86. contentInput: function (e) {
  87. this.setData({
  88. contentLength: e.detail.cursor,
  89. 'aftersale.comment': e.detail.value,
  90. });
  91. },
  92. onReasonChange: function (e) {
  93. this.setData({
  94. 'aftersale.reason': e.detail,
  95. });
  96. },
  97. showTypePicker: function () {
  98. this.setData({
  99. showPicker: true,
  100. });
  101. },
  102. onCancel: function () {
  103. this.setData({
  104. showPicker: false,
  105. });
  106. },
  107. onConfirm: function (event) {
  108. this.setData({
  109. 'aftersale.type': event.detail.index,
  110. 'aftersale.typeDesc': event.detail.value,
  111. showPicker: false,
  112. });
  113. },
  114. submit: function () {
  115. let that = this;
  116. if (that.data.aftersale.type == undefined) {
  117. util.showErrorToast('请选择退款类型');
  118. return false;
  119. }
  120. if (that.data.reason == '') {
  121. util.showErrorToast('请输入退款原因');
  122. return false;
  123. }
  124. wx.showLoading({
  125. title: '提交中...',
  126. mask: true,
  127. success: function () {
  128. }
  129. });
  130. util.request(api.AftersaleSubmit, that.data.aftersale, 'POST').then(function (res) {
  131. wx.hideLoading();
  132. if (res.errno === 0) {
  133. wx.showToast({
  134. title: '申请售后成功',
  135. icon: 'success',
  136. duration: 2000,
  137. complete: function () {
  138. wx.switchTab({
  139. url: '/pages/ucenter/index/index'
  140. });
  141. }
  142. });
  143. } else {
  144. util.showErrorToast(res.errmsg);
  145. }
  146. });
  147. },
  148. onReady: function () {
  149. // 页面渲染完成
  150. },
  151. onShow: function () {
  152. // 页面显示
  153. },
  154. onHide: function () {
  155. // 页面隐藏
  156. },
  157. onUnload: function () {
  158. // 页面关闭
  159. }
  160. })