/**
|
* 初始化详情对话框
|
*/
|
var SysCouponRecordInfoDlg = {
|
sysCouponRecordInfoData : {},
|
validateFields: {
|
name: {
|
validators: {
|
notEmpty: {
|
message: '名称不能为空'
|
}
|
}
|
},
|
money: {
|
validators: {
|
notEmpty: {
|
message: '金额不能为空'
|
},
|
regexp: {
|
regexp: /^(([1-9]{1}\d*)|(0{1}))(\.\d{1,2})?$/,
|
message: '金额格式不正确'
|
}
|
}
|
}
|
}
|
};
|
|
/**
|
* 验证数据是否为空
|
*/
|
SysCouponRecordInfoDlg.validate = function () {
|
$('#sysCouponRecordInfoForm').data("bootstrapValidator").resetForm();
|
$('#sysCouponRecordInfoForm').bootstrapValidator('validate');
|
return $("#sysCouponRecordInfoForm").data('bootstrapValidator').isValid();
|
};
|
/**
|
* 清除数据
|
*/
|
SysCouponRecordInfoDlg.clearData = function() {
|
this.sysCouponRecordInfoData = {};
|
}
|
|
/**
|
* 设置对话框中的数据
|
*
|
* @param key 数据的名称
|
* @param val 数据的具体值
|
*/
|
SysCouponRecordInfoDlg.set = function(key, val) {
|
this.sysCouponRecordInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
|
return this;
|
}
|
|
/**
|
* 设置对话框中的数据
|
*
|
* @param key 数据的名称
|
* @param val 数据的具体值
|
*/
|
SysCouponRecordInfoDlg.get = function(key) {
|
return $("#" + key).val();
|
}
|
|
/**
|
* 关闭此对话框
|
*/
|
SysCouponRecordInfoDlg.close = function() {
|
parent.layer.close(window.parent.SysCouponRecord.layerIndex);
|
}
|
|
/**
|
* 收集数据
|
*/
|
SysCouponRecordInfoDlg.collectData = function() {
|
this
|
.set('id')
|
.set('money')
|
.set('fullMoney')
|
.set('insertTime')
|
.set('companyId')
|
.set('couponUseType')
|
.set('couponType')
|
.set('name')
|
.set('effective');
|
}
|
|
/**
|
* 提交添加
|
*/
|
SysCouponRecordInfoDlg.addSubmit = function() {
|
|
this.clearData();
|
this.collectData();
|
if(!this.validate()){
|
return ;
|
}
|
if ($("#name").val().length > 20){
|
Feng.info("名称不能超过20个字");
|
return;
|
}
|
if ( $("#money").val() > 9999 ){
|
Feng.info("金额最多不能超过4位数");
|
return;
|
}
|
if($("couponType").val()==2 && $("#fullMoney").val() > 9999){
|
Feng.info("金额最多不能超过4位数");
|
return;
|
}
|
var subArr=[];
|
$(".timeClass").each(function () {
|
subArr.push($(this).find("input[name*='code']").val())
|
});
|
if(subArr.length <= 0){
|
Feng.error("请选择适用城市");
|
return;
|
}
|
this.sysCouponRecordInfoData.citys = JSON.stringify(subArr);
|
//提交信息
|
var ajax = new $ax(Feng.ctxPath + "/sysCouponRecord/add", function(data){
|
Feng.success("添加成功!");
|
window.parent.SysCouponRecord.table.refresh();
|
SysCouponRecordInfoDlg.close();
|
},function(data){
|
Feng.error("添加失败!" + data.responseJSON.message + "!");
|
});
|
ajax.set(this.sysCouponRecordInfoData);
|
ajax.start();
|
}
|
|
|
//省改变
|
SysCouponRecordInfoDlg.provinceChange = function (e) {
|
var provinceCode=$(e).val();
|
var ajax = new $ax(Feng.ctxPath + "/tCompany/change", function(data){
|
if(data!=null){
|
var content='<option value="">选择市</option>';
|
$.each(data, function(k,v) {
|
content += "<option value='"+v.code+"'>"+v.name+"</option>";
|
});
|
$("#city").empty().append(content);
|
$("#area").empty().append('<option value="">选择区</option>');
|
}
|
});
|
ajax.set("code",provinceCode);
|
ajax.start();
|
}
|
//市改变
|
SysCouponRecordInfoDlg.cityChage = function (e) {
|
var cityCode=$(e).val();
|
var ajax = new $ax(Feng.ctxPath + "/tCompany/change", function(data){
|
if(data!=null){
|
var content='<option value="">选择区</option>';
|
$.each(data, function(k,v) {
|
content += "<option value='"+v.code+"'>"+v.name+"</option>";
|
});
|
$("#area").empty().append(content);
|
}
|
});
|
ajax.set("code",cityCode);
|
ajax.start();
|
}
|
//添加区域
|
SysCouponRecordInfoDlg.addScope = function () {
|
var subCode = '';
|
var area = $("#area").val();
|
if(null == area || '' == area){
|
var city = $("#city").val();
|
if(null == city || '' == city){
|
var province = $("#province").val();
|
subCode = province;
|
}else{
|
subCode = city;
|
}
|
}else{
|
subCode = area;
|
}
|
|
if ("" == subCode){
|
Feng.info("请选择适用城市");
|
return;
|
}
|
var subArr=[];
|
$(".timeClass").each(function () {
|
subArr.push($(this).find("input[name*='code']").val())
|
});
|
for(var i=0;i<subArr.length;i++){
|
var code = subArr[i];
|
if (subCode == code) {
|
Feng.info("适用城市已存在,请重新选择");
|
return;
|
}
|
}
|
var provinceValue = $("#province option:selected").text();
|
var cityValue = "";
|
if (city != ""){
|
cityValue = $("#city option:selected").text();
|
}
|
var areaValue = "";
|
if (area != ""){
|
areaValue = $("#area option:selected").text();
|
}
|
|
var str = '<tr class="timeClass"><td>' +
|
'<input type="hidden" id="code" name="code" value="'+subCode+'">'+provinceValue+cityValue+areaValue+'</td>' +
|
'<td><button onclick="deleteSub(this)">移除</button></td></tr>';
|
$("#conn").append(str);
|
}
|
|
function deleteSub(e) {
|
$(e).parent().parent().remove();
|
}
|
|
/**
|
* 提交修改
|
*/
|
SysCouponRecordInfoDlg.editSubmit = function() {
|
|
this.clearData();
|
this.collectData();
|
|
var subArr=[];
|
$(".timeClass").each(function () {
|
subArr.push($(this).find("input[name*='code']").val())
|
});
|
if(subArr.length <= 0){
|
Feng.error("请选择适用城市");
|
return;
|
}
|
this.sysCouponRecordInfoData.citys = JSON.stringify(subArr);
|
//提交信息
|
var ajax = new $ax(Feng.ctxPath + "/sysCouponRecord/update", function(data){
|
Feng.success("修改成功!");
|
window.parent.SysCouponRecord.table.refresh();
|
SysCouponRecordInfoDlg.close();
|
},function(data){
|
Feng.error("修改失败!" + data.responseJSON.message + "!");
|
});
|
ajax.set(this.sysCouponRecordInfoData);
|
ajax.start();
|
}
|
|
$(function() {
|
Feng.initValidator("sysCouponRecordInfoForm", SysCouponRecordInfoDlg.validateFields);
|
});
|