1
|
var $ = require('yoho-jquery');
|
1
|
var $ = require('yoho-jquery');
|
2
|
-var _ = require('lodash');
|
|
|
3
|
var brandTmp = require('hbs/material/brand.hbs');
|
2
|
var brandTmp = require('hbs/material/brand.hbs');
|
4
|
var tableTmp = require('hbs/material/tbl.hbs');
|
3
|
var tableTmp = require('hbs/material/tbl.hbs');
|
5
|
var $mask = $('.mask');
|
4
|
var $mask = $('.mask');
|
6
|
var $brand = $('#brand_container');
|
5
|
var $brand = $('#brand_container');
|
7
|
var query = {
|
6
|
var query = {
|
8
|
page: 1,
|
7
|
page: 1,
|
9
|
- maxSortId: 0,
|
|
|
10
|
- middleSortId: 0,
|
|
|
11
|
- smallSortId: 0
|
8
|
+ maxSortId: '',
|
|
|
9
|
+ middleSortId: '',
|
|
|
10
|
+ smallSortId: ''
|
12
|
};
|
11
|
};
|
13
|
var brandList = {
|
12
|
var brandList = {
|
14
|
list1: [],
|
13
|
list1: [],
|
|
@@ -16,6 +15,7 @@ var brandList = { |
|
@@ -16,6 +15,7 @@ var brandList = { |
16
|
list3: [],
|
15
|
list3: [],
|
17
|
list4: []
|
16
|
list4: []
|
18
|
};
|
17
|
};
|
|
|
18
|
+var option0 = '<option value="">--请选择--</option>';
|
19
|
|
19
|
|
20
|
function brandItemEventBind() {
|
20
|
function brandItemEventBind() {
|
21
|
$('#brand_container .item').off().on('click', function() {
|
21
|
$('#brand_container .item').off().on('click', function() {
|
|
@@ -45,7 +45,7 @@ function getBrandList(_index, yhChannel) { |
|
@@ -45,7 +45,7 @@ function getBrandList(_index, yhChannel) { |
45
|
}
|
45
|
}
|
46
|
|
46
|
|
47
|
function getCategoryOpt(opts) {
|
47
|
function getCategoryOpt(opts) {
|
48
|
- var html = '';
|
48
|
+ var html = option0;
|
49
|
|
49
|
|
50
|
$.each(opts, function(k, c) {
|
50
|
$.each(opts, function(k, c) {
|
51
|
html += '<option value="' + c.sort_id + '">' + c.sort_name + '</option>';
|
51
|
html += '<option value="' + c.sort_id + '">' + c.sort_name + '</option>';
|
|
@@ -54,6 +54,18 @@ function getCategoryOpt(opts) { |
|
@@ -54,6 +54,18 @@ function getCategoryOpt(opts) { |
54
|
return html;
|
54
|
return html;
|
55
|
}
|
55
|
}
|
56
|
|
56
|
|
|
|
57
|
+function findSub(data, id) {
|
|
|
58
|
+ var sub = [];
|
|
|
59
|
+
|
|
|
60
|
+ $.each(data, function(k, c) {
|
|
|
61
|
+ if (c.sort_id === id) {
|
|
|
62
|
+ sub = c.sub;
|
|
|
63
|
+ }
|
|
|
64
|
+ });
|
|
|
65
|
+
|
|
|
66
|
+ return sub;
|
|
|
67
|
+}
|
|
|
68
|
+
|
57
|
getBrandList(1, 1);
|
69
|
getBrandList(1, 1);
|
58
|
|
70
|
|
59
|
/* 获取品类数据*/
|
71
|
/* 获取品类数据*/
|
|
@@ -72,21 +84,34 @@ $.get('/3party/material/getCategory', function(res) { |
|
@@ -72,21 +84,34 @@ $.get('/3party/material/getCategory', function(res) { |
72
|
|
84
|
|
73
|
$category1.on('change', function() {
|
85
|
$category1.on('change', function() {
|
74
|
var id = $(this).val();
|
86
|
var id = $(this).val();
|
|
|
87
|
+ var html = option0;
|
75
|
|
88
|
|
76
|
- sub = _.find(categoryData, {sort_id: id}).sub;
|
|
|
77
|
- $category2.html(getCategoryOpt(sub)).show();
|
|
|
78
|
- $category3.html('').hide();
|
|
|
79
|
- query.maxSortId = id;
|
|
|
80
|
- query.middleSortId = $category2.find('option').eq(0).attr('value');
|
89
|
+ query.maxSortId = '';
|
|
|
90
|
+ query.middleSortId = '';
|
|
|
91
|
+ query.smallSortId = '';
|
|
|
92
|
+
|
|
|
93
|
+ if ($(this).find('option:selected').index() !== 0) {
|
|
|
94
|
+ sub = findSub(categoryData, id);
|
|
|
95
|
+ html = getCategoryOpt(sub);
|
|
|
96
|
+ query.maxSortId = id;
|
|
|
97
|
+ }
|
|
|
98
|
+
|
|
|
99
|
+ $category2.html(html);
|
|
|
100
|
+ $category3.html(option0);
|
81
|
});
|
101
|
});
|
82
|
|
102
|
|
83
|
$category2.on('change', function() {
|
103
|
$category2.on('change', function() {
|
84
|
var id = $(this).val();
|
104
|
var id = $(this).val();
|
85
|
- var third = _.find(sub, {sort_id: id}).sub;
|
105
|
+ var third = [];
|
86
|
|
106
|
|
87
|
- $category3.html(getCategoryOpt(third)).show();
|
|
|
88
|
- query.middleSortId = id;
|
|
|
89
|
- query.smallSortId = $category3.find('option').eq(0).attr('value');
|
107
|
+ query.smallSortId = '';
|
|
|
108
|
+ query.middleSortId = '';
|
|
|
109
|
+
|
|
|
110
|
+ if ($(this).find('option:selected').index() !== 0) {
|
|
|
111
|
+ third = findSub(sub, id);
|
|
|
112
|
+ $category3.html(getCategoryOpt(third));
|
|
|
113
|
+ query.middleSortId = id;
|
|
|
114
|
+ }
|
90
|
});
|
115
|
});
|
91
|
|
116
|
|
92
|
$category3.on('change', function() {
|
117
|
$category3.on('change', function() {
|