DetailsOfRefund.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. // pages/DetailsOfRefund/DetailsOfRefund.js
  2. var http = require('../../utils/http.js');
  3. var util = require('../../utils/util.js');
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. showView: true, //隐藏是展示
  10. applyTime: '', //申请时间
  11. applyType: 1, //申请类型:1,仅退款,2退款退货
  12. dvyType: 1, //配送类型 1:快递 2:自提 3:及时配送
  13. isReturnLogistics: false, //配送类型 1:快递 2:自提 3:及时配送
  14. goodsNum: '', //退货数量
  15. handelTime: '', //卖家处理时间
  16. orderAmount: '', //订单总金额
  17. orderItems: {}, //订单项
  18. refundAmount: '', //退款金额
  19. goodsTotal:0,
  20. records:[],//退款流程
  21. offsetPoints:0,//退还积分
  22. refundExpiredScore:0,//过期积分
  23. freightAmount:0,
  24. refundStatusObj:{
  25. 1:'申请原因',
  26. 2:'商家待审核',
  27. 3:'申请已通过',
  28. 4:'用户撤回申请',
  29. 5:'用户待发货',
  30. // 6:'待填写配送信息',
  31. 7:'商家待收货',
  32. 10:'审核通过',
  33. 20:'驳回',
  34. 25:'已收货',
  35. 30:'退款成功',
  36. },
  37. refundDelivery: [], //收货地址对象
  38. refundId: '', //记录ID
  39. refundTime: '', //退款时间
  40. returnMoneySts: 1, //处理退款状态:(1.买家申请 2.卖家接受 3.买家发货 4.卖家收货 5.退款成功 6.买家撤回申请 7.商家拒绝 -1.退款关闭)
  41. updateTime: '', //更新时间
  42. refundSn: '', //退款编号
  43. rejectMessage: '', //拒绝理由
  44. buyerReason: '', //退款原因
  45. shopName: '', //店铺名称
  46. refundScore: 0, // 退款积分
  47. photoFiles:[],
  48. refundPhotoFiles:[],//退货物流图片
  49. addCarshow: false,
  50. selectTimeshow: false,
  51. flowShow: false,
  52. userAddrDto: {},
  53. payer: '',
  54. sendPay:'',
  55. sts: 0,
  56. nomDay: '',
  57. tomorrowDay: '',
  58. timeIntervals: [],
  59. columns: [],
  60. selectTimeshow: false,
  61. time: '',//取件时间
  62. userAddr: '',//取件地址
  63. shopInfo:null,
  64. sendInfo: {},
  65. currentSelectedIndex: -1, // 初始没有选中项,索引设为 -1
  66. cancelPay: false,
  67. remainingTime: '',
  68. timeFormat: '',
  69. orderNumSend:'',
  70. countdown_hours:'',
  71. countdown_minutes:'',
  72. statusObj:{
  73. 10:{
  74. title:'待审核',
  75. desc:'等待商家处理申请'
  76. },
  77. 20:{
  78. title:'处理中',
  79. desc:'申请通过后,将退回至原账户'
  80. },
  81. 30:{
  82. title:'驳回退款',
  83. desc:'您的申请已被商家拒绝'
  84. },
  85. 40:{
  86. title:'撤销退款',
  87. desc:'您已主动取消退款申请,如有需要可再次申请。'
  88. },
  89. 60:{
  90. title:'待退货',
  91. desc:''
  92. },
  93. 65:{
  94. title:'待商家收货',
  95. desc:'待商家收到商品,并确认不影响二次销售后,将为您退款'
  96. },
  97. 70:{
  98. title:'退款完成',
  99. desc:'申请已通过,已退回至原账户'
  100. },
  101. }
  102. },
  103. /**
  104. * 生命周期函数--监听页面加载
  105. */
  106. onLoad(options) {
  107. this.setData({
  108. orderNumSend:options.orderNumber
  109. })
  110. this.setData({
  111. refundSn: options.refundSn,
  112. });
  113. if(options.userAddrDto){
  114. this.setData({
  115. userAddrDto: JSON.parse(options.userAddrDto)
  116. })
  117. }
  118. //获取退款申请详情
  119. this.getRefundDetail()
  120. },
  121. // 配送退货提交
  122. submit(e){
  123. console.log(e);
  124. if(!this.data.time){
  125. return wx.showToast({
  126. title:'请选择时间',
  127. icon:'none'
  128. })
  129. }else if(!e.currentTarget.dataset.info){
  130. return wx.showToast({
  131. title:'请选择收件地址',
  132. icon:'none'
  133. })
  134. }
  135. let that = this
  136. var params = {
  137. url: "/p/appointment",
  138. method: "POST",
  139. data: {
  140. appointmentTime:that.data.time,
  141. deliveryAddress:e.currentTarget.dataset.info.address+e.currentTarget.dataset.info.addressName,
  142. customerName:e.currentTarget.dataset.info.receiver,
  143. refundNumber:that.data.refundSn,
  144. phoneNumber:e.currentTarget.dataset.info.mobile,
  145. refundMethod:1,
  146. },
  147. callBack: (res)=> {
  148. //获取退款申请详情
  149. that.getRefundDetail()
  150. }
  151. }
  152. http.request(params);
  153. },
  154. // 获取配送退货填写内容
  155. getRefundWriteInfo(){
  156. let that = this
  157. var params = {
  158. url: "/p/appointment/"+this.data.refundSn,
  159. method: "GET",
  160. data: {
  161. },
  162. callBack: (res)=> {
  163. let userAddr = {}
  164. userAddr.addrDetail = ''
  165. userAddr.addressName = res.data.deliveryAddress
  166. userAddr.receiver = res.data.customerName
  167. userAddr.mobile = res.data.phoneNumber
  168. that.setData({
  169. time:res.data.appointmentTime,
  170. userAddr
  171. })
  172. console.log(that.data.time);
  173. }
  174. }
  175. http.request(params);
  176. },
  177. /**
  178. * 获取退款申请详情
  179. */
  180. getRefundDetail: function (e) {
  181. var ths = this;
  182. // wx.showLoading({})
  183. var params = {
  184. url: "/p/orderRefund/info",
  185. method: "GET",
  186. data: {
  187. refundSn: this.data.refundSn //退款编号
  188. },
  189. callBack: function (res) {
  190. let img=''
  191. res.orderItems.map(item=>{
  192. img=item.pic.split(',')
  193. item.pic=img[0]
  194. })
  195. let photoFiles = []
  196. let refundPhotoFiles = []
  197. if(res.photoFiles){
  198. photoFiles = res.photoFiles.split(',')
  199. }
  200. if(res.refundDelivery.imgs){
  201. refundPhotoFiles = res.refundDelivery.imgs.split(',')
  202. }
  203. if(res.returnMoneySts == 60&&res.applyType == 2&&res.dvyType==1){//快递寄回
  204. ths.getShopAddress(res.refundDelivery.shopId)
  205. }else if((res.returnMoneySts == 65||res.returnMoneySts == 70)&&res.applyType == 2&&res.dvyType==3&&res.isReturnLogistics){
  206. ths.getRefundWriteInfo()
  207. }
  208. ths.setData({
  209. applyTime: res.applyTime, //申请时间
  210. applyType: res.applyType, //申请类型:1,仅退款,2退款退货
  211. dvyType: res.dvyType, //配送类型 1:快递 2:自提 3:及时配送
  212. isReturnLogistics: res.isReturnLogistics, //配送类型 1:快递 2:自提 3:及时配送
  213. goodsNum: res.goodsNum, //退货数量
  214. handelTime: res.handelTime, //卖家处理时间
  215. orderAmount: res.orderAmount, //订单总金额
  216. orderItems: res.orderItems, //订单项
  217. orderNumber: res.orderNumber, //订单项
  218. refundSn: res.refundSn, //退款编号
  219. refundAmount: res.refundAmount, //实际退款金额
  220. goodsTotal:res.goodsTotal,//总共退款价值
  221. records:res.records,//退款流程
  222. offsetPoints:res.offsetPoints,//退还积分
  223. refundExpiredScore:res.refundExpiredScore,//过期积分
  224. freightAmount:res.freightAmount,
  225. refundDelivery: res.refundDelivery, //收货地址对象
  226. refundId: res.refundId, //记录ID
  227. refundTime: res.refundTime, //退款时间
  228. returnMoneySts: res.returnMoneySts, //处理退款状态:(1.买家申请 2.卖家接受 3.买家发货 4.卖家收货 5.退款成功 6.买家撤回申请 7.商家拒绝 -1.退款关闭)
  229. updateTime: res.updateTime, //更新时间
  230. rejectMessage: res.rejectMessage, //拒绝理由
  231. buyerReason: res.buyerReason, //退款原因
  232. photoFiles, //图片
  233. refundPhotoFiles,//退款图片
  234. shopName: res.shopName,
  235. refundScore: res.refundScore, // 退款积分
  236. payer: res.refundDelivery.payer,//运费承担方
  237. sendPay:res.refundDelivery.deyNu //物流编号,判断是否提交成功
  238. })
  239. wx.hideLoading();
  240. // ths.get_countDown()
  241. }
  242. };
  243. http.request(params);
  244. },
  245. // 获取退货地址
  246. getShopAddress(shopId){
  247. var ths = this;
  248. var params = {
  249. url: "/p/refundAddr/info/"+shopId,
  250. method: "GET",
  251. callBack: res => {
  252. if(res.code == 200){
  253. ths.setData({
  254. shopInfo:res.data
  255. })
  256. }
  257. }
  258. };
  259. http.request(params);
  260. },
  261. // 一键复制事件
  262. copyBtn: function(e) {
  263. let data = e.currentTarget.dataset.value
  264. wx.setClipboardData({
  265. //准备复制的数据
  266. data,
  267. success: function(res) {
  268. wx.showToast({
  269. title: '复制成功',
  270. });
  271. }
  272. })
  273. },
  274. /**
  275. * 选择时间和地址
  276. */
  277. choose(e){
  278. let type = e.currentTarget.dataset.type
  279. if(type == 'time'){
  280. this.getDayTime()
  281. this.getTime()
  282. let day = []
  283. day.push({
  284. id: 1,
  285. text: this.data.nomDay
  286. }, {
  287. id: 2,
  288. text: this.data.tomorrowDay
  289. })
  290. let data = []
  291. data.push({
  292. values: day,
  293. className: 'column1',
  294. }, {
  295. values: this.data.timeIntervals,
  296. defaultIndex: 2,
  297. className: 'column2',
  298. })
  299. this.setData({
  300. selectTimeshow: true,
  301. columns: data
  302. })
  303. }else{//选择地址
  304. wx.navigateTo({
  305. url: '/pages/delivery-address/delivery-address?order=write',
  306. })
  307. }
  308. },
  309. onCancel: function () {
  310. this.setData({
  311. selectTimeshow: false
  312. })
  313. },
  314. onConfirm(event) {
  315. const {
  316. picker,
  317. value,
  318. index
  319. } = event.detail;
  320. var currentDate = new Date();
  321. var currentYear = currentDate.getFullYear();
  322. if (value.length >= 2) {
  323. const text1 = value[0].text; //text1为12月25日
  324. const text2 = value[1].text.slice(0, 5); //text2为15:00
  325. const month = ("0" + (parseInt(text1.split("月")[0]))).slice(-2); // 将中文月格式转换为数字(注意要减1,因为月份是从0开始计数),并补0
  326. const day = text1.split("月")[1].split("日")[0];
  327. const hour = text2.split(":")[0];
  328. const minute = text2.split(":")[1];
  329. const combinedText = `${currentYear}-${month}-${day} ${hour}:${minute}:00`;
  330. let dateObj = new Date(combinedText);
  331. let timestamp = Math.floor(dateObj.getTime() / 1000);
  332. // 获取配送费
  333. let that = this
  334. console.log(combinedText);
  335. this.setData({
  336. time: combinedText,
  337. selectTimeshow: false
  338. });
  339. }
  340. },
  341. // 获取今明天并转换
  342. getDayTime: function () {
  343. const today = new Date();
  344. const month = (today.getMonth() + 1).toString().padStart(2, '0');
  345. const day = today.getDate().toString().padStart(2, '0');
  346. const todayFormat = `${month}月${day}日(今天)`;
  347. const tomorrow = new Date(today.getTime() + 24 * 60 * 60 * 1000);
  348. const tomorrowMonth = (tomorrow.getMonth() + 1).toString().padStart(2, '0');
  349. const tomorrowDay = tomorrow.getDate().toString().padStart(2, '0');
  350. const tomorrowFormat = `${tomorrowMonth}月${tomorrowDay}日(明天)`;
  351. this.setData({
  352. nomDay: todayFormat,
  353. tomorrowDay: tomorrowFormat
  354. })
  355. },
  356. // 时间段转换
  357. getTime: function (selectedDate) {
  358. const timeIntervals = [];
  359. // 如果没有传入日期参数(首次加载等情况),则使用当前日期
  360. const now = selectedDate ? new Date(selectedDate) : new Date();
  361. if (isNaN(now.getTime())) {
  362. console.error('传入的日期格式不正确,无法解析为有效日期');
  363. return;
  364. }
  365. const currentTimeStamp = now.getTime();
  366. for (let hour = 0; hour < 23; hour++) {
  367. const start = hour.toString().padStart(2, '0') + ':00';
  368. const end = (hour + 1).toString().padStart(2, '0') + ':00';
  369. const interval = start + '~' + end;
  370. // 创建对应时间段开始时间的日期对象
  371. const startDate = new Date(now);
  372. startDate.setHours(hour, 0, 0, 0);
  373. const startTimestamp = startDate.getTime();
  374. // 通过比较时间戳来判断时间段是否已过去
  375. const hidden = startTimestamp < currentTimeStamp;
  376. timeIntervals.push({
  377. text: interval,
  378. disabled: hidden
  379. });
  380. }
  381. this.setData({
  382. timeIntervals
  383. });
  384. },
  385. // 日期转换方法
  386. convertDateToNumber: function (dateStr) {
  387. if (!dateStr) {
  388. throw new Error('日期字符串不能为空');
  389. }
  390. dateStr = dateStr.trim();
  391. let parts = dateStr.match(/(\d+)月(\d+)日/);
  392. if (!parts) {
  393. throw new Error('日期格式不正确,请按照XX月XX日的格式输入');
  394. }
  395. return new Date(2024, parseInt(parts[1]) - 1, parseInt(parts[2]));
  396. },
  397. /**
  398. * 填写快递信息
  399. */
  400. writeInfo(e){
  401. var refundSn = e.currentTarget.dataset.refundsn;
  402. var type = e.currentTarget.dataset.type;
  403. wx.navigateTo({
  404. url: `/pages/writeReturnLogistics/writeReturnLogistics?refundSn=${refundSn}&shopId=${this.data.refundDelivery.shopId}&type=${type}`,
  405. })
  406. },
  407. /**
  408. * 生命周期函数--监听页面初次渲染完成
  409. */
  410. onReady() {
  411. },
  412. /**
  413. * 生命周期函数--监听页面显示
  414. */
  415. onShow() {
  416. },
  417. /**
  418. * 生命周期函数--监听页面隐藏
  419. */
  420. onHide() {
  421. },
  422. /**
  423. * 生命周期函数--监听页面卸载
  424. */
  425. onUnload() {
  426. },
  427. /**
  428. * 页面相关事件处理函数--监听用户下拉动作
  429. */
  430. onPullDownRefresh() {
  431. },
  432. /**
  433. * 页面上拉触底事件的处理函数
  434. */
  435. onReachBottom() {
  436. },
  437. /**
  438. * 用户点击右上角分享
  439. */
  440. onShareAppMessage() {
  441. }
  442. })