var util = require('../../utils/util.js'); Component({ data: { history: [], content:'', hint:'', }, methods: { // 返回上一级 onCancel(e){ this.triggerEvent('cancel', {}, {}) //给cancel绑定事件 }, // 搜索 search(e){ var _this = this; var content = _this.data.content; if (content == undefined || content.replace(/\s*/g, "") == ''){ content = _this.data.hint; } wx.navigateTo({ url: '../../pages/shopTypeSecond/shopTypeSecond?content=' + content, }) }, // 数据绑定搜索框 formName: function (e) { this.setData({ content: e.detail.value }) }, jumpGoods(e) { var content = e.currentTarget.dataset.content; wx.navigateTo({ url: '../../pages/shopTypeSecond/shopTypeSecond?content=' + content, }) }, // 删除历史 cleanHistory() { var _this = this; // 删除历史 util.request("GET", '/wxapi/shopUserSearchRecord/deleteSearchRecord', {}, function (data) { if (data.status == '200') { _this.searchHistory(); } }, true); }, // 搜索历史 searchHistory() { var _this = this; util.request("GET", '/wxapi/shopUserSearchRecord/getSearchRecordList', {}, function (data) { console.log(data.rows); _this.setData({ history: data.rows }) }, true); } }, attached() { var _this = this; // 默认搜索 util.request("GET", '/wxapi/Advertising/getByType/index_search', {}, function (data) { _this.setData({ hint: data.rows[0].title }) }, true); // _this.searchHistory(); util.request("GET", '/wxapi/shopUserSearchRecord/getSearchRecordList', {}, function (data) { console.log(data.rows); _this.setData({ history: data.rows }) }, true); } })