Files
medicine_app/pages/peanut/searchFor.vue
liuyuan 192f00c069 提交
2025-10-17 18:15:48 +08:00

343 lines
6.9 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<view style=" height: 100vh; background: #f7faf9;" :style="`background:${show==1?'#f4f7ff':''}`">
<z-nav-bar>
<div style="width: 480rpx">
<u-search :clearabled="true" bgColor="#fff" borderColor="#54a966" focus v-model="bookScreen.bookName"
@custom='souBook' @clear="clear" style="width: 100%;"></u-search>
</div>
</z-nav-bar>
<view class="sear_ch" v-if="this.show==0">
<view class="sear_ch_tit">
历史搜索
</view>
<view class="sear_ch_tag">
<text v-for="item in historyList" @click="serkeyWord(item)">{{item}}</text>
</view>
</view>
<view class="sear_list" v-if="this.show==1">
<commonSearchFor :prouctList="bookList" :courseList="courseList"></commonSearchFor>
<!-- <view class="flexbox" style="display: flex; flex-wrap: wrap;">
<view class="bl_tioa" v-for="(item,index) in bookList" @click="onpageJump(item)">
<view class="bl_tioa_bg">
<image :src="item.productImages"></image>
<view>
<text class="bok_name">{{item.productName}}</text>
</view>
</view>
</view>
</view> -->
<view style="height: 1px;"></view>
<view>
<view v-if="status==0" style="text-align: center;">
<u-loading-icon style="display: inline-block;"></u-loading-icon>
<font style='vertical-align: super;margin-left: 10px;font-size: 26rpx;color: #909399;'>努力加载中</font>
</view>
<view v-if="status==1">
<u-divider text="全部加载完成"></u-divider>
</view>
</view>
<view style="padding-bottom: 20rpx;">
<u-back-top :scroll-top="scrollTop"></u-back-top>
</view>
</view>
<view v-if="this.show==1&&this.bookList==''">
<u-divider text="暂无数据"></u-divider>
</view>
<music-play :playData="playData"></music-play>
</view>
</template>
<script>
import $http from "@/config/requestConfig.js";
import commonSearchFor from './commonSearchFor.vue'
import musicPlay from '@/components/music.vue'
export default {
data() {
return {
playData:{},
scrollTop: 0,
totalPage: 0,
status: 3,
show: 0,
bookList: [],
courseList: [],
historyList: [],
bookScreen: {
authorName: '', //作者
publisherName: '', //出版社
type: '', //电子书类型
bookName: '', //关键词
is_charge: 1, //是否收费0收费1免费
state: 1,
page: 1, //当前页码数
limit: 10, //单页数据数量
},
classFen: [{
sort: '全部',
id: ''
}, {
sort: '医学',
id: 1
}, {
sort: '国学',
id: 2
}, {
sort: '文学',
id: 3
}, {
sort: '古籍',
id: 4
}],
classMian: [{
sort: '免费',
id: 1
}, {
sort: 'VIP',
id: 0
}],
};
},
// 返回顶部
onPageScroll(e) {
this.scrollTop = e.scrollTop;
},
// 下拉刷新
onReachBottom() {
setTimeout(() => {
this.getData()
}, 1000)
},
//第一次加载
onLoad(e) {
},
//页面显示
onShow() {
this.getHistory()
},
components:{
musicPlay,
commonSearchFor
},
//方法
methods: {
// 获取缓存
getHistory() {
var historyList = uni.getStorageSync('hisRecords')? uni.getStorageSync('hisRecords'):[]
historyList=[...new Set(historyList)]
if (historyList.length > 10) {
historyList= historyList.splice(10, historyList.length)
}
this.historyList=historyList
uni.setStorageSync('hisRecords', this.historyList);
},
// 获取列表数据
getData() {
$http
.request({
url: "common/homeSearch/searchData",
method: "POST", // POST、GET、PUT、DELETE具体说明查看官方文档
data: {
keyWord:this.bookScreen.bookName,
"appName":"wmys",
},
header: {
//默认 无 说明:请求头
"Content-Type": "application/json",
},
})
.then(res => {
console.log(res)
if(res.code==0){
this.bookList = res.shopProductList
this.courseList = res.courseEntities
this.status = 3
this.show = 1
}else{
this.bookList=[]
this.courseList=[]
}
}).catch(err=>{
})
},
// 清空
clear() {
this.show = 0
this.getHistory()
},
// 搜索
souBook() {
if (this.bookScreen.bookName == '') {
uni.showToast({
icon: 'none',
title: '请输入关键字'
})
return
}
this.getData();
let ArryList = []
if (uni.getStorageSync('hisRecords') == '') {
ArryList.push(this.bookScreen.bookName)
uni.setStorageSync('hisRecords', ArryList);
} else {
let value = uni.getStorageSync('hisRecords')
value.unshift(this.bookScreen.bookName)
uni.setStorageSync('hisRecords', value);
}
},
// 点击历史搜索
serkeyWord(e) {
this.bookScreen.bookName = e
this.getData();
},
// 分类选择
FenBook(e) {
if (e.id == 0) {
this.bookScreen.type = ''
} else {
this.bookScreen.type = e.id
}
this.bookScreen.page = 1
this.getData();
},
MianBook(e) {
this.bookScreen.is_charge = e.id
this.bookScreen.page = 1
this.getData();
},
// 电子书内容跳转
onpageJump(e) {
console.log(e,'e')
uni.navigateTo({
url: '/pages/goods/index/index?id=' + e.productId
});
// uni.navigateTo({
// // url: '../eBook/bookContent?Id=' + e.id
// url: '../bookShop/commodityDetail?type=2&id=' + e.productId
// });
},
},
};
</script>
<style lang="scss" scoped>
@import '@/style/mixin.scss';
.sear_ch {
margin: 50rpx 40rpx 0 40rpx;
.sear_ch_tit {
font-weight: bold;
font-size: 30rpx;
margin: 40rpx 0 0 0;
}
.sear_ch_tag {
margin: 20rpx 0 0 0;
text {
background-color: #eee;
font-size: 24rpx;
border-radius: 50rpx;
display: inline-block;
margin: 0 30rpx 20rpx 0;
padding: 10rpx 25rpx;
}
}
}
.sear_class {
margin: 20rpx 30rpx 60rpx 30rpx;
.sc_xuan {
margin-bottom: 10rpx;
.sc_con {
display: inline-block;
font-size: 28rpx;
margin-right: 20rpx;
border-radius: 20rpx;
padding: 6rpx 12rpx;
}
.sc_con_style {
color: #27b386;
background-color: #2ab58833;
}
}
}
.sear_list {
margin: 50rpx 24rpx 0 24rpx;
.bl_tioa {
width: 33.3%;
padding: 10rpx;
.bl_tioa_bg{
height: 360rpx;
background-color: #fff; margin-bottom: 20rpx;
text-align: center;
border-radius: 15rpx;
box-shadow: 0 0px 10px 1px #d3d1d133;
view {
display: block;
text { display: block;
color: #9b9b9b;
font-size: 24rpx;
line-height: 36rpx;
}
.bok_name {
font-weight: bold;
color: #333;
font-size: 26rpx;
line-height: 35rpx;
height: 103rpx;
max-height: 105rpx;
overflow: hidden;
}
}
image { display: inline-block;
padding-top:20rpx;
width: 160upx;
height: 220upx;
}
}
}
}
</style>