applyRefund.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. // pages/applyRefund/applyRefund.js
  2. var http = require('../../utils/http.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. applyType: 1, //退款方式(1:仅退款 2退款退货)
  9. refundItem: {}, //订单项数据
  10. show:false,
  11. isAll:false,
  12. photoFiles: [], //凭证图片列表
  13. buyerDesc: '', //备注说明
  14. goodList:[],
  15. reasonList:[
  16. {name:'暂不需要商品(买错/多买/漏买)'},
  17. {name:'冰品融化'},
  18. {name:'订单中有商品发错'},
  19. {name:'商品斤两不足'},
  20. {name:'商品临期到期'},
  21. {name:'商品破损/包装破损'},
  22. {name:'商品质量问题'},
  23. {name:'实物与图文描述不符'},
  24. {name:'商家通知我卖完了'},
  25. {name:'所有商品未收到'},
  26. {name:'整个订单送错'},
  27. {name:'订单少选且商家未通知我'},
  28. {name:'未在约定时间送达'},
  29. ],
  30. buyerReason: '', //退款原因
  31. total:0,
  32. refundId:0,//再次申请售后id
  33. },
  34. /**
  35. * 生命周期函数--监听页面加载
  36. */
  37. onLoad(options) {
  38. let refundId = options.refundId || 0
  39. var refundItem
  40. if(refundId){//再次申请
  41. this.loadOrderDetail(options.orderNumber,refundId)
  42. }else{
  43. refundItem = wx.getStorageSync("refundItem");
  44. console.log('拿到缓存里的订单项数据refundItem:',refundItem)
  45. refundItem.orderItemDtos.forEach(item=>{
  46. item.num = 1
  47. item.checked = true
  48. })
  49. this.setData({
  50. refundId,
  51. refundItem: refundItem,
  52. orderNumber: refundItem.orderNumber,
  53. goodsNum: refundItem.prodCount,
  54. actualTotal: refundItem.actualTotal, //总额
  55. isLastProd: refundItem.isLastProd, //是否最后一样商品
  56. addTransfee: refundItem.addTransfee, //只有一件商品可以退运费
  57. orderScore: refundItem.useScore // 单个退积分
  58. })
  59. this.totalPrice()
  60. this.checkAll()
  61. }
  62. },
  63. /**
  64. * 评价图片预览
  65. */
  66. picPreView(e){
  67. var index = e.currentTarget.dataset.index
  68. var urls = []
  69. this.data.photoFiles.forEach(el => {
  70. urls.push(el.url)
  71. })
  72. wx.previewImage({
  73. current: urls[index],
  74. urls: urls
  75. })
  76. },
  77. // 实时监听输入
  78. onInput: function(e) {
  79. // e.detail.value 即为当前输入的内容
  80. this.setData({
  81. buyerDesc: e.detail.value
  82. });
  83. },
  84. /**
  85. * 加载订单数据
  86. */
  87. loadOrderDetail: function(orderNumber,refundId) {
  88. var ths = this;
  89. wx.showLoading();
  90. //加载订单详情
  91. var params = {
  92. url: "/p/myOrder/orderDetail",
  93. method: "GET",
  94. data: {
  95. orderNumber
  96. },
  97. callBack: function(res) {
  98. res.orderItemDtos.forEach(item=>{
  99. item.num = 1
  100. item.checked = true
  101. })
  102. wx.hideLoading();
  103. ths.setData({
  104. refundId,
  105. refundItem: res,
  106. orderNumber,
  107. goodsNum: res.prodCount,
  108. actualTotal: res.actualTotal, //总额
  109. isLastProd: res.isLastProd, //是否最后一样商品
  110. addTransfee: res.addTransfee, //只有一件商品可以退运费
  111. orderScore: res.useScore // 单个退积分
  112. })
  113. ths.totalPrice()
  114. ths.checkAll()
  115. }
  116. };
  117. http.request(params);
  118. },
  119. /**
  120. * 提交退款
  121. */
  122. apply(){
  123. console.log(this.data.refundItem.orderItemDtos,this.data.refundItem.orderItemDtos.some(i=>i.checked));
  124. // 检查数据完整性
  125. if (this.data.buyerReason === '') {
  126. return wx.showToast({
  127. icon: 'none',
  128. title: '请选择退款原因',
  129. })
  130. }else if(!this.data.refundItem.orderItemDtos.some(i=>i.checked)){
  131. return wx.showToast({
  132. icon: 'none',
  133. title: '请选择退款商品',
  134. })
  135. }
  136. wx.showLoading();
  137. var pics = '';
  138. this.data.photoFiles.forEach(function (item) {
  139. pics += item.path + ',';
  140. });
  141. if (pics != '') {
  142. pics = pics.substring(0, pics.length - 1)
  143. }
  144. let goodsNum = 0
  145. let refundAmount = this.data.total
  146. let orderRefundSkuList = []
  147. this.data.refundItem.orderItemDtos.forEach(item=>{
  148. if(item.checked){
  149. orderRefundSkuList.push({
  150. "productCount": item.num,
  151. "skuId": item.skuId,
  152. "skuPrice": item.price,
  153. "orderItemId": item.orderItemId,
  154. })
  155. goodsNum+=item.num
  156. }
  157. })
  158. if(this.data.refundItem.actualTotal == 0){//积分支付 不用管退款金额
  159. refundAmount = 0
  160. }else if(refundAmount>=this.data.refundItem.actualTotal){//支付了钱的订单 并且退款钱超过实际支付钱 传实际支付金额
  161. refundAmount = this.data.refundItem.actualTotal
  162. }
  163. let data = {
  164. orderNumber: this.data.orderNumber, //订单编号
  165. applyType: this.data.applyType, //退款方式(1:仅退款 2退款退货)
  166. isReceiver: this.data.applyType == 1?0:1, //货物状态(1:已收到货 0:未收到货)
  167. buyerReason: this.data.reasonList[this.data.buyerReason].name, //退款原因
  168. goodsNum, //退款数量(0或不传值则为全部数量)
  169. refundAmount: refundAmount, //退款金额
  170. freightAmount:this.data.refundItem.transfee,
  171. buyerMobile: this.data.refundItem.userAddrDto.mobile, //手机号码(默认当前订单手机号码)
  172. buyerDesc: this.data.buyerDesc, //备注说明
  173. photoFiles: pics, //凭证图片列表
  174. refundType: goodsNum == this.data.refundItem.totalNum ?1:2, //退款单类型(1:整单退款,2:单个物品退款)
  175. orderRefundSkuList: orderRefundSkuList
  176. }
  177. if(this.data.refundId){//再次申请
  178. data.refundId = this.data.refundId
  179. console.log('再次申请');
  180. }else{
  181. console.log('申请');
  182. }
  183. var params = {
  184. url:this.data.refundId?"/p/orderRefund/applyAgain": "/p/orderRefund/apply",
  185. method: "POST",
  186. data,
  187. callBack: (res) => {
  188. wx.hideLoading();
  189. if(res.code == 500){
  190. return wx.showToast({
  191. title: res.msg,
  192. icon:'none'
  193. })
  194. }
  195. // 去到我的退款订单页面
  196. wx.redirectTo({
  197. url: '/pages/afterSales/afterSales',
  198. })
  199. }
  200. };
  201. http.request(params);
  202. },
  203. /**
  204. * 打开选择原因弹窗
  205. */
  206. choose(){
  207. this.setData({
  208. show:true
  209. })
  210. },
  211. close(){
  212. this.setData({
  213. show:false
  214. })
  215. },
  216. /**
  217. * 选择原因
  218. */
  219. chooseReason(e){
  220. console.log(e);
  221. this.setData({
  222. buyerReason:Number(e.detail.value)
  223. })
  224. },
  225. /**
  226. * 确认原因
  227. */
  228. submitReason(){
  229. this.setData({
  230. show:false
  231. })
  232. },
  233. /** */
  234. delImg(e){
  235. let index = e.currentTarget.dataset.index
  236. let photoFiles = this.data.photoFiles
  237. photoFiles.splice(index,1)
  238. this.setData({
  239. photoFiles: photoFiles
  240. })
  241. },
  242. /**
  243. * 上传图片
  244. */
  245. getUploadImg: function(e) {
  246. console.log('上传图片开始');
  247. if(this.data.photoFiles.length == 5){
  248. return wx.showToast({
  249. title: '最多可上传5张图片',
  250. })
  251. }
  252. var ths = this;
  253. wx.chooseMedia({
  254. count: 1, // 默认9
  255. mediaType: ['image'],
  256. sourceType: ['album', 'camera'],
  257. maxDuration: 30,
  258. success: function(res) {
  259. console.log('选择图片完成:',res);
  260. // 图片的本地临时文件路径列表
  261. var tempFilePaths = res.tempFiles[0].tempFilePath;
  262. wx.showLoading({
  263. mask: true
  264. })
  265. var params = {
  266. url: "/p/file/upload",
  267. filePath: tempFilePaths,
  268. name: 'file',
  269. callBack: function(res2) {
  270. console.log('上传接口:',res2);
  271. wx.hideLoading();
  272. var img = {};
  273. img.path = JSON.parse(res2).filePath;
  274. img.url = JSON.parse(res2).resourcesUrl + JSON.parse(res2).filePath;
  275. var photoFiles = ths.data.photoFiles;
  276. photoFiles.push(img);
  277. ths.setData({
  278. photoFiles: photoFiles
  279. })
  280. }
  281. };
  282. http.upload(params);
  283. }
  284. })
  285. },
  286. /**
  287. * 选择类型
  288. */
  289. radioChange(e){
  290. console.log(e);
  291. this.setData({
  292. applyType:e.detail.value
  293. })
  294. },
  295. /**
  296. * 全选
  297. */
  298. onSelectedAll(e){
  299. console.log(e,this.data);
  300. let isAll = !this.data.isAll
  301. let refundItem = this.data.refundItem
  302. refundItem.orderItemDtos.forEach(item=>{
  303. item.checked = isAll
  304. })
  305. this.setData({
  306. isAll,
  307. refundItem
  308. })
  309. this.totalPrice()
  310. },
  311. /**
  312. * 单选
  313. */
  314. onSelectedItem(e){
  315. let index = e.currentTarget.dataset.index
  316. let refundItem = this.data.refundItem
  317. refundItem.orderItemDtos[index].checked = !refundItem.orderItemDtos[index].checked
  318. this.setData({
  319. refundItem
  320. })
  321. this.checkAll()
  322. this.totalPrice()
  323. },
  324. /**
  325. * 检查全选状态
  326. */
  327. checkAll(){
  328. let isAll = this.data.refundItem.orderItemDtos.every(i=>i.checked)
  329. this.setData({
  330. isAll
  331. })
  332. },
  333. /**
  334. * 计算总价
  335. */
  336. totalPrice(){
  337. let total = 0
  338. let num = 0
  339. this.data.refundItem.orderItemDtos.forEach(item=>{
  340. if(item.checked){
  341. total+=((item.price*100)*(item.num*100))/10000
  342. num+=item.num
  343. }
  344. })
  345. if(num == this.data.refundItem.totalNum){//全部商品退款 +运费
  346. total= (total*100+ this.data.refundItem.transfee*100)/100
  347. }
  348. this.setData({
  349. total
  350. })
  351. },
  352. /**
  353. * 操作数量
  354. */
  355. changeNum(e){
  356. let index = e.currentTarget.dataset.index
  357. let num = e.currentTarget.dataset.num
  358. let refundItem = this.data.refundItem
  359. if(num == -1&&refundItem.orderItemDtos[index].num == 1){
  360. return wx.showToast({
  361. title: '数量不能小于1',
  362. duration: 1200,
  363. icon: 'none',
  364. })
  365. }else if(num == 1&&refundItem.orderItemDtos[index].num == refundItem.orderItemDtos[index].prodCount){
  366. return wx.showToast({
  367. title: '不能超过购买数量',
  368. duration: 1200,
  369. icon: 'none',
  370. })
  371. }
  372. refundItem.orderItemDtos[index].num +=num
  373. this.setData({
  374. refundItem
  375. })
  376. this.totalPrice()
  377. },
  378. /**
  379. * 生命周期函数--监听页面初次渲染完成
  380. */
  381. onReady() {
  382. },
  383. /**
  384. * 生命周期函数--监听页面显示
  385. */
  386. onShow() {
  387. },
  388. /**
  389. * 生命周期函数--监听页面隐藏
  390. */
  391. onHide() {
  392. },
  393. /**
  394. * 生命周期函数--监听页面卸载
  395. */
  396. onUnload() {
  397. },
  398. /**
  399. * 页面相关事件处理函数--监听用户下拉动作
  400. */
  401. onPullDownRefresh() {
  402. },
  403. /**
  404. * 页面上拉触底事件的处理函数
  405. */
  406. onReachBottom() {
  407. },
  408. /**
  409. * 用户点击右上角分享
  410. */
  411. onShareAppMessage() {
  412. }
  413. })