123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407 |
- <%@ page contentType="text/html;charset=UTF-8" %>
- <%@ include file="/WEB-INF/views/include/taglib.jsp" %>
- <%@ page import="java.util.*" %>
- <%@ page import="java.text.*" %>
- <%
- String datetime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime()); //获取系统时间
- request.setAttribute("currentTime", datetime);
- %>
- <html>
- <head>
- <title>促销活动信息</title>
- <meta name="decorator" content="default"/>
- <script type="text/javascript">
- $(document).ready(function () {
- //$("#name").focus();
- $("#inputForm").validate({
- submitHandler: function (form) {
- var isSubMitFlag = true, addProductArray = [], addGiftArray = [];
- var mode = $("input[name='mode']:checked").val();
- var status = $("input[name='status']:checked").val();
- var name = $("#name").val();
- if (name == "") {
- alertx("请输入促销名称");
- isSubMitFlag = false;
- return false;
- }
- if (mode == "1") {
- } else if (mode == "2") {
- if ($("#touchPrice2").val() == '') {
- alertx("请输入满减设定价");
- isSubMitFlag = false;
- return false;
- }
- if ($("#reducedPrice").val() == '') {
- alertx("请输入减免价格");
- isSubMitFlag = false;
- return false;
- }
- } else if (mode == "3") {
- if ($("#touchPrice3").val() == '') {
- alertx("请输入满赠设定价");
- isSubMitFlag = false;
- return false;
- }
- }
- if (status == "2") {
- var $beginTime = $("#beginTime").val();
- var $endTime = $("#endTime").val();
- if ($beginTime >= $endTime) {
- alertx("结束时间不能早于开始时间");
- isSubMitFlag = false;
- return false;
- }
- }
- //将促销商品和赠品信息填充进数组
- $('#contentTbody tr').each(function (index, item) {
- var $this = $(this);
- var $itemProductID = $this.find('input[name="info"]').val();
- var obj = {
- productId: $itemProductID,
- }
- addProductArray.push(obj)
- });
- $('#contentTbody1 tr').each(function (index, item) {
- var $this = $(this);
- var $itemProductID = $this.find('input[name="gift"]').val();
- var $giftNumber = $this.find('input[name="giftNumber"]').val();
- if ($giftNumber == null || $giftNumber == '') {
- alertx("请输入赠品数量");
- isSubMitFlag = false;
- return false;
- }
- if ($giftNumber <= 0) {
- alertx("赠品数量必须大于0");
- isSubMitFlag = false;
- return false;
- }
- var obj = {
- productId: $itemProductID,
- number: $giftNumber
- };
- addGiftArray.push(obj)
- })
- if (${cmPromotion.promotionProducts==null or cmPromotion.promotionProducts.size()<=1}) {
- alertx("请选择数量大于1的促销商品");
- isSubMitFlag = false;
- return false;
- }
- if (${cmPromotion.mode=="3" &&( cmPromotion.giftProducts==null or cmPromotion.giftProducts.size()==0)}) {
- alertx("请选择赠品");
- isSubMitFlag = false;
- return false;
- }
- if (isSubMitFlag) {
- var productItems = JSON.stringify(addProductArray);
- var giftItems = JSON.stringify(addGiftArray);
- $("#productIds").val(productItems);
- $("#giftIds").val(giftItems)
- loading('正在提交,请稍等...');
- form.submit();
- }
- },
- errorContainer: "#messageBox",
- errorPlacement: function (error, element) {
- $("#messageBox").text("输入有误,请先更正。");
- if (element.is(":checkbox") || element.is(":radio") || element.parent().is(".input-append")) {
- error.appendTo(element.parent().parent());
- } else {
- error.insertAfter(element);
- }
- }
- });
- });
- //选择添加商品
- function showSelect(type) {
- var showSelectProductID = '';
- if (type == 1) {
- $('#contentTbody tr').each(function (index, item) {
- var $this = $(this);
- var $itemProductID = $this.find('input[name="info"]').val();
- showSelectProductID += $itemProductID + ',';
- });
- } else {
- $('#contentTbody1 tr').each(function (index, item) {
- var $this = $(this);
- var $itemProductID = $this.find('input[name="gift"]').val();
- showSelectProductID += $itemProductID + ',';
- });
- }
- showSelectProductID = showSelectProductID.slice(0, -1)
- console.log(showSelectProductID);
- top.$.jBox("iframe:${ctx}/product/cmPromotions/findProductPage?productIds=" + showSelectProductID + "&promotionType=" + 2, {
- iframeScrolling: 'yes',
- width: $(top.document).width() - 400,
- height: $(top.document).height() - 160,
- persistent: true,
- title: "选择商品",
- buttons: {"确定": '1', "关闭": '-1'},
- submit: function (v, h, f) {
- //确定
- var $jboxFrame = top.$('#jbox-iframe');
- var $mainFrame = top.$('#mainFrame');
- if ('1' == v && 1 == $jboxFrame.size() && 1 == $mainFrame.size()) {
- var items = $jboxFrame[0].contentWindow.getCheckedItems(0);
- var items1 = "";
- var stringify = JSON.stringify(items);
- if (items.length > 0) {
- //添加数据
- $.post("${ctx}/product/activity/saveTemp", function (data) {
- if (true == data.success) {
- var productIds = $("#productIds").val();
- var giftIds = $("#giftIds").val();
- var mode = $("input[name='mode']:checked").val();
- var name = $("#name").val();
- var reducedPrice = $("#reducedPrice").val();
- var touchPrice2 = $("#touchPrice2").val();
- var touchPrice3 = $("#touchPrice3").val();
- var status = $("input[name='status']:checked").val();
- var beginTime = $("#beginTime").val();
- var endTime = $("#endTime").val();
- var delFlag1 = $("input[name='delFlag1']:checked").val();
- var delProductIds = $("#delProductIds").val();
- var delGiftIds = $("#delGiftIds").val();
- //将选中商品id与原来的促销商品或赠品id拼接
- if (type == 1) {
- if (productIds != '') {
- items = items + ',' + productIds;
- }
- if (giftIds != '') {
- items1 = giftIds;
- }
- window.location.href = "${ctx}/product/cmPromotions/form?type=2&productIds=" + items + "&giftIds=" + items1 + "&mode=" + mode + "&name=" + name +
- "&delProductIds=" + delProductIds + "&delGiftIds=" + delGiftIds +
- "&reducedPrice=" + reducedPrice + "&touchPrice2=" + touchPrice2 + "&touchPrice3=" + touchPrice3 +
- "&status=" + status + "&beginTime=" + beginTime + "&endTime=" + endTime + "&delFlag1=" + delFlag1 + "&id=${cmPromotion.id}";
- }
- if (type == 2) {
- if (giftIds != '') {
- items = items + ',' + giftIds;
- }
- if (productIds != '') {
- items1 = productIds;
- }
- window.location.href = "${ctx}/product/cmPromotions/form?type=2&productIds=" + items1 + "&giftIds=" + items + "&mode=" + mode + "&name=" + name +
- "&delProductIds=" + delProductIds + "&delGiftIds=" + delGiftIds +
- "&reducedPrice=" + reducedPrice + "&touchPrice2=" + touchPrice2 + "&touchPrice3=" + touchPrice3 +
- "&status=" + status + "&beginTime=" + beginTime + "&endTime=" + endTime + "&delFlag1=" + delFlag1 + "&id=${cmPromotion.id}";
- }
- $.jBox.tip(data.msg, 'info');
- } else {
- $.jBox.tip(data.msg, 'error');
- }
- }, "JSON");//这里返回的类型有:json,html,xml,text
- return true;
- } else {
- top.$.jBox.tip("请先勾选商品...");
- return false;
- }
- }
- return true;
- }
- });
- }
- function deleteProduct(obj, storeStatus, type) {
- //将该行数据取消勾选,若存在数据库中则将其删除
- $(".check-item[value=" + obj + "]").prop("checked", false);
- var delProductIds = $("#delProductIds").val();
- var delGiftIds = $("#delGiftIds").val();
- if (storeStatus && type == 1) {
- if (delProductIds != '') {
- delProductIds = delProductIds + "," + obj;
- } else delProductIds = obj;
- }
- if (storeStatus && type == 2) {
- if (delGiftIds != '') {
- delGiftIds = delGiftIds + "," + obj;
- } else delGiftIds = obj;
- }
- window.setTimeout(function () {
- var productItems = getCheckedItems(1);
- var giftItems = getCheckedItems(2);
- var mode = $("input[name='mode']:checked").val();
- var name = $("#name").val();
- var reducedPrice = $("#reducedPrice").val();
- var touchPrice2 = $("#touchPrice2").val();
- var touchPrice3 = $("#touchPrice3").val();
- var status = $("input[name='status']:checked").val();
- var beginTime = $("#beginTime").val();
- var endTime = $("#endTime").val();
- var delFlag1 = $("input[name='delFlag1']:checked").val();
- window.location.href = "${ctx}/product/cmPromotions/form?type=2&productIds=" + productItems + "&giftIds=" + giftItems +
- "&delProductIds=" + delProductIds + "&delGiftIds=" + delGiftIds + "&mode=" + mode + "&name=" + name +
- "&reducedPrice=" + reducedPrice + "&touchPrice2=" + touchPrice2 + "&touchPrice3=" + touchPrice3 +
- "&status=" + status + "&beginTime=" + beginTime + "&endTime=" + endTime + "&delFlag1=" + delFlag1 + "&id=${cmPromotion.id}";
- }, 100)
- }
- function getCheckedItems(type) {
- var items = new Array();
- var $items = type == 0 ? $('.check-item:checked') : type == 1 ? $("#productCheckItem:checked") : $("#giftCheckItem:checked");
- $items.each(function () {
- items.push($(this).val());
- });
- return items;
- }
- </script>
- </head>
- <body>
- <br/>
- <form:form id="inputForm" modelAttribute="cmPromotion" action="${ctx}/product/cmPromotions/save" method="post"
- class="form-horizontal">
- <div class="control-group">
- <c:if test="${cmPromotion.promotionProducts !=null and cmPromotion.promotionProducts.size()>0}">
- <label>促销商品</label>
- <table id="contentTable" class="table table-striped table-bordered table-condensed">
- <thead>
- <th style="width:20px;" class="hide"></th>
- <th>商品图片</th>
- <th>商品名称</th>
- <th>供应商</th>
- <th>机构价</th>
- </thead>
- <tbody id="contentTbody">
- <c:forEach items="${cmPromotion.promotionProducts}" var="product">
- <tr>
- <th class="hide"><input class="check-item" type="checkbox" id="productCheckItem"
- name="info" ${product.storeStatus?'':'checked'}
- value='${product.productID}'/></th>
- <td><img src="${product.mainImage}" width="50px" height="50px"></td>
- <td>${product.name}</td>
- <td>${product.shopName}</td>
- <td>${product.price}</td>
- </tr>
- </c:forEach>
- </tbody>
- </table>
- </c:if>
- <c:if test="${cmPromotion.promotionShops !=null and cmPromotion.promotionShops.size()>0}">
- <label>促销店铺:${cmPromotion.promotionShops.get(0).name}</label>
- </c:if>
- </div>
- <div class="control-group">
- <div id="discountContent1"
- style="display: ${cmPromotion.mode == null ? "inline" : cmPromotion.mode == "1"?"inline":"none"}">
- <label><font color="red">优惠价:${cmPromotion.touchPrice}</font></label>
- </div>
- <div id="discountContent2" style="display: ${cmPromotion.mode == "2" ? "inline" : "none"}">
- <label><font color="red">满${cmPromotion.touchPrice}</font></label>
- <label><font color="red">减${cmPromotion.reducedPrice}</font></label>
- </div>
- <div id="discountContent3" style="display: ${cmPromotion.mode == "3" ? "inline" : "none"}">
- <label><font color="red">满${cmPromotion.touchPrice} 赠:</font></label>
- <c:if test="${cmPromotion.giftProducts !=null and cmPromotion.giftProducts.size()>0}">
- <table id="contentTable" class="table table-striped table-bordered table-condensed">
- <thead>
- <th style="width:20px;" class="hide"></th>
- <th>商品图片</th>
- <th>商品名称</th>
- <th>供应商</th>
- <th>数量</th>
- </thead>
- <tbody id="contentTbody1">
- <c:forEach items="${cmPromotion.giftProducts}" var="product">
- <tr>
- <th class="hide"><input class="check-item" type="checkbox" id="giftCheckItem"
- name="gift" ${product.storeStatus?'':'checked'}
- value='${product.productID}'/></th>
- <td><img src="${product.mainImage}" width="50px" height="50px"></td>
- <td>${product.name}</td>
- <td>${product.shopName}</td>
- <td>${product.giftNumber}</td>
- </tr>
- </c:forEach>
- </tbody>
- </table>
- </c:if>
- </div>
- </div>
- </form:form>
- <script type="text/javascript">
- $(function () {
- })
- //促销方式修改
- $("input:radio[name='mode']").click(function () {
- var promotionType = $("input[name='mode']:checked").val();
- if ("1" == promotionType) {
- $("#discountContent1").attr("style", "display:inline");
- $("#discountContent2").attr("style", "display:none");
- $("#discountContent3").attr("style", "display:none");
- } else if ("2" == promotionType) {
- $("#discountContent1").attr("style", "display:none");
- $("#discountContent2").attr("style", "display:inline");
- $("#discountContent3").attr("style", "display:none");
- } else {
- $("#discountContent1").attr("style", "display:none");
- $("#discountContent2").attr("style", "display:none");
- $("#discountContent3").attr("style", "display:inline");
- }
- })
- //促销时效修改
- $("input:radio[name='status']").click(function () {
- var promotionStatus = $("input[name='status']:checked").val();
- var promotiondelFlag1 = $("input[name='delFlag1']:checked").val();
- if ("1" == promotionStatus) {
- $("#begin").attr("style", "display:none");
- $("#end").attr("style", "display:none");
- if (null == promotiondelFlag1) {
- $("#promotionStatus").text("进行中");
- $("#promotionStatus").attr("style", "display: inline;color:green");
- }
- } else if ("2" == promotionStatus) {
- $("#begin").attr("style", "");
- $("#end").attr("style", "");
- if (null == promotiondelFlag1) {
- updateStatus();
- }
- }
- })
- //促销日期修改
- $("#beginTime").blur(function () {
- var promotiondelFlag1 = $("input[name='delFlag1']:checked").val();
- if (null == promotiondelFlag1) updateStatus()
- });
- $("#endTime").blur(function () {
- var promotiondelFlag1 = $("input[name='delFlag1']:checked").val();
- if (null == promotiondelFlag1) updateStatus()
- });
- //促销状态修改
- $("input:checkbox[name='delFlag1']").click(function () {
- var promotiondelFlag1 = $("input[name='delFlag1']:checked").val();
- if (promotiondelFlag1 != null) {
- $("#promotionStatus").text("已关闭");
- $("#promotionStatus").attr("style", "display: inline;color:red");
- } else {
- var promotionStatus = $("input[name='status']:checked").val();
- if ("1" == promotionStatus) {
- $("#promotionStatus").text("进行中");
- $("#promotionStatus").attr("style", "display: inline;color:green");
- } else updateStatus()
- }
- })
- function updateStatus() {
- var beginTime = $("#beginTime").val();
- var beginMs = new Date(beginTime).getTime();
- var endTime = $("#endTime").val();
- var endMs = new Date(endTime).getTime();
- var nowMs = new Date().getTime();
- if (nowMs < beginMs) {
- $("#promotionStatus").text("未开始");
- $("#promotionStatus").attr("style", "display: inline;color:purple");
- } else if (nowMs > endMs) {
- $("#promotionStatus").text("已结束");
- $("#promotionStatus").attr("style", "display: inline;color:orange");
- } else {
- $("#promotionStatus").text("进行中");
- $("#promotionStatus").attr("style", "display: inline;color:green");
- }
- }
- </script>
- </body>
- </html>
|