search.js 1.29 KB
import searchModel from '../../models/brand/search';
import goMiniApp from '../../router/jump-to-miniapp';
import Yas from '../../common/yas';

let app = getApp();
let yas;

Page({
    data: {
        searchInp: '',
        searchResult: '',
        noResult: false
    },
    onLoad: function() {
        yas = new Yas(app);
        yas.pageOpenReport();
    },
    cancel: function() {
        this.setData({
            searchInp: '',
            searchResult: '',
            noResult: false
        });
    },
    search: function(event) {
        let params = {
            brandName: event.detail.value
        };

        searchModel.search(params).then(result => {
            if (result.length <= 0) {
                this.setData({
                    searchResult: '',
                    noResult: true
                });
            } else {
                this.setData({
                    searchResult: result,
                    noResult: false
                });
            }
        });
    },
    goBrandDetail: function(event) {
        let brandId = event.currentTarget.id;
        let goMiniAppParams = {
            app: 'yohobuy',
            page: 'brandDetail',
            data: {
                brand_id: brandId
            }
        };

        goMiniApp(goMiniAppParams);
    },
});