DetailsOfRefund.js 13 KB

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