productPromotionDetail.jsp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. <%@ page contentType="text/html;charset=UTF-8" %>
  2. <%@ include file="/WEB-INF/views/include/taglib.jsp" %>
  3. <%@ page import="java.util.*" %>
  4. <%@ page import="java.text.*" %>
  5. <%
  6. String datetime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime()); //获取系统时间
  7. request.setAttribute("currentTime", datetime);
  8. %>
  9. <html>
  10. <head>
  11. <title>促销活动信息</title>
  12. <meta name="decorator" content="default"/>
  13. <script type="text/javascript">
  14. $(document).ready(function () {
  15. //$("#name").focus();
  16. $("#inputForm").validate({
  17. submitHandler: function (form) {
  18. var isSubMitFlag = true, addProductArray = [], addGiftArray = [];
  19. var mode = $("input[name='mode']:checked").val();
  20. var status = $("input[name='status']:checked").val();
  21. var name = $("#name").val();
  22. if (name == "") {
  23. alertx("请输入促销名称");
  24. isSubMitFlag = false;
  25. return false;
  26. }
  27. if (mode == "1") {
  28. } else if (mode == "2") {
  29. if ($("#touchPrice2").val() == '') {
  30. alertx("请输入满减设定价");
  31. isSubMitFlag = false;
  32. return false;
  33. }
  34. if ($("#reducedPrice").val() == '') {
  35. alertx("请输入减免价格");
  36. isSubMitFlag = false;
  37. return false;
  38. }
  39. } else if (mode == "3") {
  40. if ($("#touchPrice3").val() == '') {
  41. alertx("请输入满赠设定价");
  42. isSubMitFlag = false;
  43. return false;
  44. }
  45. }
  46. if (status == "2") {
  47. var $beginTime = $("#beginTime").val();
  48. var $endTime = $("#endTime").val();
  49. if ($beginTime >= $endTime) {
  50. alertx("结束时间不能早于开始时间");
  51. isSubMitFlag = false;
  52. return false;
  53. }
  54. }
  55. //将促销商品和赠品信息填充进数组
  56. $('#contentTbody tr').each(function (index, item) {
  57. var $this = $(this);
  58. var $itemProductID = $this.find('input[name="info"]').val();
  59. var obj = {
  60. productId: $itemProductID,
  61. }
  62. addProductArray.push(obj)
  63. });
  64. $('#contentTbody1 tr').each(function (index, item) {
  65. var $this = $(this);
  66. var $itemProductID = $this.find('input[name="gift"]').val();
  67. var $giftNumber = $this.find('input[name="giftNumber"]').val();
  68. if ($giftNumber == null || $giftNumber == '') {
  69. alertx("请输入赠品数量");
  70. isSubMitFlag = false;
  71. return false;
  72. }
  73. if ($giftNumber <= 0) {
  74. alertx("赠品数量必须大于0");
  75. isSubMitFlag = false;
  76. return false;
  77. }
  78. var obj = {
  79. productId: $itemProductID,
  80. number: $giftNumber
  81. };
  82. addGiftArray.push(obj)
  83. })
  84. if (${cmPromotion.promotionProducts==null or cmPromotion.promotionProducts.size()<=1}) {
  85. alertx("请选择数量大于1的促销商品");
  86. isSubMitFlag = false;
  87. return false;
  88. }
  89. if (${cmPromotion.mode=="3" &&( cmPromotion.giftProducts==null or cmPromotion.giftProducts.size()==0)}) {
  90. alertx("请选择赠品");
  91. isSubMitFlag = false;
  92. return false;
  93. }
  94. if (isSubMitFlag) {
  95. var productItems = JSON.stringify(addProductArray);
  96. var giftItems = JSON.stringify(addGiftArray);
  97. $("#productIds").val(productItems);
  98. $("#giftIds").val(giftItems)
  99. loading('正在提交,请稍等...');
  100. form.submit();
  101. }
  102. },
  103. errorContainer: "#messageBox",
  104. errorPlacement: function (error, element) {
  105. $("#messageBox").text("输入有误,请先更正。");
  106. if (element.is(":checkbox") || element.is(":radio") || element.parent().is(".input-append")) {
  107. error.appendTo(element.parent().parent());
  108. } else {
  109. error.insertAfter(element);
  110. }
  111. }
  112. });
  113. });
  114. //选择添加商品
  115. function showSelect(type) {
  116. var showSelectProductID = '';
  117. if (type == 1) {
  118. $('#contentTbody tr').each(function (index, item) {
  119. var $this = $(this);
  120. var $itemProductID = $this.find('input[name="info"]').val();
  121. showSelectProductID += $itemProductID + ',';
  122. });
  123. } else {
  124. $('#contentTbody1 tr').each(function (index, item) {
  125. var $this = $(this);
  126. var $itemProductID = $this.find('input[name="gift"]').val();
  127. showSelectProductID += $itemProductID + ',';
  128. });
  129. }
  130. showSelectProductID = showSelectProductID.slice(0, -1)
  131. console.log(showSelectProductID);
  132. top.$.jBox("iframe:${ctx}/product/cmPromotions/findProductPage?productIds=" + showSelectProductID + "&promotionType=" + 2, {
  133. iframeScrolling: 'yes',
  134. width: $(top.document).width() - 400,
  135. height: $(top.document).height() - 160,
  136. persistent: true,
  137. title: "选择商品",
  138. buttons: {"确定": '1', "关闭": '-1'},
  139. submit: function (v, h, f) {
  140. //确定
  141. var $jboxFrame = top.$('#jbox-iframe');
  142. var $mainFrame = top.$('#mainFrame');
  143. if ('1' == v && 1 == $jboxFrame.size() && 1 == $mainFrame.size()) {
  144. var items = $jboxFrame[0].contentWindow.getCheckedItems(0);
  145. var items1 = "";
  146. var stringify = JSON.stringify(items);
  147. if (items.length > 0) {
  148. //添加数据
  149. $.post("${ctx}/product/activity/saveTemp", function (data) {
  150. if (true == data.success) {
  151. var productIds = $("#productIds").val();
  152. var giftIds = $("#giftIds").val();
  153. var mode = $("input[name='mode']:checked").val();
  154. var name = $("#name").val();
  155. var reducedPrice = $("#reducedPrice").val();
  156. var touchPrice2 = $("#touchPrice2").val();
  157. var touchPrice3 = $("#touchPrice3").val();
  158. var status = $("input[name='status']:checked").val();
  159. var beginTime = $("#beginTime").val();
  160. var endTime = $("#endTime").val();
  161. var delFlag1 = $("input[name='delFlag1']:checked").val();
  162. var delProductIds = $("#delProductIds").val();
  163. var delGiftIds = $("#delGiftIds").val();
  164. //将选中商品id与原来的促销商品或赠品id拼接
  165. if (type == 1) {
  166. if (productIds != '') {
  167. items = items + ',' + productIds;
  168. }
  169. if (giftIds != '') {
  170. items1 = giftIds;
  171. }
  172. window.location.href = "${ctx}/product/cmPromotions/form?type=2&productIds=" + items + "&giftIds=" + items1 + "&mode=" + mode + "&name=" + name +
  173. "&delProductIds=" + delProductIds + "&delGiftIds=" + delGiftIds +
  174. "&reducedPrice=" + reducedPrice + "&touchPrice2=" + touchPrice2 + "&touchPrice3=" + touchPrice3 +
  175. "&status=" + status + "&beginTime=" + beginTime + "&endTime=" + endTime + "&delFlag1=" + delFlag1 + "&id=${cmPromotion.id}";
  176. }
  177. if (type == 2) {
  178. if (giftIds != '') {
  179. items = items + ',' + giftIds;
  180. }
  181. if (productIds != '') {
  182. items1 = productIds;
  183. }
  184. window.location.href = "${ctx}/product/cmPromotions/form?type=2&productIds=" + items1 + "&giftIds=" + items + "&mode=" + mode + "&name=" + name +
  185. "&delProductIds=" + delProductIds + "&delGiftIds=" + delGiftIds +
  186. "&reducedPrice=" + reducedPrice + "&touchPrice2=" + touchPrice2 + "&touchPrice3=" + touchPrice3 +
  187. "&status=" + status + "&beginTime=" + beginTime + "&endTime=" + endTime + "&delFlag1=" + delFlag1 + "&id=${cmPromotion.id}";
  188. }
  189. $.jBox.tip(data.msg, 'info');
  190. } else {
  191. $.jBox.tip(data.msg, 'error');
  192. }
  193. }, "JSON");//这里返回的类型有:json,html,xml,text
  194. return true;
  195. } else {
  196. top.$.jBox.tip("请先勾选商品...");
  197. return false;
  198. }
  199. }
  200. return true;
  201. }
  202. });
  203. }
  204. function deleteProduct(obj, storeStatus, type) {
  205. //将该行数据取消勾选,若存在数据库中则将其删除
  206. $(".check-item[value=" + obj + "]").prop("checked", false);
  207. var delProductIds = $("#delProductIds").val();
  208. var delGiftIds = $("#delGiftIds").val();
  209. if (storeStatus && type == 1) {
  210. if (delProductIds != '') {
  211. delProductIds = delProductIds + "," + obj;
  212. } else delProductIds = obj;
  213. }
  214. if (storeStatus && type == 2) {
  215. if (delGiftIds != '') {
  216. delGiftIds = delGiftIds + "," + obj;
  217. } else delGiftIds = obj;
  218. }
  219. window.setTimeout(function () {
  220. var productItems = getCheckedItems(1);
  221. var giftItems = getCheckedItems(2);
  222. var mode = $("input[name='mode']:checked").val();
  223. var name = $("#name").val();
  224. var reducedPrice = $("#reducedPrice").val();
  225. var touchPrice2 = $("#touchPrice2").val();
  226. var touchPrice3 = $("#touchPrice3").val();
  227. var status = $("input[name='status']:checked").val();
  228. var beginTime = $("#beginTime").val();
  229. var endTime = $("#endTime").val();
  230. var delFlag1 = $("input[name='delFlag1']:checked").val();
  231. window.location.href = "${ctx}/product/cmPromotions/form?type=2&productIds=" + productItems + "&giftIds=" + giftItems +
  232. "&delProductIds=" + delProductIds + "&delGiftIds=" + delGiftIds + "&mode=" + mode + "&name=" + name +
  233. "&reducedPrice=" + reducedPrice + "&touchPrice2=" + touchPrice2 + "&touchPrice3=" + touchPrice3 +
  234. "&status=" + status + "&beginTime=" + beginTime + "&endTime=" + endTime + "&delFlag1=" + delFlag1 + "&id=${cmPromotion.id}";
  235. }, 100)
  236. }
  237. function getCheckedItems(type) {
  238. var items = new Array();
  239. var $items = type == 0 ? $('.check-item:checked') : type == 1 ? $("#productCheckItem:checked") : $("#giftCheckItem:checked");
  240. $items.each(function () {
  241. items.push($(this).val());
  242. });
  243. return items;
  244. }
  245. </script>
  246. </head>
  247. <body>
  248. <br/>
  249. <form:form id="inputForm" modelAttribute="cmPromotion" action="${ctx}/product/cmPromotions/save" method="post"
  250. class="form-horizontal">
  251. <div class="control-group">
  252. <c:if test="${cmPromotion.promotionProducts !=null and cmPromotion.promotionProducts.size()>0}">
  253. <label>促销商品</label>
  254. <table id="contentTable" class="table table-striped table-bordered table-condensed">
  255. <thead>
  256. <th style="width:20px;" class="hide"></th>
  257. <th>商品图片</th>
  258. <th>商品名称</th>
  259. <th>供应商</th>
  260. <th>机构价</th>
  261. </thead>
  262. <tbody id="contentTbody">
  263. <c:forEach items="${cmPromotion.promotionProducts}" var="product">
  264. <tr>
  265. <th class="hide"><input class="check-item" type="checkbox" id="productCheckItem"
  266. name="info" ${product.storeStatus?'':'checked'}
  267. value='${product.productID}'/></th>
  268. <td><img src="${product.mainImage}" width="50px" height="50px"></td>
  269. <td>${product.name}</td>
  270. <td>${product.shopName}</td>
  271. <td>${product.price}</td>
  272. </tr>
  273. </c:forEach>
  274. </tbody>
  275. </table>
  276. </c:if>
  277. <c:if test="${cmPromotion.promotionShops !=null and cmPromotion.promotionShops.size()>0}">
  278. <label>促销店铺:${cmPromotion.promotionShops.get(0).name}</label>
  279. </c:if>
  280. </div>
  281. <div class="control-group">
  282. <div id="discountContent1"
  283. style="display: ${cmPromotion.mode == null ? "inline" : cmPromotion.mode == "1"?"inline":"none"}">
  284. <label><font color="red">优惠价:${cmPromotion.touchPrice}</font></label>
  285. </div>
  286. <div id="discountContent2" style="display: ${cmPromotion.mode == "2" ? "inline" : "none"}">
  287. <label><font color="red">满${cmPromotion.touchPrice}</font></label>
  288. <label><font color="red">减${cmPromotion.reducedPrice}</font></label>
  289. </div>
  290. <div id="discountContent3" style="display: ${cmPromotion.mode == "3" ? "inline" : "none"}">
  291. <label><font color="red">满${cmPromotion.touchPrice} 赠:</font></label>
  292. <c:if test="${cmPromotion.giftProducts !=null and cmPromotion.giftProducts.size()>0}">
  293. <table id="contentTable" class="table table-striped table-bordered table-condensed">
  294. <thead>
  295. <th style="width:20px;" class="hide"></th>
  296. <th>商品图片</th>
  297. <th>商品名称</th>
  298. <th>供应商</th>
  299. <th>数量</th>
  300. </thead>
  301. <tbody id="contentTbody1">
  302. <c:forEach items="${cmPromotion.giftProducts}" var="product">
  303. <tr>
  304. <th class="hide"><input class="check-item" type="checkbox" id="giftCheckItem"
  305. name="gift" ${product.storeStatus?'':'checked'}
  306. value='${product.productID}'/></th>
  307. <td><img src="${product.mainImage}" width="50px" height="50px"></td>
  308. <td>${product.name}</td>
  309. <td>${product.shopName}</td>
  310. <td>${product.giftNumber}</td>
  311. </tr>
  312. </c:forEach>
  313. </tbody>
  314. </table>
  315. </c:if>
  316. </div>
  317. </div>
  318. </form:form>
  319. <script type="text/javascript">
  320. $(function () {
  321. })
  322. //促销方式修改
  323. $("input:radio[name='mode']").click(function () {
  324. var promotionType = $("input[name='mode']:checked").val();
  325. if ("1" == promotionType) {
  326. $("#discountContent1").attr("style", "display:inline");
  327. $("#discountContent2").attr("style", "display:none");
  328. $("#discountContent3").attr("style", "display:none");
  329. } else if ("2" == promotionType) {
  330. $("#discountContent1").attr("style", "display:none");
  331. $("#discountContent2").attr("style", "display:inline");
  332. $("#discountContent3").attr("style", "display:none");
  333. } else {
  334. $("#discountContent1").attr("style", "display:none");
  335. $("#discountContent2").attr("style", "display:none");
  336. $("#discountContent3").attr("style", "display:inline");
  337. }
  338. })
  339. //促销时效修改
  340. $("input:radio[name='status']").click(function () {
  341. var promotionStatus = $("input[name='status']:checked").val();
  342. var promotiondelFlag1 = $("input[name='delFlag1']:checked").val();
  343. if ("1" == promotionStatus) {
  344. $("#begin").attr("style", "display:none");
  345. $("#end").attr("style", "display:none");
  346. if (null == promotiondelFlag1) {
  347. $("#promotionStatus").text("进行中");
  348. $("#promotionStatus").attr("style", "display: inline;color:green");
  349. }
  350. } else if ("2" == promotionStatus) {
  351. $("#begin").attr("style", "");
  352. $("#end").attr("style", "");
  353. if (null == promotiondelFlag1) {
  354. updateStatus();
  355. }
  356. }
  357. })
  358. //促销日期修改
  359. $("#beginTime").blur(function () {
  360. var promotiondelFlag1 = $("input[name='delFlag1']:checked").val();
  361. if (null == promotiondelFlag1) updateStatus()
  362. });
  363. $("#endTime").blur(function () {
  364. var promotiondelFlag1 = $("input[name='delFlag1']:checked").val();
  365. if (null == promotiondelFlag1) updateStatus()
  366. });
  367. //促销状态修改
  368. $("input:checkbox[name='delFlag1']").click(function () {
  369. var promotiondelFlag1 = $("input[name='delFlag1']:checked").val();
  370. if (promotiondelFlag1 != null) {
  371. $("#promotionStatus").text("已关闭");
  372. $("#promotionStatus").attr("style", "display: inline;color:red");
  373. } else {
  374. var promotionStatus = $("input[name='status']:checked").val();
  375. if ("1" == promotionStatus) {
  376. $("#promotionStatus").text("进行中");
  377. $("#promotionStatus").attr("style", "display: inline;color:green");
  378. } else updateStatus()
  379. }
  380. })
  381. function updateStatus() {
  382. var beginTime = $("#beginTime").val();
  383. var beginMs = new Date(beginTime).getTime();
  384. var endTime = $("#endTime").val();
  385. var endMs = new Date(endTime).getTime();
  386. var nowMs = new Date().getTime();
  387. if (nowMs < beginMs) {
  388. $("#promotionStatus").text("未开始");
  389. $("#promotionStatus").attr("style", "display: inline;color:purple");
  390. } else if (nowMs > endMs) {
  391. $("#promotionStatus").text("已结束");
  392. $("#promotionStatus").attr("style", "display: inline;color:orange");
  393. } else {
  394. $("#promotionStatus").text("进行中");
  395. $("#promotionStatus").attr("style", "display: inline;color:green");
  396. }
  397. }
  398. </script>
  399. </body>
  400. </html>