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. },
  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.getRefundWriteInfo()
  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. })