@@ -160,6 +160,22 @@ var config = { | |||
* 订单退款状态 | |||
*/ | |||
getRefundStatus: "/order/getRefundStatus", | |||
/** | |||
* 查询预约状态 | |||
*/ | |||
getUserReservation: "/wxCouponOrderReservation/getUserReservation", | |||
/** | |||
* 保存/更改预约信息 | |||
*/ | |||
saveOrderReservation: "/wxCouponOrderReservation/saveOrUpdate", | |||
/** | |||
* 查询预约详情 | |||
*/ | |||
getOrderReservationDetail: "/wxCouponOrderReservation/detail", | |||
/** | |||
* 取消预约 | |||
*/ | |||
cancelReservation: "/wxCouponOrderReservation/cancelReservation", | |||
/** | |||
* 获取im客服id | |||
*/ | |||
@@ -1,9 +1,244 @@ | |||
// c:\Users\Holy-Knight-IX\Desktop\Working Space\4.TikTok-MiniPro\ttc\package2\pages\appointment\appointment.js | |||
let config = require("../../../config/config.js"); | |||
let util = require("../../../utils/util"); | |||
let Http = require("../../../utils/HttpBasics"); | |||
let app = getApp(); | |||
const imgurl = require("../../../utils/imgurl"); | |||
Page({ | |||
data: { | |||
appointmentText: "确认预约", | |||
id: "", | |||
orderId: "", | |||
startTime: "", | |||
endTime: "", | |||
mallTenantId: "", | |||
pickedAddress: "请选择地址", | |||
pickedDate: "请选择日期", | |||
pickedStartTime: "请选择", | |||
pickedEndTime: "请选择", | |||
describeStr: "", | |||
status: "" | |||
}, | |||
onLoad(options) { | |||
console.log(options, 'options'); | |||
this.setData({ | |||
id: options.id || '', | |||
orderId: options.orderId || '', | |||
startTime: options.startTime || '', | |||
endTime: options.endTime || '' | |||
}) | |||
const mallTenantId = tt.getStorageSync('mallTenantId'); | |||
if (mallTenantId) { | |||
this.setData({ | |||
mallTenantId | |||
}) | |||
} | |||
if (this.data.id) { | |||
this.getDetail(this.data.id) | |||
} | |||
}, | |||
chooseAddress() { | |||
let that = this; | |||
tt.chooseLocation({ | |||
success: function (res) { | |||
that.setData({ | |||
pickedAddress: res.address, | |||
}) | |||
}, | |||
fail: function (error) { | |||
console.log(error) | |||
}, | |||
complete: function (data) {} | |||
}) | |||
}, | |||
chooseDate(e) { | |||
console.log(e.detail.value, 'e'); | |||
this.setData({ | |||
pickedDate: e.detail.value | |||
}) | |||
}, | |||
chooseStartTime(e) { | |||
console.log(e.detail.value, 'e'); | |||
this.setData({ | |||
pickedStartTime: e.detail.value | |||
}) | |||
}, | |||
chooseEndTime(e) { | |||
console.log(e.detail.value, 'e'); | |||
this.setData({ | |||
pickedEndTime: e.detail.value | |||
}) | |||
}, | |||
describing(e) { | |||
this.setData({ | |||
describeStr: e.detail.value | |||
}) | |||
}, | |||
confirm() { | |||
const tempData = this.data | |||
if (tempData.pickedAddress == '请选择地址') { | |||
tt.showToast({ | |||
title: '请选择地址!', | |||
icon: 'fail' | |||
}); | |||
return | |||
} | |||
if (tempData.pickedDate == '请选择日期') { | |||
tt.showToast({ | |||
title: '请请选择日期!', | |||
icon: 'fail' | |||
}); | |||
return | |||
} | |||
if (tempData.pickedStartTime == '请选择') { | |||
tt.showToast({ | |||
title: '请起始时间!', | |||
icon: 'fail' | |||
}); | |||
return | |||
} | |||
if (tempData.pickedEndTime == '请选择') { | |||
tt.showToast({ | |||
title: '请结束时间!', | |||
icon: 'fail' | |||
}); | |||
return | |||
} | |||
const data = { | |||
couponOrderId: tempData.orderId, | |||
userAddress: tempData.pickedAddress, | |||
startDate: tempData.pickedDate + " " + tempData.pickedStartTime + ":00", | |||
endDate: tempData.pickedDate + " " + tempData.pickedEndTime + ":00", | |||
describeStr: tempData.describeStr, | |||
mallTenantId: tempData.mallTenantId || '' | |||
} | |||
if (this.data.id) { | |||
data.id = this.data.id | |||
} | |||
if (this.data.status == 1) { | |||
data.status = 0 | |||
} | |||
console.log(data, 'data'); | |||
this.saveOrderReservation(data) | |||
}, | |||
cancel() { | |||
tt.showModal({ | |||
title: "取消预约", | |||
content: "确定要取消预约吗?", | |||
showCancel: true, | |||
success: (res) => { | |||
if (res.confirm) { | |||
this.cancelReservation(this.data.id) | |||
} | |||
if (res.cancel) { | |||
return | |||
} | |||
}, | |||
fail: (res) => { | |||
}, | |||
}); | |||
}, | |||
cancelReservation(id) { | |||
const that = this | |||
Http.post({ | |||
url: config.api.cancelReservation, | |||
data: { | |||
id, | |||
mallTenantId: this.data.mallTenantId || '' | |||
} | |||
}).then(res => { | |||
console.log(res, 'cancelReservation'); | |||
tt.showToast({ | |||
title: '取消成功!', | |||
icon: 'success', | |||
duration: 2000, | |||
success: (res) => { | |||
setTimeout(() => { | |||
tt.navigateBack(); | |||
}, 1500); | |||
}, | |||
fail: (res) => { | |||
}, | |||
}); | |||
}).catch(err => { | |||
console.log(err, 'cancelReservation'); | |||
tt.showToast({ | |||
title: err.message, | |||
icon: 'none' | |||
}); | |||
}) | |||
}, | |||
saveOrderReservation(data) { | |||
Http.post({ | |||
url: config.api.saveOrderReservation, | |||
data | |||
}).then(res => { | |||
console.log(res, 'saveOrderReservation'); | |||
tt.showToast({ | |||
title: '预约成功!', | |||
icon: 'success', | |||
duration: 2000, | |||
success: (res) => { | |||
setTimeout(() => { | |||
tt.navigateBack(); | |||
}, 1500); | |||
}, | |||
fail: (res) => { | |||
}, | |||
}); | |||
}).catch(err => { | |||
console.log(err, 'saveOrderReservation'); | |||
tt.showToast({ | |||
title: err.message, | |||
icon: 'none' | |||
}); | |||
}) | |||
}, | |||
onLoad: function (options) { | |||
getDetail(id) { | |||
const that = this | |||
Http.get({ | |||
url: config.api.getOrderReservationDetail, | |||
data: { | |||
id, | |||
mallTenantId: this.data.mallTenantId || '' | |||
} | |||
}).then(res => { | |||
console.log(res, 'getOrderReservationDetail'); | |||
that.setData({ | |||
pickedAddress: res.data.userAddress || '请选择地址', | |||
pickedDate: util.timestampToTime(res.data.startDate, 'YYYY-MM-DD'), | |||
pickedStartTime: util.timestampToTime(res.data.startDate, 'hh:mm'), | |||
pickedEndTime: util.timestampToTime(res.data.endDate, 'hh:mm'), | |||
describeStr: res.data.describeStr, | |||
status: res.data.status, | |||
appointmentText: res.data.status == 1 ? "重新预约" : "修改预约" | |||
}) | |||
}).catch(err => { | |||
console.log(err, 'getOrderReservationDetail'); | |||
}) | |||
} | |||
}) |
@@ -1,3 +1,6 @@ | |||
{ | |||
"navigationBarTitleText": "订单预约", | |||
"navigationBarBackgroundColor": "#fff", | |||
"navigationBarTextStyle": "black", | |||
"usingComponents": {} | |||
} |
@@ -1,2 +1,36 @@ | |||
<!-- c:\Users\Holy-Knight-IX\Desktop\Working Space\4.TikTok-MiniPro\ttc\package2\pages\appointment\appointment.ttml --> | |||
<text>c:\Users\Holy-Knight-IX\Desktop\Working Space\4.TikTok-MiniPro\ttc\package2\pages\appointment\appointment.ttml</text> | |||
<view class="continer"> | |||
<view tt:if="{{ pickedAddress != '请选择地址' }}" class="addressPicker" bindtap="chooseAddress"> | |||
<text>选择服务地点:</text> | |||
<text> | |||
<text class="address">{{ pickedAddress }}</text> | |||
</text> | |||
</view> | |||
<view tt:if="{{ pickedAddress == '请选择地址' }}" class="addressPickerFlex" bindtap="chooseAddress"> | |||
<text>选择服务地点:</text> | |||
<text> | |||
<text class="address">{{ pickedAddress }}</text> | |||
</text> | |||
</view> | |||
<view class="datePickerFlex"> | |||
<picker mode="date" start="{{ startTime }}" end="{{ endTime }}" bindchange='chooseDate'>选择服务日期:</picker> | |||
<picker mode="date" start="{{ startTime }}" end="{{ endTime }}" bindchange='chooseDate' class="address"> | |||
{{ pickedDate }}</picker> | |||
</view> | |||
<view class="datePickerFlex"> | |||
<picker mode="time" bindchange='chooseTime'>预计上门时间:</picker> | |||
<picker mode="time" bindchange='chooseStartTime' class="address">{{ pickedStartTime }}</picker> | |||
- | |||
<picker mode="time" start="{{ pickedStartTime }}" bindchange='chooseEndTime' class="address">{{ pickedEndTime }} | |||
</picker> | |||
</view> | |||
<view class="textarea"> | |||
<textarea class="describe" placeholder="备注:说点什么吧" bindinput="describing" value="{{ describeStr }}"></textarea> | |||
</view> | |||
<button class="confirm" type="primary" bindtap="confirm">{{ appointmentText }}</button> | |||
<button tt:if="{{ id && status != 1 }}" type="primary" bindtap="cancel">取消预约</button> | |||
</view> |
@@ -1 +1,65 @@ | |||
/* c:\Users\Holy-Knight-IX\Desktop\Working Space\4.TikTok-MiniPro\ttc\package2\pages\appointment\appointment.ttss */ | |||
/* c:\Users\Holy-Knight-IX\Desktop\Working Space\4.TikTok-MiniPro\ttc\package2\pages\appointment\appointment.ttss */ | |||
page { | |||
font-size: 30rpx; | |||
box-sizing: border-box !important; | |||
} | |||
.continer { | |||
width: 90%; | |||
height: 100%; | |||
margin: auto; | |||
} | |||
.addressPicker { | |||
background-color: #fff; | |||
border-radius: 20rpx; | |||
padding: 30rpx; | |||
margin: 35rpx auto; | |||
} | |||
.address { | |||
color: #8a8a8a; | |||
} | |||
.addressPickerFlex { | |||
display: flex; | |||
justify-content: space-between; | |||
background-color: #fff; | |||
border-radius: 20rpx; | |||
padding: 30rpx; | |||
margin: 35rpx auto; | |||
} | |||
.datePicker { | |||
background-color: #fff; | |||
border-radius: 20rpx; | |||
padding: 30rpx; | |||
margin: 35rpx auto; | |||
} | |||
.datePickerFlex { | |||
display: flex; | |||
justify-content: space-between; | |||
background-color: #fff; | |||
border-radius: 20rpx; | |||
padding: 30rpx; | |||
margin: 35rpx auto; | |||
} | |||
.textarea { | |||
margin: 35rpx auto; | |||
overflow: hidden; | |||
border-radius: 20rpx; | |||
} | |||
.describe { | |||
width: 100%; | |||
background-color: #fff; | |||
padding: 25rpx; | |||
} | |||
.confirm { | |||
background-color: #3c89ff; | |||
margin-bottom: 20rpx; | |||
} |
@@ -306,7 +306,7 @@ Page({ | |||
let param = { | |||
id: this.data.cardData.couponOrderId, | |||
cUserId: this.data.cardData.cuserId, | |||
updateDate: util.formatTime(Number(that.data.cardData.updateDate), "yyyy-MM-dd hh:mm:ss") | |||
updateDate: util.timestampToTime(Number(that.data.cardData.updateDate), "YYYY-MM-DD hh:mm:ss") | |||
} | |||
Http.get({ | |||
url: config.api.queryCardStatus, | |||
@@ -327,7 +327,7 @@ Page({ | |||
let param = { | |||
id: this.data.cardData.couponOrderId, | |||
cUserId: this.data.cardData.cuserId, | |||
updateDate: util.formatTime(Number(this.data.cardData.updateDate), "yyyy-MM-dd hh:mm:ss") | |||
updateDate: util.timestampToTime(Number(this.data.cardData.updateDate), "YYYY-MM-DD hh:mm:ss") | |||
} | |||
this.setData({ | |||
@@ -788,7 +788,7 @@ Page({ | |||
clearInterval(that.data.setInterval) | |||
} | |||
if (res.data.actStatus == 0) { | |||
var beginTime = util.formatTime(res.data.beginTime, "yyyy-MM-dd hh:mm:ss"); | |||
var beginTime = util.timestampToTime(res.data.beginTime, "YYYY-MM-DD hh:mm:ss"); | |||
if (util.timechuo(beginTime).indexOf('-') == 0) { | |||
that.setData({ | |||
beginTime: "活动已结束", | |||
@@ -799,7 +799,7 @@ Page({ | |||
}); | |||
} | |||
} else { | |||
var endTime = util.formatTime(res.data.endTime, "yyyy-MM-dd hh:mm:ss"); | |||
var endTime = util.timestampToTime(res.data.endTime, "YYYY-MM-DD hh:mm:ss"); | |||
if (util.timechuo(endTime).indexOf('-') == 0) { | |||
that.setData({ | |||
endtime: "活动已结束", | |||
@@ -818,8 +818,8 @@ Page({ | |||
if (res.data.type == 10) { | |||
that.setData({ | |||
salePriceStr: res.data.salePriceStr, | |||
pickEndDate: util.formatTime(res.data.pickEndDate, "yyyy-MM-dd"), | |||
pickStartDate: util.formatTime(res.data.pickStartDate, "yyyy-MM-dd"), | |||
pickEndDate: util.timestampToTime(res.data.pickEndDate, "YYYY-MM-DD"), | |||
pickStartDate: util.timestampToTime(res.data.pickStartDate, "YYYY-MM-DD"), | |||
priceStr: res.data.priceStr, | |||
tailPriceStr: res.data.tailPriceStr, | |||
origPriceStr: res.data.origPriceStr | |||
@@ -827,12 +827,12 @@ Page({ | |||
} | |||
if (res.data.validType == 1) { | |||
that.setData({ | |||
soldStartTime: util.formatTime(res.data.soldStartTime, "yyyy-MM-dd") || null, | |||
soldEndTime: util.formatTime(res.data.soldEndTime, "yyyy-MM-dd") || null, | |||
validStartDate: util.formatTime(res.data.validStartDate, "yyyy-MM-dd"), | |||
validEndDate: util.formatTime(res.data.validEndDate, "yyyy-MM-dd"), | |||
pickStartDate: util.formatTime(res.data.pickStartDate, "yyyy-MM-dd"), | |||
pickEndDate: util.formatTime(res.data.pickEndDate, "yyyy-MM-dd"), | |||
soldStartTime: util.timestampToTime(res.data.soldStartTime, "YYYY-MM-DD") || null, | |||
soldEndTime: util.timestampToTime(res.data.soldEndTime, "YYYY-MM-DD") || null, | |||
validStartDate: util.timestampToTime(res.data.validStartDate, "YYYY-MM-DD"), | |||
validEndDate: util.timestampToTime(res.data.validEndDate, "YYYY-MM-DD"), | |||
pickStartDate: util.timestampToTime(res.data.pickStartDate, "YYYY-MM-DD"), | |||
pickEndDate: util.timestampToTime(res.data.pickEndDate, "YYYY-MM-DD"), | |||
}); | |||
} else { | |||
if (res.data.validDays) { | |||
@@ -138,6 +138,8 @@ | |||
<shop tt:if="{{mallList.length>0}}" mallList="{{mallList}}"></shop> | |||
<image tt:if="{{data.type == 69}}" class="alerting" mode='widthFix' src="../../../assets/images/appointment.png"> | |||
</image> | |||
<view class='notes'> | |||
<view class="notesH">购买须知</view> | |||
<view class="timeText">使用期</view> | |||
@@ -377,6 +377,10 @@ button::after { | |||
padding-bottom: 30rpx; | |||
} | |||
.alerting { | |||
width: 100%; | |||
} | |||
.nodesD { | |||
height: 87rpx; | |||
line-height: 87rpx; | |||
@@ -60,7 +60,12 @@ Page({ | |||
IMorderId: "", | |||
outOrderId: "", | |||
outRefundOrderId: "", | |||
canIUseRefund: false | |||
canIUseRefund: false, | |||
isAppointment: false, | |||
appointStart: "", | |||
appointEnd: "", | |||
appointmentId: "", | |||
appointmentStatus: "" | |||
}, | |||
imCallback(e) { | |||
@@ -175,6 +180,48 @@ Page({ | |||
}) | |||
}, | |||
goAppointment(e) { | |||
const that = this | |||
const orderId = e.currentTarget.dataset.id | |||
const id = this.data.appointmentId | |||
const startTime = that.data.order.validStartDate | |||
const endTime = that.data.order.validEndDate | |||
console.log(startTime, endTime); | |||
tt.navigateTo({ | |||
url: `/package2/pages/appointment/appointment?id=${id}&orderId=${orderId}&startTime=${startTime}&endTime=${endTime}`, | |||
}); | |||
}, | |||
getUserReservation(couponOrderId) { | |||
const that = this | |||
Http.get({ | |||
url: config.api.getUserReservation, | |||
data: { | |||
couponOrderId, | |||
mallTenantId: this.data.mallTenantId || '' | |||
} | |||
}).then(res => { | |||
console.log(res, 'getUserReservation'); | |||
if (res.data) { | |||
const appointStart = util.timestampToTime(res.data.startDate, 'YYYY-MM-DD hh:mm:ss') | |||
const appointEnd = util.timestampToTime(res.data.endDate, 'hh:mm:ss') | |||
const appointmentId = res.data.id | |||
const appointmentStatus = res.data.status | |||
that.setData({ | |||
appointStart, | |||
appointEnd, | |||
appointmentId, | |||
appointmentStatus, | |||
isAppointment: true | |||
}) | |||
} | |||
}).catch(err => { | |||
console.log(err, 'getUserReservation'); | |||
}) | |||
}, | |||
getOrderStatus(orderId) { | |||
const that = this | |||
Http.get({ | |||
@@ -222,13 +269,6 @@ Page({ | |||
}) | |||
}, | |||
goAppointment(e) { | |||
const id = e.currentTarget.dataset.id | |||
tt.navigateTo({ | |||
url: `/package2/pages/appointment/appointment?id=${id}`, | |||
}); | |||
}, | |||
getIm() { //获取im客服id | |||
const that = this | |||
Http.get({ | |||
@@ -259,8 +299,10 @@ Page({ | |||
const couponChannelId = res.data.orders[0].couponChannelId | |||
const orderID = res.data.orders[0].id | |||
const cOrderID = res.data.orders[0].couponOrderId | |||
that.getOrderStatus(orderID) | |||
that.getUserReservation(cOrderID) | |||
that.getIm() | |||
const extParam = res.data.extParam || null | |||
if (extParam) { | |||
@@ -394,16 +436,16 @@ Page({ | |||
tenantId: res.data.tenantId | |||
}) | |||
} | |||
var createDate = util.formatTime(res.data.orders[0].createDate, "yyyy-MM-dd"); | |||
var createDate = util.timestampToTime(res.data.orders[0].createDate, "YYYY-MM-DD"); | |||
let tempData = res.data.orders[0] | |||
tempData.deliveryInfo = tempData.deliveryInfo ? JSON.parse(tempData.deliveryInfo) : "" | |||
tempData.itemGroup = tempData.itemGroup ? JSON.parse(tempData.itemGroup) : "" | |||
tempData.soldStartTime = util.formatTime(tempData.soldStartTime, "yyyy-MM-dd") || null, | |||
tempData.soldEndTime = util.formatTime(tempData.soldEndTime, "yyyy-MM-dd") || null, | |||
tempData.soldStartTime = util.timestampToTime(tempData.soldStartTime, "YYYY-MM-DD") || null, | |||
tempData.soldEndTime = util.timestampToTime(tempData.soldEndTime, "YYYY-MM-DD") || null, | |||
tempData.validStartDate = util.formatTime(tempData.validStartDate, "yyyy-MM-dd") | |||
tempData.validEndDate = util.formatTime(tempData.validEndDate, "yyyy-MM-dd") | |||
tempData.validStartDate = util.timestampToTime(tempData.validStartDate, "YYYY-MM-DD") | |||
tempData.validEndDate = util.timestampToTime(tempData.validEndDate, "YYYY-MM-DD") | |||
tempData.couponOrderIdS = tempData.couponOrderId ? tempData.couponOrderId.slice(0, 4) + `******` + tempData.couponOrderId.slice(14) : '' | |||
@@ -116,14 +116,18 @@ | |||
--> | |||
<!-- bindtap="powerDrawer" --> | |||
<view tt:if="{{order.type != 69}}" class='dhCode' data-id="{{order.id}}" bindtap="goAppointment"> | |||
<view tt:if="{{order.type == 69 && order.couponOrderStatus == 0}}" class='dhCode' data-id="{{order.couponOrderId}}" | |||
bindtap="goAppointment"> | |||
<view style="width:86%;clear: both;"> | |||
<text class="fl">预约时间:</text> | |||
<text class="fr" style="color: #d4a971;">点击预约</text> | |||
</view> | |||
<view> | |||
<!-- <image class="spcode" src="{{spcodeUrl}}" mode='widthFix'></image> | |||
<image class="rArrow" src="{{chevronUrl}}" mode='widthFix'></image> --> | |||
<text tt:if="{{ !isAppointment }}" class="fr" style="color: #d4a971;">点击预约</text> | |||
<text tt:if="{{ isAppointment && appointmentStatus == 0 }}" class="fr" | |||
style="color: #d4a971;">{{appointStart}}-{{appointEnd}}</text> | |||
<text | |||
tt:if="{{ isAppointment && ( appointmentStatus == 1 || appointmentStatus == 2 || appointmentStatus == 3 ) }}" | |||
class="fr" style="color: #d4a971;">预约已取消 | |||
</text> | |||
</view> | |||
</view> | |||
@@ -210,6 +214,8 @@ | |||
</view> | |||
</view> | |||
<image tt:if="{{order.type == 69}}" class="alerting" mode='widthFix' src="../../../assets/images/appointment.png"> | |||
</image> | |||
<view class='notes'> | |||
<view class="notesH"> | |||
@@ -19,6 +19,17 @@ page { | |||
z-index: 99999; | |||
} | |||
.alerting { | |||
width: 100%; | |||
} | |||
.cancelAppoint { | |||
color: #ffffff; | |||
background-color: #ff0000; | |||
border-radius: 5rpx; | |||
padding: 5rpx 3rpx; | |||
} | |||
.serviceBox2 { | |||
width: 50rpx; | |||
height: 50rpx; | |||
@@ -56,8 +56,20 @@ | |||
"scene": "011007", | |||
"launchFrom": "scan", | |||
"location": "audit" | |||
}, | |||
{ | |||
"id": 1686207127735, | |||
"name": "预约功能调试", | |||
"pathName": "package2/pages/appointment/appointment", | |||
"query": "id=826355515227168768&startTime=2023-05-29&endTime=2023-06-28", | |||
"scene": "990001", | |||
"launchFrom": "scan", | |||
"location": "qr_code" | |||
} | |||
] | |||
} | |||
}, | |||
"setting": { | |||
"mockLogin": false | |||
} | |||
} |
@@ -8,10 +8,11 @@ function convertUTCTimeToLocalTime(UTCDateString) { | |||
if (!UTCDateString) { | |||
return '-'; | |||
} | |||
function formatFunc(str) { //格式化显示 | |||
function formatFunc(str) { //格式化显示 | |||
return str > 9 ? str : '0' + str | |||
} | |||
var date2 = new Date(UTCDateString); //这步是关键 | |||
var date2 = new Date(UTCDateString); //这步是关键 | |||
var year = date2.getFullYear(); | |||
var mon = formatFunc(date2.getMonth() + 1); | |||
var day = formatFunc(date2.getDate()); | |||
@@ -20,7 +21,7 @@ function convertUTCTimeToLocalTime(UTCDateString) { | |||
hour = hour >= 24 ? hour - 24 : hour; | |||
hour = formatFunc(hour); | |||
var min = formatFunc(date2.getMinutes()); | |||
var dateStr = ' ' + hour + ':' + min ; | |||
var dateStr = ' ' + hour + ':' + min; | |||
return dateStr; | |||
} | |||
@@ -29,15 +30,15 @@ function convertUTCTimeToLocalTime(UTCDateString) { | |||
// return new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, ''); | |||
// } | |||
function moodsText(Num){//人气值处理 Num人气值 返回字符串 处理到万位 | |||
function moodsText(Num) { //人气值处理 Num人气值 返回字符串 处理到万位 | |||
let sing = "" | |||
if(Num>10000){ | |||
sing = (Num/10000).toFixed(2)+"w" | |||
}else{ | |||
sing =Num | |||
} | |||
return sing | |||
if (Num > 10000) { | |||
sing = (Num / 10000).toFixed(2) + "w" | |||
} else { | |||
sing = Num | |||
} | |||
return sing | |||
} | |||
const formatTime = (date, fmt) => { | |||
@@ -69,9 +70,9 @@ const formatTime = (date, fmt) => { | |||
if (new RegExp("(" + k + ")").test(fmt)) | |||
fmt = fmt.replace( | |||
RegExp.$1, | |||
RegExp.$1.length == 1 | |||
? o[k] | |||
: ("00" + o[k]).substr(("" + o[k]).length) | |||
RegExp.$1.length == 1 ? | |||
o[k] : | |||
("00" + o[k]).substr(("" + o[k]).length) | |||
); | |||
return fmt; | |||
} catch (error) { | |||
@@ -104,6 +105,7 @@ function qrc(id, code, width, height) { | |||
height: convert_length(height) | |||
}); | |||
} | |||
function fmtDate(obj) { | |||
if (typeof obj === 'string' && obj.length === 13) { | |||
obj = Number(obj); | |||
@@ -121,6 +123,57 @@ function fmtDate(obj) { | |||
); | |||
} | |||
/** | |||
* @description 根据时间戳获取时间 | |||
* @param {*} timestamp 必传,number类型,时间戳数据(10位及以下,10位至13位);若不传,则返回:“无时间戳” | |||
* @param {*} format 选传,string类型,提供以下时间格式:YYYY-MM-DD hh:mm:ss、YYYY/MM/DD hh:mm:ss、YYYY.MM.DD hh:mm:ss、YYYY MM DD hh:mm:ss、YYYY年MM月DD日 hh:mm:ss、YYYY-MM-DD、YYYY/MM/DD、YYYY.MM.DD、YYYY MM DD、YYYY年MM月DD日、hh:mm:ss、hh:mm;若不传,则默认为:YYYY-MM-DD | |||
* @returns 根据要求的时间格式 | |||
* @version V 1.0, Created by YWQ, 2022.10.20 | |||
*/ | |||
function timestampToTime(timestamp, format) { | |||
//时间戳为10位需*1000,时间戳为13位不需乘1000 | |||
const length = timestamp ? timestamp.length : '' | |||
if (length <= 10) { | |||
var date = new Date(timestamp * 1000) | |||
} else { | |||
var date = new Date(timestamp) | |||
} | |||
let Y = String(date.getFullYear()) | |||
let M = String(date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) | |||
let D = String(date.getDate() + 1 < 10 ? '0' + (date.getDate()) : date.getDate()) | |||
let h = String(date.getHours() + 1 < 10 ? '0' + (date.getHours()) : date.getHours()) | |||
let m = String(date.getMinutes() + 1 < 10 ? '0' + (date.getMinutes()) : date.getMinutes()) | |||
let s = String(date.getSeconds() + 1 < 10 ? '0' + (date.getSeconds()) : date.getSeconds()) | |||
// return Y + M + D + h + m + s | |||
if (format == "YYYY-MM-DD hh:mm:ss") { | |||
return Y + "-" + M + "-" + D + " " + h + ":" + m + ":" + s | |||
} else if (format == "YYYY/MM/DD hh:mm:ss") { | |||
return Y + "/" + M + "/" + D + " " + h + ":" + m + ":" + s | |||
} else if (format == "YYYY.MM.DD hh:mm:ss") { | |||
return Y + "." + M + "." + D + " " + h + ":" + m + ":" + s | |||
} else if (format == "YYYY MM DD hh:mm:ss") { | |||
return Y + " " + M + " " + D + " " + h + ":" + m + ":" + s | |||
} else if (format == "YYYY年MM月DD日 hh:mm:ss") { | |||
return Y + "年" + M + "月" + D + "日" + " " + h + ":" + m + ":" + s | |||
} else if (format == "YYYY-MM-DD") { | |||
return Y + "-" + M + "-" + D | |||
} else if (format == "YYYY/MM/DD") { | |||
return Y + "/" + M + "/" + D | |||
} else if (format == "YYYY.MM.DD") { | |||
return Y + "." + M + "." + D | |||
} else if (format == "YYYY MM DD") { | |||
return Y + " " + M + " " + D | |||
} else if (format == "YYYY年MM月DD日") { | |||
return Y + "年" + M + "月" + D + "日" | |||
} else if (format == "hh:mm:ss") { | |||
return h + ":" + m + ":" + s | |||
} else if (format == "hh:mm") { | |||
return h + ":" + m | |||
} else { | |||
return Y + "-" + M + "-" + D | |||
} | |||
} | |||
//计算下单的时间与现在的时间的 | |||
function timechuo(startTime) { | |||
var s1 = new Date(startTime.replace(/-/g, "/")); | |||
@@ -137,20 +190,20 @@ function timechuo(startTime) { | |||
var minute = Math.floor(runTime / 60); | |||
var runTime = runTime % 60; | |||
var second = runTime; | |||
if (day && !year && !month){ | |||
if (day && !year && !month) { | |||
return (day + '天' + hour + "小时" + minute + "分钟") | |||
} else if (month && !year){ | |||
return ((month*30+day) +'天' + hour + "小时" + minute + "分钟") | |||
} else if (month && !year) { | |||
return ((month * 30 + day) + '天' + hour + "小时" + minute + "分钟") | |||
} else if (year) { | |||
return ((year*365 + month*30+ day) + '天' + hour + "小时" + minute + "分钟") | |||
}else{ | |||
return ((year * 365 + month * 30 + day) + '天' + hour + "小时" + minute + "分钟") | |||
} else { | |||
return (hour + "小时" + minute + "分钟") | |||
} | |||
} | |||
//计算时间差 | |||
function timecha(endTime,startTime) { | |||
function timecha(endTime, startTime) { | |||
var s1 = new Date(endTime.replace(/-/g, "/")); | |||
var s2 = new Date(startTime.replace(/-/g, "/")); | |||
var runTime = parseInt((s1.getTime() - s2.getTime()) / 1000); | |||
@@ -165,8 +218,9 @@ function timecha(endTime,startTime) { | |||
var minute = Math.floor(runTime / 60); | |||
var runTime = runTime % 60; | |||
var second = runTime; | |||
return (month+"月"+day+"天"+hour+"小时"+minute+"分钟") | |||
return (month + "月" + day + "天" + hour + "小时" + minute + "分钟") | |||
} | |||
function isJSON(str) { | |||
if (typeof str == 'string') { | |||
console.log("string") | |||
@@ -202,6 +256,7 @@ module.exports = { | |||
fmtDate: fmtDate, | |||
timechuo: timechuo, | |||
timecha: timecha, | |||
moodsText:moodsText, | |||
convertUTCTimeToLocalTime: convertUTCTimeToLocalTime | |||
}; | |||
moodsText: moodsText, | |||
convertUTCTimeToLocalTime: convertUTCTimeToLocalTime, | |||
timestampToTime: timestampToTime | |||
}; |