brand-relation.js
2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
var $ = require('jquery'),
common = require('../../common/common');
var e = new common.edit('#brandWrap'),
brandSelectArr = [];
common.util.__ajax({
url: '/goods/brands/queryBrandsByStatus'
}, function(res) {
var data = res.data,
map = {},
firstName = '';
$.each(data, function(i, item) {
firstName = item.brandAlif.toUpperCase();
if (/^[a-zA-Z]$/.test(firstName)) {
if (!map.hasOwnProperty(firstName)) {
map[firstName] = [];
}
map[firstName].push(item);
} else {
if (!map.hasOwnProperty('0-9')) {
map['0-9'] = [];
}
map['0-9'].push(item);
}
});
$('.brand-list').html(common.util.__template2($('#brandTemp').html(), {
map: map
}));
if (NETSALEDATA.brandRelationList) {
$('.selected-brand').html(common.util.__template2($('#brandShowTemp').html(), {
brandRelationList: NETSALEDATA.brandRelationList,
brandRelation: brandSelectArr.join('|')
}));
};
e.init();
if ($('.contentpanel').data('type') == 'info') {
$('.brand-list').find('input').attr('disabled', true);
}
}, true);
$.each(NETSALEDATA.brandRelationList, function(index, value) {
brandSelectArr.push(value.brandId);
});
$('#brandWrap').on('change', 'input[name="brandRelationList"]', function() {
var $val = parseInt($(this).val()),
position = brandSelectArr.indexOf($val);
if (position == -1) {
brandSelectArr.push($val);
$('<div class="col-sm-2" data-id="' + $val + '">' + $(this).data('name') + '</div>').appendTo($('.selected-brand'));
} else {
brandSelectArr.splice(position, 1);
$('div[data-id="' + $val + '"]').remove();
};
});
$('#saveBrandRelation').on('click', function() {
e.submit('/goods/product/saveBrandRelation', function(option) {
option.data = GOLABDATA.fire("LYbrandRelation");
option.success = function(res) {
res = res.data;
if (res.code == '200') {
e.$tip(res.message, function() {}, 'growl-success');
} else {
e.$tip(res.message);
}
return false;
}
});
});
GOLABDATA.on("LYbrandRelation", function() {
return e.submit('', function(option) {
option.data.productSkn = $('#productSkn').val();
option.data.brandRelationList = JSON.stringify(option.data.brandRelationList.split('|'));
option.debug = true;
});
});