|
|
var $ = require('yoho-jquery');
|
|
|
const brand_tmp = require('hbs/material/brand.hbs');
|
|
|
var _ = require('lodash');
|
|
|
var brandTmp = require('hbs/material/brand.hbs');
|
|
|
var tableTmp = require('hbs/material/tbl.hbs');
|
|
|
var $mask = $('.mask');
|
|
|
var $brand = $('#brand_container');
|
|
|
var query = {
|
|
|
page: 1,
|
|
|
maxSortId: 0,
|
|
|
middleSortId: 0,
|
|
|
smallSortId: 0
|
|
|
};
|
|
|
|
|
|
let $mask = $('.mask');
|
|
|
let $brand = $('#brand_container');
|
|
|
function brandItemEventBind() {
|
|
|
$('#brand_container .item').off().on('click', function() {
|
|
|
var id = $(this).data('id');
|
|
|
var text = $(this).text();
|
|
|
|
|
|
query.brandId = id;
|
|
|
$('#brand').val(text);
|
|
|
$mask.hide();
|
|
|
$brand.hide();
|
|
|
});
|
|
|
}
|
|
|
|
|
|
/* 获取品牌数据*/
|
|
|
function getBrandList(_index, yhChannel) {
|
|
|
$.get('/3party/material/newBrandList?yh_channel=' + yhChannel, function(data) {
|
|
|
var list = [];
|
|
|
|
|
|
list = Object.keys(data.data.all_list).map(item => {
|
|
|
return { name: item, content: data.data.all_list[item] };
|
|
|
});
|
|
|
list['focus' + _index] = true;
|
|
|
$('#brand_container').html(brandTmp({ list }));
|
|
|
brandItemEventBind();
|
|
|
});
|
|
|
}
|
|
|
|
|
|
function getCategoryOpt(opts) {
|
|
|
var html = '';
|
|
|
|
|
|
$.each(opts, function(k, c) {
|
|
|
html += '<option value="' + c.sort_id + '">' + c.sort_name + '</option>';
|
|
|
});
|
|
|
|
|
|
return html;
|
|
|
}
|
|
|
|
|
|
getBrandList(1, 1);
|
|
|
|
|
|
/* 获取品类数据*/
|
|
|
$.get('/3party/material/getCategory', function(res) {
|
|
|
var $category1 = $('#category-1'),
|
|
|
$category2 = $('#category-2'),
|
|
|
$category3 = $('#category-3'),
|
|
|
sub = [],
|
|
|
categoryData = [];
|
|
|
|
|
|
if (res && res.code === 200) {
|
|
|
categoryData = res.data.sort;
|
|
|
|
|
|
$category1.html(getCategoryOpt(categoryData));
|
|
|
query.maxSortId = $category1.find('option').eq(0).attr('value');
|
|
|
|
|
|
let query = {};
|
|
|
$category1.on('change', function() {
|
|
|
var id = $(this).val();
|
|
|
|
|
|
$('#filter').on('change', () => {
|
|
|
if ($('#filter').find('option:selected').attr('value') == 3) {
|
|
|
$('.date').show();
|
|
|
sub = _.find(categoryData, {sort_id: id}).sub;
|
|
|
$category2.html(getCategoryOpt(sub)).show();
|
|
|
$category3.html('').hide();
|
|
|
query.maxSortId = id;
|
|
|
query.middleSortId = $category2.find('option').eq(0).attr('value');
|
|
|
});
|
|
|
|
|
|
$category2.on('change', function() {
|
|
|
var id = $(this).val();
|
|
|
var third = _.find(sub, {sort_id: id}).sub;
|
|
|
|
|
|
$category3.html(getCategoryOpt(third)).show();
|
|
|
query.middleSortId = id;
|
|
|
query.smallSortId = $category3.find('option').eq(0).attr('value');
|
|
|
});
|
|
|
|
|
|
$category3.on('change', function() {
|
|
|
query.smallSortId = $(this).val();
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
|
|
|
/* 品牌点击*/
|
|
|
$('#brand').on('click', () => {
|
|
|
if ($brand.css('display') == 'none') {
|
|
|
$('#brand').on('click', function() {
|
|
|
if ($brand.css('display') === 'none') {
|
|
|
$brand.css('display', 'block');
|
|
|
$mask.show();
|
|
|
} else {
|
...
|
...
|
@@ -29,40 +105,42 @@ $mask.click(function() { |
|
|
});
|
|
|
|
|
|
$(document).on('click', '#brand_container .nav span', function() {
|
|
|
var yhChannel = $(this).attr('yh_channel');
|
|
|
|
|
|
$('#brand_container .nav span').removeClass('focus');
|
|
|
$(this).addClass('focus');
|
|
|
let yh_channel = $(this).attr('yh_channel');
|
|
|
|
|
|
getBrandList($(this).attr('_index'), yh_channel);
|
|
|
getBrandList($(this).attr('_index'), yhChannel);
|
|
|
});
|
|
|
|
|
|
/* 获取品牌数据*/
|
|
|
function getBrandList(_index, yh_channel) {
|
|
|
$.get('/3party/material/newBrandList?yh_channel=' + yh_channel, data => {
|
|
|
let list = [];
|
|
|
list = Object.keys(data.data.all_list).map(item => {
|
|
|
return { name: item, content: data.data.all_list[item] };
|
|
|
});
|
|
|
list['focus' + _index] = true;
|
|
|
$('#brand_container').html(brand_tmp({ list }));
|
|
|
brand_item_event_bind();
|
|
|
});
|
|
|
}
|
|
|
getBrandList(1, 1);
|
|
|
$('.start-time').on('change', function() {
|
|
|
query.shelveTimeBegin = $(this).val() + ' 00:00:00';
|
|
|
});
|
|
|
|
|
|
/* 获取品类数据*/
|
|
|
$.get('/3party/material/getCategory', data => {
|
|
|
console.log(data);
|
|
|
$('.end-time').on('change', function() {
|
|
|
query.shelveTimeEnd = $(this).val() + ' 23:59:59';
|
|
|
});
|
|
|
|
|
|
function brand_item_event_bind() {
|
|
|
$('#brand_container .item').off().on('click', function() {
|
|
|
let id = $(this).data('id');
|
|
|
let text = $(this).text();
|
|
|
$('.search-btn').on('click', function() {
|
|
|
$.ajax({
|
|
|
url: '/3party/material/getList',
|
|
|
data: query,
|
|
|
type: 'get',
|
|
|
success: function(data) {
|
|
|
if (data && data.code === 200) {
|
|
|
$('.table-data').html(tableTmp({product_list: data.data.product_list}));
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
|
|
|
query.brandId = id;
|
|
|
$('#brand').val(text);
|
|
|
$mask.hide();
|
|
|
$brand.hide();
|
|
|
$('.search-recommend-btn').on('click', function() {
|
|
|
$.ajax({
|
|
|
url: '/3party/material/getRecommendlist',
|
|
|
type: 'get',
|
|
|
success: function(data) {
|
|
|
if (data && data.code === 200) {
|
|
|
$('.table-data').html(tableTmp({product_list: data.data.product_list}));
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
} |
|
|
}); |
...
|
...
|
|