applyRefund.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../config/api.js');
  3. Page({
  4. data: {
  5. index:'',
  6. orderId: 0,
  7. orderInfo: {},
  8. orderGoods: [],
  9. aftersale: {
  10. pictures: [],
  11. typeDesc:'',
  12. reason:'',
  13. amount:''
  14. },
  15. reasonActive:{
  16. id:'',
  17. name:''
  18. },
  19. reasonPopupShow:false,
  20. reasonList:[],
  21. columns: ['地址约错', '约不到想要的服务时间','活动/优惠未享受','服务质量问题'],
  22. contentLength: 0,
  23. fileList: [],
  24. imgList:[],
  25. },
  26. onLoad: function (options) {
  27. // 页面初始化 options为页面跳转所带来的参数
  28. this.setData({
  29. orderId: options.id
  30. });
  31. this.getOrderDetail();
  32. this.getRefudnType();
  33. this.getAmount();
  34. },
  35. getRefudnType() {
  36. let that = this;
  37. util.request(api.AftersaleRefundType).then(function (res) {
  38. if (res.errno === 0) {
  39. that.setData({
  40. reasonList: res.data,
  41. columns: res.data.map((obj => obj.name))
  42. })
  43. console.info(that.data.refundTypes)
  44. }
  45. });
  46. },
  47. getAmount:function(){
  48. util.request(api.AftersaleAmount, {
  49. orderId: this.data.orderId
  50. }).then(res=> {
  51. if (res.errno === 0) {
  52. console.log(res.data);
  53. this.setData({
  54. 'aftersale.amount': res.data.refundAmount
  55. });
  56. }
  57. });
  58. },
  59. getOrderDetail: function () {
  60. wx.showLoading({
  61. title: '加载中'
  62. });
  63. setTimeout(function () {
  64. wx.hideLoading();
  65. }, 2000);
  66. let that = this;
  67. util.request(api.OrderDetail, {
  68. orderId: that.data.orderId
  69. }).then(function (res) {
  70. if (res.errno === 0) {
  71. console.log(res.data);
  72. that.setData({
  73. orderInfo: res.data,
  74. });
  75. }
  76. wx.hideLoading();
  77. });
  78. },
  79. deleteImage(event) {
  80. const {
  81. fileList = []
  82. } = this.data;
  83. fileList.splice(event.detail.index, 1);
  84. this.setData({
  85. fileList: fileList
  86. });
  87. let urls = [];
  88. fileList.forEach(function (e) {
  89. urls.push(e.url);
  90. });
  91. this.setData({
  92. "aftersale.pictures": urls
  93. });
  94. },
  95. afterRead(event) {
  96. const {
  97. file
  98. } = event.detail;
  99. let that = this;
  100. const uploadTask = wx.uploadFile({
  101. url: api.StorageUpload,
  102. filePath: file.path,
  103. name: 'file',
  104. success: function (res) {
  105. var _res = JSON.parse(res.data);
  106. if (_res.errno === 0) {
  107. var url = _res.data.url;
  108. that.data.aftersale.pictures.push(url);
  109. const {
  110. fileList = []
  111. } = that.data;
  112. fileList.push({
  113. ...file,
  114. url: url
  115. });
  116. that.setData({
  117. fileList: fileList
  118. });
  119. }
  120. },
  121. fail: function (e) {
  122. wx.showModal({
  123. title: '错误',
  124. content: '上传失败',
  125. showCancel: false
  126. });
  127. }
  128. });
  129. },
  130. previewImage: function (e) {
  131. wx.previewImage({
  132. current: e.currentTarget.id,
  133. // 当前显示图片的http链接
  134. urls: this.data.files // 需要预览的图片http链接列表
  135. });
  136. },
  137. contentInput: function (e) {
  138. this.setData({
  139. contentLength: e.detail.cursor,
  140. 'aftersale.comment': e.detail.value
  141. });
  142. },
  143. onReasonChange: function (e) {
  144. console.log(e);
  145. this.setData({
  146. 'aftersale.reason': e.detail.value
  147. });
  148. },
  149. onCommentChange: function (e) {
  150. console.log(e);
  151. this.setData({
  152. 'aftersale.comment': e.detail.value
  153. });
  154. },
  155. showTypePicker: function () {
  156. this.setData({
  157. showPicker: true
  158. });
  159. },
  160. onCancel: function () {
  161. this.setData({
  162. showPicker: false
  163. });
  164. },
  165. bindPickerChange: function (event) {
  166. console.log(event);
  167. this.setData({
  168. 'aftersale.type': event.detail.value,
  169. 'aftersale.typeDesc': this.data.columns[event.detail.value],
  170. });
  171. },
  172. submit: function () {
  173. let that = this;
  174. if (that.data.reasonActive.id == '') {
  175. util.showErrorToast('请选择退款原因');
  176. return false;
  177. }
  178. if (that.data.aftersale.reason == '') {
  179. util.showErrorToast('请填写补充描述');
  180. return false;
  181. }
  182. // let name = that.data.aftersale.typeDesc;
  183. // let vals = this.data.refundTypes.filter(item =>item.name == name);
  184. // that.setData({
  185. // type:vals[0].id
  186. // })
  187. // console.log(that.data.aftersale);
  188. // if (that.data.aftersale.reason == '') {
  189. // util.showErrorToast('请输入退款原因');
  190. // return false;
  191. // }
  192. wx.showLoading({
  193. title: '提交中...',
  194. mask: true,
  195. success: function () {}
  196. });
  197. // this.setData({
  198. // "aftersale.pictures": this.data.imgList
  199. // });
  200. let params={
  201. orderId:this.data.orderId,
  202. pictures: this.data.imgList,
  203. type:this.data.reasonActive.id,
  204. typeDesc:this.data.reasonActive.name,
  205. reason:this.data.aftersale.reason,
  206. amount:this.data.aftersale.amount
  207. }
  208. util.request(api.AftersaleSubmit, params, 'POST').then(function (res) {
  209. wx.hideLoading();
  210. if (res.errno === 0) {
  211. wx.showToast({
  212. title: '申请售后成功',
  213. icon: 'success',
  214. duration: 2000,
  215. complete: function () {
  216. wx.navigateBack({
  217. delta: 1
  218. });
  219. // wx.redirectTo({
  220. // url: '/pages/ucenter/aftersaleList/aftersaleList'
  221. // });
  222. }
  223. });
  224. } else {
  225. util.showErrorToast(res.errmsg);
  226. }
  227. });
  228. },
  229. previewImg(e){
  230. let img=e.currentTarget.dataset.img;
  231. let imgs=this.data.imgList
  232. wx.previewImage({
  233. current:img , // 当前显示图片的http链接
  234. urls:imgs // 需要预览的图片http链接列表
  235. })
  236. },
  237. delImg(e){
  238. let imgs=this.data.imgList;
  239. let index=e.currentTarget.dataset.index;
  240. imgs.splice(index,1);
  241. this.setData({
  242. imgList:imgs
  243. })
  244. },
  245. uploadImg(){
  246. if(this.data.imgList.length>=3){
  247. wx.showToast({
  248. title: '最多上传3张图片',
  249. icon: 'none',
  250. duration: 2000
  251. });
  252. return false;
  253. }
  254. let that=this;
  255. let count= 3-that.data.imgList.length;
  256. wx.chooseImage({
  257. count:count,
  258. sizeType: ['original', 'compressed'],
  259. sourceType: ['album', 'camera'],
  260. success: function (res) {
  261. console.log(res);
  262. let tempFilePaths=res.tempFilePaths;
  263. wx.showLoading({
  264. title: '上传中...',
  265. });
  266. for(let i=0;i<tempFilePaths.length;i++){
  267. let imgs=that.data.imgList;
  268. if(imgs.length>=3){
  269. that.setData({
  270. imgList:imgs
  271. });
  272. return false;
  273. }else{
  274. wx.uploadFile({
  275. url: api.StorageUpload,
  276. filePath: tempFilePaths[i],
  277. name: 'file',
  278. success (res){
  279. console.log(res);
  280. let data=JSON.parse(res.data);
  281. if(data.errno==0){
  282. imgs.push(data.data.url);
  283. that.setData({
  284. imgList:imgs
  285. });
  286. }else{
  287. console.log('上传失败')
  288. }
  289. }
  290. })
  291. }
  292. }
  293. wx.hideLoading();
  294. }
  295. });
  296. },
  297. onReady: function () {
  298. // 页面渲染完成
  299. },
  300. onShow: function () {
  301. // 页面显示
  302. },
  303. onHide: function () {
  304. // 页面隐藏
  305. },
  306. onUnload: function () {
  307. // 页面关闭
  308. },
  309. showReason(){
  310. this.setData({
  311. reasonPopupShow:true
  312. })
  313. },
  314. onReasonPopupClose(){
  315. this.setData({
  316. reasonPopupShow:false
  317. });
  318. },
  319. onReasonClick(){
  320. //阻止事件冒泡,不要删
  321. },
  322. reasonItemSelect(e){
  323. let reason=e.currentTarget.dataset.reason;
  324. this.setData({
  325. reasonActive:reason,
  326. });
  327. },
  328. reasonItemConfirm(){
  329. if (this.data.reasonActive.id === '') {
  330. util.showErrorToast("请选择退款原因");
  331. return false;
  332. }
  333. this.setData({
  334. reasonPopupShow:false
  335. });
  336. },
  337. });