/**
|
* 初始化详情对话框
|
*/
|
var language =$("#language").val()
|
var SysCouponActivityInfoDlg = {
|
sysCouponActivityInfoData : {},
|
validateFields: {
|
name: {
|
validators: {
|
notEmpty: {
|
message: language==1?'活动标题不能为空':(language==2?'The activity title cannot be empty':'Judul aktivitas tidak dapat kosong')
|
}
|
}
|
},
|
effective: {
|
validators: {
|
notEmpty: {
|
message: language==1?'有效天数不能为空':(language==2?'The number of valid days cannot be empty':'Jumlah hari yang valid tidak dapat kosong')
|
},
|
regexp: {
|
regexp: /^[1-9]\d*$/,
|
message: language==1?'有效天数格式不正确':(language==2?'The valid days format is incorrect':'Format hari yang valid tidak benar')
|
}
|
}
|
},
|
number: {
|
validators: {
|
notEmpty: {
|
message: language==1?'张数不能为空':(language==2?'The tensor cannot be empty':'Tensor tidak dapat kosong')
|
},
|
regexp: {
|
regexp: /^[1-9]\d*$/,
|
message: language==1?'张数格式不正确':(language==2?'The number format is incorrect':'Format nomor tidak benar')
|
}
|
}
|
}
|
}
|
};
|
/**
|
* 验证数据是否为空
|
*/
|
SysCouponActivityInfoDlg.validate = function () {
|
$('#sysCouponActivityInfoForm').data("bootstrapValidator").resetForm();
|
$('#sysCouponActivityInfoForm').bootstrapValidator('validate');
|
return $("#sysCouponActivityInfoForm").data('bootstrapValidator').isValid();
|
};
|
/**
|
* 清除数据
|
*/
|
SysCouponActivityInfoDlg.clearData = function() {
|
this.sysCouponActivityInfoData = {};
|
}
|
|
/**
|
* 设置对话框中的数据
|
*
|
* @param key 数据的名称
|
* @param val 数据的具体值
|
*/
|
SysCouponActivityInfoDlg.set = function(key, val) {
|
this.sysCouponActivityInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
|
return this;
|
}
|
|
/**
|
* 设置对话框中的数据
|
*
|
* @param key 数据的名称
|
* @param val 数据的具体值
|
*/
|
SysCouponActivityInfoDlg.get = function(key) {
|
return $("#" + key).val();
|
}
|
|
/**
|
* 关闭此对话框
|
*/
|
SysCouponActivityInfoDlg.close = function() {
|
parent.layer.close(window.parent.SysCouponActivity.layerIndex);
|
}
|
|
/**
|
* 收集数据
|
*/
|
SysCouponActivityInfoDlg.collectData = function() {
|
this
|
.set('id')
|
.set('money')
|
.set('fullMoney')
|
.set('companyId')
|
.set('name')
|
.set('effective')
|
.set('sendType')
|
.set('number')
|
.set('sendUserId').set('allNum');
|
}
|
|
/**
|
* 提交添加
|
*/
|
SysCouponActivityInfoDlg.addSubmit = function() {
|
|
this.clearData();
|
this.collectData();
|
if(!this.validate()){
|
return ;
|
}
|
var activityId = $("#activityId").val();
|
if($.trim(activityId)==""){
|
if(language==1){
|
Feng.error("请选择优惠券!");
|
}else if(language==2){
|
Feng.error("Please select the coupon!");
|
}else {
|
Feng.error("Silakan pilih kupon!");
|
}
|
|
return;
|
}
|
|
var allNum = $("#allNum").val();
|
if($.trim(allNum)==""){
|
if(language==1){
|
Feng.error("请填写优惠券总数!");
|
}else if(language==2){
|
Feng.error("Please fill in the total number of coupons!");
|
}else {
|
Feng.error("Silakan isi jumlah total kupon!");
|
}
|
return;
|
}
|
var sendType = $("input[name='sendType']:checked").val();
|
var subArr=[];
|
$(".timeClass").each(function () {
|
subArr.push({
|
//companyName,nickName,phone
|
userId:$(this).find("input[name*='userId']").val(),
|
companyName:$(this).find("input[name*='companyName']").val(),
|
nickName:$(this).find("input[name*='nickName']").val(),
|
phone:$(this).find("input[name*='phone']").val(),
|
})
|
});
|
if(sendType==2 && subArr.length <= 0){
|
if(language==1){
|
Feng.error("请选择用户");
|
}else if(language==2){
|
Feng.error("Please select User");
|
}else {
|
Feng.error("Silakan pilih Pengguna");
|
}
|
|
return;
|
}
|
//提交信息
|
var ajax = new $ax(Feng.ctxPath + "/sysCouponActivity/add", function(data){
|
Feng.success("添加成功!");
|
window.parent.SysCouponActivity.table.refresh();
|
SysCouponActivityInfoDlg.close();
|
},function(data){
|
Feng.error("添加失败!" + data.responseJSON.message + "!");
|
});
|
ajax.set(this.sysCouponActivityInfoData);
|
ajax.set("activityId",activityId);
|
ajax.set("sendUserId",JSON.stringify(subArr));
|
ajax.set("sendType",sendType);
|
ajax.set("allNum",allNum);
|
ajax.start();
|
}
|
|
/**
|
* 提交修改
|
*/
|
SysCouponActivityInfoDlg.editSubmit = function() {
|
|
this.clearData();
|
this.collectData();
|
|
if(!this.validate()){
|
return ;
|
}
|
var activityId = $("#activityId").val();
|
if($.trim(activityId)==""){
|
if(language==1){
|
Feng.error("请选择优惠券!");
|
}else if(language==2){
|
Feng.error("Please select the coupon!");
|
}else {
|
Feng.error("Silakan pilih kupon!");
|
}
|
return;
|
}
|
var sendType = $("input[name='sendType']:checked").val();
|
var subArr=[];
|
$(".timeClass").each(function () {
|
subArr.push({
|
//companyName,nickName,phone
|
userId:$(this).find("input[name*='userId']").val(),
|
companyName:$(this).find("input[name*='companyName']").val(),
|
nickName:$(this).find("input[name*='nickName']").val(),
|
phone:$(this).find("input[name*='phone']").val(),
|
})
|
});
|
if(sendType==2 && subArr.length <= 0){
|
if(language==1){
|
Feng.error("请选择用户");
|
}else if(language==2){
|
Feng.error("Please select User");
|
}else {
|
Feng.error("Silakan pilih Pengguna");
|
}
|
return;
|
}
|
//提交信息
|
var ajax = new $ax(Feng.ctxPath + "/sysCouponActivity/update", function(data){
|
Feng.success("添加成功!");
|
window.parent.SysCouponActivity.table.refresh();
|
SysCouponActivityInfoDlg.close();
|
},function(data){
|
Feng.error("添加失败!" + data.responseJSON.message + "!");
|
});
|
ajax.set(this.sysCouponActivityInfoData);
|
ajax.set("activityId",activityId);
|
ajax.set("sendUserId",JSON.stringify(subArr));
|
ajax.set("sendType",sendType);
|
ajax.start();
|
}
|
/**
|
* 立即处理
|
*/
|
SysCouponActivityInfoDlg.immediately = function(){
|
|
this.clearData();
|
this.collectData();
|
|
if(!this.validate()){
|
return ;
|
}
|
var remark = $("#remark").val();
|
if (remark.length > 250){
|
if(language==1){
|
Feng.info("备注不能超过250个字");
|
}else if(language==2){
|
Feng.info("Remarks should not exceed 250 words");
|
}else {
|
Feng.info("Perhatian seharusnya tidak melebihi 250 kata");
|
}
|
return;
|
}
|
var state = $("input[name='state']:checked").val();
|
//提交信息
|
var ajax = new $ax(Feng.ctxPath + "/sysCouponActivity/immediately", function(data){
|
if(language==1){
|
Feng.success("处理成功!");
|
}else if(language==2){
|
Feng.success("Deal with success!");
|
}else {
|
Feng.success("Menghadapi sukses!");
|
}
|
window.parent.SysCouponActivity.table.refresh();
|
SysCouponActivityInfoDlg.close();
|
},function(data){
|
if(language==1){
|
Feng.error("处理失败!" + data.responseJSON.message + "!");
|
}else if(language==2){
|
Feng.error("Fail!" + data.responseJSON.message + "!");
|
}else {
|
Feng.error("Gagal!" + data.responseJSON.message + "!");
|
}
|
|
});
|
ajax.set("id",$("#id").val());
|
ajax.set("state",state);
|
ajax.set("remark",$("#remark").val());
|
ajax.start();
|
}
|
|
/**
|
* 跳转到选择优惠券页面
|
*/
|
SysCouponActivityInfoDlg.toSelectCouponOpt = function () {
|
var index = layer.open({
|
type: 2,
|
title: language==1?'选择优惠券':(language==2?'Choose Coupons':'Pilih Coupons'),
|
area: ['90%', '80%'], //宽高
|
fix: false, //不固定
|
maxmin: true,
|
content: Feng.ctxPath + '/sysCouponActivity/sysCouponRecord'
|
});
|
this.layerIndex = index;
|
}
|
|
SysCouponActivityInfoDlg.toSelectUserOpt = function () {
|
var index = layer.open({
|
type: 2,
|
title: language==1?'选择用户':(language==2?'Select a user':'Pilih pengguna'),
|
area: ['90%', '80%'], //宽高
|
fix: false, //不固定
|
maxmin: true,
|
content: Feng.ctxPath + '/sysCouponActivity/user'
|
});
|
this.layerIndex = index;
|
}
|
/**
|
* 选择优惠券后数据回显
|
* @param id
|
* @param couponUseType
|
* @param couponType
|
* @param money
|
*/
|
SysCouponActivityInfoDlg.selectCouponOpt=function(id,couponUseType,couponType,money){
|
if(language==1){
|
$("#couponUseType").val(couponUseType==0?"":couponUseType==1?"摩托车券":couponUseType==4?"":"");
|
$("#couponType").val(couponType==1?"抵扣":"满减");
|
$("#money").val(money);
|
$("#activityId").val(id);
|
}else if(language==2){
|
$("#couponUseType").val(couponUseType==0?"":couponUseType==1?"Motorcycle coupon":couponUseType==4?"":"");
|
$("#couponType").val(couponType==1?"deduction":"Full reduction");
|
$("#money").val(money);
|
$("#activityId").val(id);
|
}else {
|
$("#couponUseType").val(couponUseType==0?"":couponUseType==1?"Kupon motor":couponUseType==4?"":"");
|
$("#couponType").val(couponType==1?"deduksi":"Pengurangan penuh");
|
$("#money").val(money);
|
$("#activityId").val(id);
|
}
|
|
}
|
/**
|
* 选择用户后数据回显
|
* @param id
|
* @param companyName
|
* @param nickName
|
* @param phone
|
*/
|
SysCouponActivityInfoDlg.selecUserOpt=function(id,companyName,nickName,phone){
|
//获取所有的值
|
var subArr=[];
|
$(".timeClass").each(function () {
|
subArr.push({
|
userId:$(this).find("input[name*='userId']").val(),
|
})
|
});
|
for(var i=0;i<subArr.length;i++){
|
var userId = subArr[i].userId;
|
if (userId == id) {
|
if(language==1){
|
Feng.info("用户已选择,请重新选择");
|
}else if(language==2){
|
Feng.info("The user has selected, please select again");
|
}else {
|
Feng.info("Pengguna telah memilih, silakan memilih lagi");
|
}
|
|
return;
|
}
|
}
|
var str = '<tr class="timeClass">' +
|
'<td><input type="hidden" id="userId" name="userId" value="'+id+'"><input type="hidden" id="nickName" name="nickName" value="'+nickName+'">' + nickName + '</td>' +
|
'<td><input type="hidden" id="phone" name="phone" value="'+phone+'">' + phone + '</td>' +
|
'<td><input type="hidden" id="companyName" name="companyName" value="'+companyName+'">' + companyName + '</td><td><button onclick="deleteSub(this)">Remove</button></td></tr>';
|
$("#coun").append(str);
|
}
|
function deleteSub(e) {
|
$(e).parent().parent().remove();
|
}
|
$(function() {
|
Feng.initValidator("sysCouponActivityInfoForm", SysCouponActivityInfoDlg.validateFields);
|
});
|