123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- // pages/components/blocks/search_box/search_box.js
- const getReq = require('../../../../config.js').getReq;
- let app = getApp()
- Component({
- /**
- * 组件的属性列表
- */
- properties: {
- },
- /**
- * 组件的初始数据
- */
- data: {
- inputVal:'',
- searchItems:[]
- },
- /**
- * 组件的方法列表
- */
- methods: {
- skip_target(e){
- let word = e.target.dataset.word;
- app.navigateto(`/pages/brand/brand?keyword=${word}&title=${word}`)
- },
- search_btn(){
- let inputVal = this.data.inputVal;
- if (!inputVal) {
- return;
- }
- app.navigateto(`/pages/brand/brand?keyword=${inputVal}&title=${inputVal}`)
- },
- input(e){
- let self = this;
- let val = e.detail.value;
- this.setData({
- inputVal: val
- });
- if (val == "") {
- clearTimeout(this.search);
- self.setData({
- searchItems: []
- })
- return;
- }
- clearTimeout(this.search);
- this.search = setTimeout(function(){
- getReq({
- act: 'search',
- op: 'suggest_words',
- keyword: val
- }, function (res) {
- if (res.code == 200) {
- if(res.datas.words == null) {
- self.setData({
- searchItems:[]
- })
- }
- else {
- self.setData({
- searchItems: res.datas.words
- });
- }
- }
- })
- },300);
-
- }
- }
- })
|