123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- <template>
- <view class="container">
- <view class="tui-searchbox">
- <view class="tui-search-input">
- <icon type="search" :size='13' color='#333'></icon>
- <input confirm-type="search" placeholder="大家都在搜:代祭扫" :focus="true" auto-focus placeholder-class="tui-input-plholder"
- class="tui-input" v-model.trim="key" @input="inputKey"/>
- <icon type="clear" :size='13' color='#bcbcbc' @tap="cleanKey" v-show="key"></icon>
- </view>
- <view class="tui-cancle" @tap="back">取消</view>
- </view>
- <view class="tui-search-history" v-show="history.length>0 && !key">
- <view class="tui-history-header">
- <view class="tui-search-title">搜索历史</view>
- <tui-icon name="delete" :size='14' color='#333' @tap="openActionSheet" class="tui-icon-delete"></tui-icon>
- </view>
- <view class="tui-history-content">
- <block v-for="(item,index) in history" :key="index">
- <tui-tag margin="0 24rpx 24rpx 0" type="gray" shape="circle">{{item}}</tui-tag>
- </block>
- </view>
- </view>
- <view v-show="key">
- <view class="tui-header">
- <view class="tui-header-left tui-noboredr">搜索 “{{key}}”</view>
- </view>
- <view class="tui-result-box">
- <block v-for="(item,index) in searchList" :key="index">
- <view class="tui-result-item" hover-class="tui-opcity" :hover-stay-time="150">
- <rich-text :nodes="item.showKey"></rich-text>
- </view>
- </block>
- </view>
- </view>
- <!-- <view class="tui-search-hot">
- <view class="tui-hot-header">
- <view class="tui-search-title">大家正在搜</view>
- </view>
- <view class="tui-hot-content">
- <block v-for="(item,index) in hot" :key="index">
- <tui-tag type="gray" shape="circle">{{item}}</tui-tag>
- </block>
- </view>
- </view> -->
- <tui-actionsheet :show="showActionSheet" :tips="tips" @click="itemClick" @cancel="closeActionSheet"></tui-actionsheet>
- </view>
- </template>
- <script>
- import tuiButton from "@/components/thorui/tui-button/tui-button"
- import tuiIcon from "@/components/thorui/tui-icon/tui-icon"
- import tuiBadge from "@/components/thorui/tui-badge/tui-badge"
- import tuiTag from "@/components/thorui/tui-tag/tui-tag"
- import tuiNomore from "@/components/thorui/tui-nomore/tui-nomore"
- import tuiTopDropdown from "@/components/thorui/tui-top-dropdown/tui-top-dropdown"
- import tuiBottomPopup from "@/components/thorui/tui-bottom-popup/tui-bottom-popup"
- import tuiNumberbox from "@/components/thorui/tui-numberbox/tui-numberbox"
- import tuiDrawer from "@/components/thorui/tui-drawer/tui-drawer"
- import tuiActionsheet from "@/components/thorui/tui-actionsheet/tui-actionsheet"
- const util = require("@/utils/util.js")
- export default {
- components:{
- tuiButton,
- tuiIcon,
- tuiBadge,
- tuiTag,
- tuiNomore,
- tuiTopDropdown,
- tuiBottomPopup,
- tuiNumberbox,
- tuiDrawer,
- tuiActionsheet
- },
- data() {
- return {
- history: [
- "代祭扫",
- "蜡烛",
- "香火",
- "龙飞凤舞"
- ],
- hot: [
- "代祭扫",
- "蜡烛",
- "香火",
- "龙飞凤舞"
- ],
- key: "",
- showActionSheet: false,
- tips: "确认清空搜索历史吗?",
- searchResult:["按照展示的列表输入关键词看效果","thorui","2019退役球星","搜索关键词高亮显示","模拟搜索结果集","开源不易,需要鼓励","人人为我,我为人人"],
- searchList:[]
- }
- },
- methods: {
- back: function() {
- uni.navigateBack();
- },
- cleanKey: function() {
- this.key = ''
- },
- closeActionSheet: function() {
- this.showActionSheet = false
- },
- openActionSheet: function() {
- this.showActionSheet = true
- },
- itemClick: function(e) {
- let index = e.index;
- if (index == 0) {
- this.showActionSheet = false;
- this.history = []
- }
- },
- inputKey: function(e) {
- this.key = util.trim(e.detail.value);
- if (!this.key) {
- this.searchList = [];
- return;
- }
- //根据关键词查找
- let arr = []
- //实际开发中,根据搜索返回结果集,此处只是做展示提示搜索哪些文字
- this.searchResult.forEach((item) => {
- arr.push({
- key: item,
- showKey: util.replaceAll(item, this.key, `<label style="color:#E41F19">${this.key}</label>`)
- })
- })
- this.searchList = arr
- }
- }
- }
- </script>
- <style>
- page {
- color: #333;
- background: #fff;
- }
- .container {
- padding: 0 30rpx 30rpx 30rpx;
- box-sizing: border-box;
- width: 100%;
- }
- .tui-searchbox {
- padding: 30rpx 0;
- box-sizing: border-box;
- display: flex;
- align-items: center;
- }
- .tui-search-input {
- width: 100%;
- height: 66rpx;
- border-radius: 35rpx;
- padding: 0 30rpx;
- box-sizing: border-box;
- background: #f2f2f2;
- display: flex;
- align-items: center;
- flex-wrap: nowrap;
- }
- .tui-input {
- flex: 1;
- color: #333;
- padding: 0 16rpx;
- font-size: 28rpx;
- }
- .tui-input-plholder {
- font-size: 28rpx;
- color: #b2b2b2;
- }
- .tui-cancle {
- color: #888;
- font-size: 28rpx;
- padding-left: 30rpx;
- flex-shrink: 0;
- }
- .tui-history-header {
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 30rpx 0;
- }
- .tui-history-content{
- display: flex;
- align-items: center;
- flex-wrap: wrap;
- }
- .tui-icon-delete {
- padding: 10rpx;
- }
- .tui-search-title {
- font-size: 28rpx;
- font-weight: bold;
- }
- .tui-hot-header {
- padding: 30rpx 0;
- }
-
- .tui-header {
- padding: 26rpx 0;
- box-sizing: border-box;
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .tui-header-left {
- font-size: 30rpx;
- color: #222;
- border-left: 4rpx solid #EB0909;
- padding-left: 10rpx;
- word-break: break-all;
- }
-
- .tui-noboredr {
- border-left: 0 !important;
- }
- .tui-result-box {
- font-size: 28rpx;
- }
-
- .tui-result-item {
- line-height: 28rpx;
- padding: 28rpx 0;
- }
- </style>
|