import * as dayjs from "dayjs";
|
type timeType = 'startTime'|'endTime';
|
Page({
|
/**
|
* 页面的初始数据
|
*/
|
data: {
|
isShowStartDatePopup:false,
|
isShowEndDatePopup:false,
|
minStartDate: new Date().getTime() + 1000 * 60 * 15,
|
maxStartDate: new Date().getTime() + 1000 * 60 * 60 * 24 * 180,
|
startDate: new Date().getTime() + 1000 * 60 * 60, //new Date().getTime(),
|
startTime: '',
|
startDateAndTime: [] as any,
|
minEndDate: new Date().getTime() + 1000 * 60 * 45,
|
maxEndDate: new Date().getTime() + 1000 * 60 * 60 * 24 * 180,
|
endDate: new Date().getTime() + 1000 * 60 * 240, //new Date().getTime(),
|
endTime: '',
|
endDateAndTime: [] as any,
|
formatter(type:string, value:string) {
|
// console.log(type,value)
|
if (type === "year") {
|
return `${value}年`;
|
} else if (type === "month") {
|
return `${value}月`;
|
} else if (type === "day") {
|
return `${value}日`;
|
}
|
return value;
|
},
|
doccode:'',
|
qrCodeUrl:"", //https://res.wx.qq.com/op_res/BbVNeczA1XudfjVqCVoKgfuWe7e3aUhokktRVOqf_F0IqS6kYR--atCpVNUUC3zr
|
},
|
|
|
/**
|
* 检查
|
*/
|
|
async onSubmit() {
|
let data = {
|
docCode:this.data.doccode,
|
startTime:`${this.data.startTime}:00`,
|
endTime:`${this.data.endTime}:00`,
|
};
|
let checkStartTime = this.checkTime("startTime", "请选择计划开始时间");
|
let checkEndTime = this.checkTime("endTime", "请选择计划结束时间");
|
console.log('待提交数据',data);
|
if (!checkStartTime||!checkEndTime){
|
return;
|
}
|
let [error, result] = await wx.$utils.to(
|
wx.$http.request({
|
url:`/shopping/panicBuyingLive/saveRoomStep3.do`,
|
data,
|
method: 'POST'
|
})
|
)
|
if (error){
|
console.log(error);
|
return;
|
}
|
console.log("新建房间--第三步",result);
|
if (result.qrcodeUrl){
|
let authentication =this.selectComponent('#my-anchor-authentication');
|
authentication.showQrCodeDialog(result.qrcodeUrl);
|
return;
|
}
|
if (result.state=='success'){
|
wx.navigateBack({
|
delta: 3
|
})
|
}
|
},
|
|
/**
|
* 生命周期函数--监听页面加载
|
*/
|
onLoad: function (options) {
|
let doccode = options.doccode || '';
|
let currentLiveRoomData = wx.globalData.currentLiveRoomData;
|
console.log('正在编辑的直播间数据',currentLiveRoomData);
|
if (currentLiveRoomData&&JSON.stringify(currentLiveRoomData) != '{}'){
|
let startDate = this.data.startDate;
|
let endDate = this.data.endDate;
|
let lives = {
|
startTime: currentLiveRoomData.StartTime,
|
endTime: currentLiveRoomData.EndTime,
|
startDate: currentLiveRoomData.StartTime?new Date(currentLiveRoomData.StartTime).getTime():startDate,
|
endDate: currentLiveRoomData.EndTime?new Date(currentLiveRoomData.EndTime).getTime():endDate,
|
};
|
// if (currentLiveRoomData.StartTime){
|
// startDate = new Date(currentLiveRoomData.StartTime).getTime()
|
// }
|
// if (currentLiveRoomData.EndTime){
|
// endDate = new Date(currentLiveRoomData.EndTime).getTime()
|
// }
|
console.log('已有时间',lives);
|
this.setData({
|
...lives,
|
})
|
}
|
this.handleDateAndTime()
|
this.setData({
|
doccode,
|
})
|
},
|
/**
|
* 生命周期函数--监听页面显示
|
*/
|
onShow: function () {},
|
formatTime(time: any) {
|
// const date:any = dayjs(time);
|
// console.log();
|
// return `${date.$y}-${date.$M + 1}-${date.$D} ${date.$H}:${date.$m}`;
|
return dayjs(time).format('YYYY-MM-DD HH:mm');
|
},
|
handleDateAndTime(){
|
let waitHandle = this.data;
|
let startTime = waitHandle.startTime|| this.formatTime(new Date().getTime() + 1000 * 60 * 60);
|
let endTime =waitHandle.endTime|| this.formatTime(new Date().getTime() + 1000 * 60 * 240);
|
this.setData({
|
startTime,
|
endTime,
|
startDateAndTime: startTime.split(' '),
|
endDateAndTime: endTime.split(' '),
|
})
|
|
},
|
showStartDatePopup(){
|
this.setData({
|
isShowStartDatePopup: true
|
})
|
},
|
onStartDatePopupClose(){
|
this.setData({
|
isShowStartDatePopup: false
|
})
|
},
|
onEnterStartDate(event: { detail: any; }) {
|
let detail = event.detail;
|
const dateTime:any = this.formatTime(event.detail);
|
console.log("选择开播时间", dateTime,detail);
|
this.setData({
|
startDate: detail,
|
startTime: dateTime,
|
minEndDate: detail + 1000 * 60 * 30,
|
});
|
this.handleDateAndTime();
|
this.onStartDatePopupClose();
|
this.checkTime("startTime", "请选择计划开始时间");
|
},
|
showEndDatePopup(){
|
this.setData({
|
isShowEndDatePopup: true
|
})
|
},
|
onEndDatePopupClose(){
|
this.setData({
|
isShowEndDatePopup: false
|
})
|
},
|
onEnterEndDate(event: { detail: any; }) {
|
const date:any = this.formatTime(event.detail);
|
console.log("选择下播时间", date,event.detail);
|
this.setData({
|
endTime: date,
|
endDate: event.detail,
|
});
|
// this.triggerEvent('selectedEndTime',{
|
// endTime: date
|
// });
|
this.handleDateAndTime();
|
this.onEndDatePopupClose();
|
this.checkTime("endTime", "请选择计划结束时间");
|
},
|
checkTime(time:timeType, msg:string) {
|
if (this.data[time] == '') {
|
this.setData({
|
[time + "Error"]: msg,
|
});
|
console.log(this.data.startTime);
|
return false;
|
}
|
let startDate = this.data.startDate;
|
let endDate = this.data.endDate;
|
console.log(this.data);
|
if (time==='startTime'){
|
if (startDate&&endDate&&(startDate - endDate > 0)) {
|
this.setData({
|
["startTimeError"]: "开始时间需小于结束时间",
|
});
|
return false;
|
}
|
}
|
if (time==='endTime'){
|
if (startDate&&endDate&&(endDate - startDate < 0)) {
|
this.setData({
|
["endTimeError"]: "结束时间需大于开始时间",
|
});
|
return false;
|
}
|
}
|
if (startDate&&endDate&&(Math.abs(startDate - endDate)<1000*60*30)){
|
this.setData({
|
[time + "Error"]: "所选时间范围间隔不得短于30分钟",
|
});
|
return false;
|
}
|
if (startDate&&endDate&&(Math.abs(startDate - endDate)>1000*60*60*24)){
|
this.setData({
|
[time + "Error"]: "所选时间范围必须在24小时以内",
|
});
|
return false;
|
}
|
this.setData({
|
["startTimeError"]: "",
|
["endTimeError"]: "",
|
});
|
return true;
|
// this.handleLiveTime()
|
},
|
});
|
|
export {}
|