const app = getApp() const util = require("../../../utils/jmsUtil.js"); const api = require('../../../api/jms.js'); import moment from 'moment' Page({ data: { waitMatchCount:'', watiServiceCount:'', totalCount:'', userInfo:{ userName:'', headImg:'', fraName:'', }, timer: "", dayCalendar: { day: '', workerOrderInfoDTOList: [], workerName: '', }, currentMonth: moment(new Date()).format('YYYY-MM'), calcendarFold: true, stickShow: false, today: util.formetdate(new Date()), currentDay: util.formetdate(new Date()), isLeaveFold: true, orderDisable: true, orderDisable1: false, ticketList: [{}, {}], monthInfo: { recCode: '', fraName: '', workerName: '' }, workerDayInfoList: [], weekCalendar: [], wholeCalendar: [], myqr_show: false, myqr_url: '', myqr_blur: 0 ,//背景模糊值 activeTab:7, page:1, limit:70, serviceList:[] }, onPageScroll(e) { // console.log(e.scrollTop); // if(e.scrollTop > 200){ // this.setData({ // stickShow: true // }); // } else { // this.setData({ // stickShow: false // }); // } }, leaveFold() { let fold = this.data.isLeaveFold; this.setData({ isLeaveFold: !fold }); }, copyCode(e) { let code = this.data.monthInfo.recCode; wx.setClipboardData({ data: code, success: function (res) { wx.showToast({ title: '复制成功', icon: 'none', duration: 2000 }); } }) }, copyNum(e) { let bookno = e.currentTarget.dataset.bookno; console.log(bookno); wx.setClipboardData({ data: bookno, success: function (res) { wx.showToast({ title: '复制成功', icon: 'none', duration: 2000 }); } }) }, callUp(e) { let status = e.currentTarget.dataset.status; let phone = e.currentTarget.dataset.phone; let stateName=e.currentTarget.dataset.statusval; util.request(api.addCusmobileLog, { bookDetailId:e.currentTarget.dataset.serviceid, phone:phone, stateName:stateName, fraId:this.data.userInfo.fraId, fraName:this.data.userInfo.fraName }, 'POST').then(res => { }); if (status == '1' || status == '2'|| status == '7') { wx.makePhoneCall({ phoneNumber: phone }); } }, openMap(e) { //打开地图 let status = e.currentTarget.dataset.status; let address = e.currentTarget.dataset.address; if (status == '待履约' || status == '服务中') { let lnglat = e.currentTarget.dataset.lnglat.split(','); let lng = ''; let lat = ""; if (lnglat.length > 0) { lng = Number(lnglat[0]); lat = Number(lnglat[1]); } console.log(lng, lat); wx.openLocation({ latitude: lat, longitude: lng, // name: address, address: address, scale: 28 }); } }, goSchedule() { wx.navigateTo({ url: '/pages/upgrade/scheduleCalc/scheduleCalc', }) }, goDetail(e) { let id = e.currentTarget.dataset.id; wx.navigateTo({ url: '/pages/upgrade/ticketDetail/ticketDetail?bookTradeNo=' + id, }); }, evalMaster(e) { let id = e.currentTarget.dataset.id; let workerno = e.currentTarget.dataset.workerno; this.setData({ evalMasterShow: true, star: 0, masterComment: '', bookTradeNo: id, workerNo: workerno }); }, onClickMsterOverlay() { this.setData({ evalMasterShow: false, }); }, onClickDiscipleOverlay() { this.setData({ evalDiscipleShow: false, }); }, onStarChange(event) { this.setData({ star: event.detail, }); }, onRadioChange(event) { this.setData({ radioDisciple: event.detail, }); }, bindMasterComment(e) { this.setData({ masterComment: e.detail.value }) }, bindDiscipleComment(e) { this.setData({ discipleComment: e.detail.value }) }, stop: function () { //阻止弹框冒泡和捕获的空事件,不要删除!!! }, submitEvalMaster() { if (this.data.star == 0) { wx.showToast({ title: '请选择评价星级', icon: 'none' }) } else if (this.data.masterComment == '') { wx.showToast({ title: '请输入跟单体会', icon: 'none' }) } else { util.request(api.discipleFeedback, { feedback: this.data.discipleComment, level: this.data.star, bookTradeNo: this.data.bookTradeNo, workerNo: this.data.workerNo }, 'GET').then(res => { if (res.errno === 0) { wx.showToast({ title: '评价成功', icon: 'none' }) this.setData({ evalMasterShow: false, }); this.getDayCalendar(); } else { wx.showToast({ title: res.errmsg, icon: 'none' }) } }); } }, evalDisciple(e) { let id = e.currentTarget.dataset.id; let workerno = e.currentTarget.dataset.workerno; this.setData({ evalDiscipleShow: true, radioDisciple: '通过', discipleComment: '', bookTradeNo: id, workerNo: workerno }); }, submitEvalDisciple() { if (this.data.radioDisciple == '') { wx.showToast({ title: '请选择是否通过', icon: 'none' }) } else if (this.data.discipleComment == '') { wx.showToast({ title: '请输入内容', icon: 'none' }) } else { util.request(api.masterFeedback, { remark: this.data.discipleComment, feedback: this.data.radioDisciple, bookTradeNo: this.data.bookTradeNo, workerNo: this.data.workerNo }, 'GET').then(res => { if (res.errno === 0) { wx.showToast({ title: '评价成功', icon: 'none' }) this.setData({ evalDiscipleShow: false, }); this.getDayCalendar(); } else { wx.showToast({ title: res.errmsg, icon: 'none' }) } }); } }, goProblemList(e) { // this.setData({ // navigateType: 1 // }) let id = e.currentTarget.dataset.id; wx.navigateTo({ url: '/pages/problem/list/list?bookTradeNo=' + id, }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { // let current=this.data.wholeCalendar.filter(item=>{return item.day==this.data.currentDay}); // if(current.length==0){ // return false; // } // let week=current[0].weekOfYear; // let weekCalendar=this.data.wholeCalendar.filter(item=>{ // return item.weekOfYear==week; // }); // this.setData({ // workerDayInfoList:weekCalendar, // weekCalendar:weekCalendar // }); this.getMonthCalender(false, 'first'); let userInfo=wx.getStorageSync('userInfo'); console.log(userInfo); this.setData({ userInfo:userInfo }); // this.getDayCalendar(); }, closeMyQr() { this.setData({ myqr_show: false, myqr_blur: 0 }); }, goSaveQrcode: function () { //保存二维码图片 let that = this; console.info(that.data.myqr_url); wx.downloadFile({ url: that.data.myqr_url, success: function (res) { if (res.statusCode === 200) { let img = res.tempFilePath; wx.saveImageToPhotosAlbum({ filePath: img, success(res) { that.closeMyQr(); wx.showModal({ title: '提示', showCancel:false, content: '此单复购专属二维码图片已保存到您的相册' }) }, fail(res) { wx.showModal({ title: '提示', showCancel:false, content: '网络或授权问题 图片保存失败 请重试' }) } }) } else wx.showModal({ title: '提示', showCancel:false, content: '网络或授权问题 图片保存失败 请重试' }) }, fail(res) { wx.showModal({ title: '提示', showCancel:false, content: '网络或授权问题 图片保存失败 请重试' }) } }) }, getQrCode(e) { //获取复购码 let bookno = e.currentTarget.dataset.bookno; util.request(api.getWorkerQrCode, { bookTradeNo: bookno }, 'GET').then(res => { if (res.errno === 0) { wx.showToast({ title: '获取成功', icon: 'none' }) this.setData({ myqr_show: true, myqr_blur: 20, myqr_url: res.data }); wx.pageScrollTo({ scrollTop: 0, }); } else { wx.showToast({ title: res.errmsg, icon: 'none' }) } }); }, /** * 生命周期函数--监听页面显示 */ onShow: function () { // this.getDayCalendar(); // let timer = setInterval(() => { // console.log('定时刷新日历数据', new Date()); // this.getMonthCalender(); // this.getDayCalendar(); // }, 2 * 60 * 1000); // this.setData({ // timer: timer // }); this.setData({ activeTab:app.globalData.activeTab, currentDay:app.globalData.currentDay }); this.getDayCalendar(); }, onHide: function () { console.log('onHide'); // clearInterval(this.data.timer); }, onUnload: function () { console.log('onunload'); // clearInterval(this.data.timer); }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { this.getMonthCalender(); this.setData({ page:1 }); this.getDayCalendar(); }, getDayCalendar() { wx.showLoading({ title: '加载中...', }); util.request(api.ServiceList, { reservationStartTime: this.data.currentDay, reservationEndTime:this.data.currentDay, status:this.data.activeTab==0?'':this.data.activeTab, limit:this.data.limit, page:this.data.page }, 'GET').then(res => { // console.log(res); wx.hideLoading(); if (res.errno === 0) { res.data.list.forEach(f=>{ }) this.setData({ totalPages:Math.ceil(res.data.total/this.data.limit) }); if (this.data.page == 1) { this.setData({ serviceList: res.data.list, }); } else{ this.setData({ serviceList: this.data.serviceList.concat(res.data.list), }); } } }).catch(err => { wx.hideLoading(); }); }, getMonthCalender(flag, tag) { wx.showLoading({ title: '加载中...', }); util.request(api. GetCalendar, { month: this.data.currentMonth, }, 'GET').then(res => { console.log(res); wx.hideLoading(); if (res.errno === 0) { this.setData({ wholeCalendar: res.data }); if (flag) { this.setData({ calcendarFold: false, workerDayInfoList: this.data.wholeCalendar, }); } let current = this.data.wholeCalendar.filter(item => { return item.day == this.data.currentDay }); if (current.length == 0) { return false; } let week = current[0].weekOfYear; let weekCalendar = this.data.wholeCalendar.filter(item => { return item.weekOfYear == week; }); this.setData({ weekCalendar: weekCalendar, waitMatchCount:current[0].waitMatchCount, waitServiceCount:current[0].waitServiceCount, totalCount:current[0].totalCount }); if (tag == 'first') { this.setData({ workerDayInfoList: weekCalendar, }); } if (this.data.calcendarFold) { this.setData({ workerDayInfoList: weekCalendar, }); } else { this.setData({ workerDayInfoList: this.data.wholeCalendar, }); } } else { wx.showToast({ title: res.errmsg, duration: 3000, icon: 'none' }); } }).catch(err => { wx.hideLoading(); }); }, switchDay(e) { let day = e.currentTarget.dataset.day; let item=e.currentTarget.dataset.item; this.setData({ currentDay: day, waitMatchCount:item.waitMatchCount, waitServiceCount:item.waitServiceCount, totalCount:item.totalCount }); app.globalData.currentDay=day; this.getDayCalendar(); }, calcendarCollapse() { let calcendarFold = this.data.calcendarFold; if (calcendarFold) { this.setData({ workerDayInfoList: this.data.wholeCalendar, calcendarFold: !calcendarFold }); } else { this.setData({ workerDayInfoList: this.data.weekCalendar, calcendarFold: !calcendarFold }); } }, lastMonth() { console.log(this.data); let params = util.getYearMonth(this.data.currentMonth, '-'); this.setData({ currentMonth: params }); this.getMonthCalender(true); }, nextMonth() { let params = util.getYearMonth(this.data.currentMonth, '+'); console.log(params); this.setData({ currentMonth: params }); this.getMonthCalender(true); }, goIssueTicket() { wx.navigateTo({ url: '/pages/upgrade/issueTicket/issueTicket', }) }, arriveCus(e) { let status = e.currentTarget.dataset.status; let id = e.currentTarget.dataset.id; if (status == '待履约') { wx.showModal({ title: '', content: '确定已经到门?', success: res => { if (res.confirm) { util.request(api.ClockIn, { relationTradeNo: id, }, 'POST').then(res => { if (res.errno === 0) { wx.showToast({ title: '操作成功' }); this.getDayCalendar(); } else { wx.showToast({ title: res.errmsg, icon: 'none' }); // util.showErrorToast(res.errmsg); } }); } } }); } }, finishOrder(e) { let status = e.currentTarget.dataset.status; let id = e.currentTarget.dataset.id; if (status == '服务中') { wx.showModal({ title: '', content: '确定服务完成?', success: res => { if (res.confirm) { util.request(api.ServiceProvided, { relationTradeNo: id, }, 'POST').then(res => { if (res.errno === 0) { wx.showToast({ title: '操作成功' }); this.getDayCalendar(); } else { wx.showToast({ title: res.errmsg, icon: 'none' }); // util.showErrorToast(res.errmsg); } }); } } }); } }, exitLogin: function () { wx.showModal({ title: '', confirmColor: '#b4282d', content: '退出登录?', success: function (res) { if (!res.confirm) { return; } // util.request(api.AuthLogout, {}, 'POST'); app.globalData.hasLogin = false; wx.removeStorageSync('token'); wx.removeStorageSync('userInfo'); // wx.redirectTo({ // url: '/pages/temp/login/login' // }); wx.redirectTo({ url: '/pages/index/index' }); } }) }, onTabChange(e) { this.setData({ activeTab: e.detail.name, page:1 }); app.globalData.activeTab=e.detail.name; this.getDayCalendar(); }, onReachBottom() { // if (this.data.totalPages > this.data.page) { // this.setData({ // page: this.data.page + 1 // }); // this.getGoodsList(); // } else { // wx.showToast({ // title: '没有更多工单了', // icon: 'none', // duration: 2000 // }); // return false; // } }, handleCopy(e) { let serviceid= e.currentTarget.dataset.serviceid; let item=this.data.serviceList.filter(item=>{return item.serviceId==serviceid}); let row=item[0]; let address = row.address.slice(0, -5) + '*****' let data = `工单编号:${row.serviceId}\n商品简称:${row.orderType ? row.orderType : ''}\n预约时间:${row.bookTime}\n服务地址:${address}\n服务备注:${row.message}` wx.setClipboardData({ data: data, success: function (res) { wx.showToast({ title: '复制成功', icon: 'none', duration: 2000 }); } }) }, // 接单 handleTake(e){ let serviceid= e.currentTarget.dataset.serviceid; wx.navigateTo({ url: '/pages/temp/takeOrder/takeOrder?serviceid='+serviceid, }); }, // 转发 handleSend(e){ let serviceid= e.currentTarget.dataset.serviceid; wx.navigateToMiniProgram({ appId:'wxcd00bbeb981bec8b', path:'/pages/upgrade/tempDetail/tempDetail?id='+serviceid+"&mini=1", envVersion:'release',//develop开发版,trial体验版,release正式版 success(res){ console.log('跳转小程序成功'+res) }, }); }, // 取消工单 handleCancel(e){ let serviceid= e.currentTarget.dataset.serviceid; wx.navigateTo({ url: '/pages/temp/cancelOrder/cancelOrder?serviceid='+serviceid, }); }, // 修改预约 handleAppoint(e){ let item= e.currentTarget.dataset.item; app.globalData.orderInfo=item; wx.navigateTo({ url: '/pages/temp/assignOrder/assignOrder', }); }, // 完成工单 handleFinish(e){ let serviceid= e.currentTarget.dataset.serviceid; wx.showModal({ title: '', content: '确定要手动完成此服务单吗?', success: res => { if (res.confirm) { util.request(api.CompleteServiceOrder, { serviceId: serviceid, fraId:this.data.userInfo.fraId, fraName:this.data.userInfo.fraName }, 'GET').then(res => { if (res.errno === 0) { wx.showToast({ title: '操作成功' }); this.getDayCalendar(); } else { wx.showToast({ title: res.errmsg, icon: 'none' }); // util.showErrorToast(res.errmsg); } }); } } }); }, supplyCode(e){ console.log(e) let bookno = e.currentTarget.dataset.serviceid; app.globalData.diffId=0; wx.navigateTo({ url: '/pages/temp/supplyRecord/supplyRecord?bookno='+bookno, }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, })