applyRefund.js 10 KB

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