// pages/liveRoomCreate/liveRoomCreate.js
|
const utils = require("../../utils/util.js");
|
const app = getApp();
|
Page({
|
/**
|
* 页面的初始数据
|
*/
|
data: {
|
currentStep: 0,
|
type: "0",
|
steps: [
|
{
|
text: "① 基本信息",
|
inactiveIcon: "location-o",
|
activeIcon: "success",
|
},
|
{
|
text: "② 直播间配置",
|
inactiveIcon: "like-o",
|
activeIcon: "plus",
|
},
|
],
|
timeErrorMsg: {
|
start: "请选择计划直播开始时间",
|
end: "请选择计划直播结束时间",
|
tips: "开播时间和结束时间间隔不得短于30分钟",
|
},
|
screenTypeOptions: [
|
{ text: "竖屏", value: 0 },
|
{ text: "横屏", value: 1 },
|
],
|
screenType: 0,
|
isFeedsPublic: false,
|
isShowInHomepage: false,
|
isLike: true,
|
isComment: true,
|
isGoods: true,
|
isShare: true,
|
isReplay: true,
|
isKf: false,
|
showQrCode: false,
|
qrCodeUrl:"", //https://res.wx.qq.com/op_res/BbVNeczA1XudfjVqCVoKgfuWe7e3aUhokktRVOqf_F0IqS6kYR--atCpVNUUC3zr
|
minStartDate: new Date().getTime() + 1000 * 60 * 20,
|
maxStartDate: new Date().getTime() + 1000 * 60 * 60 * 24 * 180,
|
startDate: "", //new Date().getTime(),
|
minEndDate: new Date().getTime() + 1000 * 60 * 40,
|
maxEndDate: new Date().getTime() + 1000 * 60 * 60 * 24 * 180,
|
endDate: "", //new Date().getTime(),
|
formatter(type, value) {
|
// console.log(type,value)
|
if (type === "year") {
|
return `${value}年`;
|
} else if (type === "month") {
|
return `${value}月`;
|
} else if (type === "day") {
|
return `${value}日`;
|
}
|
return value;
|
},
|
},
|
|
// 切换直播类型
|
onChangeType(event) {
|
|
this.setData({
|
type: event.detail,
|
});
|
},
|
onClickType(event) {
|
// console.log('ddd',event);
|
const { name } = event.currentTarget.dataset;
|
this.setData({
|
type: name,
|
});
|
},
|
|
/**
|
* 选择时间
|
*/
|
onInputStartDate() {},
|
onEnterStartDate(e) {
|
let startTime = utils.formatTime(e.detail);
|
if (
|
this.data.endDate &&
|
Math.abs(e.detail - this.data.endDate) > 1000 * 60 * 60 * 24
|
) {
|
let date = e.detail + 1000 * 60 * 60 * 24;
|
let time = utils.formatTime(date);
|
this.setData({
|
endDate: date,
|
endTime: time,
|
});
|
}
|
if (
|
this.data.endDate &&
|
Math.abs(e.detail - this.data.endDate) < 1000 * 60 * 30
|
) {
|
let date = e.detail + 1000 * 60 * 30;
|
let time = utils.formatTime(date);
|
this.setData({
|
endDate: date,
|
endTime: time,
|
});
|
}
|
// if (this.data.endDate && e.detail > this.data.endDate) {
|
// }
|
console.log("选择开播时间", startTime);
|
this.setData({
|
startDate: e.detail,
|
startTime: startTime,
|
maxEndDate: e.detail + 1000 * 60 * 60 * 24,
|
minEndDate: e.detail + 1000 * 60 * 30,
|
});
|
this.handleLiveTime();
|
this.onCancelStartDate();
|
},
|
onCancelStartDate() {
|
// console.log(e);
|
this.selectComponent("#start-time").toggle();
|
this.checkTime("start", "请选择计划直播开始时间");
|
},
|
|
onInputEndDate() {},
|
// onTitleTap(){
|
// if (!this.data.startTime){
|
// wx.showToast({
|
// title: '请先选择开播时间',
|
// duration: 2000
|
// })
|
//
|
// }
|
// },
|
|
onEnterEndDate(e) {
|
let endTime = utils.formatTime(e.detail);
|
console.log("选择下播时间", endTime);
|
this.setData({
|
endDate: e.detail,
|
endTime: endTime,
|
// maxStartDate: e.detail - 1000 * 60 * 30,
|
// minStartDate: e.detail + 1000 * 60 * 20,
|
// e.detail - 1000 * 60 * 30 + (new Date().getTime() - e.detail)
|
});
|
// this.handleLiveTime();
|
this.onCancelEndDate();
|
},
|
onCancelEndDate() {
|
// console.log(e);
|
this.selectComponent("#end-time").toggle();
|
this.checkTime("end", "请选择计划直播结束时间");
|
},
|
|
handleLiveTime() {
|
console.log("iii");
|
|
let startDate = this.data.startDate;
|
let startTime = this.data.startTime;
|
let endDate = this.data.endDate;
|
let endTime = this.data.endTime;
|
if (!startTime || !endTime) return;
|
if (startDate - endDate > 0) {
|
this.setData({
|
startDate: endDate,
|
startTime: endTime,
|
endDate: startDate,
|
endTime: startTime,
|
});
|
}
|
},
|
|
checkTime(time, msg) {
|
if (this.data[time + "Time"] == null) {
|
this.setData({
|
[time + "TimeError"]: msg,
|
});
|
return false;
|
}
|
this.setData({
|
[time + "TimeError"]: "",
|
});
|
return true;
|
// this.handleLiveTime()
|
},
|
|
onChangeFeeds({ detail }) {
|
// 需要手动对 checked 状态进行更新
|
this.setData({ isFeedsPublic: detail });
|
},
|
onChangeShowHomepage({ detail }) {
|
// 需要手动对 checked 状态进行更新
|
this.setData({ isShowInHomepage: detail });
|
},
|
/**
|
*
|
*/
|
checkAnchorName(event) {
|
let value = event.detail.value;
|
console.log(value);
|
this.setData({
|
anchorName: value,
|
});
|
this.checkInput("anchorName");
|
},
|
checkRoomTitle(event) {
|
let value = event.detail.value;
|
this.setData({
|
roomTitle: value,
|
});
|
this.checkInput("roomTitle");
|
},
|
checkAnchorWechat(event) {
|
let value = event.detail.value;
|
this.setData({
|
anchorWechat: value,
|
});
|
this.checkInput("anchorWechat");
|
},
|
checkSubAnchorWechat(event) {
|
let value = event.detail.value;
|
this.setData({
|
subAnchorWechat: value,
|
});
|
if (value.length>0) {
|
this.checkInput("subAnchorWechat");
|
} else{
|
this.setData({
|
subAnchorWechatError: ""
|
});
|
}
|
},
|
|
checkInput(type) {
|
let options = {
|
anchorName: {
|
error: "主播昵称必须为2-15个字",
|
regExp: /^.{2,15}$/,
|
},
|
roomTitle: {
|
error: "直播标题必须为3-17个字",
|
regExp: /^.{3,17}$/,
|
},
|
anchorWechat: {
|
error: "微信号不合规",
|
regExp: /^[a-zA-Z][a-zA-Z\d_-]{5,19}$/,
|
},
|
subAnchorWechat: {
|
error: "微信号不合规",
|
regExp: /^[a-zA-Z][a-zA-Z\d_-]{5,19}$/,
|
},
|
};
|
// let msg = {
|
// anchorName: '请输入主播昵称',
|
// anchorName2: '主播昵称必须为2-15个字',
|
// roomTitle: '请输入直播标题',
|
// roomTitle2: '直播标题必须为3-17个字',
|
// }
|
// // /^[a-zA-Z][a-zA-Z\d_-]{5,19}$/
|
// let length = {
|
// anchorName:2,
|
// roomTitle: 3,
|
// anchorWechat
|
// }
|
let value = this.data[type] || "";
|
console.log(value, options[type].regExp.test(value));
|
if (!options[type].regExp.test(value)) {
|
this.setData({
|
[type + "Error"]: options[type].error,
|
});
|
return false;
|
} else {
|
this.setData({
|
[type + "Error"]: "",
|
});
|
return true;
|
}
|
},
|
|
/**
|
* 检查
|
*/
|
|
async onClickNextStep() {
|
let arr = [];
|
let doccode = this.data.doccode||'';
|
let type = this.data.type;
|
let startTime = this.data.startTime;
|
let endTime = this.data.endTime;
|
let anchorName = this.data.anchorName;
|
let roomTitle = this.data.roomTitle;
|
let anchorWechat = this.data.anchorWechat;
|
let subAnchorWechat = this.data.subAnchorWechat||'';
|
let screenType = this.data.screenType;
|
let isFeedsPublic = this.data.isFeedsPublic;
|
let isShowBannerPhotoOnHomePage = this.data.isShowInHomepage;
|
arr.push(this.checkTime("start", "请选择计划直播开始时间"));
|
arr.push(this.checkTime("end", "请选择计划直播结束时间"));
|
arr.push(this.checkInput("anchorName"));
|
arr.push(this.checkInput("roomTitle"));
|
arr.push(this.checkInput("anchorWechat"));
|
if (subAnchorWechat.length>0) {
|
arr.push(this.checkInput("subAnchorWechat"));
|
}
|
|
// console.log("直播类型", type);
|
// console.log("开播时间", startTime);
|
// console.log("下播时间", endTime);
|
// console.log("主播昵称", anchorName);
|
// console.log("房间标题", roomTitle);
|
// console.log("主播微信", anchorWechat);
|
// console.log("屏幕类型", screenType);
|
// console.log("官方收录", isFeedsPublic);
|
if (arr.includes(false)) {
|
console.log("不能下一步");
|
return;
|
}
|
let data = {
|
type,
|
startTime,
|
endTime,
|
anchorName,
|
name: roomTitle,
|
anchorWechat,
|
subAnchorWechat,
|
screenType,
|
isFeedsPublic,
|
doccode,
|
isShowBannerPhotoOnHomePage
|
};
|
console.log("第一步表单数据", data);
|
|
let [err, res] = await utils.to(
|
wx.$http.request({
|
url: "/shopping/live/saveRoomStep1.do",
|
data,
|
})
|
);
|
if (err) {
|
return;
|
}
|
console.log("新建房间--第一步", res);
|
this.setData({
|
currentStep: 1,
|
doccode: res.doccode,
|
logoUrl:app.globalData.logoUrl,
|
shopName:app.globalData.shopName
|
});
|
},
|
|
/**
|
* 第二步--上传图片
|
*/
|
uploadImg(imgType) {
|
wx.chooseImage({
|
count: 1, // 默认9
|
sizeType: ["original", "compressed"], // 可以指定是原图还是压缩图,默认二者都有
|
sourceType: ["album", "camera"], // 可以指定来源是相册还是相机,默认二者都有
|
success: (res) => {
|
// console.log(res.data)
|
// this.setData({
|
// imageList: res.tempFilePaths,
|
// tempFiles: res.tempFiles
|
// })
|
let imgList = res.tempFilePaths;
|
let files = res.tempFiles;
|
let fieldid = imgType;
|
let doccode = this.data.doccode;
|
console.log(imgList, files, fieldid, doccode);
|
// this.setData({
|
// [imgType]: imgList[0],
|
// });
|
// return;
|
wx.uploadFile({
|
url: utils.getUrl(
|
"/shopping/live/saveRoomAttachment.do?doccode=" +
|
doccode +
|
"&fieldid=" +
|
fieldid
|
),
|
// url: app.globalData.reqBase + '/shopping/confirm.do?m=uploadAttachment&doccode='+ doccode +'&rowid='+rowid,
|
formData: {
|
file: files[0],
|
},
|
filePath: imgList[0],
|
name: "data",
|
success: (res) => {
|
console.log(res);
|
// return;
|
if (!utils.requestError(res)) {
|
return false;
|
}
|
// console.log(data);
|
this.setData({
|
[imgType]: res.data.url,
|
[imgType + "Error"]: "",
|
});
|
},
|
fail: function (errmsg) {
|
console.log("uploadImage fail, errMsg is", errmsg);
|
utils.requestFail(
|
errmsg,
|
"/shopping/live/saveRoomAttachment.do?doccode="
|
);
|
},
|
});
|
},
|
});
|
},
|
uploadShareImg() {
|
this.uploadImg("shareImg");
|
},
|
uploadFeedsImg() {
|
this.uploadImg("feedsImg");
|
},
|
uploadCoverImg() {
|
this.uploadImg("coverImg");
|
},
|
uploadBannerPhoto() {
|
this.uploadImg("bannerPhoto");
|
},
|
|
onClickLastStep() {
|
this.setData({
|
currentStep: 0,
|
});
|
},
|
|
onChangeLike({ detail }) {
|
this.setData({ isLike: detail });
|
},
|
onChangeComment({ detail }) {
|
this.setData({ isComment: detail });
|
},
|
onChangeGoods({ detail }) {
|
this.setData({ isGoods: detail });
|
},
|
onChangeShare({ detail }) {
|
this.setData({ isShare: detail });
|
},
|
onChangeReplay({ detail }) {
|
this.setData({ isReplay: detail });
|
},
|
|
showErrorMsg(imgType,errMsg){
|
wx.showToast({
|
title: errMsg,
|
icon: "none",
|
duration: 2000,
|
});
|
this.setData({
|
[imgType + "Error"]: errMsg,
|
});
|
},
|
isImgUpload(){
|
if (!this.data.shareImg) {
|
let errMsg = "请上传分享卡片封面图片";
|
this.showErrorMsg('shareImg',errMsg)
|
return false;
|
}
|
if (!this.data.feedsImg&&this.data.isFeedsPublic) {
|
let errMsg = "请上传直播卡片封面";
|
this.showErrorMsg('feedsImg',errMsg)
|
return false;
|
}
|
if (!this.data.bannerPhoto&&this.data.isShowInHomepage) {
|
let errMsg = "请上传直播间首页入口封面";
|
this.showErrorMsg('bannerPhoto',errMsg)
|
return false;
|
}
|
if (!this.data.coverImg) {
|
let errMsg = "请上传直播间背景墙";
|
this.showErrorMsg('coverImg',errMsg)
|
return false;
|
}
|
return true;
|
},
|
|
async onClickSubmit() {
|
let data = {
|
doccode: this.data.doccode,
|
closeLike: !this.data.isLike,
|
closeGoods: !this.data.isGoods,
|
closeComment: !this.data.isComment,
|
closeReplay: !this.data.isReplay,
|
closeShare: !this.data.isShare,
|
closeKf: true,
|
};
|
console.log("第二步设置数据", data);
|
if (!this.isImgUpload()) {
|
return;
|
}
|
|
// /shopping/live/saveRoomStep2.do?doccode=XXX&closeLike=false&closeGoods=false&closeComment=false&closeReplay=false&closeShare=false&closeKf=false
|
let [err, res] = await utils.to(
|
wx.$http.request({
|
url: "/shopping/live/saveRoomStep2.do",
|
data,
|
})
|
);
|
if (err) {
|
return;
|
}
|
console.log("新建房间--第二步", res);
|
if (res.QrCodeUrlUnid) {
|
wx.showLoading();
|
await this.downloadQr(res.QrCodeUrlUnid);
|
wx.hideLoading();
|
this.setData({
|
showQrCode: true,
|
qrCodeUrl:res.QrCodeUrlUnid
|
});
|
} else {
|
wx.showToast({
|
title: '直播间创建成功',
|
icon: "none",
|
duration: 2000,
|
});
|
setTimeout(()=>{
|
wx.redirectTo({
|
url: "../myLiveRoom/myLiveRoom",
|
});
|
},2000)
|
|
// 'https://res.wx.qq.com/op_res/BbVNeczA1XudfjVqCVoKgfuWe7e3aUhokktRVOqf_F0IqS6kYR--atCpVNUUC3zr'
|
}
|
},
|
|
async isAuthorizeSave() {
|
let [err, res] = await utils.to(wx.pro.getSetting());
|
if (err) {
|
return false;
|
}
|
console.log("getSetting", res);
|
return res.authSetting["scope.writePhotosAlbum"] !== false;
|
},
|
|
async downloadQr(qrCodeUrl) {
|
let [err, res] = await utils.to(
|
wx.pro.downloadFile({
|
// url: this.data.qrCodeUrl
|
url: qrCodeUrl,
|
})
|
);
|
if (err) {
|
console.log("downloadQr", err);
|
return;
|
}
|
console.log("----downloadQr",res);
|
if (res.statusCode === 200) {
|
// imgDownloadSum++;
|
console.log('......头像',res.tempFilePath)
|
this.setData({
|
qrCodeTempUrl: res.tempFilePath
|
})
|
}else{
|
wx.showToast({
|
title: '二维码下载失败,请重试',
|
icon: "none",
|
duration: 3000,
|
});
|
}
|
},
|
|
async saveQrImg() {
|
wx.showLoading({
|
title: "保存中...",
|
});
|
let isAuthorizeSave = await this.isAuthorizeSave();
|
if (!isAuthorizeSave) {
|
wx.hideLoading();
|
wx.showModal({
|
title: "提示",
|
content: "您还未授权保存到相册,请在接下来打开的设置页面开启相册授权!",
|
success(res) {
|
if (res.confirm) {
|
console.log("用户点击确定");
|
wx.openSetting({
|
success(res) {
|
console.log(res.authSetting);
|
},
|
});
|
} else if (res.cancel) {
|
console.log("用户点击取消");
|
}
|
},
|
});
|
return;
|
}
|
wx.saveImageToPhotosAlbum({
|
filePath: this.data.qrCodeTempUrl,
|
success: (res) => {
|
wx.showToast({
|
title: "二维码已保存到本地,赶紧分享给主播认证吧!",
|
icon: "none",
|
duration: 3000,
|
});
|
},
|
complete: () => {
|
wx.hideLoading();
|
},
|
});
|
},
|
getTimeMS(time){
|
return new Date(time.replace('-','/')).getTime();
|
},
|
async getRoomData(doccode){
|
let [err,res] = await utils.to(
|
wx.$http.request({
|
url:'/shopping/live/getLiveRoomListForMe.do',
|
data:{
|
doccode
|
}
|
})
|
)
|
if (err) {
|
console.log(err);
|
return;
|
}
|
|
let roomData = res.list[0];
|
console.log('编辑直播间。。。',roomData.Type.toString(),roomData.Type);
|
|
this.setData({
|
anchorName: roomData.AnchorName,
|
anchorWechat: roomData.AnchorWechat,
|
subAnchorWechat: roomData.SubAnchorWechat,
|
roomTitle: roomData.RoomName,
|
screenType: roomData.ScreenType,
|
isFeedsPublic: roomData.isFeedsPublic,
|
isShowInHomepage:roomData.isShowBannerPhotoOnHomePage,
|
type:roomData.Type.toString()||'0',
|
startDate:this.getTimeMS(roomData.StartTime),
|
endDate:this.getTimeMS(roomData.EndTime),
|
startTime:roomData.StartTime,
|
endTime:roomData.EndTime,
|
doccode:roomData.DocCode,
|
shareImg:roomData.ShareImgUnid||'',
|
coverImg:roomData.CoverImgUnid||'',
|
feedsImg:roomData.FeedsImgUnid||'',
|
bannerPhoto:roomData.BannerPhoto||'',
|
isLike: !roomData.isCloseLike,
|
isComment: !roomData.isCloseComment,
|
isGoods: !roomData.isCloseGoods,
|
isShare: !roomData.isCloseShare,
|
isReplay: !roomData.isCloseReplay,
|
})
|
},
|
/**
|
* 生命周期函数--监听页面加载
|
*/
|
onLoad: function (options) {
|
wx.$http.request({
|
url:'/shopping/account.do?m=accountInfo',
|
}).then((res)=>{
|
console.log('获取用户信息',res);
|
this.setData({
|
HeadImgUrl:res.UserInfo.HeadImgUrl
|
})
|
})
|
let doccode = options.doccode || '';
|
if (doccode) {
|
this.getRoomData(doccode);
|
}
|
this.setData({
|
isShowBannerOnHomePage:app.globalData.isShowBannerPhotoOnHomePageForLiveUser
|
})
|
},
|
|
/**
|
* 生命周期函数--监听页面初次渲染完成
|
*/
|
onReady: function () {},
|
|
/**
|
* 生命周期函数--监听页面显示
|
*/
|
onShow: function () {},
|
|
/**
|
* 生命周期函数--监听页面隐藏
|
*/
|
onHide: function () {},
|
|
/**
|
* 生命周期函数--监听页面卸载
|
*/
|
onUnload: function () {},
|
|
/**
|
* 页面相关事件处理函数--监听用户下拉动作
|
*/
|
onPullDownRefresh: function () {},
|
|
/**
|
* 页面上拉触底事件的处理函数
|
*/
|
onReachBottom: function () {},
|
|
/**
|
* 用户点击右上角分享
|
*/
|
// onShareAppMessage: function () {
|
|
// }
|
});
|