|
|
// 尺码管理
|
|
|
var $ = require('jquery');
|
|
|
var edit = require('../common/edit');
|
|
|
var dropDown = require('../common/dropDown');
|
|
|
var dropDown = require('../common/dropDown');
|
|
|
var Handlebars = require('yoho.handlebars')
|
|
|
common = require('../common/common');
|
|
|
|
|
|
exports.init = function() {
|
|
|
$('.getsize').on('click', function() {
|
|
|
$.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);
|
|
|
|
|
|
var g = new common.grid({
|
|
|
el: '#size-list',
|
|
|
columns: [
|
|
|
{display: "编号", name: "id"},
|
|
|
{display: "尺码名", name: "sizeName"},
|
|
|
{
|
|
|
display: "操作", name: "", render: function (item) {
|
|
|
return '<a class="btn btn-info add2" data-index="' + item.__index + '">编辑</a>';
|
|
|
}
|
|
|
})
|
|
|
});
|
|
|
$('#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);
|
|
|
g.init($('#url').val());
|
|
|
|
|
|
$('#size-list').on('click', '.add2', function () {
|
|
|
|
|
|
if (curPage - 1 >= pageCount) {
|
|
|
console.log('err data');
|
|
|
return false;
|
|
|
}
|
|
|
var item = g.rows[$(this).data("index")];
|
|
|
|
|
|
for (var i = 0; i < pageCount && i < paginitionLength; i++) {
|
|
|
arr[i] = i + 1;
|
|
|
}
|
|
|
console.log(item);
|
|
|
// 修改尺码
|
|
|
common.dialog.confirm("修改尺码属性",
|
|
|
common.util.__template($("#template").html(), {id: item.id, input: item.sizeName})
|
|
|
, function () {
|
|
|
common.util.__ajax({
|
|
|
url: '/erpproduct/size/updateSize',
|
|
|
data: function () {
|
|
|
|
|
|
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);
|
|
|
}
|
|
|
if($("#input").val()==""){
|
|
|
return "尺码名不能为空";
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
for (var k = 0; k < arr.length; k++) {
|
|
|
arr[k] = pageCount - paginitionLength + k + 1;
|
|
|
}
|
|
|
}
|
|
|
return {
|
|
|
id: item.id,
|
|
|
sizeName: $("#input").val()
|
|
|
}
|
|
|
}
|
|
|
}, function () {
|
|
|
g.reload();
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
|
|
|
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('');
|
|
|
|
|
|
// 添加尺码
|
|
|
$('#add').on('click', function () {
|
|
|
|
|
|
common.dialog.confirm("添加尺码属性",
|
|
|
common.util.__template($("#template").html(), {id: "", input: ""})
|
|
|
, function () {
|
|
|
common.util.__ajax({
|
|
|
url: '/erpproduct/size/addSize',
|
|
|
data: {
|
|
|
sizeName: $("#input").val()
|
|
|
}
|
|
|
}, function () {
|
|
|
g.reload();
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
var pagecm = Handlebars.compile($("#pagenation-template").html().replace(/\\/g, ''));
|
|
|
|
|
|
$('#pagewrapper').html(pagecm({
|
|
|
totalPages: $('#totalPages').text(),
|
|
|
number:$('#number').text()
|
|
|
}));
|
|
|
}; |
|
|
\ No newline at end of file |
...
|
...
|
|