/**
|
* 初始化详情对话框
|
*/
|
var couponInfoDlg = {
|
couponInfoData: {},
|
goodsPicArray: [], //商品图片数组
|
goodsCover: '', //商品封面图
|
storeIds: [],
|
};
|
|
/**
|
* 清除数据
|
*/
|
couponInfoDlg.clearData = function () {
|
this.couponInfoData = {};
|
}
|
|
/**
|
* 设置对话框中的数据
|
*
|
* @param key 数据的名称
|
* @param val 数据的具体值
|
*/
|
couponInfoDlg.set = function (key, val) {
|
this.couponInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
|
return this;
|
}
|
|
/**
|
* 设置对话框中的数据
|
*
|
* @param key 数据的名称
|
* @param val 数据的具体值
|
*/
|
couponInfoDlg.get = function (key) {
|
return $("#" + key).val();
|
}
|
|
/**
|
* 关闭此对话框
|
*/
|
couponInfoDlg.close = function () {
|
parent.layer.close(window.parent.TCoupon.layerIndex);
|
}
|
|
|
/**
|
* 兑换方式1
|
*/
|
function exchangeMethod1() {
|
$("#needAmount").hide();
|
$("#needIntegral").show();
|
$('#requiredPoints').val('');
|
$('#requiredCash').val('');
|
}
|
|
/**
|
* 兑换方式2
|
*/
|
function exchangeMethod2() {
|
$("#needAmount").show();
|
$("#needIntegral").show();
|
$('#requiredPoints').val('');
|
$('#requiredCash').val('');
|
}
|
|
/**
|
* 兑换方式3
|
*/
|
function exchangeMethod3() {
|
$("#needAmount").show();
|
$("#needIntegral").hide();
|
$('#requiredPoints').val('');
|
$('#requiredCash').val('');
|
}
|
|
/**
|
* 全国通用
|
*/
|
function scopeOfApplication1() {
|
$("#storeSelect").hide();
|
$("#citySelect").hide();
|
}
|
/**
|
* 指定城市
|
*/
|
function scopeOfApplication2() {
|
$("#storeSelect").hide();
|
$("#citySelect").show();
|
}
|
/**
|
* 指定门店
|
*/
|
function scopeOfApplication3() {
|
$("#storeSelect").show();
|
$("#citySelect").hide();
|
}
|
|
/**
|
* 满减券
|
*/
|
function radio1() {
|
$("#conditionalAmount").removeAttr("disabled");
|
$("#deductionAmount").removeAttr("disabled");
|
|
$("#voucherAmount").val('')
|
$("#voucherAmount").attr('disabled', 'disabled');
|
|
$("#experienceName").val('')
|
$("#experienceName").attr('disabled', 'disabled');
|
}
|
|
/**
|
* 代金券
|
*/
|
function radio2() {
|
$("#voucherAmount").removeAttr("disabled");
|
|
$("#conditionalAmount").val('')
|
$("#deductionAmount").val('')
|
$("#deductionAmount").attr('disabled', 'disabled');
|
$("#conditionalAmount").attr('disabled', 'disabled');
|
|
$("#experienceName").val('')
|
$("#experienceName").attr('disabled', 'disabled');
|
|
}
|
|
/**
|
* 体验券
|
*/
|
function radio3() {
|
$("#experienceName").removeAttr("disabled");
|
|
$("#conditionalAmount").val('')
|
$("#deductionAmount").val('')
|
$("#deductionAmount").attr('disabled', 'disabled');
|
$("#conditionalAmount").attr('disabled', 'disabled');
|
|
$("#voucherAmount").val('')
|
$("#voucherAmount").attr('disabled', 'disabled');
|
|
}
|
|
|
function changeCity(n){
|
|
var provinceSelect = null;
|
if (n === undefined || n === null || n === ''){
|
provinceSelect = document.getElementById("provinceData");
|
}else {
|
provinceSelect = document.getElementById("provinceData"+n);
|
}
|
|
var citySelect = null;
|
if (n === undefined || n === null || n === ''){
|
citySelect = document.getElementById("cityData");
|
}else {
|
citySelect = document.getElementById("cityData"+n);
|
}
|
|
var selectedProvince = provinceSelect.value;
|
// 清空城市下拉框
|
citySelect.innerHTML = '<option value="">请选择</option>';
|
if (selectedProvince === "") {
|
return;
|
}
|
var ajax = new $ax(Feng.ctxPath + "/tCouponManage/getCity", function(data){
|
data.forEach(province => {
|
var option = document.createElement("option");
|
option.value = province.id; // 根据你的数据结构确定省份的id字段
|
option.text = province.name; // 根据你的数据结构确定省份的name字段
|
citySelect.appendChild(option);
|
});
|
},function(data){
|
console.log('data:',data)
|
Feng.error("获取失败!" + data.responseJSON.message + "!");
|
});
|
ajax.set('province',selectedProvince);
|
ajax.start();
|
}
|
|
function getProvince(n){
|
var ajax = new $ax(Feng.ctxPath + "/tCouponManage/getProvince", function(data){
|
var provinceSelect = null;
|
if (n === undefined || n === null || ''){
|
provinceSelect = document.getElementById("provinceData");
|
}else {
|
provinceSelect = document.getElementById("provinceData"+n);
|
}
|
data.forEach(province => {
|
var option = document.createElement("option");
|
option.value = province.id; // 根据你的数据结构确定省份的id字段
|
option.text = province.name; // 根据你的数据结构确定省份的name字段
|
provinceSelect.appendChild(option);
|
});
|
},function(data){
|
Feng.error("下拉失败!" + data.responseJSON.message + "!");
|
});
|
ajax.start();
|
}
|
|
function storeList(){
|
var index = layer.open({
|
type: 2,
|
title: '门店列表',
|
area: ['80%', '80%'], //宽高
|
fix: false, //不固定
|
maxmin: true,
|
content: Feng.ctxPath + '/tCouponManage/storeList'
|
});
|
this.layerIndex = index;
|
}
|
|
|
var num = 0;
|
couponInfoDlg.addBranch = function () {
|
num=num+1;
|
var a= "";
|
a = "<div style=\'margin-left: 25%\' class=\"col-sm-9 control-label\">\n" +
|
" <select class=\"col-sm-1\" id=\'provinceData"+num+"\' style=\"margin-top: 1%;width: 25%\" onchange=\'changeCity("+num+")\'>\n" +
|
" <option value=\"\">请选择</option>\n" +
|
" </select>\n" +
|
" <label class=\"col-sm-1\" style=\"width: 9%;margin-top: 7px\">省</label>\n" +
|
" <select class=\"col-sm-1\" style=\"margin-top: 1%;width: 25%\" id=\'cityData"+num+"\'>\n" +
|
" <option value=\"\">请选择</option>\n" +
|
" </select>\n" +
|
" <label class=\"col-sm-1\" style=\"width: 7%;margin-top: 7px\">市</label>\n" +
|
" <label name=\"addBranch\" class=\"col-sm-1\" onclick=\"couponInfoDlg.delete(this)\" style=\"border: 0px;cursor: pointer;margin-top: 1%\"><i class=\"fa fa-trash\"></i></label>"+
|
" </div>";
|
$("#cityDemo").append($(a));
|
getProvince(num);
|
}
|
|
|
|
couponInfoDlg.delete = function (o) {
|
$(o).parent("div").remove()
|
}
|
|
/**
|
* 提交
|
*/
|
couponInfoDlg.addSubmit = function () {
|
|
var cityIds = [];
|
// 优惠券名称
|
var couponName = $('#name').val();
|
// 优惠券类型
|
var prescription = $('#prescription').val();
|
// 说明
|
var illustrate = $('#illustrate').val();
|
// 发放方式
|
var distributionMethod = $('#distributionMethod').val();
|
// 所需积分
|
var requiredPoints = $('#requiredPoints').val();
|
// 用户人群
|
let userGroup = $(':radio[name="userGroup"]:checked').val();
|
|
// 发放数量
|
var quantityIssued = $('#quantityIssued').val();
|
// 限领数量
|
var pickUpQuantity = $('#pickUpQuantity').val();
|
// 有效期
|
var periodOfValidity = $('#periodOfValidity').val();
|
|
let exchangeMethod = $(':radio[name="exchangeMethod"]:checked').val();
|
|
var requiredCash = $('#requiredCash').val();
|
|
var company = $('#company').val();
|
if (company === '2'){
|
var myselect=document.getElementById('cityData');
|
var seCity = myselect.options[myselect.selectedIndex].value;
|
if (seCity === null || seCity === undefined || seCity === ''){
|
return Feng.error('请选中一个省市');
|
}
|
cityIds.push(seCity);
|
if (this.num > 0){
|
for (let i = 1; i <= num; i++) {
|
var insSelect=document.getElementById('cityData'+i);
|
var inData = insSelect.options[insSelect.selectedIndex].value;
|
if (inData !== undefined || inData !== null || inData !== ''){
|
cityIds.push(inData);
|
}
|
}
|
}
|
}
|
|
if (company === '3'){
|
|
}
|
|
console.log('11111111')
|
|
//提交信息
|
var ajax = new $ax(Feng.ctxPath + "/tCouponManage/commitData", function (data) {
|
Feng.success("添加成功!");
|
window.parent.TCoupon.table.refresh();
|
couponInfoDlg.close();
|
}, function (data) {
|
Feng.error("添加失败!" + data.responseJSON.message + "!");
|
});
|
ajax.set("userType",1);
|
ajax.set("cityManagerId",1);
|
ajax.set("couponName",couponName);
|
ajax.set("prescription",prescription);
|
ajax.set("condition",$('#conditionalAmount').val());
|
ajax.set("subtraction",$('#deductionAmount').val());
|
ajax.set("discount",$('#voucherAmount').val());
|
ajax.set("experience",$('#experienceName').val());
|
ajax.set("illustrate",illustrate);
|
ajax.set("distributionMethod",distributionMethod);
|
ajax.set("requiredPoints",requiredPoints);
|
ajax.set("requiredCash",requiredCash);
|
ajax.set("userGroup",userGroup);
|
ajax.set("quantityIssued",quantityIssued);
|
ajax.set("pickUpQuantity",pickUpQuantity);
|
ajax.set("periodOfValidity",periodOfValidity);
|
ajax.set("exchangeMethod",exchangeMethod);
|
ajax.set("goodImg",this.goodsCover);
|
ajax.set("goodImgs",this.goodsPicArray);
|
ajax.set("company",$('#company').val());
|
ajax.set("cityIds",cityIds);
|
ajax.set("storeIds",this.storeIds);
|
ajax.start();
|
|
}
|
|
/**
|
* 收集数据
|
*/
|
couponInfoDlg.collectData = function () {
|
this
|
.set('couponId')
|
.set('name')
|
.set('type')
|
.set('typeName')
|
.set('times')
|
.set('sheetsNum')
|
.set('auditStatus')
|
.set('reason')
|
.set('remark')
|
.set('startTime')
|
.set('endTime')
|
.set('activityId')
|
.set('createId')
|
.set('createTime')
|
.set('timeType')
|
.set('expDay')
|
.set('couponCode')
|
.set('instructions')
|
.set('belongs')
|
.set('useTimes');
|
}
|
|
|
$(function () {
|
getProvince(null);
|
radio1();
|
var userType = $('#userType').val();
|
if (userType === '1'){
|
// 兑换方式
|
$('#exchangeType').show();
|
$('#needAmount').show();
|
$('#needIntegral').show();
|
// 图片
|
$('#app').show();
|
$('#app1').show();
|
// 适用范围
|
$('#belongsCon').show();
|
$('#belongsNationwide').show();
|
$('#belongsCity').show();
|
$('#belongsStore').show();
|
}
|
if (userType === '2'){
|
$('#needIntegral').show();
|
$('#belongsCon').show();
|
$('#belongsStore').show();
|
$('#storeSelect').show();
|
}
|
});
|