var app = getApp(); var util = require("../../utils/util.js"); let pageid = ""; let timer = null; let endTotal = 0 let num = 0 Page({ /** * 页面的初始数据 */ data: { appAssetsUrl2: app.appAssetsUrl2, // 行家id id: null, // 主题id topicId: null, topicList: [], content: null, price: null, groupList: [], groupList3: [], bottomLeft: app.bottomLeft, onePer: true, // 单人请教 addressIndex: 0, addressArray: [], tuanList: [ { endtime: "2022-10-12 21:25:06", }, { endtime: "2022-10-15 21:25:06", }, { endtime: "2022-10-15 21:25:06", }, { endtime: "2022-10-13 21:25:06", }, ], time: "07:00", timelist: [ [ "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", ], ["00", "15", "30", "45"], ], hourIndex: 0, minuteIndex: 0, date: "", startDate: "", addressPopup: false, pickMove: false, groupWay: 0, // 拼团方式 groupNumberPeople: 0, //拼团人数 storeId: null, // 门店id contents: "", //预约内容 topicPrice: 0, payPrice: 0, timeList: [], //空余时间 isGroup: false, // 是否有拼团 aa: [], }, showTime() { this.popup.showPopup(); }, // 场地 showAddress() { this.setData({ addressPopup: true, }); }, //场地change bindChange(e) { console.log(e); this.setData({ addressIndex: e.detail.value, }); }, pickstart() { this.setData({ pickMove: true, }); }, pickend() { this.setData({ pickMove: false, }); }, confirmAddress() { if (this.data.pickMove) { return; } this.setData({ addressPopup: false, storeId: this.data.addressArray[this.data.addressIndex].id, }); }, toStoreDetail(e) { console.log(e, 111); wx.navigateTo({ url: "/expert/storedetail/storedetail?id=" + e.currentTarget.dataset.id, }); }, putblur(e) { this.setData({ contents: e.detail.value, }); }, submit() { if (this.data.topicId === null) { return app.showError("请选择话题!"); } if (this.data.groupNumberPeople == 0 && !this.data.onePer) { return app.showError("请选择拼团人数!"); } if (this.data.contents == "") { return app.showError("请输入预约内容!"); } if (!util.getUserId()) { wx.reLaunch({ url: "/pages/login", }); return; } wx.requestSubscribeMessage({ tmplIds: [ "7W7QGAJiJ5xzYZtzzG3vaiVrGGtUYklkqKGCFpMP2wU", "LyWMllU4dWpy1Y8tS39EhOBLUSQWmUb_yDFKoJojKq8", ], success: (success) => {}, fail: (fail) => {}, complete: (complete) => { app._post_form( "meet/consult", "", { content: this.data.contents, expertId: this.data.id, groupNumberPeople: this.data.groupNumberPeople, groupWay: this.data.groupWay, meetPrice: this.data.payPrice, meetTime: this.data.date + " " + this.data.time + ":00", storeId: this.data.storeId, topicId: this.data.topicId, type: 0, id: util.getUserId(), }, (res) => { if (res.code == 0) { wx.showActionSheet({ itemList: ["微信支付"], success: (response) => { if (response.tapIndex === 0) { wx.showLoading({ title: "正在处理...", mask: true, }); wx.requestPayment({ timeStamp: res.map.timestamp, nonceStr: res.map.nonce_str, package: "prepay_id=" + res.map.prepay_id, signType: "MD5", paySign: res.map.sign, success: (result) => { if (result.errMsg == "requestPayment:ok") { wx.showLoading({ title: "正在处理...", mask: true, }); console.log(result, 11111111); wx.hideLoading(); // wx.showModal({ // title: "温馨提示", // content: "支付成功!", // showCancel: false, // }); wx.showToast({ title: "支付成功!", icon: "none", duration: 1500, }); setTimeout(() => { wx.navigateTo({ url: "/expert/success/success?expertId=" + this.data.id + "&meetId=" + res.map.businessId + "&onePer=" + this.data.onePer, }); },2000) } else { wx.hideLoading(); wx.showToast({ title: "支付失败!", icon: "none", duration: 1500, }); } }, fail: (error) => { wx.hideLoading(); wx.showToast({ title: "支付失败!", icon: "none", duration: 1500, }); }, }); } }, fail(errors) {}, }); } else { wx.showModal({ title: "温馨提示", content: res.msg, showCancel: false, }); } }, function (res) {} ); }, }); console.log(util.getUserId()); // wx.navigateTo({ // url: '/expert/success/success' // }) }, hiddenAddress() { this.setData({ addressPopup: false, }); }, know() { this.popup.hidePopup(); }, //话题选择change msgChange(e) { let that = this; let temp; if (e && e.hasOwnProperty("detail")) { temp = e.detail.value; } else { temp = e; } console.log(e,'20') for (let item of this.data.topicList) { if (item.id == temp) { this.setData({ topicId: temp, content: item.topicDescribe, price: item.topicPrice, payPrice: that.data.onePer ? item.topicPrice : that.data.groupNumberPeople == 0 ? item.topicPrice : item.topicPrice / that.data.groupNumberPeople, }); this.getGroupList(); } } }, //日期change bindDateChange(e) { this.setData({ date: e.detail.value, }); }, //时间change timeChange(e) { this.setData({ time: e.detail.value, }); }, bindMultiPickerChange(e) { console.log(e, 11111111); let hourIndex = e.detail.value[0]; let minuteIndex = e.detail.value[1]; this.setData({ hourIndex: hourIndex, minuteIndex: minuteIndex, time: this.data.timelist[0][[hourIndex]] + ":" + this.data.timelist[1][minuteIndex], }); }, //拼团方式change pinChange(e) { let that = this; if (e.detail.value == "1") { this.setData({ onePer: false, payPrice: that.data.price, }); } else { this.setData({ onePer: true, payPrice: that.data.price, groupNumberPeople: 0, }); } this.setData({ groupWay: e.detail.value, }); }, //拼团人数 perChange(e) { let that = this; this.setData({ groupNumberPeople: e.detail.value, payPrice: that.data.price / e.detail.value, }); }, //更多拼团 more() { this.getGroupList(); this.popup1.showPopup(); }, // 参与拼团 joinGroup(e) { // console.log(e.currentTarget.dataset.meetid); // console.log(e.currentTarget.dataset.expertId); if (!util.getUserId()) { wx.reLaunch({ url: "/pages/login", }); return; } wx.navigateTo({ url: "/meet/meet/addmeet?expertId=" + e.currentTarget.dataset.expertid + "&meetId=" + e.currentTarget.dataset.meetid + "&memberId=" + e.currentTarget.dataset.memberid }); // console.log('expertId',e.currentTarget.dataset.expertid) // console.log('expertId1',this.data.id) // console.log(e) // console.log(this.data.onePer,'111222') // app._put_form( // "meet/joinTheGroup", // "", // { // id: util.getUserId(), // meetId: e.currentTarget.dataset.meetid, // }, // (res) => { // if (res.code === 0) { // wx.showActionSheet({ // itemList: ["微信支付"], // success: (response) => { // if (response.tapIndex === 0) { // wx.showLoading({ // title: "正在处理...", // mask: true, // }); // wx.requestPayment({ // timeStamp: res.map.timestamp, // nonceStr: res.map.nonce_str, // package: "prepay_id=" + res.map.prepay_id, // signType: "MD5", // paySign: res.map.sign, // success: (result) => { // if (result.errMsg == "requestPayment:ok") { // wx.showLoading({ // title: "正在处理...", // mask: true, // }); // console.log(result, 11111111); // wx.hideLoading(); // wx.showToast({ // title: "拼团成功", // icon: "success", // }); // wx.navigateTo({ // url: // "/expert/success/success?expertId=" + // this.data.id + // "&meetId=" + // res.map.businessId + // "&onePer=" + // false, // }); // } else { // wx.hideLoading(); // wx.showToast({ // title: "支付失败!", // icon: "none", // duration: 1500, // }); // } // }, // fail: (error) => { // wx.hideLoading(); // wx.showToast({ // title: "支付失败!", // icon: "none", // duration: 1500, // }); // }, // }); // } // }, // }); // // this.getGroupList(); // } // } // ); }, freeTime(id) { app._get(`expert/info/${id}`, {}, (res) => { if (res.code === 0) { this.setData({ timeList: res.expert.periodBOList, }); } }); }, //场地change // addressChange(e) { // this.setData({ // addressIndex: e.detail.value, // }) // }, //取消事件 _error(e) { this[e.currentTarget.dataset.name].hidePopup(); clearInterval(timer); endTotal = 0 num = 0 // this.setData({ // maskShow: false, // isDjs: false, // time: 5 // }) }, //倒计时 nowTime(res) { //时间函数 num++ let that = this; // var endTotal = 0 let len = res.length; //时间数据长度 if(endTotal == len) { clearInterval(timer); return; } for (let i = 0; i < len; i++) { if(res[i].difftime == '已结束!') { continue } let localDate = new Date(); var intDiff = res[i].groupWayEndTime; //获取数据中的时间 let endTime = new Date(intDiff); let stratTime = (new Date(res[i].currentTime)).getTime() + num*1000 // console.log(endTime.getTime(),localDate.getTime(),'ooooooooooppppp111') //计算秒数,取数据只取当月的,所以从天开始 // let s = (endTime.getTime() - localDate.getTime()) / 1000; let s = (endTime.getTime() - stratTime) / 1000; // let s = (endTime.getTime() - stratTime.getTime()) / 1000; // console.log(intDiff) var day = 0, hour = 0, minute = 0, second = 0, msg = ""; if (s > 0) { //转换时间 day = Math.floor(s / 86400); // hour = // Math.floor((s % 86400) / 3600) < 10 // ? "0" + Math.floor((s % 86400) / 3600) // : Math.floor((s % 86400) / 3600); hour =Math.floor(s / 60 / 60) < 10 ? '0' + Math.floor(s / 60 / 60) : Math.floor(s / 60 / 60); minute = Math.floor((s % 3600) / 60) < 10 ? "0" + Math.floor((s % 3600) / 60) : Math.floor((s % 3600) / 60); second = Math.floor(s % 60) < 10 ? "0" + Math.floor(s % 60) : Math.floor(s % 60); msg = hour + ":" + minute + ":" + second; } else { msg = "已结束!"; endTotal++ // res[i].difftime = msg; // clearInterval(timer); } // console.log(str); res[i].difftime = msg; //在数据中添加difftime参数名,把时间放进去 } that.setData({ // wearList: res groupList: res.slice(0, 10), groupList3: res.slice(0, 3), }); // this.setData({ // groupList: res.list.slice(0, 10), // groupList3: res.list.slice(0, 3), // }); // console.log(that.data.groupList3) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { console.log(options); if (options.topicId) { this.setData({ topicId: options.topicId, }); } console.log(options,'options.topicId') this.setData({ id: options.id, topicPrice: options.price, payPrice: options.price, }); this.getTopic(options.id); this.getMeetAddressList(options.id); this.freeTime(options.id); var currentDate = new Date() var preDate = new Date(currentDate.getTime() + (2*24*3600*1000)) let year = preDate.getFullYear() let mon = preDate.getMonth() + 1 let day = preDate.getDate() let s = year + '-' + (mon<10?('0'+mon):mon) + '-' + (day<10?('0'+day):day) this.setData({ date: s, startDate: s }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { //获得popup组件 this.popup = this.selectComponent("#popup"); this.popup1 = this.selectComponent("#popup1"); }, /** * 生命周期函数--监听页面显示 */ onShow: function () {}, // 获取擅长话题 getTopic(id) { let that = this app._get( "experttopic/list", { expertId: id, }, (res) => { if (res.code === 0) { this.setData({ topicList: res.list, }); if (this.data.topicId) { this.data.topicList.forEach((v, i) => { if (v.id == this.data.topicId) { v.checked = true; } else { v.checked = false; } }); this.setData({ topicList: this.data.topicList, }); this.msgChange(this.data.topicId); }else { this.setData({ topicId: res.list[0].id, 'topicList[0].checked': true, content: res.list[0].topicDescribe, price: res.list[0].topicPrice, payPrice: that.data.onePer ? res.list[0].topicPrice : that.data.groupNumberPeople == 0 ? res.list[0].topicPrice : res.list[0].topicPrice / that.data.groupNumberPeople, }); // this.setData({ // topicId: temp, // content: item.topicDescribe, // price: item.topicPrice, // payPrice: that.data.onePer // ? item.topicPrice // : that.data.groupNumberPeople == 0 // ? item.topicPrice // : item.topicPrice / that.data.groupNumberPeople, // }); } this.getGroupList() console.log(this.data.topicId,'topicId2222') } } ); }, // 拼团列表 getGroupList() { clearInterval(timer); this.setData({ groupList: [], groupList3: [], }); app._get( "meet/groupList", { expertId: this.data.id, topicId: this.data.topicId, }, (res) => { if (res.code === 0) { // this.setData({ // groupList: res.list.slice(0, 10), res.list // groupList3: res.list.slice(0, 3), // }); // this.nowTime(this.data.tuanList); if (res.list.length > 0) { timer = setInterval(this.nowTime, 990, res.list); } } } ); }, // 约见场地列表 getMeetAddressList(expertId) { let that = this; app._get(`expert/meetingVenueList/${expertId}`, {}, (res) => { if (res.code === 0) { this.setData({ addressArray: res.list, storeId: res.list[0].id, }); } }); }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () {}, onUnload: function () { clearInterval(timer); endTotal = 0 num = 0 // this.data.groupList.forEach((v, k) => { // clearInterval(v.timer); // }); // this.data.groupList.forEach((v, k) => { // clearInterval(v.timer); // // clearTimeout(v.timer) // // var index = "groupList[" + k + "].timer"; //这里必须这样拼接 // // this.setData({ // // [index]: null, // // }); // console.log(this.data.aa) // }); }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () {}, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () {}, showShareMenu: function () { wx.showShareMenu(); }, hideShareMenu() { wx.hideShareMenu(); }, });