/**
|
* 初始化车辆品牌管理详情对话框
|
*/
|
|
var ids = null;
|
var tdArrList = new Array();
|
var tdUserList = new Array();
|
|
var userList = [];
|
var driverList = [];
|
|
var couponData = [];
|
|
var userIds = null;
|
var driverIds = null;
|
|
var MerchantActivityGiveInfoDlg = {
|
merchantActivityInfoData: {},
|
validateFields: {
|
name: {
|
validators: {
|
notEmpty: {
|
message: '活动标题不能为空'
|
}
|
}
|
},
|
}
|
};
|
|
|
/**
|
* 验证数据是否为空
|
*/
|
MerchantActivityGiveInfoDlg.validate = function () {
|
$('#merchantActivityForm').data("bootstrapValidator").resetForm();
|
$('#merchantActivityForm').bootstrapValidator('validate');
|
return $("#merchantActivityForm").data('bootstrapValidator').isValid();
|
};
|
|
/**
|
* 清除数据
|
*/
|
MerchantActivityGiveInfoDlg.clearData = function () {
|
this.merchantActivityInfoData = {};
|
}
|
|
/**
|
* 设置对话框中的数据
|
*
|
* @param key 数据的名称
|
* @param val 数据的具体值
|
*/
|
MerchantActivityGiveInfoDlg.set = function (key, val) {
|
this.merchantActivityInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
|
return this;
|
}
|
|
/**
|
* 设置对话框中的数据
|
*
|
* @param key 数据的名称
|
* @param val 数据的具体值
|
*/
|
MerchantActivityGiveInfoDlg.get = function (key) {
|
return $("#" + key).val();
|
}
|
|
/**
|
* 关闭此对话框
|
*/
|
MerchantActivityGiveInfoDlg.close = function () {
|
|
if (window.parent.MerchantActivityGive != null) {
|
parent.layer.close(window.parent.MerchantActivityGive.layerIndex);
|
} else
|
parent.layer.close(window.parent.MerchantActivityExamine.layerIndex);
|
|
}
|
|
/**
|
* 收集数据
|
*/
|
MerchantActivityGiveInfoDlg.collectData = function () {
|
this
|
.set('id')
|
.set('name')
|
.set('merchantId')
|
.set('companyType')
|
.set('companyId')
|
.set('activityType')
|
.set('name')
|
.set('orderType')
|
.set('type')
|
.set('orderAmountFull')
|
.set('orderNumber')
|
.set('effectiveDays')
|
.set('auditStatus')
|
.set('auditNote')
|
.set('auditUserId')
|
.set('auditTime')
|
.set('status')
|
.set('state')
|
.set('state')
|
.set('merchantActivitySlaveList')
|
.set('createTime');
|
}
|
|
/**
|
* 提交添加
|
*/
|
MerchantActivityGiveInfoDlg.addSubmit = function () {
|
|
this.clearData();
|
this.collectData();
|
|
if (!this.validate()) {
|
return;
|
}
|
|
var merchantId = $("#merchantId").valueOf();
|
if ("" == merchantId) {
|
Feng.info("请选择商家");
|
return;
|
}
|
|
var effectiveDays = $("#effectiveDays").val();
|
if (effectiveDays == null || effectiveDays == "") {
|
Feng.info("请输入活动有效天数");
|
return;
|
}
|
|
if (!priceParameter()) {
|
return;
|
}
|
if (!verificationUser()) {
|
return;
|
}
|
|
var merchantIds = "";
|
var merchantIdAll = $("#merchantIdAll").val();
|
if (merchantIdAll == null) {
|
Feng.error("请选择商家");
|
return
|
}
|
for (var i = 0; i < merchantIdAll.length; i++) {
|
if (i > 0) {
|
merchantIds += ",";
|
}
|
merchantIds += merchantIdAll[i]
|
}
|
this.set("merchantIds", merchantIds);
|
|
|
this.set("merchantActivitySlaveList", tdArrList);
|
this.set("userList", tdUserList);
|
|
var data = this.merchantActivityInfoData;
|
|
$.ajax({
|
url: Feng.ctxPath + "/merchantActivityGive/add",
|
type: "post",
|
contentType: "application/json;charset=utf-8",
|
data: JSON.stringify(data),
|
success: function (json) {
|
if (json.code == 200) {
|
Feng.success("添加成功!");
|
window.parent.MerchantActivityGive.table.refresh();
|
MerchantActivityGiveInfoDlg.close();
|
} else {
|
Feng.error("修改失败!" + json.message + "!");
|
}
|
}
|
});
|
}
|
|
/**
|
* 提交修改
|
*/
|
MerchantActivityGiveInfoDlg.editSubmit = function () {
|
|
this.clearData();
|
this.collectData();
|
if (!this.validate()) {
|
return;
|
}
|
var merchantId = $("#merchantId").valueOf();
|
if ("" == merchantId) {
|
Feng.info("请选择商家");
|
return;
|
}
|
MerchantActivityGiveInfoDlg.set("content", MerchantActivityGiveInfoDlg.editor.getContent());
|
//提交信息
|
|
var ajax = new $ax(Feng.ctxPath + "/merchantActivity/update", function (data) {
|
Feng.success("修改成功!");
|
window.parent.MerchantActivity.table.refresh();
|
MerchantActivityGiveInfoDlg.close();
|
}, function (data) {
|
Feng.error("修改失败!" + data.responseJSON.message + "!");
|
});
|
ajax.set(this.merchantActivityInfoData);
|
ajax.start();
|
}
|
|
|
MerchantActivityGiveInfoDlg.choiceCouponAll = function (val, type) {
|
couponData = [];
|
|
ids = "";
|
for (var i = 0; i < val.length; i++) {
|
if (i > 0) {
|
ids += ",";
|
}
|
ids += val[i].id;
|
}
|
var str = "";
|
couponData = val;
|
|
if (type == 1) {
|
for (var i in val) {
|
str += '<tr><td style="display: none">' + val[i].id + '</td>' +
|
'<td style="display: none">' + val[i].merchantId + '</td>' +
|
'<td>' + val[i].merchantName + '</td>' +
|
'<td>' + val[i].name + '</td>' +
|
'<td>' + "满" + val[i].fullAmount + "减" + val[i].discount + "券" + '</td>' +
|
'</tr>';
|
}
|
$("#table").html("<th>所属商家</th><th>商家券名称</th><th>优惠金额</th>");
|
$("#tableList").html(str);
|
}
|
if (type == 2) {
|
for (var i in val) {
|
str += '<tr><td style="display: none">' + val[i].id + '</td>' +
|
'<td style="display: none">' + val[i].merchantId + '</td>' +
|
'<td>' + val[i].merchantName + '</td>' +
|
'<td>' + val[i].name + '</td>' +
|
'</tr>';
|
}
|
$("#table").html("<th>所属商家</th><th>商家券名称</th>");
|
$("#tableList").html(str);
|
}
|
};
|
|
/**
|
* 选择商家重置商家券数据
|
*/
|
function merchantChoice() {
|
var merchantIds = [];
|
var merchantIdAll = $("#merchantIdAll").val();
|
for (var i = 0; i < merchantIdAll.length; i++) {
|
merchantIds.push(merchantIdAll[i])
|
}
|
var dataList = [];
|
for (var i = 0; i < merchantIds.length; i++) {
|
for (var j = 0; j < couponData.length; j++) {
|
if (merchantIds[i] == couponData[j].merchantId) {
|
dataList.push(couponData[j]);
|
}
|
}
|
}
|
couponData = dataList;
|
if (dataList.length > 0) {
|
MerchantActivityGiveInfoDlg.choiceCouponAll(dataList, dataList[0].type)
|
}
|
}
|
|
/**
|
* 用户选择显示
|
* @param val
|
* @param type
|
*/
|
MerchantActivityGiveInfoDlg.choiceUserAll = function (val, type) {
|
var allList = [];
|
var idsAll = "";
|
|
for (var i = 0; i < val.length; i++) {
|
if (i > 0) {
|
idsAll += ",";
|
}
|
idsAll += val[i].id;
|
}
|
if (type == 1) {
|
userIds = idsAll;
|
userList = val;
|
}
|
if (type == 2) {
|
driverIds = idsAll;
|
driverList = val;
|
}
|
for (var i in userList) {
|
allList.push(userList[i]);
|
}
|
for (var i in driverList) {
|
allList.push(driverList[i]);
|
}
|
|
var str = "";
|
for (var i in allList) {
|
str += '<tr><td style="display: none">' + allList[i].id + '</td>' +
|
'<td style="display: none">' + allList[i].type + '</td>' +
|
'<td>' + allList[i].nickName + '</td>' +
|
'<td>' + allList[i].phone + '</td>' +
|
'<td>' + allList[i].companyName + '</td>' +
|
'<td> <a href="#" onclick="MerchantActivityGiveInfoDlg.deleteThis(this)">删除</a></td>' +
|
'</tr>';
|
}
|
$("#tableUser").html("<th>用户昵称</th><th>手机号</th><th>注册地所属分公司</th><th>操作</th>");
|
$("#tableUserList").html(str);
|
};
|
|
|
/**
|
* 商家卷选择
|
* @param type
|
*/
|
MerchantActivityGiveInfoDlg.choiceCoupon = function (type) {
|
var merchantIds = "";
|
|
if (ids == null || ids == "undefined") {
|
ids = 0;
|
}
|
var merchantIdAll = $("#merchantIdAll").val();
|
if (merchantIdAll == null) {
|
Feng.error("请选择商家");
|
return
|
}
|
|
for (var i = 0; i < merchantIdAll.length; i++) {
|
if (i > 0) {
|
merchantIds += ",";
|
}
|
merchantIds += merchantIdAll[i]
|
}
|
var title = "商家券选择";
|
if (type == 2) {
|
title = "商品券选择";
|
}
|
var index = layer.open({
|
type: 2,
|
title: title,
|
fix: false, //不固定
|
area: ['80%', '80%'], //宽高
|
maxmin: true,
|
content: Feng.ctxPath + '/merchantActivityGive/choiceCoupon?ids=' + ids + "&type=" + type + "&merchantIds=" + merchantIds
|
});
|
this.layerIndex = index;
|
};
|
|
|
MerchantActivityGiveInfoDlg.choiceUser = function (type) {
|
|
var id = null;
|
if (type == 1) {
|
if (userIds == null || userIds == "undefined") {
|
id = 0;
|
} else
|
id = userIds;
|
}
|
if (type == 2) {
|
if (driverIds == null || driverIds == "undefined") {
|
id = 0;
|
} else
|
id = driverIds;
|
}
|
var index = layer.open({
|
type: 2,
|
title: '用户选择',
|
fix: false, //不固定
|
area: ['80%', '80%'], //宽高
|
maxmin: true,
|
content: Feng.ctxPath + '/merchantActivityGive/choiceUser?ids=' + id + "&type=" + type
|
});
|
this.layerIndex = index;
|
}
|
|
|
/*删除用户*/
|
MerchantActivityGiveInfoDlg.deleteThis = function (e) {
|
$(e).parent().parent().remove();
|
|
var trList = $(e).parent().parent().children("td");
|
var id = trList.eq(0).text();
|
var type = trList.eq(1).text();
|
|
if (type == 1) {
|
var idsAll = "";
|
var ids = userIds.split(",");
|
for (var i = 0; i < ids.length; i++) {
|
if (id == ids[i]) {
|
ids.splice(i, 1)
|
}
|
}
|
for (var i = 0; i < ids.length; i++) {
|
if (i > 0) {
|
idsAll += ",";
|
}
|
idsAll += ids[i];
|
}
|
userIds = idsAll;
|
}
|
if (type == 2) {
|
var idsAll = "";
|
var ids = driverIds.split(",");
|
for (var i = 0; i < ids.length; i++) {
|
if (id == ids[i]) {
|
ids.splice(i, 1)
|
}
|
}
|
for (var i = 0; i < ids.length; i++) {
|
if (i > 0) {
|
idsAll += ",";
|
}
|
idsAll += ids[i];
|
}
|
driverIds = idsAll;
|
}
|
}
|
|
function typeChoice() {
|
|
var vs = $("#type").val();
|
|
if (vs == 1) {
|
|
couponData=[];
|
$("#volume1").show();
|
$("#volume2").hide();
|
$(".volume2").hide();
|
|
ids = null;
|
$("#table").html("<th>所属商家</th><th>商家券名称</th><th>优惠金额</th>");
|
$("#tableList").html("");
|
}
|
|
if (vs == 2) {
|
couponData=[];
|
|
$("#volume2").show();
|
$(".volume2").show();
|
$("#volume1").hide();
|
|
ids = null;
|
$("#table").html("<th>所属商家</th><th>商家券名称</th>");
|
$("#tableList").html("");
|
}
|
}
|
|
/**
|
* 验证商家券
|
* @returns {boolean}
|
*/
|
function priceParameter() {
|
tdArrList = [];
|
var trList = $("#tableList").children("tr");
|
if (trList.length < 1) {
|
Feng.error("请选择商家券");
|
return false;
|
}
|
|
for (var i = 0; i < trList.length; i++) {
|
var tdArr = new Array();
|
var tdArr = trList.eq(i).find("td");
|
|
var id = tdArr.eq(0).text();//id
|
var merchantId = tdArr.eq(1).text();//merchantId
|
var data = {
|
"merchantCouponId": id,//商家卷Id
|
"merchantId": merchantId,//商家Id
|
};
|
tdArrList.push(data)
|
}
|
return true;
|
}
|
|
/**
|
* 验证用户信息
|
* @returns {boolean}
|
*/
|
function verificationUser() {
|
tdUserList = [];
|
|
var trList = $("#tableUserList").children("tr");
|
if (trList.length < 1) {
|
Feng.error("请选择赠送用户");
|
return false;
|
}
|
for (var i = 0; i < trList.length; i++) {
|
var tdArr = new Array();
|
var tdArr = trList.eq(i).find("td");
|
|
var id = tdArr.eq(0).text();//用户id
|
var type = tdArr.eq(1).text();//用户类型
|
var data = {
|
"userId": id,//商家卷Id
|
"type": type,//商家卷Id
|
};
|
tdUserList.push(data)
|
}
|
return true;
|
}
|
|
|
$(function () {
|
|
Feng.initValidator("merchantActivityForm", MerchantActivityGiveInfoDlg.validateFields);
|
|
$("#merchantId").val($("#merchantId_").val())
|
|
$("#orderType").val($("#asList").val())
|
|
});
|