aftersale.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. columns: ['不想要\不喜欢', '7天无理由退款', '搬家/出差', '重复购买', '地址超服务范围', '地址约错', '约不到想要的服务时间', '活动/优惠未享受', '服务质量问题'],
  13. contentLength: 0,
  14. refundTypes: [], //退款原因
  15. fileList: []
  16. },
  17. onLoad: function (options) {
  18. // 页面初始化 options为页面跳转所带来的参数
  19. this.setData({
  20. orderId: options.id
  21. });
  22. this.getOrderDetail();
  23. this.getRefudnType();
  24. },
  25. getRefudnType() {
  26. let that = this;
  27. util.request(api.AftersaleRefundType).then(function (res) {
  28. if (res.errno === 0) {
  29. that.setData({
  30. refundTypes: res.data,
  31. columns: res.data.map((obj => obj.name))
  32. })
  33. console.info(that.data.refundTypes)
  34. }
  35. });
  36. },
  37. getOrderDetail: function () {
  38. wx.showLoading({
  39. title: '加载中',
  40. });
  41. setTimeout(function () {
  42. wx.hideLoading()
  43. }, 2000);
  44. let that = this;
  45. util.request(api.OrderDetail, {
  46. orderId: that.data.orderId
  47. }).then(function (res) {
  48. if (res.errno === 0) {
  49. console.log(res.data);
  50. that.setData({
  51. orderInfo: res.data.orderInfo,
  52. orderGoods: res.data.orderGoods,
  53. 'aftersale.orderId': that.data.orderId,
  54. 'aftersale.amount': res.data.orderInfo.actualPrice - res.data.orderInfo.freightPrice
  55. });
  56. }
  57. wx.hideLoading();
  58. });
  59. },
  60. deleteImage(event) {
  61. const {
  62. fileList = []
  63. } = this.data;
  64. fileList.splice(event.detail.index, 1)
  65. this.setData({
  66. fileList: fileList
  67. })
  68. let urls = [];
  69. fileList.forEach(function (e) {
  70. urls.push(e.url);
  71. })
  72. this.setData({
  73. "aftersale.pictures": urls
  74. })
  75. },
  76. afterRead(event) {
  77. const {
  78. file
  79. } = event.detail
  80. let that = this
  81. const uploadTask = wx.uploadFile({
  82. url: api.StorageUpload,
  83. filePath: file.path,
  84. name: 'file',
  85. success: function (res) {
  86. var _res = JSON.parse(res.data);
  87. if (_res.errno === 0) {
  88. var url = _res.data.url
  89. that.data.aftersale.pictures.push(url)
  90. const {
  91. fileList = []
  92. } = that.data;
  93. fileList.push({
  94. ...file,
  95. url: url
  96. });
  97. that.setData({
  98. fileList: fileList
  99. })
  100. }
  101. },
  102. fail: function (e) {
  103. wx.showModal({
  104. title: '错误',
  105. content: '上传失败',
  106. showCancel: false
  107. })
  108. },
  109. })
  110. },
  111. previewImage: function (e) {
  112. wx.previewImage({
  113. current: e.currentTarget.id, // 当前显示图片的http链接
  114. urls: this.data.files // 需要预览的图片http链接列表
  115. })
  116. },
  117. contentInput: function (e) {
  118. this.setData({
  119. contentLength: e.detail.cursor,
  120. 'aftersale.comment': e.detail.value,
  121. });
  122. },
  123. onReasonChange: function (e) {
  124. this.setData({
  125. 'aftersale.reason': e.detail,
  126. });
  127. },
  128. showTypePicker: function () {
  129. this.setData({
  130. showPicker: true,
  131. });
  132. },
  133. onCancel: function () {
  134. this.setData({
  135. showPicker: false,
  136. });
  137. },
  138. onConfirm: function (event) {
  139. let name = event.detail.value;
  140. let typeId = 0;
  141. let vals = this.data.refundTypes.filter(item =>item.name == event.detail.value);
  142. typeId = vals[0].id;
  143. this.setData({
  144. //'aftersale.type': event.detail.index,
  145. //'aftersale.typeDesc': event.detail.value,
  146. 'aftersale.type': typeId,
  147. 'aftersale.typeDesc': name,
  148. showPicker: false,
  149. });
  150. },
  151. submit: function () {
  152. let that = this;
  153. if (that.data.aftersale.type == undefined) {
  154. util.showErrorToast('请选择退款类型');
  155. return false;
  156. }
  157. console.log(that.data.aftersale.reason);
  158. if (!that.data.aftersale.reason) {
  159. util.showErrorToast('请输入退款原因');
  160. return false;
  161. }
  162. wx.showLoading({
  163. title: '提交中...',
  164. mask: true,
  165. success: function () {
  166. }
  167. });
  168. util.request(api.AftersaleSubmit, that.data.aftersale, 'POST').then(function (res) {
  169. wx.hideLoading();
  170. if (res.errno === 0) {
  171. wx.showToast({
  172. title: '申请售后成功',
  173. icon: 'success',
  174. duration: 2000,
  175. complete: function () {
  176. wx.redirectTo({
  177. url: '/pages/ucenter/aftersaleList/aftersaleList'
  178. });
  179. }
  180. });
  181. } else {
  182. util.showErrorToast(res.errmsg);
  183. }
  184. });
  185. },
  186. onReady: function () {
  187. // 页面渲染完成
  188. },
  189. onShow: function () {
  190. // 页面显示
  191. },
  192. onHide: function () {
  193. // 页面隐藏
  194. },
  195. onUnload: function () {
  196. // 页面关闭
  197. }
  198. })