applyRefund.js 8.3 KB

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