applyRefund.js 8.0 KB

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