123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- // pages/search/search.js
- const { searchGoods } = require('../../API/appraise')
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- historyStorage: [],//历史搜索
- historyStorageShow: false,//清空历史记录
- flag: true,//换一批推荐
- inputValue: "",
- replaceValue: "",
- searchResult: [{title: "短裤"}, {title: "短裙"}, {title: "连衣裙"}, {title: "卫衣"}, {title: "外套"}],
- search: false,
- page: 1,
- pageSize: 6,
- searchTo: []
- },
- //输入数据显示搜索推荐
- showResult(){
- this.setData({
- show: true
- })
- },
- getInputValue(e){
- const {value, cursor, keyCode} = e.detail;
- this.setData({
- inputValue: value
- })
- // 边输入边请求获取数据
- // if(this.data.inputValue != "") {
- // this.getSearchGoods()
- // }
- },
- putInputValue(e){
- this.setData({
- inputValue: e.currentTarget.dataset.postname
- })
- },
- //开始搜索
- searchBegin(e){
- let _this = this;
- var data = e.currentTarget.dataset.searchdata;
- console.log(data);
- // _this.data.replaceValue = e.currentTarget.dataset.postname;
- wx.setStorageSync(
- 'historyStorage',
- _this.data.historyStorage.concat(_this.data.inputValue)
- )
- this.getSearchGoods()
- setTimeout(() => {
- console.log(this.data.searchTo);
- var new_search = JSON.stringify(this.data.searchTo)
- let new_arr = encodeURIComponent(new_search)
- wx.navigateTo({
- url: '../../pages/com_search/com_search?comList=' + new_arr,
- })
- }, 1000)
- },
- //删除搜索数据
- deleteInput(){
- this.setData({
- inputValue: ""
- })
- },
- //清空历史记录
- remove(){
- var _this = this
- wx.showModal({
- title: '提示',
- content: '确认清除所有历史记录?',
- success: function(res) {
- if(res.confirm) {
- wx.removeStorageSync(
- 'historyStorage'
- ),
- _this.setData({
- historyStorage: []
- })
- } else {
- console.log("点击取消");
- }
- }
- })
- },
- //点击搜索历史复制到input框
- copyHistory(e) {
- var his = e.currentTarget.dataset.history
- this.setData({
- inputValue: his
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- //异步获取数据
- var x = wx.getStorageSync(
- 'historyStorage',
- )
- //将之前的数据和现在得到的异步数据拼接渲染
- this.setData({
- historyStorage: [...this.data.historyStorage ,...x]
- })
- },
- getSearchGoods() {
- searchGoods(this.data).then((res) => {
- const {code, message, data} = res.data.data;
- console.log(data);
- this.setData({
- searchTo: data
- })
- }).catch((err) => {
- console.log(err);
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- if(this.data.inputValue != "") {
- this.getSearchGoods()
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
|