You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
147 lines
4.2 KiB
147 lines
4.2 KiB
10 months ago
|
<template>
|
||
|
<BaseContainer class="search-page">
|
||
|
<NavBar title="搜索" />
|
||
|
<view class="form">
|
||
|
<view class="left flex-center-x">
|
||
|
<i class="iconfont2 iconsousuo"></i>
|
||
|
<input v-model.trim="search" confirm-type="search" @confirm="onSearch(search)" placeholder="输入搜索课程" />
|
||
|
<i v-show="search" class="iconfont iconguanbi2" @click="search = ''"></i>
|
||
|
</view>
|
||
|
<view class="right flex flex-center" @click="onSearch(search)">搜索</view>
|
||
|
</view>
|
||
|
<view v-if="historyList.length" class="section">
|
||
|
<view class="title">
|
||
|
<view class="text">历史记录</view>
|
||
|
<i class="iconfont iconshanchu" @click="deleteHistory"></i>
|
||
|
</view>
|
||
|
<view class="content">
|
||
|
<text v-for="(item, index) in historyList" :key="index" @click="onSearch(item.search)">{{ item.search }}</text>
|
||
|
</view>
|
||
|
</view>
|
||
|
<view v-if="hotList.length" class="section">
|
||
|
<view class="title">
|
||
|
<view class="text">热门搜索</view>
|
||
|
</view>
|
||
|
<view class="content">
|
||
|
<text v-for="(item, index) in hotList" :key="index" @click="onSearch(item)">{{
|
||
|
item
|
||
|
}}</text>
|
||
|
</view>
|
||
|
</view>
|
||
|
<view v-if="specialList.length" class="special-section">
|
||
|
<view class="title">专题</view>
|
||
|
<view>
|
||
|
<navigator v-for="item in specialList" :key="item.id" :url="getJumpUrl(item)">
|
||
|
<view class="image">
|
||
|
<image :src="item.image" mode="aspectFill" :alt="item.title" />
|
||
|
<view v-if="item.type == 1" class="type">图文</view>
|
||
|
<view v-else-if="item.type == 2" class="type">音频</view>
|
||
|
<view v-else-if="item.type == 3" class="type">视频</view>
|
||
|
<view v-else-if="item.type == 5" class="type">专栏</view>
|
||
|
</view>
|
||
|
<view class="text">
|
||
|
<view class="special-title">{{ item.title }}</view>
|
||
|
<view class="label">
|
||
|
<text v-for="(label, index) in item.label" :key="index">{{ label }}</text>
|
||
|
</view>
|
||
|
<view class="money-total">
|
||
|
<view class="money">
|
||
|
¥<text>{{ item.money }}</text>
|
||
|
</view>
|
||
|
<view v-if="!item.is_light" class="total">共{{ item.count }}节</view>
|
||
|
</view>
|
||
|
</view>
|
||
|
</navigator>
|
||
|
</view>
|
||
|
</view>
|
||
|
<image v-if="isEmpty" class="empty" mode="aspectFit" :src="getImgPath('/wap/first/zsff/images/no_search.png')"
|
||
|
alt="暂无搜索结果" />
|
||
|
</BaseContainer>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
|
import {
|
||
|
getSearchHistory,
|
||
|
getHotSearch,
|
||
|
getSearchContent,
|
||
|
clearSearchHistory,
|
||
|
} from "@/api/index";
|
||
|
|
||
|
export default {
|
||
|
data() {
|
||
|
return {
|
||
|
search: "",
|
||
|
historyList: [],
|
||
|
hotList: [],
|
||
|
specialList: [],
|
||
|
limit: 10,
|
||
|
singleDetailsURL: "/pages/special/single_details",
|
||
|
detailsURL: "/pages/special/details",
|
||
|
isEmpty: false,
|
||
|
};
|
||
|
},
|
||
|
watch: {
|
||
|
specialList(val) {
|
||
|
this.isEmpty = !val.length;
|
||
|
},
|
||
|
},
|
||
|
created() {
|
||
|
this.getSearchHistory();
|
||
|
this.getHotSearch();
|
||
|
},
|
||
|
onShareAppMessage() {
|
||
|
return {};
|
||
|
},
|
||
|
onShareTimeline() {
|
||
|
return {};
|
||
|
},
|
||
|
methods: {
|
||
|
getJumpUrl(item) {
|
||
|
return item.is_light ? this.singleDetailsURL : this.detailsURL + "?id=" + item.id;
|
||
|
},
|
||
|
// 获取搜索历史
|
||
|
getSearchHistory() {
|
||
|
getSearchHistory().then(({ data }) => {
|
||
|
this.historyList = data;
|
||
|
});
|
||
|
},
|
||
|
// 获取热门搜索
|
||
|
getHotSearch() {
|
||
|
getHotSearch().then(({ data }) => {
|
||
|
this.hotList = data;
|
||
|
});
|
||
|
},
|
||
|
// 搜索内容
|
||
|
async onSearch(search) {
|
||
|
if (!search || this.loading) {
|
||
|
return;
|
||
|
}
|
||
|
this.loading = true;
|
||
|
uni.showLoading({
|
||
|
mask: true,
|
||
|
});
|
||
|
|
||
|
try {
|
||
|
const { data } = await getSearchContent(search, this.limit);
|
||
|
this.specialList = data.special;
|
||
|
if(this.specialList.length == 0){
|
||
|
this.$util.showMsg("未查询到相关数据");
|
||
|
}
|
||
|
uni.hideLoading();
|
||
|
} catch (err) {
|
||
|
this.$util.showMsg(err.message);
|
||
|
uni.hideLoading();
|
||
|
}
|
||
|
|
||
|
this.loading = false;
|
||
|
},
|
||
|
// 删除搜索历史
|
||
|
deleteHistory() {
|
||
|
clearSearchHistory().then(() => {
|
||
|
this.historyList = [];
|
||
|
});
|
||
|
},
|
||
|
},
|
||
|
};
|
||
|
</script>
|