aftersale.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. let urls=[];
  52. fileList.forEach(function(e){
  53. urls.push(e.url);
  54. })
  55. this.setData({
  56. "aftersale.pictures": urls
  57. })
  58. },
  59. afterRead(event) {
  60. const { file } = event.detail
  61. let that = this
  62. const uploadTask = wx.uploadFile({
  63. url: api.StorageUpload,
  64. filePath: file.path,
  65. name: 'file',
  66. success: function (res) {
  67. var _res = JSON.parse(res.data);
  68. if (_res.errno === 0) {
  69. var url = _res.data.url
  70. that.data.aftersale.pictures.push(url)
  71. const { fileList = [] } = that.data;
  72. fileList.push({ ...file, url: url });
  73. that.setData({
  74. fileList: fileList
  75. })
  76. }
  77. },
  78. fail: function (e) {
  79. wx.showModal({
  80. title: '错误',
  81. content: '上传失败',
  82. showCancel: false
  83. })
  84. },
  85. })
  86. },
  87. previewImage: function (e) {
  88. wx.previewImage({
  89. current: e.currentTarget.id, // 当前显示图片的http链接
  90. urls: this.data.files // 需要预览的图片http链接列表
  91. })
  92. },
  93. contentInput: function (e) {
  94. this.setData({
  95. contentLength: e.detail.cursor,
  96. 'aftersale.comment': e.detail.value,
  97. });
  98. },
  99. onReasonChange: function (e) {
  100. this.setData({
  101. 'aftersale.reason': e.detail,
  102. });
  103. },
  104. showTypePicker: function () {
  105. this.setData({
  106. showPicker: true,
  107. });
  108. },
  109. onCancel: function () {
  110. this.setData({
  111. showPicker: false,
  112. });
  113. },
  114. onConfirm: function (event) {
  115. this.setData({
  116. 'aftersale.type': event.detail.index,
  117. 'aftersale.typeDesc': event.detail.value,
  118. showPicker: false,
  119. });
  120. },
  121. submit: function () {
  122. let that = this;
  123. if (that.data.aftersale.type == undefined) {
  124. util.showErrorToast('请选择退款类型');
  125. return false;
  126. }
  127. console.log(that.data.aftersale.reason);
  128. if (that.data.aftersale.reason == '') {
  129. util.showErrorToast('请输入退款原因');
  130. return false;
  131. }
  132. wx.showLoading({
  133. title: '提交中...',
  134. mask: true,
  135. success: function () {
  136. }
  137. });
  138. util.request(api.AftersaleSubmit, that.data.aftersale, 'POST').then(function (res) {
  139. wx.hideLoading();
  140. if (res.errno === 0) {
  141. wx.showToast({
  142. title: '申请售后成功',
  143. icon: 'success',
  144. duration: 2000,
  145. complete: function () {
  146. wx.redirectTo({
  147. url: '/pages/ucenter/aftersaleList/aftersaleList'
  148. });
  149. }
  150. });
  151. } else {
  152. util.showErrorToast(res.errmsg);
  153. }
  154. });
  155. },
  156. onReady: function () {
  157. // 页面渲染完成
  158. },
  159. onShow: function () {
  160. // 页面显示
  161. },
  162. onHide: function () {
  163. // 页面隐藏
  164. },
  165. onUnload: function () {
  166. // 页面关闭
  167. }
  168. })