|
@@ -323,16 +323,31 @@ function getUserCoupons(userId) {
|
|
|
/************************添加会所 end**********************************************************/
|
|
|
|
|
|
// 兑换优惠券
|
|
|
-$("#redeemCoupons").on("click", function(){
|
|
|
+$("#redeemCoupons").on("click", function(){
|
|
|
var userId = $("#inputForm").find("[name*='bpOrderUserinfo.userId']").val();
|
|
|
if (userId && userId*1 > 0) {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- // 获取用户总优惠券
|
|
|
- getUserCoupons(userId);
|
|
|
+ var html = '<div style="text-align:center;padding-top:12px;"><input id="couponsCode" name="couponsCode" type="text" maxlength="16" placeholder="请输入16位兑换码"></div>';
|
|
|
+ var submit = function (v, h, f) {
|
|
|
+ if (f.couponsCode == '' || isNaN(f.couponsCode)) {
|
|
|
+ $.jBox.tip("请输入兑换码!", 'error', { focusId: "couponsCode" });
|
|
|
+ }
|
|
|
+ var bool = new RegExp("^[A-Za-z0-9]{16}$").test(f.couponsCode);
|
|
|
+ if (!bool) {
|
|
|
+ // 16位数字和字母
|
|
|
+ $.jBox.tip("请输入正确的兑换码!", 'error', { focusId: "couponsCode" });
|
|
|
+ }else{
|
|
|
+ $.post($("#ctx").val() + "/coupon/cmCouponClub/redeem", {'redemptionCode': f.couponsCode, 'userId': userId}, function (data) {
|
|
|
+ if (0 === data.code*1) {
|
|
|
+ $.jBox.tip(data.msg, 'info');
|
|
|
+ // 获取用户总优惠券
|
|
|
+ getUserCoupons(userId);
|
|
|
+ } else {
|
|
|
+ $.jBox.tip(data.msg, 'error');
|
|
|
+ }
|
|
|
+ }, "JSON");
|
|
|
+ }
|
|
|
+ };
|
|
|
+ $.jBox(html, { title: "兑换优惠券", buttons: { '立即兑换': true }, submit: submit });
|
|
|
} else {
|
|
|
alertx('请您先选择会所!');
|
|
|
}
|
|
@@ -439,10 +454,15 @@ function getShownCouponList(){
|
|
|
|
|
|
// 设置页面显示
|
|
|
function setPageCoupon() {
|
|
|
- var html = '<li><label><input type="radio" name="clubCouponId" value="0"><span class="couponDesc">不使用优惠券</span></label></li>';
|
|
|
+ var clubCouponId = $("#clubCouponId").val()*1;
|
|
|
+ var html = '<li><label><input type="radio" name="clubCouponId" value="0"><span class="couponDesc none">不使用优惠券</span></label></li>';
|
|
|
selectCoupons.forEach(function(item){
|
|
|
+ var checked = '';
|
|
|
+ if (clubCouponId === item.clubCouponId) {
|
|
|
+ checked = 'checked="checked"';
|
|
|
+ }
|
|
|
html += '<li><label>';
|
|
|
- html += ' <input type="radio" name="clubCouponId" value="'+item.clubCouponId +'">';
|
|
|
+ html += ' <input type="radio" name="clubCouponId" value="'+item.clubCouponId +'" '+checked+'>';
|
|
|
html += ' <span class="couponDesc">';
|
|
|
html += ' <span>'+item.couponName+'</span>';
|
|
|
html += ' <span>'+item.couponDesc+'</span>';
|
|
@@ -450,6 +470,9 @@ function setPageCoupon() {
|
|
|
html += '</span></label></li>';
|
|
|
});
|
|
|
$("#couponBox").find(".couponContent").html(html);
|
|
|
+ if (clubCouponId > 0) {
|
|
|
+ $("#couponBox").find("input[name=clubCouponId]").trigger("change");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 勾选优惠券重新计算总价
|
|
@@ -461,9 +484,10 @@ $("#couponBox").on("change", "input[name=clubCouponId]", function(){
|
|
|
selectCoupons.forEach(function(item){
|
|
|
if(item.clubCouponId*1 === clubCouponId) {
|
|
|
couponPrice = item.couponAmount;
|
|
|
+ $("#clubCouponId").val(clubCouponId);
|
|
|
+ $("#couponAmount").val(couponPrice);
|
|
|
}
|
|
|
});
|
|
|
- $("#couponAmount").val(couponPrice);
|
|
|
// 重新计算总价
|
|
|
setOrderFee();
|
|
|
});
|