DetailsOfRefund.js 13 KB

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