/**
|
* 管理初始化
|
*/
|
var TCoupon = {
|
id: "TCouponTable", //表格id
|
seItem: null, //选中的条目
|
table: null,
|
layerIndex: -1
|
};
|
|
// console.log("父级页面"+window.parent.getElementById("counpons"+$("#index").val()));
|
console.log("父级页面" + window.parent.document.getElementById("counpons" + $("#index").val()).value);
|
console.log( $("#index").val());
|
|
var ids = window.parent.document.getElementById("counpons" + $("#index").val()).value;
|
|
// console.log("==========radio=="+ids)
|
/**
|
* 初始化表格的列
|
*/
|
TCoupon.initColumn = function () {
|
return [
|
{field: 'selectItem', checkbox: true, formatter: function (value,row) {
|
if(ids.indexOf(row.id)!= -1){
|
return {checked:true};
|
}}},
|
{title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
|
{title: '优惠券名称', field: 'name', visible: true, align: 'center', valign: 'middle'},
|
|
{title: '优惠券类型', field: 'type', visible: true, align: 'center', valign: 'middle',
|
formatter: function (value, row, index) {
|
return {1: "满减券", 2: "代金券", 3: "体验券"}[value]
|
}},
|
{title: '优惠券详情', field: 'illustrate', visible: true, align: 'center', valign: 'middle'},
|
];
|
};
|
|
/**
|
* 检查是否选中
|
*/
|
TCoupon.check = function () {
|
var selected = $('#' + this.id).bootstrapTable('getSelections');
|
if(selected.length == 0){
|
Feng.info("请先选中表格中的某一记录!");
|
return false;
|
}else{
|
TCoupon.seItem = selected[0];
|
TCoupon.seItem1 = selected;
|
|
return true;
|
}
|
};
|
|
/**
|
* 点击添加
|
*/
|
TCoupon.openAdd = function () {
|
var index = layer.open({
|
type: 2,
|
title: '添加',
|
area: ['100%', '100%'], //宽高
|
fix: false, //不固定
|
maxmin: true,
|
content: Feng.ctxPath + '/tCouponManage/coupon_add'
|
});
|
this.layerIndex = index;
|
};
|
|
|
|
TCoupon.backids = function (i) {
|
console.log("aaaaaa"+i)
|
|
var selected = $('#' + this.id).bootstrapTable('getSelections');
|
// if(selected.length == 0){
|
// Feng.info("请先选中表格中的某一记录!");
|
// return false;
|
// }else{
|
|
|
// return true;
|
// }
|
if (selected.length != 0) {
|
TCoupon.seItem = selected[0];
|
TCoupon.seItem1 = selected;
|
|
var ids = TCoupon.seItem1.map(function(item) {
|
return item.id;
|
}).join(",");
|
// console.log("aaaaaa"+TCoupon.seItem1.map(function(item) {
|
// return item.id;
|
// }).join(","))
|
|
|
// if (window.parent.document.getElementById("counpons"+i).value==null||window.parent.document.getElementById("counpons"+i).value==""){
|
window.parent.document.getElementById("counpons"+i).value = ids;
|
// }else {
|
// window.parent.document.getElementById("counpons"+i).value = window.parent.document.getElementById("counpons"+i).value + ','+TCoupon.seItem.id;
|
//
|
// }
|
window.parent.layer.closeAll();
|
}else {
|
window.parent.document.getElementById("counpons"+i).value = "";
|
window.parent.layer.closeAll();
|
|
}
|
|
};
|
|
/**
|
* 点击编辑
|
*/
|
TCoupon.openChange = function () {
|
if (this.check()){
|
let id = TCoupon.seItem.id
|
let name = TCoupon.seItem.name
|
let quantityIssued = TCoupon.seItem.quantityIssued
|
let pickUpQuantity = TCoupon.seItem.pickUpQuantity
|
let illustrate = TCoupon.seItem.illustrate
|
let hasPickQty = TCoupon.seItem.hasPickQty
|
var index = layer.load(1,{
|
type: 1
|
, title: '编辑优惠券'
|
, area: ['50%', '50%']
|
, offset: 'auto' //具体配置参考:http://www.layui.com/doc/modules/layer.html#offset
|
, id: 'layerDemo' //防止重复弹出cge
|
, content: '<div class="form-horizontal">' +
|
' <div class="col-sm-11" >' +
|
' <div class="col-sm-11">' +
|
' <div class="form-group">\n' +
|
' <label class="col-sm-3 control-label">优惠券名称:</label>\n' +
|
' <div class="col-sm-9">\n' +
|
' <label class="form-control" id="name" >'+name+'</label> '+
|
' </div>\n' +
|
' </div>\n'+
|
' <div class="form-group">\n' +
|
' <label class="col-sm-3 control-label">发放数量:</label>\n' +
|
' <div class="col-sm-9">\n' +
|
' <input class="form-control" id="num" value="'+quantityIssued+'" > '+
|
' </div>\n' +
|
' </div>\n' +
|
' <div class="form-group">\n' +
|
' <label class="col-sm-3 control-label">限领数量:</label>\n' +
|
' <div class="col-sm-9">\n' +
|
' <input class="form-control" id="num1" value="'+pickUpQuantity+'" > '+
|
' </div>\n' +
|
' </div>\n' +
|
' <div class="form-group">\n' +
|
' <label class="col-sm-3 control-label">优惠券说明:</label>\n' +
|
' <div class="col-sm-9">\n' +
|
' <textarea class="form-control" id="text" >'+illustrate+'</textarea> '+
|
' </div>\n' +
|
' </div>\n' +
|
' </div>' +
|
' </div>' +
|
'</div>'
|
, btn: ['关闭', '保存']
|
, btnAlign: 'c' //按钮居中
|
, shade: 0.5 //不显示遮罩
|
,load:1
|
, yes: function () {
|
layer.closeAll();
|
},
|
btn2:function () {
|
let num = $("#num").val()
|
if(num==''){
|
Feng.info("请输入发放数量")
|
return false;
|
}
|
let num1 = $("#num1").val()
|
if(num1==''){
|
Feng.info("请输入限领数量")
|
return false;
|
}
|
let text = $("#text").val()
|
if(text==''){
|
Feng.info("请输入优惠券说明")
|
return false;
|
}
|
|
if(num<hasPickQty){
|
Feng.info("发放数量不能小于已领取数量")
|
return false;
|
}
|
var ajax = new $ax(Feng.ctxPath + "/tCouponManage/update", function (data) {
|
if (data.code == 200) {
|
Feng.success("操作成功!");
|
window.location.reload();
|
window.parent.layer.closeAll();
|
} else if(data=="repeat"){
|
window.location.reload();
|
window.parent.layer.closeAll();
|
Feng.error("请勿重复操作");
|
}else {
|
return Feng.error(data.msg);
|
}
|
}, function (data) {
|
Feng.error("操作失败!")
|
window.location.reload();
|
window.parent.layer.closeAll();
|
return Feng.error("操作失败!");
|
});
|
ajax.set("id", id);
|
ajax.set("num", num);
|
ajax.set("num1", num1);
|
ajax.set("text", text);
|
ajax.start();
|
layer.closeAll();
|
}
|
});
|
|
this.layerIndex = index;
|
}
|
};
|
|
|
|
/**
|
* 上架
|
*/
|
|
|
/**
|
* 下架
|
*/
|
TCoupon.offShelf = function () {
|
|
|
};
|
|
|
/**
|
* 打开查看详情
|
*/
|
TCoupon.openDetail = function () {
|
if (this.check()) {
|
var index = layer.open({
|
type: 2,
|
title: '详情',
|
area: ['100%', '100%'], //宽高
|
fix: false, //不固定
|
maxmin: true,
|
content: Feng.ctxPath + '/tCouponManage/coupon_detail/' + TCoupon.seItem.id
|
});
|
this.layerIndex = index;
|
}
|
};
|
|
|
|
|
/**
|
* 打开领取记录
|
*/
|
TCoupon.openCollectionRecord = function () {
|
if (this.check()) {
|
var index = layer.open({
|
type: 2,
|
title: '详情',
|
area: ['800px', '420px'], //宽高
|
fix: false, //不固定
|
maxmin: true,
|
content: Feng.ctxPath + '/tCouponManage/coupon_record/' + TCoupon.seItem.id
|
});
|
this.layerIndex = index;
|
}
|
};
|
TCoupon.onShelf = function (e) {
|
if (this.check()) {
|
var ajax = new $ax(Feng.ctxPath + "/tCouponManage/onShelf", function(data){
|
if(data.code==200){
|
Feng.success("操作成功!")
|
TCoupon.table.refresh();
|
}
|
},function(data){
|
Feng.error("操作失败!" + data.responseJSON.message + "!");
|
});
|
ajax.set("id",TCoupon.seItem.id)
|
ajax.set("type",e)
|
ajax.start();
|
}
|
};
|
|
|
|
/**
|
* 查询列表
|
*/
|
TCoupon.search = function () {
|
var queryData = {};
|
queryData['name'] = $("#name").val();
|
queryData['type'] = $("#type").val();
|
queryData['distributionMethod'] = $("#distributionMethod").val();
|
queryData['userPopulation'] = $("#userPopulation").val();
|
queryData['status'] = $("#status").val();
|
queryData['state'] = $("#state").val();
|
TCoupon.table.refresh({query: queryData});
|
};
|
|
|
/**
|
* 重置搜索
|
*/
|
TCoupon.resetSearch = function () {
|
$("#name").val('');
|
$("#type").val('');
|
$("#distributionMethod").val('');
|
$("#userPopulation").val('');
|
$("#status").val('');
|
$("#state").val('');
|
TCoupon.search();
|
};
|
|
$(function () {
|
// console.log("父级"+window.parent.document.getElementById("cityCode").val())
|
var defaultColunms = TCoupon.initColumn();
|
var table = new BSTable(TCoupon.id, "/tCouponManage/list1", defaultColunms);
|
table.setPaginationType("client");
|
// table.queryParams = function (params) {
|
// // 在这里添加您的自定义参数
|
// params.cityCode = window.parent.document.getElementById("cityCode").value;
|
// params.customParam2 = window.parent.document.getElementById("cityCode").value;
|
// return params;
|
// };
|
var cityCode = ""
|
console.log("看看市")
|
console.log(window.parent.document.getElementById("cityCode"))
|
if (!window.parent.document.getElementById("cityCode")== null){
|
cityCode = window.parent.document.getElementById("cityCode").value;
|
}
|
table.queryParams = {'cityCode': window.parent.document.getElementById("cityCode").value,
|
'storeId': window.parent.document.getElementById("storeId").value}
|
table.height=600
|
TCoupon.table = table.init();
|
});
|