brand-cooperation.js
4.97 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
'use strict';
var $ = require('jquery'),
common = require('../common/common');
var ENUM = {
cooperateTypeId: {
0: '未设置',
1: '代销',
2: '经销',
3: '自主'
}
}
new common.dropDown({
el: '#brandCooperation'
});
var brandSet = new common.dropDown({
el: '#brandCooperationSet'
});
var g = new common.grid({
el: "#basicTable",
parms: function() {
return {
brandName: common.util.__input("brand"),
cooperateTypeId: common.util.__input("brandCooperation"),
setFlag: common.util.__input("brandCooperationSet")
};
},
columns: [{
display: 'ID',
name: 'brandId'
}, {
display: '品牌',
name: 'brandName'
}, {
display: '合作模式',
name: 'cooperateTypeName'
}, {
display: '是否设置',
render: function(item) {
if (item.cooperateTypeId == 0) {
return '未设置';
} else {
return '已设置';
}
}
},
{
display: '操作信息',
render: function(item) {
var html = '';
if (item.updateUserName) {
html += '<p>' + item.updateUserName + '</p>';
} else if (item.addUserName) {
html += '<p>' + item.addUserName + '</p>';
}
if (item.updateTime) {
var date = new Date(item.updateTime * 1000),
now = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
html += '<p>' + now + '</p>';
}
return html;
}
}, {
display: '操作',
render: function(item) {
var htmlArr = [];
if (item.cooperateTypeId != 1) {
htmlArr.push('<a href="javascript:;" class="btn btn-info btn-xs cooperate-type" data-brandid="' + item.brandId + '" data-id="' + item.id + '" data-type="1">代销</a>');
}
if (item.cooperateTypeId != 2) {
htmlArr.push('<a href="javascript:;" class="btn btn-info btn-xs cooperate-type" data-brandid="' + item.brandId + '" data-id="' + item.id + '" data-type="2">经销</a>');
}
if (item.cooperateTypeId != 3) {
htmlArr.push('<a href="javascript:;" class="btn btn-info btn-xs cooperate-type" data-brandid="' + item.brandId + '" data-id="' + item.id + '" data-type="3">自主</a>');
}
return htmlArr.join('');
}
}
]
});
g.init($("#gridurl").val());
$('#basicTable').on('click', '.cooperate-type', function() {
var $brandId = $(this).data('brandid'),
$id = $(this).data('id'),
brandType = $(this).data('type');
common.util.__ajax({
url: '/goods/brandCooperation/update',
data: {
brandId: $brandId,
id: $id,
cooperateTypeId: brandType
}
}, function(res) {
g.reload();
});
});
//筛选
$("#filter-btn").click(function() {
g.reload(1);
});
//回车筛选
$('#brand').on('keyup', function(event) {
if (event.keyCode == 13) {
$("#filter-btn").trigger('click');
}
});
//全部
$("#all-btn").click(function() {
$('#brandCooperationSet').val('-1').trigger('change');
$('#brandCooperation').val('-1').trigger('change');
$('#brand').val('');
g.reload();
});
//批量导入按钮点击事件
$('#import-btn').on('click', function() {
/*if ($('#basicTable').css('display') == 'none') {
location.reload();
}*/
$('#basicTable, .bulk-import').toggle();
$('.panel-default a').addClass('disabled');
$('.panel-default input, .panel-default select').attr('disabled', true);
});
$(' #sure-change, .priceTable-wrap').hide();
$('#upload-input').after('<div class="file-name btn btn-default">请选择文件</div>');
var loadModal = null;
common.edit.ajaxfileupload("#upload-input", {
params: {
type: "brandCooperation",
__type: "batch-import"
},
onStart: function() {
loadModal = common.dialog.load();
$('.file-name').text($('#upload-input').val().replace("C:\\fakepath\\", ""));
},
onComplete: function(response) {
loadModal.close();
if (response.code == 200) {
var li = '';
$.each(response.data.failFileReason, function(i, value) {
li += '<li>' + value + '</li>';
});
$('#error-msg').html(li);
if (response.data.succesList && response.data.succesList.length > 0) {
common.util.__tip(response.message, 'success');
}
} else {
common.util.__tip(response.message, 'warning');
}
}
});