File: /web/data/www.tbbprovision.com/static/manage/js/pro.js
/**
* author : liaoyaping
* createTime : 2017/5/12 11:21
* description :
*/
var proobj = {
cate_list : function(){
//删除
$('.del-btn').click(function(){
var cate_id = $(this).attr('data-id');
//询问框
layer.confirm('确定删除此记录?', {
skin:'layui-layer-molv',
'title':'警告',
icon:3,
btn: ['删除','关闭'] //按钮
}, function(){
jQuery.ajax({
method:'post',
url:'/admin/product/cate_del/',
data:{cate_id:cate_id},
timeout:5000,
dataType:'json',
beforeSend:function(){
layer.msg('数据处理中',{icon:16,time:0,shade:[0.8,'#000']});
},
success:function($d){
layer.msg($d.response_content, {icon: 1,time:1000},function(){
window.location.reload();
});
},
error:function(xhrData){
layer.msg(errorMessage(xhrData.responseText),{time:1000,icon:7});
}
});
},function(){
layer.msg('操作取消',{time:500});
});
});
//新增
$('#add').click(function(){
var index = layer.open({
type: 2,
title: ['新增产品分类'],
shadeClose: true,
shade: [true,'rgba(0,0,0,.5)'],
maxmin: true,
shift:2,
offset:['0','10%'],
area: ['90%', '100%'],
content: '/admin/product/cate_add/'
});
});
//编辑
$('.edit-btn').click(function(){
var cate_id = $(this).attr('data-id');
var index = layer.open({
type: 2,
title: ['编辑产品分类'],
shadeClose: true,
shift:2,
shade: [true,'rgba(0,0,0,.5)'],
offset:['0','10%'],
maxmin: true,
area: ['90%', '100%'],
content: '/admin/product/cate_edit/?cate_id='+cate_id
});
});
$('.data-toggle-btn').click(function(){
$(this).toggleClass('fa-minus-square');
var obj = $(this).attr('data-toggle');
var obj_class = $(this).attr('data-class');
$('.'+obj).toggleClass(obj_class);
});
},
cate_edit : function(){
$('.i-checks').iCheck({
checkboxClass: 'icheckbox_square-green',
radioClass: 'iradio_square-green'
});
$('#defaultForm').bootstrapValidator({
message: '这是个无效值',
feedbackIcons: {/*input状态样式图片*/
//valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {/*验证:规则*/
cate_name: {//验证input项:验证规则
validators: {
notEmpty: { message: '分类名称不能为空'},
stringLength: { min: 2, max: 100, message: '分类名称长度必须在2到100之间'}
}
},
my_order:{
validators:{
regexp: {
regexp: /^[0-9]{0,3}$/,
message: '排序只能是0~3位数字'
}
}
}
}
})
.on('success.form.bv', function(e) {//点击提交之后
e.preventDefault();
var $form = $(e.target);
var bv = $form.data('bootstrapValidator');
$.ajax({
type: "post",
url: "/admin/product/cate_edit_post/",
dataType: 'json',
timeout:10000,
data: $('body').find('form').serialize(),//表单数据
beforeSend:function(){
layer.msg('数据处理中', {
time:0,
icon:16,
shade: [0.8,'#000'] //0.1透明度的白色背景
});
$('#validateBtn').button('loading');
},
success: function (d) {
parent.location.reload();
parent.layer.closeAll('iframe');//关闭弹窗
},
error:function(xhrData){
layer.msg(errorMessage(xhrData.responseText),{time:1000,icon:2});
layer.closeAll('msg');
$('#validateBtn').button('reset');
}
});
});
$('#validateBtn').click(function() {
$('#defaultForm').bootstrapValidator('validate');
});
//图片
global.upload();
},
cate_add:function(){
$('.i-checks').iCheck({
checkboxClass: 'icheckbox_square-green',
radioClass: 'iradio_square-green'
});
$('#defaultForm').bootstrapValidator({
message: '这是个无效值',
feedbackIcons: {/*input状态样式图片*/
//valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {/*验证:规则*/
cate_name: {//验证input项:验证规则
validators: {
notEmpty: { message: '分类名称不能为空'},
stringLength: { min: 2, max: 100, message: '分类名称长度必须在2到100之间'}
}
},
my_order:{
validators:{
regexp: {
regexp: /^[0-9]{0,3}$/,
message: '排序只能是0~3位数字'
}
}
}
}
})
.on('success.form.bv', function(e) {//点击提交之后
e.preventDefault();
var $form = $(e.target);
var bv = $form.data('bootstrapValidator');
$.ajax({
type: "post",
url: "/admin/product/cate_add_post/",
dataType: 'json',
timeout:10000,
data: $('body').find('form').serialize(),//表单数据
beforeSend:function(){
layer.msg('数据处理中', {
time:0,
icon: 16
,shade: [0.4,'#000']
});
$('#validateBtn').button('loading');
},
success: function (d) {
parent.location.reload();
parent.layer.closeAll('iframe');//关闭弹窗
},
error:function(xhrData){
layer.msg(errorMessage(xhrData.responseText),{time:1000,icon:2});
layer.closeAll('msg');
$('#validateBtn').button('reset');
}
});
});
$('#validateBtn').click(function() {
$('#defaultForm').bootstrapValidator('validate');
});
//图片
global.upload();
},
/*attribute-list*/
attribute_list : function(){
window.$bootstrapTable = $('#table2').bootstrapTable({
url:'/admin/product/attribute_list_json/',
method:'post',
striped:true,
search:false,
height:'700',
toolbar:'#toolbar',
pageSize:50,
pageList:[50,100],
sortOrder:'desc',
showColumns:true,
showRefresh:true,
idField:'attr_id',
showToggle:false,
sidePagination:'server',
selectItemName:'attr_id',
clickToSelect:true,
totalRows:5,
columns: [{
field: 'attr_id',
title: 'ID',
checkbox:true,
formatter: function(value,row){
row['post_id'] = value;
}
},
{ title: 'ID',width:"5%" ,formatter:function(value,row){return row['post_id'];}},
{ field: 'my_order', title: '排序',width:"5%" },
{ field: 'name', title: '属性名称' },
{ field: 'unit', title: '单位' },
{ field: 'type', title: '单位' ,formatter:function(value){return (value==1?"输入框":(value==2?"下拉框 ":'文本框'));}},
{ field: '', title: '操作', width: '8%',
formatter: function(value,row,index){
return "<a class='item-edit-btn btn btn-info btn-list' title='编辑' data-id='"+row.post_id+"'><span class='fa fa-pencil'></span></a>";
}
}],
onClickRow: function (row, $element) {
curRow = row;
},
onLoadSuccess: function(data){
$('.item-edit-btn').click(function(){
var query_strint = $(this).attr('data-id');
var index = layer.open({
type: 2,
title: ['编辑产品属性'],
shadeClose: true,
shade: [true,'rgba(0,0,0,.5)'],
maxmin: true,
shift:2,
offset:['0','20%'],
area: ['80%', '100%'],
content: '/admin/product/attribute_edit/?attr_id='+query_strint
});
});
}
});
//新增
$('#add').click(function(){
var index = layer.open({
type: 2,
title: ['新增产品属性'],
shadeClose: true,
shade: [true,'rgba(0,0,0,.5)'],
maxmin: true,
shift:2,
offset:['0','20%'],
area: ['80%', '100%'],
content: '/admin/product/attribute_add/'
});
});
//删除
$('#remove').click(function(){
//询问框
layer.confirm('确定删除此记录?', {
'title':['提示'],
btn: ['删除','关闭'] //按钮
}, function(){
jQuery.ajax({
method:'post',
url:'/admin/product/attribute_del/',
data:global.get_selected_str('input[name="attr_id"]:checked','id'),
dataType:'json',
timeout:10000,
beforeSend:function(){
layer.closeAll('confirm');
layer.msg('数据处理中',{icon:16,time:0,shade:[0.8,'#000']});
},
success:function($d){
$bootstrapTable.bootstrapTable('refresh');
layer.msg($d.response_content, {icon: 1,time:1000});
},
error:function(xhrData){
layer.msg(errorMessage(xhrData.responseText),{time:2000,icon:7});
}
});
});
});
},
attribute_add:function(){
$('.i-checks').on('ifChecked', function(event){ //ifCreated 事件应该在插件初始化之前绑定
var box = $('.attribute-list-container');
box.removeClass('hide');
if($(this).find('input').val()==2){
box.show();
}else{
box.hide();
}
});
$('.i-checks').iCheck({
checkboxClass: 'icheckbox_square-green',
radioClass: 'iradio_square-green'
});
//属性下拉框内容
$('#defaultForm').bootstrapValidator({
message: '这是个无效值',
feedbackIcons: {/*input状态样式图片*/
//valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {/*验证:规则*/
name: {//验证input项:验证规则
validators: {
notEmpty: { message: '属性名称不能为空'}
}
},
my_order:{
validators:{
regexp: {
regexp: /^[0-9]{0,3}$/,
message: '排序只能是0~3位数字'
}
}
}
}
}).on('success.form.bv', function(e) {//点击提交之后
e.preventDefault();
var $form = $(e.target);
var bv = $form.data('bootstrapValidator');
$.ajax({
type: "post",
url: $('#defaultForm').attr('action'),
dataType: 'json',
timeout:10000,
data: $('body').find('form').serialize(),//表单数据
beforeSend:function(){
layer.msg('数据处理中', {
time:0,
icon: 16
,shade: [0.4,'#000']
});
$('#validateBtn').button('loading');
},
success: function (d) {
parent.$bootstrapTable.bootstrapTable('refresh');
parent.layer.closeAll('iframe');//关闭弹窗
},
error:function(xhrData){
layer.msg(errorMessage(xhrData.responseText),{time:1000,icon:2});
layer.closeAll('msg');
$('#validateBtn').button('reset');
}
});
});
$('#validateBtn').click(function() {
$('#defaultForm').bootstrapValidator('validate');
});
},
/*products list */
list : function(){
var $bootstrapTable = $('#table2').bootstrapTable({
url:'/admin/product/list_json/',
method:'post',
striped:true,
search:true,
height:'700',
toolbar:'#toolbar',
sortOrder:'desc',
showColumns:true,
showRefresh:true,
idField:'proid',
showToggle:false,
sidePagination:'server',
selectItemName:'proid',
clickToSelect:true,
totalRows:5,
queryParams:function(data){
data.cate_id = $('#cate_id').val();
data.ext_id = $('#ext_id').val();
data.start_add_date = $('#datetimepicker').val();
data.last_add_date = $('#datetimepicker2').val();
return data;
},
columns: [{
field: 'proid',
title: 'ID',
checkbox:true,
formatter: function(value,row){
row['post_id'] = value;
}
},{
field: 'my_order',
title: '排序',
width:'5%',
align:'left',
sortable:true,
formatter: function (value, row, index) {
if (row['post_gid']!=1) {
return "<a class='edit-btn' href=\"#\" name=\"new_my_order\" data-type=\"text\" data-pk=\"" + value + "\" data-title=\"排序\">" + value + "</a>";
}else{
return value;
}
}
},{
field: 'picture',
title: '产品图片',
width: '7%',
formatter:function(value){
if(value){
return "<img class='lazy' width='50' height='50' src='"+value+"'>";
}else{
return "<img width='50' height='50' src='/static/manage/img/webuploader.png'>";
}
}
},{
field: 'name',
title: '名称'
},{
field: 'n_d',
title: '内径',
sortable:true,
formatter:function(value,row){
return value + " / " + row['n_d_unit']
}
},{
field: 'u_D',
title: '外径',
sortable: true,
formatter:function(value,row){
return value + " / " + row['u_D_unit']
}
},{
field: 'u_H',
title: '高度',
sortable: true,
formatter:function(value,row){
return value + " / " + row['u_H_unit']
}
},{
field: 'u_B',
title: '宽度',
sortable: true,
formatter:function(value,row){
return value + " / " + row['u_B_unit']
}
},{
field: 'n_m',
title: '重量',
sortable: true,
formatter:function(value,row){
return value + " / " + row['n_m_unit']
}
},{
field: 'cate_id',
title: '分类',
formatter:function(value,row,index){
return row.cate_name;
}
},{
field: 'acc_time',
title: '添加时间',
sortable:true
},{
field: 'views',
title: '浏览量',
sortable:true
},{
title: '其它属性',
formatter:function(value,row,index){
return (row['is_index']==1?"<div class='label label-info'>首页显示</div><div class='blank5'></div>":"")+(row['is_recommend']==1?"<div class='label label-success'>推荐产品</div><div class='blank5'></div>":"")+(row['is_show']==1?"<div class='label label-primary'>前台显示</div><div class='blank5'></div>":"<div class='label label-warning'>前台隐藏</div><div class='blank5'></div>");
}
},{
field: '',
title: '操作',
width: '8%',
formatter: function(value,row,index){
return "<a class='item-edit-btn btn btn-info btn-list' title='编辑' href='/admin/product/pro_edit/?proid="+row.post_id+"' data-id='"+row.post_id+"'><span class='fa fa-pencil'></span></a> <a class='item-copy-btn btn btn-info btn-list' title='复制' data-id='"+row.post_id+"'><span class='fa fa-copy'></span></a>";
}
}],
onClickRow: function (row, $element) {
curRow = row;
},
onLoadSuccess: function(data){
$("#table2 .edit-btn").editable({
url: function (params) {
var sName = $(this).attr("name");
curRow[sName] = params.value;
$.ajax({
type: 'POST',
url: "/admin/product/pro_order/",
data: curRow,
dataType: 'JSON',
success: function (xhrData) {
layer.msg(xhrData.response_content,{icon:1,time:500},function(){
$bootstrapTable.bootstrapTable('refresh');
});
},
error: function (xhrData) {
//失败了重新刷新
layer.msg(errorMessage(xhrData.responseText),{icon:7,time:1000},function () {
$bootstrapTable.bootstrapTable('refresh');
});
}
});
},
type: 'text',
// mode : 'inline',
placement:'right',
validate: function (value) { //字段验证
if (!$.trim(value)) {
return '不能为空';
}
var patten = /^[0-9]{1,3}$/;
if(!patten.test(value)){
return '排序只能为1~3位数字';
}
}
});
$('.item-copy-btn').click(function(){
var query_strint = $(this).attr('data-id');
var index = layer.confirm('即将进入复制模式?', {
title:'提示',
icon:3,
btn: ['继续复制','取消'] //按钮
}, function(){
window.location = '/admin/product/pro_copy/?id='+query_strint;
});
});
}
});
//分类搜索
$('#cate_id').change(function(){
$bootstrapTable.bootstrapTable('refresh');
});
//其它属性
$('#ext_id').change(function(){
$bootstrapTable.bootstrapTable('refresh');
});
//时间选择
$('#datetimepicker').datetimepicker({timepicker:false,format:'Y/m/d',
onSelectDate: function(dateText, inst) {
$bootstrapTable.bootstrapTable('refresh');
}
});
//时间选择
$('#datetimepicker2').datetimepicker({timepicker:false,format:'Y/m/d',
onSelectDate: function(dateText, inst) {
$bootstrapTable.bootstrapTable('refresh');
}
});
//删除
$('#remove').click(function(){
//询问框
layer.confirm('确定删除此记录?', {
'title':'提示',
icon:3,
btn: ['删除','关闭'] //按钮
}, function(){
jQuery.ajax({
method:'post',
url:'/admin/product/pro_del/',
data:global.get_selected_str('input[name="proid"]:checked','id'),
dataType:'json',
timeout:10000,
beforeSend:function(){
layer.closeAll('confirm');
layer.msg('数据处理中',{icon:16,time:0,shade:[0.8,'#000']});
},
success:function($d){
$bootstrapTable.bootstrapTable('refresh');
layer.msg($d.response_content, {icon: 1,time:1000});
},
error:function(xhrData){
layer.msg(errorMessage(xhrData.responseText),{time:2000,icon:7});
}
});
});
});
//批量操作
$('.bat-btn').click(function(){
var that = $(this);
//询问框
layer.confirm('确定此批量操作?', {
'title':'提示',
icon:3,
btn: ['确定','关闭'] //按钮
}, function(){
jQuery.ajax({
method:'post',
url:that.attr('data'),
data:global.get_selected_str('input[name="proid"]:checked','id'),
dataType:'json',
timeout:10000,
beforeSend:function(){
layer.closeAll('confirm');
layer.msg('数据处理中',{icon:16,time:0,shade:[0.8,'#000']});
},
success:function($d){
$bootstrapTable.bootstrapTable('refresh');
layer.msg($d.response_content, {icon: 1,time:1000});
},
error:function(xhrData){
layer.msg(errorMessage(xhrData.responseText),{time:2000,icon:7});
}
});
});
});
},
edit:function(){
$('.i-checks').iCheck({
checkboxClass: 'icheckbox_square-green',
radioClass: 'iradio_square-green'
});
//打开添加属性列表
$('.attr-page-btn').click(function(){
layer.open({
type: 2,
title: ['选择产品属性'],
shadeClose: true,
shade: [true,'rgba(0,0,0,.5)'],
skin: 'layui-layer-demo', //样式类名
maxmin: true,
shift:2,
offset:['0','50%'],
area: ['50%', '100%'],
content: '/admin/product/choice_attribute/'
});
});
//移除一条属性
$('body').delegate('.remove_attribute','click',function(){
$(this).parent().parent().parent().parent().remove();
});
$('#defaultForm').bootstrapValidator({
message: '这是个无效值',
feedbackIcons: {/*input状态样式图片*/
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {/*验证:规则*/
name: {//验证input项:验证规则
validators: {
notEmpty: { message: '产品名称不能为空'},
stringLength: { min: 2, max: 100, message: '产品名称长度必须在2到100之间'}
}
},
my_order:{
validators:{
regexp: {
regexp: /^[0-9]{0,3}$/,
message: '排序只能是0~3位数字'
}
}
}
}
})
.on('success.form.bv', function(e) {//点击提交之后
e.preventDefault();
var $form = $(e.target);
var bv = $form.data('bootstrapValidator');
$.ajax({
type: "post",
url: $('#defaultForm').attr('action'),
dataType: 'json',
timeout:15000,
data: $('body').find('form').serialize(),//表单数据
beforeSend:function(){
layer.msg('数据处理中', {time:0,icon:16,shade: [0.8,'#000']});
$('#validateBtn').button('loading');
},
success: function (d) {
window.location = '/admin/product/list/';
},
error:function(xhrData){
layer.msg(errorMessage(xhrData.responseText),{time:1000,icon:2});
$('#validateBtn').button('reset');
}
});
});
$('#validateBtn').click(function() {
$('#defaultForm').bootstrapValidator('validate');
});
//图片
global.upload();
$(".pic-list").sortable({connectWith: ".pic-list"}).disableSelection();
}
};