DetailsOfRefund.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  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. goodsNum: '', //退货数量
  13. handelTime: '', //卖家处理时间
  14. orderAmount: '', //订单总金额
  15. orderItems: {}, //订单项
  16. refundAmount: '', //退款金额
  17. refundDelivery: [], //收货地址对象
  18. refundId: '', //记录ID
  19. refundTime: '', //退款时间
  20. returnMoneySts: 1, //处理退款状态:(1.买家申请 2.卖家接受 3.买家发货 4.卖家收货 5.退款成功 6.买家撤回申请 7.商家拒绝 -1.退款关闭)
  21. updateTime: '', //更新时间
  22. refundSn: '', //退款编号
  23. rejectMessage: '', //拒绝理由
  24. buyerReason: '', //退款原因
  25. shopName: '', //店铺名称
  26. refundScore: 0, // 退款积分
  27. addCarshow: false,
  28. selectTimeshow: false,
  29. flowShow: false,
  30. userAddrDto: {},
  31. payer: '',
  32. sendPay:'',
  33. sts: 0,
  34. nomDay: '',
  35. tomorrowDay: '',
  36. timeIntervals: [],
  37. columns: [],
  38. combinedTextValue: '',
  39. sendInfo: {},
  40. currentSelectedIndex: -1, // 初始没有选中项,索引设为 -1
  41. steps: [{
  42. text: '步骤一',
  43. desc: '描述信息',
  44. inactiveIcon: 'location-o',
  45. activeIcon: 'success',
  46. },
  47. {
  48. text: '步骤二',
  49. desc: '描述信息',
  50. inactiveIcon: 'circle',
  51. activeIcon: 'plus',
  52. },
  53. {
  54. text: '步骤三',
  55. desc: '描述信息',
  56. inactiveIcon: 'circle',
  57. activeIcon: 'cross',
  58. },
  59. {
  60. text: '步骤四',
  61. desc: '描述信息',
  62. inactiveIcon: 'circle',
  63. activeIcon: 'fail',
  64. },
  65. ],
  66. cancelPay: false,
  67. remainingTime: '',
  68. timeFormat: '',
  69. orderNumSend:'',
  70. countdown_hours:'',
  71. countdown_minutes:''
  72. },
  73. /**
  74. * 生命周期函数--监听页面加载
  75. */
  76. onLoad: function (options) {
  77. this.setData({
  78. orderNumSend:options.orderNumber
  79. })
  80. this.getTime()
  81. this.setData({
  82. refundSn: options.refundSn,
  83. });
  84. if(options.userAddrDto){
  85. this.setData({
  86. userAddrDto: JSON.parse(options.userAddrDto)
  87. })
  88. }
  89. //获取退款申请详情
  90. this.getRefundDetail()
  91. },
  92. /**
  93. * 更多说明&收起
  94. */
  95. onChangeShowState: function () {
  96. var that = this;
  97. that.setData({
  98. showView: (!that.data.showView)
  99. })
  100. },
  101. // 发起配送
  102. sendDistribution: function () {
  103. this.setData({
  104. addCarshow: true
  105. })
  106. },
  107. onClose: function () {
  108. this.setData({
  109. addCarshow: false
  110. })
  111. },
  112. timeOnClose: function () {
  113. this.setData({
  114. selectTimeshow: false
  115. })
  116. },
  117. submitBtn:function(){
  118. if (Object.keys(this.data.sendInfo).length === 0) {
  119. wx.showToast({
  120. title: '请先选择取件时间',
  121. icon: 'none'
  122. })
  123. return
  124. }
  125. this.submitExpress()
  126. },
  127. submitExpress:function(){
  128. var params = {
  129. url: `/p/orderRefund/submitExpress/${this.data.refundSn}`,
  130. method: "GET",
  131. callBack: res => {
  132. wx.showToast({
  133. title: '提交成功',
  134. icon: 'none',
  135. })
  136. this.setData({
  137. addCarshow:false
  138. })
  139. this.getRefundDetail()
  140. }
  141. };
  142. http.request(params);
  143. },
  144. // 辅助函数,将中文日期格式转换为YYYY-MM-DD格式
  145. formatDate: function (dateStr) {
  146. let parts = dateStr.match(/(\d+)月(\d+)日/);
  147. if (parts) {
  148. let month = parseInt(parts[1]);
  149. let day = parseInt(parts[2]);
  150. let year = new Date().getFullYear();
  151. return `${year}-${month.toString().padStart(2, '0')}-${day.toString().padStart(2, '0')}`;
  152. }
  153. return dateStr;
  154. },
  155. selectUpTime: function () {
  156. this.getDayTime()
  157. this.getTime()
  158. let day = []
  159. day.push({
  160. id: 1,
  161. text: this.data.nomDay
  162. }, {
  163. id: 2,
  164. text: this.data.tomorrowDay
  165. })
  166. let data = []
  167. data.push({
  168. values: day,
  169. className: 'column1',
  170. }, {
  171. values: this.data.timeIntervals,
  172. defaultIndex: 2,
  173. className: 'column2',
  174. })
  175. this.setData({
  176. selectTimeshow: true,
  177. columns: data
  178. })
  179. },
  180. // 获取今明天并转换
  181. getDayTime: function () {
  182. const today = new Date();
  183. const month = (today.getMonth() + 1).toString().padStart(2, '0');
  184. const day = today.getDate().toString().padStart(2, '0');
  185. const todayFormat = `${month}月${day}日`;
  186. const tomorrow = new Date(today.getTime() + 24 * 60 * 60 * 1000);
  187. const tomorrowMonth = (tomorrow.getMonth() + 1).toString().padStart(2, '0');
  188. const tomorrowDay = tomorrow.getDate().toString().padStart(2, '0');
  189. const tomorrowFormat = `${tomorrowMonth}月${tomorrowDay}日`;
  190. this.setData({
  191. nomDay: todayFormat,
  192. tomorrowDay: tomorrowFormat
  193. })
  194. },
  195. // 时间段转换
  196. getTime: function (selectedDate) {
  197. const timeIntervals = [];
  198. // 如果没有传入日期参数(首次加载等情况),则使用当前日期
  199. const now = selectedDate ? new Date(selectedDate) : new Date();
  200. if (isNaN(now.getTime())) {
  201. console.error('传入的日期格式不正确,无法解析为有效日期');
  202. return;
  203. }
  204. const currentTimeStamp = now.getTime();
  205. for (let hour = 0; hour < 23; hour++) {
  206. const start = hour.toString().padStart(2, '0') + ':00';
  207. const end = (hour + 1).toString().padStart(2, '0') + ':00';
  208. const interval = start + '~' + end;
  209. // 创建对应时间段开始时间的日期对象
  210. const startDate = new Date(now);
  211. startDate.setHours(hour, 0, 0, 0);
  212. const startTimestamp = startDate.getTime();
  213. // 通过比较时间戳来判断时间段是否已过去
  214. const hidden = startTimestamp < currentTimeStamp;
  215. timeIntervals.push({
  216. text: interval,
  217. disabled: hidden
  218. });
  219. }
  220. this.setData({
  221. timeIntervals
  222. });
  223. },
  224. // 日期转换方法
  225. convertDateToNumber: function (dateStr) {
  226. if (!dateStr) {
  227. throw new Error('日期字符串不能为空');
  228. }
  229. dateStr = dateStr.trim();
  230. let parts = dateStr.match(/(\d+)月(\d+)日/);
  231. if (!parts) {
  232. throw new Error('日期格式不正确,请按照XX月XX日的格式输入');
  233. }
  234. return new Date(2024, parseInt(parts[1]) - 1, parseInt(parts[2]));
  235. },
  236. // 选择器change事件
  237. onChange(event) {
  238. const {
  239. picker,
  240. value,
  241. index
  242. } = event.detail;
  243. value.map((item, index) => {
  244. if (index === 0) {
  245. var date1 = this.convertDateToNumber(item.text);
  246. var date2 = new Date();
  247. if (date1 > date2) {
  248. this.updateTimeIntervalsDisabled(item.id);
  249. } else {
  250. this.updateTimeIntervalsDisabled(item.id);
  251. }
  252. }
  253. })
  254. },
  255. onConfirm(event) {
  256. const {
  257. picker,
  258. value,
  259. index
  260. } = event.detail;
  261. var currentDate = new Date();
  262. var currentYear = currentDate.getFullYear();
  263. if (value.length >= 2) {
  264. const text1 = value[0].text; //text1为12月25日
  265. const text2 = value[1].text.slice(0, 5); //text2为15:00
  266. const month = ("0" + (parseInt(text1.split("月")[0]))).slice(-2); // 将中文月格式转换为数字(注意要减1,因为月份是从0开始计数),并补0
  267. const day = text1.split("月")[1].split("日")[0];
  268. const hour = text2.split(":")[0];
  269. const minute = text2.split(":")[1];
  270. const combinedText = `${currentYear}-${month}-${day} ${hour}:${minute}:00`;
  271. let dateObj = new Date(combinedText);
  272. let timestamp = Math.floor(dateObj.getTime() / 1000);
  273. // 获取配送费
  274. let that = this
  275. var params = {
  276. url: "/p/orderRefund/refundPrice",
  277. method: "GET",
  278. data: {
  279. refundSn: this.data.refundSn, //退款编号
  280. deliveryTime: timestamp
  281. },
  282. callBack: function (res) {
  283. that.setData({
  284. sendInfo: res
  285. })
  286. }
  287. };
  288. http.request(params);
  289. this.setData({
  290. combinedTextValue: combinedText,
  291. selectTimeshow: false
  292. });
  293. }
  294. },
  295. onCancel: function () {
  296. this.setData({
  297. selectTimeshow: false
  298. })
  299. },
  300. toPaySend: function () {
  301. if (Object.keys(this.data.sendInfo).length === 0) {
  302. wx.showToast({
  303. title: '请先选择取件时间',
  304. icon: 'none'
  305. })
  306. return
  307. } else {
  308. let that = this
  309. wx.showLoading({
  310. mask: true
  311. });
  312. var params = {
  313. url: "/p/order/refundPay",
  314. method: "POST",
  315. data: {
  316. payType: 1,
  317. orderType: 1,
  318. orderNumbers: this.data.refundSn
  319. },
  320. callBack: (res) => {
  321. wx.hideLoading();
  322. wx.requestPayment({
  323. timeStamp: res.timeStamp,
  324. nonceStr: res.nonceStr,
  325. package: res.packageValue,
  326. signType: res.signType,
  327. paySign: res.paySign,
  328. success: e => {
  329. wx.showModal({
  330. title: '支付成功',
  331. content: '',
  332. showCancel: false,
  333. success: () => {
  334. this.setData({
  335. addCarshow:false
  336. })
  337. this.submitExpress()
  338. }
  339. })
  340. },
  341. fail: err => {
  342. // this.countdownTime()
  343. // that.setData({
  344. // cancelPay: true,
  345. // addCarshow:false
  346. // })
  347. }
  348. })
  349. }
  350. };
  351. http.request(params);
  352. }
  353. },
  354. atoncePaySend: function () {
  355. wx.showLoading({
  356. mask: true
  357. });
  358. var params = {
  359. url: "/p/order/refundPay",
  360. method: "POST",
  361. data: {
  362. payType: 1,
  363. orderType: 1,
  364. orderNumbers: this.data.refundSn
  365. },
  366. callBack: (res) => {
  367. wx.hideLoading();
  368. wx.requestPayment({
  369. timeStamp: res.timeStamp,
  370. nonceStr: res.nonceStr,
  371. package: res.packageValue,
  372. signType: res.signType,
  373. paySign: res.paySign,
  374. success: e => {
  375. wx.showModal({
  376. title: '支付成功',
  377. content: '',
  378. showCancel: false,
  379. success: () => {
  380. // this.setData({
  381. // cancelPay: false
  382. // })
  383. this.getRefundDetail()
  384. }
  385. })
  386. },
  387. fail: err => {}
  388. })
  389. }
  390. };
  391. http.request(params);
  392. },
  393. // 倒计时
  394. countdownTime: function () {
  395. // 十五分钟对应的毫秒数
  396. const fifteenMinutesInMs = 15 * 60 * 1000;
  397. const targetTimeStamp = this.data.sendInfo.touchTime;
  398. // 计算增加十五分钟后的时间戳
  399. const newTimeStamp = targetTimeStamp + fifteenMinutesInMs;
  400. const currentTimeStamp = newTimeStamp;
  401. const diff = currentTimeStamp - targetTimeStamp;
  402. if (diff > 0) {
  403. this.setData({
  404. remainingTime: diff,
  405. });
  406. this.countdown();
  407. } else {
  408. }
  409. },
  410. // 倒计时
  411. countdown: function () {
  412. const interval = setInterval(() => {
  413. if (this.data.remainingTime <= 0) {
  414. clearInterval(interval);
  415. this.setData({
  416. cancelPay: false
  417. })
  418. return;
  419. }
  420. this.setData({
  421. remainingTime: this.data.remainingTime - 1000,
  422. });
  423. // 将剩余时间(毫秒)转换为时分秒格式
  424. const hours = Math.floor(this.data.remainingTime / (1000 * 60 * 60));
  425. const minutes = Math.floor((this.data.remainingTime % (1000 * 60 * 60)) / (1000 * 60));
  426. const seconds = Math.floor((this.data.remainingTime % (1000 * 60)) / 1000);
  427. const timeFormat = `${this.padZero(hours)}:${this.padZero(minutes)}:${this.padZero(seconds)}`;
  428. this.setData({
  429. timeFormat: timeFormat
  430. });
  431. }, 1000);
  432. },
  433. // 辅助函数,用于将数字转换为两位数格式(不足两位前面补0)
  434. padZero(num) {
  435. return num < 10 ? '0' + num : num.toString();
  436. },
  437. // 根据id判断是否开启disabled
  438. updateTimeIntervalsDisabled(id) {
  439. let datatime = this.data.timeIntervals.map(subItem => {
  440. if (id === 2) {
  441. subItem.disabled = false;
  442. } else if (id === 1) {
  443. // 选中当天重新调用getTime方法判断当前时间
  444. this.getTime()
  445. }
  446. return subItem;
  447. });
  448. // copy上面的数据结构,待优化
  449. let day = []
  450. day.push({
  451. id: 1,
  452. text: this.data.nomDay
  453. }, {
  454. id: 2,
  455. text: this.data.tomorrowDay
  456. })
  457. let data = []
  458. data.push({
  459. values: day,
  460. className: 'column1',
  461. }, {
  462. values: this.data.timeIntervals,
  463. defaultIndex: 2,
  464. className: 'column2',
  465. })
  466. this.setData({
  467. timeIntervals: datatime,
  468. columns: data
  469. });
  470. },
  471. flowBution: function () {
  472. wx.navigateTo({
  473. url: '/pages/MaterialFlowInfo/MaterialFlowInfo?refundSn=' + this.data.refundSn
  474. })
  475. // this.setData({
  476. // flowShow: true
  477. // })
  478. // wx.navigateTo({
  479. // url: '/pages/MaterialFlow/MaterialFlow',
  480. // })
  481. },
  482. flowOnClose: function () {
  483. this.setData({
  484. flowShow: false
  485. })
  486. },
  487. /**
  488. * 获取退款申请详情
  489. */
  490. getRefundDetail: function (e) {
  491. var ths = this;
  492. // wx.showLoading({})
  493. var params = {
  494. url: "/p/orderRefund/info",
  495. method: "GET",
  496. data: {
  497. refundSn: this.data.refundSn //退款编号
  498. },
  499. callBack: function (res) {
  500. let img=''
  501. res.orderItems.map(item=>{
  502. img=item.pic.split(',')
  503. item.pic=img[0]
  504. })
  505. ths.setData({
  506. applyTime: res.applyTime, //申请时间
  507. applyType: res.applyType, //申请类型:1,仅退款,2退款退货
  508. goodsNum: res.goodsNum, //退货数量
  509. handelTime: res.handelTime, //卖家处理时间
  510. orderAmount: res.orderAmount, //订单总金额
  511. orderItems: res.orderItems, //订单项
  512. refundSn: res.refundSn, //退款编号
  513. refundAmount: res.refundAmount, //退款金额
  514. refundDelivery: res.refundDelivery, //收货地址对象
  515. refundId: res.refundId, //记录ID
  516. refundTime: res.refundTime, //退款时间
  517. returnMoneySts: res.returnMoneySts, //处理退款状态:(1.买家申请 2.卖家接受 3.买家发货 4.卖家收货 5.退款成功 6.买家撤回申请 7.商家拒绝 -1.退款关闭)
  518. updateTime: res.updateTime, //更新时间
  519. rejectMessage: res.rejectMessage, //拒绝理由
  520. buyerReason: res.buyerReason, //退款原因
  521. shopName: res.shopName,
  522. refundScore: res.refundScore, // 退款积分
  523. payer: res.refundDelivery.payer,//运费承担方
  524. sendPay:res.refundDelivery.deyNu //物流编号,判断是否提交成功
  525. })
  526. wx.hideLoading();
  527. ths.get_countDown()
  528. }
  529. };
  530. http.request(params);
  531. },
  532. /**
  533. * 同意后倒计时
  534. * @param {*} e
  535. */
  536. get_countDown:function(){
  537. const start = new Date(this.data.handelTime);
  538. const end = new Date(start.getTime() + 48 * 60 * 60 * 1000);
  539. const interval = setInterval(() => {
  540. const now = new Date();
  541. const diff = end - now;
  542. if (diff <= 0) {
  543. clearInterval(interval);
  544. this.setData({
  545. countdown_hours: '00天',
  546. countdown_minutes:'00分钟'
  547. });
  548. } else {
  549. const hours = Math.floor(diff / (1000 * 60 * 60));
  550. const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
  551. this.setData({
  552. countdown_hours:String(hours).padStart(2, '0'),
  553. countdown_minutes:String(minutes).padStart(2, '0')
  554. // countdown_time:`${String(hours).padStart(2, '0')}小时${String(minutes).padStart(2, '0')}分钟`
  555. });
  556. }
  557. }, 1000);
  558. },
  559. /**
  560. * 撤销退货退款申请
  561. */
  562. cancelApplication: function (e) {
  563. console.log('撤销申请')
  564. wx.showModal({
  565. title: '撤销',
  566. content: '确定要撤销本次申请?',
  567. success: (res) => {
  568. if (res.confirm) {
  569. wx.showLoading({})
  570. var params = {
  571. url: "/p/orderRefund/cancel",
  572. method: "PUT",
  573. data: this.data.refundSn, //退款订单编号
  574. callBack: function (res) {
  575. wx.hideLoading();
  576. wx.navigateTo({
  577. url: '/pages/afterSales/afterSales',
  578. })
  579. }
  580. };
  581. http.request(params);
  582. } else {
  583. console.log('取消')
  584. }
  585. }
  586. })
  587. },
  588. /**
  589. * 跳转修改退款申请
  590. */
  591. // toAlterRefundApply: function (e) {
  592. // var refundSn = e.currentTarget.dataset.refundsn;
  593. // console.log(e.currentTarget.dataset.refundsn)
  594. // wx.navigateTo({
  595. // url: '/pages/applyRefund/applyRefund?refundSn=' + refundSn,
  596. // })
  597. // },
  598. /**
  599. * 填写物流信息
  600. */
  601. toLogisticsPage: function (e) {
  602. var refundSn = e.currentTarget.dataset.refundsn;
  603. console.log(e.currentTarget.dataset.refundsn)
  604. wx.navigateTo({
  605. url: '/pages/writeReturnLogistics/writeReturnLogistics?refundSn=' + refundSn,
  606. })
  607. },
  608. /**
  609. * 生命周期函数--监听页面初次渲染完成
  610. */
  611. onReady: function () {
  612. },
  613. /**
  614. * 生命周期函数--监听页面显示
  615. */
  616. onShow: function () {
  617. },
  618. /**
  619. * 生命周期函数--监听页面隐藏
  620. */
  621. onHide: function () {
  622. },
  623. /**
  624. * 生命周期函数--监听页面卸载
  625. */
  626. onUnload: function () {
  627. },
  628. /**
  629. * 页面相关事件处理函数--监听用户下拉动作
  630. */
  631. onPullDownRefresh: function () {
  632. },
  633. /**
  634. * 页面上拉触底事件的处理函数
  635. */
  636. onReachBottom: function () {
  637. },
  638. /**
  639. * 用户点击右上角分享
  640. */
  641. onShareAppMessage: function () {
  642. }
  643. })