yohoCoin.js
6.18 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
//yoho币
'use strict';
var $ = require('jquery'),
common=require('../common/common');
var pricePercent = 0.2; //yoho币审核比例线
var ENUM = {
gender: {
1: '男',
2: '女',
3: '通用'
},
status: {
0: '未设置',
1: '<font color="#428bca">待审核</font>',
2: '<font color="#5cb85c">通过</font>',
3: '<font color="#d9534f">驳回</font>'
}
}
new common.dropDown({
el: '#shop',
ajax: 'shopsRest'
});
new common.dropDown({
el: '#brand',
ajax: 'brand'
});
new common.dropDown({
el: '#supplier',
ajax: 'querySupplier'
});
//多级菜单
var tabTree = new common.tabTree("#sortTree", {status: 1, sortLevel: 1});
tabTree.init();
var g = new common.grid({
el: "#yohoCoin_table",
parms: function() {
var select = tabTree.getAddress();
return {
productSkn: common.util.__input("skn"),
shopId: common.util.__input("shop"),
brandId: common.util.__input("brand"),
supplierId: common.util.__input("supplier"),
gender: common.util.__input("gender"),
auditStatus: common.util.__input("auditStatus"),
maxSortId: select[0] ? select[0].id : "",
middleSortId: select[1] ? select[1].id : "",
smallSortId: select[2] ? select[2].id : "",
sortId: select[3] ? select[3].id : ""
};
},
columns: [{
display: '',
render: function(item){
var html = "";
if(item.__index == 0){
$("#yohoCoin_table").find("thead tr th").html($("#coinListHead").html());
}
item.genderName = ENUM.gender[item.gender];
item.statusName = ENUM.status[item.productPrice.coinStatus];
html += common.util.__template2($("#coinList").html(),item);
return html;
}
}]
});
g.init($("#gridurl").val());
/**********************接口*************************/
//保存接口
function ajaxSave(productSkn, yohoCoin, auditorId, salesPrice){
common.util.__ajax({
url:'/good/yohoCoin/set',
data: {
"productSkn": productSkn,
"returnCoin": yohoCoin,
"salesPrice": salesPrice,
"auditorId": auditorId
}
},function(rs){
console.log(rs);
if(yohoCoin < (salesPrice * pricePercent)){
$('._' + productSkn).find(".returnYohoCoin").text(yohoCoin);
}
});
}
//批量导入接口
function ajaxUpload(){
var loadModal = null;
common.edit.ajaxfileupload('#yohoCoinUpload',{
params: {
type: "price",
__type: "batch-import"
},
onStart: function() {
loadModal = common.dialog.load();
$('.file-name').text($('#upload-input').val().replace("C:\\fakepath\\", ""));
},
onComplete: function(response) {
console.log(response);
if (loadModal) {
loadModal.close();
}
if (response.code == 200) {
} else {
common.util.__tip(response.message, 'warning');
}
}
});
}
/**********************校验*************************/
//吊牌价跟销售价校验
function checkPrice(retailPrice, salesPrice){
if(retailPrice == salesPrice){
return true;
}else{
common.util.__tip("销售价与吊牌价不同,YOHO币只能为0!");
return false;
}
}
//yoho币金额校验
function checkYohoCoin(yohoCoin, auditor, price){
if(yohoCoin.val()){
if(!isNaN(yohoCoin.val())){
if(yohoCoin.val() < 0){
yohoCoin.focus().select().addClass("error");
common.util.__tip("YOHO币金额不能小于0!");
return false;
}
//yoho币大于等于销售额的20%需要校验审核人
if(yohoCoin.val() >= (price * pricePercent)){
return checkAuditor(auditor);
}
}else{
yohoCoin.focus().select().addClass("error");
common.util.__tip("YOHO币金额必须为数字!");
return false;
}
}else{
yohoCoin.focus().addClass("error");
common.util.__tip("YOHO币金额不能为空!");
return false;
}
return true;
}
//审核人校验
function checkAuditor(auditor){
if(auditor.val() == ""){
auditor.focus().addClass("error");
common.util.__tip("审核人不能为空!");
return false;
}
return true;
}
/**********************事件*************************/
//保存操作
$(document).on('click', '.btn-save', function() {
var productSkn = $(this).data('productskn');
var sknDom = $('._' + productSkn);
var retailPrice = sknDom.find('.retailPrice').text(); //吊牌价
var salesPrice = sknDom.find('.salesPrice').text(); //销售价
if(checkPrice(retailPrice, salesPrice)){
var yohoCoinInput = sknDom.find('.editor-yohoCoin');
var auditorInput = sknDom.find('.editor-auditor');
if(checkYohoCoin(yohoCoinInput, auditorInput, salesPrice)){
ajaxSave(productSkn, yohoCoinInput.val(), auditorInput.val(), salesPrice);
}
}
});
//显示修改
$(document).on('click', '.btn-modify', function() {
if($(this).hasClass("openEditor")){
$(this).text("修改").removeClass("openEditor");
$(this).parents(".dataForShow").find(".dataForEditor td").hide();
}else{
$(this).text("收起").addClass("openEditor");
$(this).parents(".dataForShow").find(".dataForEditor td").show();
}
});
//显示批量导入
$(document).on('click', '#import-btn', function() {
$('.dataTables_wrapper').hide();
$('#yohoCoinSearch').hide();
$('.bulk-import').show();
});
//返回列表
$(document).on('click', '#return-btn', function() {
$('.bulk-import').hide();
$('#yohoCoinSearch').show();
$('.dataTables_wrapper').show();
});
//筛选
$(document).on('click', '#filter-btn', function() {
g.reload(1);
});
//全部
$(document).on('click', '#all-btn', function() {
location.href = '';
});
//校验失败编辑
$(document).on('change', '#yohoCoin_table .error', function() {
$(this).removeClass('error');
});