diff --git a/src/views/secondHandCar/forSale.vue b/src/views/secondHandCar/forSale.vue index 7e736045..1392f892 100644 --- a/src/views/secondHandCar/forSale.vue +++ b/src/views/secondHandCar/forSale.vue @@ -106,7 +106,6 @@ export default { mixins:[myMixins], data(){ return{ - show:false, current: 0, noClick:true, id:'', @@ -144,14 +143,15 @@ export default { document.addEventListener('visibilitychange', async ( ) => { let state = document.visibilityState if (state == 'hidden') { // 用户离开了 - console.log("用户离开了") - await this.getDuration() + console.log("用户离开了1") + await this.getDuration(1); + console.log("用户离开了2") } }); }, - destroyed() { - this.getDuration() - }, + /* destroyed() { + this.getDuration(1) + },*/ methods:{ formatToWan(num) { let result = (num / 10000).toString(); @@ -163,25 +163,23 @@ export default { } return result + '万'; }, - getDuration(){ + getDuration(type){ // 页面卸载时记录离开时间并计算浏览时长 const endTime = new Date(); const duration = (endTime - this.startTime) / 1000; // 计算时长(秒)\ - this.saveRecord(duration); + this.saveRecord(duration,type); }, - async saveRecord(duration){ - await saveRecord({type: this.recordType, carInfoId: this.id, duration}) + async saveRecord(duration,type){ + await saveRecord({type: type, carInfoId: this.id, duration}) }, handle(){ - this.show=true + this.getDuration(2) Dialog.alert({ message:this.detailInfo.contactNumber , confirmButtonText:'拨打电话', showCancelButton:true, }).then(async() => { - this.recordType=2 window.location.href = `tel:${this.detailInfo.contactNumber}`; - await this.getDuration() }).catch(() => { // on cancel }); diff --git a/src/views/secondHandCar/wantBuySale.vue b/src/views/secondHandCar/wantBuySale.vue index 43ad258a..fab91b36 100644 --- a/src/views/secondHandCar/wantBuySale.vue +++ b/src/views/secondHandCar/wantBuySale.vue @@ -67,7 +67,6 @@ export default { detailInfo:'', duration:'', startTime: null, // 记录进入时间 - recordType:1, isList:false, } }, @@ -88,31 +87,31 @@ export default { document.addEventListener('visibilitychange', async ( ) => { let state = document.visibilityState if (state == 'hidden') { // 用户离开了 - console.log("用户离开了") - await this.getDuration() + console.log("用户离开了1") + await this.getDuration(1); + console.log("用户离开了2") } }); }, - destroyed() { - this.getDuration() - }, + /*destroyed() { + this.getDuration(1) + },*/ methods:{ - getDuration(){ + getDuration(type){ const endTime = new Date(); const duration = (endTime - this.startTime) / 1000; // 计算时长(秒) - this.saveRecord(duration); + this.saveRecord(duration,type); }, - async saveRecord(duration){ - await saveRecord({type:this.recordType,carInfoId:this.id,duration}) + async saveRecord(duration,type){ + await saveRecord({type:type,carInfoId:this.id,duration}) }, handle(){ + this.getDuration(2) Dialog.alert({ message:this.detailInfo.contactNumber , confirmButtonText:'拨打电话', showCancelButton:true, }).then(() => { - this.recordType=2 - this.getDuration() window.location.href = `tel:${this.detailInfo.contactNumber}`; }).catch(() => { // on cancel