2019-09-06 23:53:10 +08:00

184 lines
6.7 KiB
JavaScript
Executable File

var mmg;
function initGrid(){
var h = WST.pageHeight();
var cols = [
{title:'图标', name:'' ,width:50, align:'center', renderer: function(val,item,rowIndex){
var adGoodsImg = item['adGoodsImg'].split(',');
return'<img src="'+WST.conf.IMGURL+'/'+adGoodsImg[0]+'" height="28px" width="100"/>';
}},
{title:'广告名称', name:'adName' ,width:80},
{title:'商品名称', name:'goodsName' ,width:130},
{title:'商品种类', name:'adGoodsStatus' ,width:30,renderer: function(val,item,rowIndex){
if(item['adGoodsStatus']==1){return "精选"}
if(item['adGoodsStatus']==2){return "推荐"}
if(item['adGoodsStatus']==3){return "热卖"}
}},
{title:'广告开始日期', name:'startDate' ,width:50},
{title:'广告结束日期', name:'endDate' ,width:50},
{title:'操作', name:'' ,width:80, align:'center', renderer: function(val,item,rowIndex){
var h = "";
if(WST.GRANT.GGGL_02)h += "<a class='btn btn-blue' href='javascript:toEdit("+item['adGoodsId']+")'><i class='fa fa-pencil'></i>修改</a> ";
if(WST.GRANT.GGGL_03)h += "<a class='btn btn-red' href='javascript:toDel(" + item['adGoodsId'] + ")'><i class='fa fa-trash-o'></i>删除</a> ";
return h;
}}
];
mmg = $('.mmg').mmGrid({height: h-155,indexCol: true, cols: cols,method:'POST',
url: WST.U('admin/adgoods/pageQuery'), fullWidthRows: true, autoLoad: true,
plugins: [
$('#pg').mmPaginator({})
]
});
$('#headTip').WSTTips({width:90,height:35,callback:function(v){
if(v){
mmg.resize({height:h-155});
}else{
mmg.resize({height:h-128});
}
}});
}
function toEdit(id){
location.href = WST.U('admin/adgoods/toEdit','id='+id);
}
function toDel(id){
var box = WST.confirm({content:"您确定要删除该记录吗?",yes:function(){
var loading = WST.msg('正在提交数据,请稍后...', {icon: 16,time:60000});
$.post(WST.U('admin/Adgoods/del'),{id:id},function(data,textStatus){
layer.close(loading);
var json = WST.toAdminJson(data);
if(json.status=='1'){
WST.msg("操作成功",{icon:1});
layer.close(box);
loadQuery();
}else{
WST.msg(json.msg,{icon:2});
}
});
}});
}
function loadQuery(){
var query = WST.getParams('.query');
query.page = 1;
mmg.load(query);
}
var oldSort;
function changeSort(t,id){
$(t).attr('ondblclick'," ");
var html = "<input type='text' id='sort-"+id+"' style='width:30px;padding:2px;' onblur='doneChange(this,"+id+")' value='"+$(t).html()+"' />";
$(t).html(html);
$('#sort-'+id).focus();
$('#sort-'+id).select();
oldSort = $(t).html();
}
function doneChange(t,id){
var sort = ($(t).val()=='')?0:$(t).val();
if(sort==oldSort){
$(t).parent().attr('ondblclick','changeSort(this,'+id+')');
$(t).parent().html(parseInt(sort));
return;
}
$.post(WST.U('admin/adgoods/changeSort'),{id:id,adSort:sort},function(data){
var json = WST.toAdminJson(data);
if(json.status==1){
$(t).parent().attr('ondblclick','changeSort(this,'+id+')');
$(t).parent().html(parseInt(sort));
}
});
}
//查询
function adsQuery(){
var query = WST.getParams('.query');
grid.set('url',WST.U('admin/adgoods/pageQuery',query));
}
function editInit(){
var laydate = layui.laydate;
form = layui.form;
laydate.render({
elem: '#startDate'
});
laydate.render({
elem: '#endDate'
});
//文件上传
WST.upload({
pick:'#adFilePicker',
formData: {dir:'adspic'},
compress:false,//默认不对图片进行压缩
accept: {extensions: 'gif,jpg,jpeg,png',mimeTypes: 'image/jpg,image/jpeg,image/png,image/gif'},
callback:function(f){
var json = WST.toAdminJson(f);
if(json.status==1){
$('#uploadMsg').empty().hide();
var html = '<img src="'+WST.conf.IMGURL+'/'+json.savePath+json.thumb+'" />';
$('#preview').html(html);
// 图片路径
$('#adGoodsImg').val(json.savePath+json.name);
}
},
progress:function(rate){
$('#uploadMsg').show().html('已上传'+rate+"%");
}
});
/* 表单验证 */
$('#adsForm').validator({
fields: {
adGoodsStatus: {
rule:"required",
msg:{required:"请选择广告商品类型"},
tip:"请选择广告商品类型",
ok:"验证通过",
},
adId: {
rule:"required;",
msg:{required:"广告名称不能为空"},
tip:"请输入广告名称",
ok:"验证通过",
},
adGoodsImg: {
rule:"required;",
msg:{required:"请上传广告图片"},
tip:"请上传广告图片",
ok:"",
},
goodsId: {
rule:"required;",
msg:{required:"请上传广告商品"},
tip:"请上传广告商品",
ok:"",
},
startDate: {
rule:"required;match(lt, endDate, date)",
msg:{required:"请选择广告开始时间",match:"必须小于广告结束时间"},
ok:"验证通过",
},
endDate: {
rule:"required;match(gt, startDate, date)",
msg:{required:"请选择广告结束时间",match:"必须大于广告开始时间"},
ok:"验证通过",
}
},
valid: function(form){
var params = WST.getParams('.ipt');
var loading = WST.msg('正在提交数据,请稍后...', {icon: 16,time:60000});
$.post(WST.U('admin/Adgoods/'+((params.adGoodsId==0)?"add":"edit")),params,function(data,textStatus){
layer.close(loading);
var json = WST.toAdminJson(data);
if(json.status=='1'){
WST.msg("操作成功",{icon:1});
location.href=WST.U('Admin/Adgoods/index');
}else{
WST.msg(json.msg,{icon:2});
}
});
}
});
}
//