diff --git a/pagesInn/inn/innHome.vue b/pagesInn/inn/innHome.vue index 686fb72..6878809 100644 --- a/pagesInn/inn/innHome.vue +++ b/pagesInn/inn/innHome.vue @@ -263,9 +263,9 @@ class="more-wrapper" > 置顶动态 + + + 取消置顶 + { - //两列商品宽度 - that.picColumnWidth = (e.screenWidth - uni.upx2px(92)) / 2 + 'px'; + // 两列商品宽度 + this.picColumnWidth = (e.screenWidth - uni.upx2px(92)) / 2 + 'px' } - }); + }) }, - // 下拉刷新 - onPullDownRefresh() { - if (this.activeIndex == 0) { - this.page = 1; - this.loading = false; - this.loadend = false; - this.fetchInnInfoList(); - } else { - this.fetchInnDetail(); + onShow() { + if (!this.isLoad) { + return } + if (this.inn.hasProduct <= 0) { + this.fetchGoods() + } + this.fetchInnInfoList() + this.fetchInnDetail() }, methods: { changeShare() { - this.showShare = !this.showShare; + this.showShare = !this.showShare }, goGoodsConByID(item) { this.$yrouter.push({ @@ -486,22 +485,21 @@ export default { query: { id: item.id } - }); + }) }, saveImg() { - let that = this; + const _this = this uni.getSetting({ success: getRes => { if (getRes.authSetting["scope.writePhotosAlbum"]) { - that.downloadImage(); + _this.downloadImage() } else { uni.authorize({ scope: "scope.writePhotosAlbum", success: () => { - that.downloadImage(); + _this.downloadImage() }, fail: () => { - console.log("authorize fail") uni.openSetting({ success: openRes => { console.log(typeof openRes, openRes) @@ -523,20 +521,20 @@ export default { }) }, downloadImage() { - let that = this; - const randomID = () => Math.random().toString(36).substring(2); + const _this = this + const randomID = () => Math.random().toString(36).substring(2) uni.downloadFile({ - url: this.posterUrl, //网络图片的地址 - filePath: wx.env.USER_DATA_PATH + "/share_" + randomID() + ".png", //指定的本地文件路径 + url: this.posterUrl, // 网络图片的地址 + filePath: wx.env.USER_DATA_PATH + "/share_" + randomID() + ".png", // 指定的本地文件路径 success: downRes => { uni.saveImageToPhotosAlbum({ - filePath: downRes.filePath, //临时文件地址 + filePath: downRes.filePath, // 临时文件地址 success: function () { uni.showToast({ title: "保存成功", icon: "success", success() { - that.showShare = false; + _this.showShare = false } }) }, @@ -556,147 +554,122 @@ export default { } }) }, - doExpandDesc: function () { - this.isExpand = !this.isExpand; - }, - showQrcode: function () { - uni.previewImage({ - current: 0, - urls: [this.inn.qrcode] - }); - }, zanInn: function () { getHotelZan(this.inn.id).then(() => { - this.isLike = !this.isLike; - this.fetchInnDetail(); + this.isLike = !this.isLike + this.fetchInnDetail() }).catch((err) => { uni.showToast({ title: err.msg + '', icon: 'none', mask: false, duration: 1500 - }); + }) }) }, infoClick: function (info) { - this.$yrouter.push('/pagesInn/inn/innInfoDetail?id=' + info.id); + this.$yrouter.push('/pagesInn/inn/innInfoDetail?id=' + info.id) }, publishBtnClick: function () { - this.$yrouter.push('/pagesInn/inn/innInfoPublish?hotelId=' + this.inn.id); + this.$yrouter.push('/pagesInn/inn/innInfoPublish?hotelId=' + this.inn.id) }, modifyBtnClick: function () { - this.$yrouter.push("/pagesInn/inn/innProfileEdit?hotel=" + encodeURIComponent(JSON.stringify(this.inn))); - // this.$yrouter.push('/pagesInn/inn/innProfileEdit'); + uni.setStorageSync('MY_HOTEL_INFO', JSON.stringify(this.inn)) + this.$yrouter.push("/pagesInn/inn/innProfileEdit?id=" + this.inn.id) }, - //删除客栈动态 + // 删除客栈动态 deleteInnInfo: function (info, index) { - let that = this; - that.toggleMoreHandle(index) + const _this = this + _this.toggleMoreHandle(index) uni.showModal({ - title: '确认删除此动态?', - content: '', + title: '提示', + content: '确认删除此动态?', showCancel: true, cancelText: '取消', confirmText: '确认', success: res => { - if (res.confirm) { - uni.showLoading(); + uni.showLoading() postHotelNewsDel({ id: info.id, - hotelId: that.inn.id + hotelId: _this.inn.id }).then((res1) => { - uni.hideLoading(); - that.$dialog.toast({ + uni.hideLoading() + _this.$dialog.toast({ mes: '删除成功!' - }); + }) // 删除成功刷新动态列表 - that.page = 1; - that.loading = false; - that.loadend = false; - that.fetchInnInfoList(); + _this.fetchInnInfoList() }).catch((err) => { - uni.hideLoading(); + uni.hideLoading() uni.showToast({ title: err.msg, icon: "none", duration: 1500 - }); + }) }) } } - }); + }) }, fetchInnInfoList: function () { - let that = this; - if (that.loading) return; //阻止下次请求(false可以进行请求); - if (that.loadend) return; //阻止结束当前请求(false可以进行请求); - that.loading = true; - getHotelNewsList({ - page: that.page, - limit: that.limit, - hotelId: that.id - }).then(res => { - that.loading = false; - //apply();js将一个数组插入另一个数组; - if (that.page == 1) { - that.infoArray = []; - } - that.infoArray.push.apply(that.infoArray, res.data.map((info) => { - var pt = info.createdTime.replace(/-/g, "/"); - info.year = formatDateTime(pt, 'yyyy'); - info.monthDay = formatDateTime(pt, 'MM/dd'); - info.time = formatDateTime(pt, 'HH:mm:ss'); - info.showMore = false - return info; - })); - that.loadend = res.data.length < that.limit; //判断所有数据是否加载完成; - that.page = that.page + 1; - }).catch((err) => { - - }).finally(() => { - uni.stopPullDownRefresh(); - }); - }, - handleRichText: function (str) { - if (str != null) { - return `简介:` + str.replace(/<\/?[^>]*>/g, ''); - } else { - return ''; + const _this = this + if (_this.loading) { + return } + _this.loading = true + _this.infoArray = [] + getHotelNewsList({ + page: 1, + limit: 9999, + hotelId: _this.id + }).then(res => { + _this.loading = false + _this.infoArray.push.apply(_this.infoArray, res.data.map((info) => { + var pt = info.createdTime.replace(/-/g, "/") + info.year = formatDateTime(pt, 'yyyy') + info.monthDay = formatDateTime(pt, 'MM/dd') + info.time = formatDateTime(pt, 'HH:mm:ss') + info.showMore = false + return info + })) + }).finally(() => { + _this.loading = false + uni.stopPullDownRefresh() + }) }, fetchInnDetail: function () { - const that = this + const _this = this let reqFn = null - if (that.isMyInn) { + if (_this.isMyInn) { reqFn = getHotelDetail } else { reqFn = getHomeHotelDetail } - reqFn(that.id).then((res) => { + reqFn(_this.id).then((res) => { const { success, data } = res if (success) { - that.isLoad = true - that.inn = data - that.isLike = data.zanVo !== null - that.isFavorite = data.hasFavorite - that.favoriteCount = data.favoriteCount - that.inn.latitude = that.inn.latitude ? parseFloat(that.inn.latitude) : 24.993587 - that.inn.longitude = that.inn.longitude ? parseFloat(that.inn.longitude) : 102.779656 + _this.isLoad = true + _this.inn = data + _this.isLike = data.zanVo !== null + _this.isFavorite = data.hasFavorite + _this.favoriteCount = data.favoriteCount + _this.inn.latitude = _this.inn.latitude ? parseFloat(_this.inn.latitude) : 24.993587 + _this.inn.longitude = _this.inn.longitude ? parseFloat(_this.inn.longitude) : 102.779656 // 该店铺无商品则不显示“精选商品” if (data.hasProduct <= 0) { - that.activeIndex = 1 - that.tabList[0].isShow = false + _this.activeIndex = 1 + _this.tabList[0].isShow = false } else { - that.fetchGoods() + _this.fetchGoods() } // coverType: 1-图片,2-视频 if (data.coverType === 2) { uni.getSystemInfo({ success: info => { const screenWidth = info.windowWidth - that.videoStyle.width = screenWidth + 'px' - that.videoStyle.height = screenWidth * 500 / 750 + 'px' + _this.videoStyle.width = screenWidth + 'px' + _this.videoStyle.height = screenWidth * 500 / 750 + 'px' } }) // 视频宽高自适应 @@ -728,23 +701,21 @@ export default { */ } } - }).catch((err) => { - }).finally(() => { - uni.stopPullDownRefresh(); - }); + uni.stopPullDownRefresh() + }) }, initPoster() { - getPoster(this.id).then(({data}) => this.posterUrl = data); + getPoster(this.id).then(({data}) => this.posterUrl = data) }, showLocation: function () { if (!this.inn.latitude || !this.inn.longitude) { - this.$dialog.error('暂无位置信息'); + this.$dialog.error('暂无位置信息') } else { uni.openLocation({ latitude: this.inn.latitude, longitude: this.inn.longitude - }); + }) } }, showPic: function (index) { @@ -754,28 +725,25 @@ export default { }) }, changeTab: function (index) { - this.activeIndex = index; - this.page = 1; - this.loading = false; - this.loadend = false; - //刷新数据 + this.activeIndex = index + this.loading = false + // 刷新数据 switch (this.activeIndex) { case 1: - this.fetchInnInfoList(); - break; + this.fetchInnInfoList() + break case 0: - this.goodsPage = 1; - this.goodsList = []; - this.fetchGoods(); - break; + this.goodsList = [] + this.fetchGoods() + break default: - break; + break } }, fetchGoods() { getHotelGoodList({ id: this.inn.id, - page: this.goodsPage, + page: 1, limit: 12 }).then(res => { const { success, data } = res @@ -802,9 +770,9 @@ export default { fail: (res) => { console.log('调用失败!') } - }); + }) } else { - this.$dialog.error('电话为空'); + this.$dialog.error('电话为空') } }, async doneFavorite() { @@ -827,14 +795,14 @@ export default { }, viewAllGoodHandle() { uni.navigateTo({ - url: '/pagesInn/inn/innGoodList?id=' + this.inn.id, + url: '/pagesInn/inn/innGoodList?id=' + this.inn.id }) }, - setTopInfoHandle(item) { + setTopInfoHandle(item, isTop) { uni.showLoading() setTopHotelNew({ id: item.id, - isTop: 1 + isTop }).then(res => { const { success } = res if (success) { @@ -851,37 +819,6 @@ export default { } - -