DetailsOfRefund.js 13 KB

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