소스 검색

前端小程序更新sdy

zhongtianhaoyuan 3 년 전
부모
커밋
3a0d2f9ac8
1개의 변경된 파일73개의 추가작업 그리고 19개의 파일을 삭제
  1. 73 19
      pageA/product/lookup.vue

+ 73 - 19
pageA/product/lookup.vue

@@ -6,7 +6,7 @@
 				<text style='color: #ccc;text-indent:6px;' class="cuIcon-search"></text>
 				<input type="text" v-model="searchKeyWord" @input="doSearch" placeholder="请输入货名或标题" confirm-type="search"></input>
 			</view>
-			<view style="width:4%;flex:1;">取消</view>
+			<view style="width:4%;flex:1;">{{content}}</view>
 			</view>
 			<!-- mSearch组件 如果使用原样式,删除组件元素-->
 			<!-- <mSearch class="mSearch-input-box" :mode="2" button="inside" :placeholder="defaultKeyword" @search="doSearch(false)" @input="inputChange" @confirm="doSearch(false)" v-model="keyword"></mSearch> -->
@@ -63,7 +63,7 @@
 				</view>
 			</view>
 			<scroll-view class="keyword-box" v-show="!isShowKeywordList" scroll-y>
-				<view class="keyword-block" v-if="oldKeywordList.length>0">
+				<view class="keyword-block" v-if="oldKeywordList.records.length>0">
 					<view class="keyword-list-header">
 						<view style='font-size:16px;font-weight:600;'>最近搜索</view>
 						<view>
@@ -74,7 +74,7 @@
 						</view>
 					</view>
 					<view class="keyword">
-						<view v-for="(keyword,index) in oldKeywordList" @tap="doSearch(keyword)" :key="index">{{keyword}}</view>
+						<view v-for="(keyword,index) in oldKeywordList.records" @tap="doSearch(keyword)" :key="index">{{keyword.searchContent}}</view>
 					</view>
 				</view>
 				 <view class="keyword-block">
@@ -85,7 +85,7 @@
 						</view>
 					</view>
 					<view class="keyword" v-if="forbid==''">
-						<view v-for="(keyword,index) in hotKeywordList" @tap="doSearch(keyword)" :key="index">{{keyword}}</view>
+						<view v-for="(keyword,index) in hotKeywordList" @tap="doSearch(keyword)" :key="index">{{keyword.searchContent}}</view>
 					</view>
 				</view> 
 			</scroll-view>
@@ -94,6 +94,9 @@
 </template>
 
 <script>
+	import {
+		mapState
+	} from 'vuex';
 	//引用mSearch组件,如不需要删除即可
 	import mSearch from '@/components/mehaotian-search-revision.vue';
 	export default {
@@ -104,28 +107,34 @@
 				pageSize:10,
 				currentPage:1,
 				oldKeywordList: [],
-				hotKeywordList: ["玉米","大豆","小麦","水稻","高粱","玉米淀粉","豆粕"],
+				hotKeywordList: [],
 				keywordList: [],
 				forbid: '',
 				isShowKeywordList: false,
 				TabCur:0,
 				isLoadMore:false,
 				loadStatus:'',
+				content:'搜索'
 			}
 		},
 		onLoad(options) {
 			this.searchKeyWord=options.searchKeyWord
 			this.TabCur = options.TabCur
-			this.init();
 			if(this.searchKeyWord){
 				this.isShowKeywordList=true
 				this.getData()
 			}
 		},
+		onShow() {
+			this.init();
+		},
 		components: {
 			//引用mSearch组件,如不需要删除即可
 			mSearch
 		},
+		computed: {
+			...mapState(['hasLogin', 'userInfo'])
+		},
 		methods: {
 			//详情
 			navToDetailPage(item) {
@@ -148,13 +157,26 @@
 			init() {
 				this.loadDefaultKeyword();
 				this.loadOldKeyword();
-				// this.loadHotKeyword();
+				this.loadHotKeyword();
 
 			},
 			blur(){
 				uni.hideKeyboard()
 			},
-			
+			loadHotKeyword(){
+				this.$api.doRequest('get', '/searchRecordsInfo/selectRecommendedSearchRecordsInfo',{pageSize:this.pageSize,
+				currentPage:this.currentPage,commonId:this.userInfo.id}).then(res => {
+					uni.hideLoading()
+					this.hotKeywordList=res.data.data.records
+				})
+				.catch(res => {
+					uni.showToast({
+						title: res.errmsg,
+						icon:'none',
+						duration: 2000
+					})
+				});
+			},
 			tabSelect(e) {
 				if(e.currentTarget.dataset.id){
 					this.TabCur = e.currentTarget.dataset.id;
@@ -193,13 +215,13 @@
 			},
 			//加载历史搜索,自动读取本地Storage
 			loadOldKeyword() {
-				uni.getStorage({
-					key: 'OldKeys',
-					success: (res) => {
-						var OldKeys = JSON.parse(res.data);
-						this.oldKeywordList = OldKeys;
-					}
-				});
+				var that=this
+				this.$api.doRequest('get', '/searchRecordsInfo/selectSearchRecordsInfo',{pageSize:this.pageSize,
+				currentPage:this.currentPage,commonId:this.userInfo.id}).then(res => {
+					uni.hideLoading()
+					that.oldKeywordList=res.data.data
+					console.log(that.oldKeywordList)
+				})
 			},
 			//监听输入
 			inputChange(event) {
@@ -242,14 +264,27 @@
 			},
 			//清除历史搜索
 			oldDelete() {
+				var that=this
 				uni.showModal({
 					content: '确定清除历史搜索记录?',
 					success: (res) => {
 						if (res.confirm) {
-							console.log('用户点击确定');
-							this.oldKeywordList = [];
-							uni.removeStorage({
-								key: 'OldKeys'
+							this.$api.doRequest('post', '/searchRecordsInfo/api/deleteSearchRecordsInfo',{commonId:this.userInfo.id}).then(res => {
+								that.oldKeywordList=[]
+								if(res.data.code==200){
+									uni.showToast({
+										title: '清除历史搜索成功',
+										icon:'none',
+										duration: 2000
+									})
+								}
+							})
+							.catch(res => {
+								uni.showToast({
+									title: '清除历史搜索成功',
+									icon:'none',
+									duration: 2000
+								})
 							});
 						} else if (res.cancel) {
 							console.log('用户点击取消');
@@ -265,17 +300,35 @@
 			doSearch(e) {
 				if(e.detail){
 					if(e.detail.value.length>0){
+						this.content='取消'
 						this.isShowKeywordList=true
+						this.$api.doRequest('post', '/searchRecordsInfo/api/addInfo',{commonId:this.userInfo.id,searchContent:e.detail.value}).then(res => {
+						})
+						.catch(res => {
+							
+						});
 					}else{
+						this.content='搜索'
 						this.isShowKeywordList=false
+						this.loadOldKeyword()
+						this.loadHotKeyword()
 					}
 				}
 				else if(e){
 					if(e.length>0){
 						this.isShowKeywordList=true
+						this.content='取消'
 						this.searchKeyWord = e
+						this.$api.doRequest('post', '/searchRecordsInfo/api/addInfo',{commonId:this.userInfo.id,searchContent:e}).then(res => {
+						})
+						.catch(res => {
+							
+						})
 					}else{
+						this.content='搜索'
 						this.isShowKeywordList=false
+						this.loadOldKeyword()
+						this.loadHotKeyword()
 					}
 				}
 				uni.showLoading({
@@ -288,6 +341,7 @@
 				} else {
 					param1 = '/salePlanInfo/selectSalePlanInfo'
 				}
+				console.log(this.userInfo)
 				this.$api.doRequest('get', param1,{pageSize:this.pageSize,
 				currentPage:this.currentPage,searchKeyWord:this.searchKeyWord}).then(res => {
 					uni.hideLoading()