123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- <template>
- <view class="">
- <navbar :config="config" backColor="#999999"></navbar>
- <view class="search-box" :style="{'height':topFixedHeight + 'rpx'}">
- <view class="search">
- <u-search border-color="transparent" bg-color="transparent" :show-action="false"
- search-icon-color="#000" placeholder-color="#999999" color="#333333"
- :placeholder="defaultKeyword ? defaultKeyword : '请输入检索关键字'" v-model="keyword"
- @search="searchData"></u-search>
- <text class="search-btn" @click.stop="searchData">搜索</text>
- </view>
- </view>
- <scroll-view class="search-content" :style="{'height':pageHeight+ 'px'}" scroll-y="true">
- <view class="" v-show="searchContent" style="min-height: 100%;">
- <template v-if="searchList.length > 0 || searchLoading">
- <view class="search-item" v-for="item in searchList" @click.stop="$openPage(item)">
- <image class="search-icon" :src="$getImgPath(item.icon)" mode="aspectFit"></image>
- <text class="search-text">{{item.thirdName}}</text>
- <text class="search-look iconfont_yige"></text>
- </view>
- </template>
- <template v-else>
- <view class="empty-data">
- <EmptyDate />
- </view>
- </template>
- </view>
- <view class="" v-show="!searchContent">
- <view class="search-hint" v-if="keywordArr && keywordArr.length > 0">
- <view class="hint-title">
- <text>历史搜索</text>
- <text @click.stop="clearSearchRecord()">清除</text>
- </view>
- <view class="hint-content">
- <block v-for="item in keywordArr">
- <text v-if="item" @click.stop="defaultSearch(item)">{{ item }}</text>
- </block>
- </view>
- </view>
- <view class="search-hint" v-if="topSearch && topSearch.length > 0">
- <view class="hint-title">
- 热门搜索
- </view>
- <view class="hint-content">
- <block v-for="item in topSearch">
- <text v-if="item" @click.stop="defaultSearch(item)">{{ item }}</text>
- </block>
- </view>
- </view>
- </view>
- </scroll-view>
- </view>
- </template>
- <script>
- import {
- getThirdSearch
- } from "@/api/government.js"
- import Mixin from "./Mixin.js"
- import {
- getSearchInfo
- } from "@/api/government.js"
- export default {
- mixins: [Mixin],
- data() {
- return {
- topFixedHeight: 100,
- config: {
- back: true,
- closePath: '',
- title: '搜索',
- color: 'black',
- backgroundColor: [1, '#fff'],
- statusBarFontColor: 'black'
- },
- topSearch: [],
- keyword: "",
- defaultKeyword: '',
- keywordArr: [],
- searchContent: false,
- searchList: [],
- searchLoading: false
- }
- },
- onLoad() {
- uni.getStorage({
- key: this.$keys.search_keyword,
- success: res => {
- // this.keywordArr = ['社会白社会白社会白社会白社会白社会白社会白社会白社会白社会白社会白社会白社会白社会白', ...res.data] || []
- this.keywordArr = res.data || []
- },
- fail: err => {
- this.keywordArr = []
- }
- });
- getSearchInfo().then(res => {
- const data = res.data || {}
- this.defaultKeyword = data?.defaultKeyword;
- const arr = data?.keywords.split(",")
- this.topSearch = arr;
- })
- },
- onShow() {
- },
- methods: {
- clearSearchRecord() {
- uni.removeStorage({
- key: this.$keys.search_keyword,
- success: res => {
- this.keywordArr = []
- }
- });
- },
- defaultSearch(e) {
- this.keyword = e;
- this.searchData()
- },
- searchData() {
- if (!this.keyword && !this.defaultKeyword) return
- this.keyword = this.keyword || this.defaultKeyword
- const text = this.keyword;
- this.searchLoading = true;
- this.searchList = [];
- this.searchContent = true;
- getThirdSearch({
- keyword: text,
- status:true
- }).then(res => {
- this.searchList = res.rows
- }).finally(() => {
- this.searchLoading = false;
- this.setHotKeyword(text)
- })
- },
- setHotKeyword(text) {
- try {
- this.keywordArr.forEach((el, index) => {
- if (el === text) {
- this.keywordArr.splice(index, 1)
- throw new Error()
- }
- });
- } catch (e) {
- //TODO handle the exception
- }
- if (this.keywordArr.length >= 10) {
- this.keywordArr.splice(9, this.keywordArr.length - 9)
- }
- this.keywordArr.unshift(this.keyword)
- uni.setStorage({
- key: this.$keys.search_keyword,
- data: this.keywordArr,
- success: function() {
- console.log('success');
- }
- });
- }
- },
- watch: {
- keyword: {
- handler: function(newKw, oldKw) {
- if (!newKw && this.searchContent) this.searchContent = false
- }
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .search-box {
- padding: 0 30rpx;
- display: flex;
- align-items: center;
- .search {
- width: 100%;
- border: 1rpx solid #999999;
- border-radius: 42rpx;
- height: 82rpx;
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding-right: 38rpx;
- .search-btn {
- font-size: 30rpx;
- font-family: Microsoft YaHei, Microsoft YaHei-Bold;
- font-weight: 700;
- text-align: left;
- color: #5fcee5;
- }
- }
- }
- .search-content {
- width: 100%;
- padding: 0 30rpx;
- box-sizing: border-box;
- .search-item {
- width: 100%;
- height: 100rpx;
- display: flex;
- justify-content: space-between;
- align-items: center;
- border-bottom: 1rpx solid #eee;
- .search-icon {
- width: 50rpx;
- height: 50rpx;
- }
- .search-text {
- flex: 1;
- padding: 0 20rpx;
- font-size: 30rpx;
- font-family: Microsoft YaHei, Microsoft YaHei-Regular;
- font-weight: 400;
- color: #333333;
- }
- .search-look {
- font-size: 34rpx;
- color: #c2c2c2;
- }
- }
- .empty-data {
- padding-top: 100rpx;
- }
- }
- .search-hint {
- padding-top: 40rpx;
- .hint-title {
- font-size: 34rpx;
- font-weight: bold;
- padding-bottom: 10rpx;
- display: flex;
- justify-content: space-between;
- align-items: center;
- text+text {
- font-size: 28rpx;
- font-weight: 400;
- color: #b9b8b8;
- }
- }
- .hint-content {
- width: 100%;
- display: flex;
- align-items: stretch;
- flex-wrap: wrap;
- text {
- flex-shrink: 0;
- margin: 20rpx 20rpx 0 0;
- // border-radius: 5rpx;
- padding: 15rpx 30rpx;
- font-size: 24rpx;
- line-height: 1.3;
- background: #f6f8fa;
- border-radius: 20rpx;
- }
- }
- }
- // .search-page {
- // width: 100%;
- // padding: 0 20rpx;
- // }
- </style>
|