sizeChart.js
3.62 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
// 尺码管理
var $ = require('jquery');
var edit = require('../common/edit');
var dropDown = require('../common/dropDown');
var dropDown = require('../common/dropDown');
var Handlebars = require('yoho.handlebars')
exports.init = function() {
$('.getsize').on('click', function() {
console.log($(this).data('id'));
$.ajax({
url: '/erpproduct/size/getSize',
type: 'POST',
dataType: "json",
data: {
id: $(this).data('id')
},
success: function(data) {
console.log(data.data.data);
var siezNameBox = [];
siezNameBox.push('<input type="hidden" id="id" value="'+data.data.data.id+'" />');
siezNameBox.push('<input class="form-control"id="siezName" type="text" value="'+data.data.data.sizeName+'" />');
$('#siezNameBox').html(siezNameBox);
}
})
});
$('#addSize').on('click',function(){
$('#siezNameBox').html('<input id="siezName" class="form-control" type="text" value="" />');
$('#modal-id').modal('show');
})
$('.add').on('click', function() {
var id= $('#id').val();
var siezName= $('#siezName').val();
console.log(siezName);
if(!id){
__ajax({
url:'/erpproduct/size/addSize',
data:{
sizeName: siezName
}
})
}else{
__ajax({
url:'/erpproduct/size/updateSize',
data:{
id:id,
sizeName: siezName
}
})
}
})
function __ajax(options,callback){
$.ajax({
type: 'POST',
url: options.url,
dataType: 'json',
data:options.data||{},
success: function(res) {
res=res.data;
if (res.code === 200) {
$.gritter.add({
title: options.msg||"提交成功",
class_name: 'growl-success',
sticky: false,
time: '1000',
after_open: function() {
callback&&callback();
}
});
setInterval(function(){
history.go(0);
},1000)
} else {
$.gritter.add({
title: '提交失败',
class_name: 'growl-danger',
sticky: false,
time: '1000'
});
setInterval(function(){
history.go(0);
},1000)
}
}
});
}
function getArr(curPage, pageCount) {
var arr = [];
//改变标签数,最好是奇数.......
var paginitionLength = 5;
var middle = Math.ceil(paginitionLength / 2);
if (curPage - 1 >= pageCount) {
console.log('err data');
return false;
}
for (var i = 0; i < pageCount && i < paginitionLength; i++) {
arr[i] = i + 1;
}
if (curPage <= middle) {
return arr;
}
if (curPage > middle && curPage < pageCount + 1 - middle) {
for (var p = 0; p < arr.length; p++) {
arr[p] = curPage - (paginitionLength - middle - p);
}
} else {
for (var k = 0; k < arr.length; k++) {
arr[k] = pageCount - paginitionLength + k + 1;
}
}
return arr;
}
Handlebars.registerHelper("page", function(value) {
var html = [];
var all = getArr(this.number,this.totalPages);
html.push('<li><a href="/erpproduct/size/index/1" aria-label="Previous">«</a></li>')
$.each(all, function(index) {
html.push('<li><a href="/erpproduct/size/index/' + all[index] + '" aria-label="Previous">' + all[index] + '</a></li>');
})
html.push('<li><a href="/erpproduct/size/index/'+this.totalPages+'" aria-label="Previous">»</a></li>')
return html.join('');
});
var pagecm = Handlebars.compile($("#pagenation-template").html().replace(/\\/g, ''));
$('#pagewrapper').html(pagecm({
totalPages: $('#totalPages').text(),
number:$('#number').text()
}));
};