applyRefund.js 9.0 KB

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