<template> <view class="main pt0"> <view class="search"> <u-search placeholder="搜索工作" bgColor="white" v-model="param.title" :showAction="false" @search="search()" @clear="clear()"></u-search> </view> <view class="list"> <view class="history" v-if="!focus"> <view class="title">搜索历史</view> <view class="del" v-if="history.length > 0" @click="del()"> <text class="icon"></text> <text>清除</text> </view> <view class="tag" v-for="(item, index) in history" :key="item" @click="(param.title = item), search()">{{ item }}</view> </view> <job :list="list"></job> <view class="loading" v-if="loadMore"><u-loadmore :status="loadMore ? 'loading' : 'nomore'" /></view> <u-empty v-if="!loadMore && list.length == 0"></u-empty> </view> </view> </template> <script> export default { data() { return { list: [], focus: false, history: uni.getStorageSync('history') || [], param: { pageNum: 1, pageSize: 10, type: 0, orderBy: 'id' }, loadMore: false }; }, onLoad(e) { if (this.getLocation()) { this.param.latitude = this.getLocation().latitude; this.param.longitude = this.getLocation().longitude; } }, methods: { getData() { this.http.request({ url: '/app/position/list', data: this.param, loading: 'false', success: (res) => { this.loadMore = res.data.pages > this.param.pageNum ? true : false; this.list.push(...res.data.rows); } }); }, go(url) { uni.navigateTo({ url: url }); }, search() { if (this.param.title.trim()) { this.focus = true; if (this.history.filter((item) => item == this.param.title.trim()) == 0) { this.history.unshift(this.param.title); uni.setStorageSync('history', this.history); } this.refresh(); } }, del() { uni.removeStorageSync('history'); this.history = []; }, clear() { this.focus = false; this.param.title = ''; this.list = []; }, //刷新数据 refresh() { this.loadMore = true; this.param.pageNum = 1; this.list = []; this.getData(); } }, //上拉加载 onReachBottom() { if (this.loadMore) { this.param.pageNum++; this.getData(); } } }; </script> <style lang="scss"> .search { margin-bottom: 15px; } .history { overflow: hidden; .title { margin-bottom: 12px; font-weight: bold; } .del { float: right; font-size: 14px; margin-top: -30px; color: #f44336; .icon { padding-right: 3px; } } .tag { float: left; padding: 4px 10px; border-radius: 30px; background-color: white; margin-right: 10px; margin-bottom: 5px; font-size: 14px; color: $font-c; } } </style>