123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <template>
- <view>
- <view style="background-color: #E75F37;padding: 20rpx;">
- <u-search placeholder="请输入商品名称" bgColor="#fff" searchIconColor='#E75F37' :actionStyle="{color:'#FFF'}"
- :searchIconSize='24' v-model="keyword" @search="goBack()" @custom="goBack()" focus @clear='clear'></u-search>
- </view>
- <view class="recentSearches" v-if="recentSearches.length != 0">
- <view class="recentSearches-head">
- <view class="recentSearches-headLeft">
- <u-icon name="clock" color="#C4C4C4"></u-icon>
- <view style="font-size: 26rpx;margin-left: 6rpx;">最近搜索</view>
- </view>
- <view class="recentSearches-headRight">
- <u-icon name="trash" size="20px" @click="searchDeleteShow = true" color="#C4C4C4"></u-icon>
- </view>
- </view>
- <view class="recentSearches-text">
- <u-tag v-for="(item,index) in recentSearches" :key="index" :text="item" bgColor="#EFEFEF"
- color="#414141" borderColor="#EFEFEF" size="medium" closable :show="item" @close="tagClose(index)"
- shape="circle" @click.stop="tagSearches(item)"></u-tag>
- </view>
- <u-modal :show="searchDeleteShow" content="确认删除搜索记录吗?" showCancelButton @confirm="searchDeletefun"
- @cancel="searchDeleteShow = false" ref="uModal" :asyncClose="true">
- </u-modal>
- </view>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- keyword: '',
- recentSearches: [], // 搜索数据
- searchDeleteShow: false, // 搜索全部删除弹窗
- homePage: false,
- }
- },
- onLoad(data) {
- if (uni.getStorageSync('recentSearches')) {
- this.recentSearches = uni.getStorageSync('recentSearches').slice(0, 10);
- }
- this.keyword = data.searchData
- },
- methods: {
- clear(){
- console.log(11111)
- },
- goBack() {
- uni.$emit('searchData', this.keyword)
- uni.navigateBack({})
- },
- // 搜索全部删除
- searchDeletefun() {
- this.recentSearches = []
- uni.setStorageSync('recentSearches', this.recentSearches);
- this.searchDeleteShow = false
- },
- // 点击搜索
- tagSearches(name) {
- this.keyword = name;
- uni.$emit('searchData', name)
- uni.navigateBack({})
- },
- // 最近搜索点击关闭按钮
- tagClose(index) {
- this.recentSearches.splice(index, 1)
- uni.setStorageSync('recentSearches', this.recentSearches);
- },
- }
- }
- </script>
- <style lang="scss" scoped>
- .tagClass {
- display: flex;
- padding: 41rpx 63rpx;
- background-color: #fff;
- justify-content: space-around;
- ::v-deep .u-tag--mini {
- font-size: 28rpx;
- line-height: 22px;
- padding: 0rpx 24rpx;
- }
- }
- .recentSearches {
- padding: 38rpx 32rpx;
- background-color: #fff;
- .recentSearches-head {
- display: flex;
- align-items: center;
- justify-content: space-between;
- color: #C4C4C4;
- .recentSearches-headLeft {
- display: flex;
- align-items: center;
- }
- .recentSearches-headRight {}
- }
- .recentSearches-text {
- display: flex;
- flex-wrap: wrap;
- align-items: baseline;
- .recentSearches-textWidth {
- // width: 140rpx;
- }
- }
- }
- </style>
|