organizeSinglePromotionForm.jsp 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  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. if (${cmOrganizePromotion.promotionProducts==null or cmOrganizePromotion.promotionProducts.size()==0}) {
  22. alertx("请选择促销商品");
  23. isSubMitFlag = false;
  24. return false;
  25. }
  26. if (${cmOrganizePromotion.promotionProducts.size()>1}) {
  27. alertx("只能选择一种商品,请删除多出的商品");
  28. isSubMitFlag = false;
  29. return false;
  30. }
  31. if (mode == "1") {
  32. if ($("#touchPrice1").val() == '') {
  33. alertx("请输入优惠价");
  34. isSubMitFlag = false;
  35. return false;
  36. }else if(isNaN($("#touchPrice1").val())||$("#touchPrice1").val().indexOf('0')==0){
  37. alertx('请输入正确的优惠价!');
  38. isSubMitFlag = false;
  39. return false;
  40. }else {
  41. var price1 = $("#price1").val();
  42. if (parseFloat($("#touchPrice1").val()) >= parseFloat(price1)) {
  43. alertx('优惠价必须小于机构价'+price1);
  44. isSubMitFlag = false;
  45. return false;
  46. }
  47. }
  48. }else if (mode == "2") {
  49. debugger
  50. if ($("#touchPrice2").val() == '') {
  51. alertx("请输入满减设定价");
  52. isSubMitFlag = false;
  53. return false;
  54. }else if(isNaN($("#touchPrice2").val())||$("#touchPrice2").val().indexOf('0')==0){
  55. alertx('请输入正确的满减设定价!');
  56. isSubMitFlag = false;
  57. return false;
  58. }else {
  59. var price1 = $("#price1").val();
  60. if (parseFloat($("#touchPrice2").val()) <parseFloat(price1)) {
  61. alertx('满减设定价需大于或等于商品机构价'+price1);
  62. isSubMitFlag = false;
  63. return false;
  64. }
  65. }
  66. if ($("#reducedPrice").val() == '') {
  67. alertx("请输入减免价格");
  68. isSubMitFlag = false;
  69. return false;
  70. }else if(isNaN($("#reducedPrice").val())||$("#reducedPrice").val().indexOf('0')==0){
  71. alertx('请输入正确的减免价格!');
  72. isSubMitFlag = false;
  73. return false;
  74. }
  75. if (parseFloat($("#reducedPrice").val()) > parseFloat($("#touchPrice2").val())) {
  76. alertx("减免价格必须小于满减设定价")
  77. isSubMitFlag = false;
  78. return false;
  79. }
  80. }else if (mode == "3") {
  81. if ($("#touchPrice3").val() == '') {
  82. alertx("请输入满赠设定价");
  83. isSubMitFlag = false;
  84. return false;
  85. }else if(isNaN($("#touchPrice3").val())||$("#touchPrice3").val().indexOf('0')==0){
  86. alertx('请输入正确的满赠设定价!');
  87. isSubMitFlag = false;
  88. return false;
  89. }else {
  90. var price1 = $("#price1").val();
  91. if (parseFloat($("#touchPrice3").val()) < parseFloat(price1)) {
  92. alertx('满赠设定价需大于或等于商品机构价'+price1);
  93. isSubMitFlag = false;
  94. return false;
  95. }
  96. }
  97. }
  98. if (mode=="3" &&( ${cmOrganizePromotion.giftProducts==null or cmOrganizePromotion.giftProducts.size()==0})) {
  99. alertx("请至少选择1个赠送的商品");
  100. isSubMitFlag = false;
  101. return false;
  102. }
  103. //将促销商品和赠品信息填充进数组
  104. $('#contentTbody tr').each(function (index, item) {
  105. var $this = $(this);
  106. var $itemProductID = $this.find('input[name="info"]').val();
  107. var obj = {
  108. productId: $itemProductID,
  109. }
  110. addProductArray.push(obj)
  111. });
  112. $('#contentTbody1 tr').each(function (index, item) {
  113. var $this = $(this);
  114. var $itemProductID = $this.find('input[name="gift"]').val();
  115. var $giftNumber = $this.find('input[name="giftNumber"]').val();
  116. if ($giftNumber == null || $giftNumber == '' ) {
  117. alertx("请输入赠品数量");
  118. isSubMitFlag = false;
  119. return false;
  120. }
  121. if ( $giftNumber <= 0 ) {
  122. alertx("赠品数量必须大于0");
  123. isSubMitFlag = false;
  124. return false;
  125. }
  126. var obj = {
  127. productId: $itemProductID,
  128. number: $giftNumber
  129. };
  130. addGiftArray.push(obj)
  131. })
  132. if (status == "2") {
  133. var $beginTime = $("#beginTime").val();
  134. var $endTime = $("#endTime").val();
  135. if ($beginTime >= $endTime) {
  136. alertx("结束时间不能早于开始时间");
  137. isSubMitFlag = false;
  138. return false;
  139. }
  140. }
  141. if (isSubMitFlag) {
  142. var productItems = JSON.stringify(addProductArray);
  143. var giftItems = JSON.stringify(addGiftArray);
  144. $("#productIds").val(productItems);
  145. $("#giftIds").val(giftItems)
  146. loading('正在提交,请稍等...');
  147. form.submit();
  148. }
  149. },
  150. errorContainer: "#messageBox",
  151. errorPlacement: function(error, element) {
  152. $("#messageBox").text("输入有误,请先更正。");
  153. if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
  154. error.appendTo(element.parent().parent());
  155. } else {
  156. error.insertAfter(element);
  157. }
  158. }
  159. });
  160. });
  161. //选择添加商品
  162. function showSelect(type) {
  163. var showSelectProductID = '';
  164. var url = '';
  165. var title = '';
  166. var delProductIds = $("#delProductIds").val();
  167. if (type == 1) {
  168. $('#contentTbody tr').each(function (index, item) {
  169. var $this = $(this);
  170. var $itemProductID = $this.find('input[name="info"]').val();
  171. showSelectProductID += $itemProductID + ',';
  172. });
  173. url = "${ctx}/weisha/cmOrganizePromotions/findProductPage?productIds=" + showSelectProductID + "&promotionType=1&delProductIds=" + delProductIds +"&organizeId=" + $("#organizeId").val();
  174. title = "选择促销单品";
  175. } else {
  176. $('#contentTbody1 tr').each(function (index, item) {
  177. var $this = $(this);
  178. var $itemProductID = $this.find('input[name="gift"]').val();
  179. showSelectProductID += $itemProductID + ',';
  180. });
  181. url ="${ctx}/weisha/cmOrganizePromotions/findProductPage?productIds=" + showSelectProductID +"&organizeId=" + $("#organizeId").val()
  182. title = "选择促销赠品";
  183. }
  184. showSelectProductID = showSelectProductID.slice(0, -1)
  185. console.log(showSelectProductID);
  186. top.$.jBox("iframe:"+url, {
  187. iframeScrolling: 'yes',
  188. width: $(top.document).width() - 400,
  189. height: $(top.document).height() - 160,
  190. persistent: true,
  191. title: title,
  192. buttons: {"确定": '1', "关闭": '-1'},
  193. submit: function (v, h, f) {
  194. //确定
  195. var $jboxFrame = top.$('#jbox-iframe');
  196. var $mainFrame = top.$('#mainFrame');
  197. if ('1' == v && 1 == $jboxFrame.size() && 1 == $mainFrame.size()) {
  198. var items = $jboxFrame[0].contentWindow.getCheckedItems(0);
  199. var items1 = "";
  200. var stringify = JSON.stringify(items);
  201. if (items.length > 0) {
  202. //添加数据
  203. $.post("${ctx}/product/activity/saveTemp", function (data) {
  204. if (true == data.success) {
  205. var productIds = $("#productIds").val();
  206. var giftIds = $("#giftIds").val();
  207. var mode = $("input[name='mode']:checked").val();
  208. var reducedPrice = $("#reducedPrice").val();
  209. var touchPrice1 = $("#touchPrice1").val();
  210. var touchPrice2 = $("#touchPrice2").val();
  211. var touchPrice3 = $("#touchPrice3").val();
  212. var status = $("input[name='status']:checked").val();
  213. var beginTime = $("#beginTime").val();
  214. var endTime = $("#endTime").val();
  215. var delFlag1 = $("input[name='delFlag1']:checked").val();
  216. var delProductIds = $("#delProductIds").val();
  217. var delGiftIds = $("#delGiftIds").val();
  218. var organizeId = $("#organizeId").val();
  219. //将选中商品id与原来的促销商品或赠品id拼接
  220. if (type == 1 ) {
  221. items = items;
  222. if (giftIds != '') {
  223. items1 = giftIds;
  224. }
  225. window.location.href = "${ctx}/weisha/cmOrganizePromotions/form?type=1&productIds=" + items + "&giftIds=" + items1 + "&mode=" + mode +
  226. "&delProductIds=" + delProductIds + "&delGiftIds=" + delGiftIds +
  227. "&reducedPrice=" + reducedPrice + "&touchPrice1=" + touchPrice1 + "&touchPrice2=" + touchPrice2 + "&touchPrice3=" + touchPrice3 +
  228. "&status=" + status + "&beginTime=" + beginTime + "&endTime=" + endTime + "&delFlag1=" + delFlag1 + "&id=${cmOrganizePromotion.id}" +
  229. "&searchDbFlag=0&organizeId=" + organizeId;
  230. }
  231. if (type == 2) {
  232. if (giftIds != '') {
  233. items = items + ',' + giftIds;
  234. }
  235. if (productIds != '') {
  236. items1 = productIds;
  237. }
  238. window.location.href = "${ctx}/weisha/cmOrganizePromotions/form?type=1&productIds=" + items1 + "&giftIds=" + items + "&mode=" + mode +
  239. "&delProductIds="+delProductIds+"&delGiftIds="+delGiftIds+
  240. "&reducedPrice=" + reducedPrice + "&touchPrice1=" + touchPrice1 + "&touchPrice2=" + touchPrice2 + "&touchPrice3=" + touchPrice3 +
  241. "&status=" + status + "&beginTime=" + beginTime + "&endTime=" + endTime + "&delFlag1=" + delFlag1 + "&id=${cmOrganizePromotion.id}&organizeId=" + organizeId;
  242. }
  243. $.jBox.tip(data.msg, 'info');
  244. } else {
  245. $.jBox.tip(data.msg, 'error');
  246. }
  247. }, "JSON");//这里返回的类型有:json,html,xml,text
  248. return true;
  249. } else {
  250. top.$.jBox.tip("请先勾选商品...");
  251. return false;
  252. }
  253. }
  254. return true;
  255. }
  256. });
  257. }
  258. function deleteProduct(obj, storeStatus,type) {
  259. //将该行数据取消勾选,若存在数据库中则将其删除
  260. debugger
  261. $(".check-item[value=" + obj + "]").prop("checked", false);
  262. var delProductIds = $("#delProductIds").val();
  263. var delGiftIds = $("#delGiftIds").val();
  264. if (storeStatus && type == 1) {
  265. if (delProductIds != '') {
  266. delProductIds = delProductIds + "," + obj;
  267. }else delProductIds = obj;
  268. }
  269. if (storeStatus && type == 2) {
  270. if (delGiftIds != '') {
  271. delGiftIds = delGiftIds + "," + obj;
  272. }else delGiftIds = obj;
  273. }
  274. window.setTimeout(function () {
  275. var productItems = getCheckedItems(1);
  276. var giftItems = getCheckedItems(2);
  277. var mode = $("input[name='mode']:checked").val();
  278. var reducedPrice = $("#reducedPrice").val();
  279. var touchPrice1 = $("#touchPrice1").val();
  280. var touchPrice2 = $("#touchPrice2").val();
  281. var touchPrice3 = $("#touchPrice3").val();
  282. var status = $("input[name='status']:checked").val();
  283. var beginTime = $("#beginTime").val();
  284. var endTime = $("#endTime").val();
  285. var delFlag1 = $("input[name='delFlag1']:checked").val();
  286. var organizeId = $("#organizeId").val();
  287. window.location.href = "${ctx}/weisha/cmOrganizePromotions/form?type=1&productIds=" + productItems + "&giftIds=" + giftItems +
  288. "&delProductIds="+delProductIds+"&delGiftIds="+delGiftIds+ "&mode=" + mode +
  289. "&reducedPrice=" + reducedPrice + "&touchPrice1=" + touchPrice1 + "&touchPrice2=" + touchPrice2 + "&touchPrice3=" + touchPrice3 +
  290. "&status=" + status + "&beginTime=" + beginTime + "&endTime=" + endTime + "&delFlag1=" + delFlag1 + "&id=${cmOrganizePromotion.id}" +
  291. "&searchDbFlag=0&organizeId=" + organizeId;
  292. },100)
  293. }
  294. function getCheckedItems(type) {
  295. debugger
  296. var items = new Array();
  297. var $items = type==0? $('.check-item:checked'):type==1?$("#productCheckItem:checked"):$("#giftCheckItem:checked");
  298. $items.each(function () {
  299. items.push($(this).val());
  300. });
  301. return items;
  302. }
  303. </script>
  304. </head>
  305. <body>
  306. <ul class="nav nav-tabs">
  307. <li><a href="${ctx}/weisha/cmMallOrganize/">组织列表</a></li>
  308. <li><a href="${ctx}/weisha/cmOrganizePromotions/list?type=1&organizeId=${cmOrganizePromotion.organizeId}">单品促销</a></li>
  309. <li class="active"><a href="${ctx}/weisha/cmOrganizePromotions/form?id=${cmOrganizePromotion.id}&type=1&organizeId=${cmOrganizePromotion.organizeId}">${not empty cmOrganizePromotion.id?'编辑':'添加'}单品促销</a></li>
  310. </ul><br/>
  311. <input hidden="hidden" id="price1" value="${price1}">
  312. <form:form id="inputForm" modelAttribute="cmOrganizePromotion" action="${ctx}/weisha/cmOrganizePromotions/save" method="post" class="form-horizontal">
  313. <form:hidden path="id"/>
  314. <form:hidden path="organizeId"/>
  315. <form:hidden path="type"/>
  316. <form:hidden path="productIds" id="productIds"/>
  317. <form:hidden path="giftIds" id="giftIds"/>
  318. <form:hidden path="shopIds" id="shopIds"/>
  319. <form:hidden path="delProductIds" id="delProductIds"/>
  320. <form:hidden path="delGiftIds" id="delGiftIds"/>
  321. <form:hidden path="searchDbFlag" id="searchDbFlag"/>
  322. <sys:message content="${message}"/>
  323. <div class="control-group">
  324. <label><label style="color: red">*</label>促销商品:</label>
  325. <label><a href="JavaScript:;" onclick="showSelect(1)">请选择促销单品</a></label>
  326. <c:if test="${cmOrganizePromotion.promotionProducts !=null and cmOrganizePromotion.promotionProducts.size()>0}">
  327. <table id="contentTable" class="table table-striped table-bordered table-condensed">
  328. <thead>
  329. <th style="width:20px;" class="hide"></th>
  330. <th>商品图片</th>
  331. <th>商品名称</th>
  332. <th>供应商</th>
  333. <th>机构价</th>
  334. <th>操作</th>
  335. </thead>
  336. <tbody id="contentTbody">
  337. <c:forEach items="${cmOrganizePromotion.promotionProducts}" var="product">
  338. <tr>
  339. <th class="hide"><input class="check-item" type="checkbox" id="productCheckItem"
  340. name="info" ${product.storeStatus?'':'checked'}
  341. value='${product.productID}'/></th>
  342. <td><img src="${product.mainImage}" width="50px" height="50px"></td>
  343. <td>${product.name}</td>
  344. <td>${product.shopName}</td>
  345. <td>${product.price}</td>
  346. <td>
  347. <a href="javaScript:;"
  348. onclick="deleteProduct('${product.productID}',${product.storeStatus},1)">删除</a>
  349. </td>
  350. </tr>
  351. </c:forEach>
  352. </tbody>
  353. </table>
  354. </c:if>
  355. </div>
  356. <div class="control-group" id="promotionType">
  357. <label>促销方式:</label>
  358. <input type="radio" id="promotionType1" name="mode" value="1" ${cmOrganizePromotion.mode == null ? "checked" : cmOrganizePromotion.mode == "1"?"checked":""} />优惠价
  359. <input type="radio" id="promotionType2" name="mode" value="2" ${cmOrganizePromotion.mode == "2" ? "checked" : ""} />满减
  360. <input type="radio" id="promotionType3" name="mode" value="3" ${cmOrganizePromotion.mode == "3" ? "checked" : ""} />满赠
  361. </div>
  362. <div class="control-group">
  363. <label style="display: inline"><label style="color: red">*</label>优惠内容:</label>
  364. <div id="discountContent1" style="display: ${cmOrganizePromotion.mode == null ? "inline" : cmOrganizePromotion.mode == "1"?"inline":"none"}" >
  365. <label><font color="red">优惠价</font></label>
  366. <form:input path="touchPrice1" id="touchPrice1" htmlEscape="false" maxlength="7" class="input-xlarge " onkeyup="onlynum(this)"/>
  367. </div>
  368. <div id="discountContent2" style="display: ${cmOrganizePromotion.mode == "2" ? "inline" : "none"}">
  369. <label><font color="red">满</font></label>
  370. <form:input path="touchPrice2" id="touchPrice2" htmlEscape="false" maxlength="7" class="input-xlarge " onkeyup="onlynum(this)"/>
  371. <label><font color="red">减</font></label>
  372. <form:input path="reducedPrice" id="reducedPrice" htmlEscape="false" maxlength="7" class="input-xlarge " onkeyup="onlynum(this)"/>
  373. </div>
  374. <div id="discountContent3" style="display: ${cmOrganizePromotion.mode == "3" ? "inline" : "none"}">
  375. <label><font color="red">满</font></label>
  376. <form:input path="touchPrice3" id="touchPrice3" htmlEscape="false" maxlength="7" class="input-xlarge" onkeyup="onlynum(this)"/>
  377. <label><a href="JavaScript:;" onclick="showSelect(2)">请选择赠品</a></label>
  378. <c:if test="${cmOrganizePromotion.giftProducts !=null and cmOrganizePromotion.giftProducts.size()>0}">
  379. <table id="contentTable" class="table table-striped table-bordered table-condensed">
  380. <thead>
  381. <th style="width:20px;" class="hide"></th>
  382. <th></th>
  383. <th>商品图片</th>
  384. <th>商品名称</th>
  385. <th>供应商</th>
  386. <th>数量</th>
  387. <th>操作</th>
  388. </thead>
  389. <tbody id="contentTbody1">
  390. <c:forEach items="${cmOrganizePromotion.giftProducts}" var="product">
  391. <tr>
  392. <td>赠</td>
  393. <th class="hide"><input class="check-item" type="checkbox" id="giftCheckItem"
  394. name="gift" ${product.storeStatus?'':'checked'}
  395. value='${product.productID}'/></th>
  396. <td><img src="${product.mainImage}" width="50px" height="50px"></td>
  397. <td>${product.name}</td>
  398. <td>${product.shopName}</td>
  399. <td><input id="actPrice1" name="giftNumber" style="width:50px;"
  400. value="${product.giftNumber}" type="number" maxlength="7" step="1"></td>
  401. <td>
  402. <a href="javaScript:;"
  403. onclick="deleteProduct('${product.productID}',${product.storeStatus},2)">删除</a>
  404. </td>
  405. </tr>
  406. </c:forEach>
  407. </tbody>
  408. </table>
  409. </c:if>
  410. </div>
  411. </div>
  412. <div class="control-group">
  413. <label>促销时效:</label>
  414. <input type="radio" name="status" value="1" ${cmOrganizePromotion.status == null ? "checked" : cmOrganizePromotion.status == "1"?"checked":""} />永久
  415. <input type="radio" name="status" value="2" ${cmOrganizePromotion.status == "2" ? "checked" : ""} />区间有效
  416. </div>
  417. <div class="control-group" id="begin" style="display: ${cmOrganizePromotion.status == null ? "none" : cmOrganizePromotion.status == "1"?"none":""}" >
  418. <label>开始时间:</label>
  419. <input name="beginTime" type="text" readonly="readonly" maxlength="20"
  420. class="input-medium Wdate required" id="beginTime"
  421. value="<fmt:formatDate value="${cmOrganizePromotion.beginTime}" pattern="yyyy-MM-dd HH:mm:ss"/>"
  422. onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});"/>
  423. </div>
  424. <div class="control-group" id="end" style="display: ${cmOrganizePromotion.status == null ? "none" : cmOrganizePromotion.status == "1"?"none":""}" >
  425. <label>结束时间:</label>
  426. <input name="endTime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate required"
  427. id="endTime"
  428. value="<fmt:formatDate value="${cmOrganizePromotion.endTime}" pattern="yyyy-MM-dd HH:mm:ss"/>"
  429. onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});"/>
  430. </div>
  431. <div class="control-group">
  432. <label style="display: inline" id="testStatus">促销状态:</label>
  433. <label style="display: inline;color: ${cmOrganizePromotion.delFlag1 == null || cmOrganizePromotion.delFlag1 == '' ?"green":cmOrganizePromotion.delFlag1 == "0"?"red":cmOrganizePromotion.delFlag1 == "1"?"purple":cmOrganizePromotion.delFlag1 == "2"?"green":"orange"}" id="promotionStatus" >${cmOrganizePromotion.delFlag1 == null || cmOrganizePromotion.delFlag1 == '' ?"进行中":cmOrganizePromotion.delFlag1 == "0"?"已关闭":cmOrganizePromotion.delFlag1 == "1"?"未开始":cmOrganizePromotion.delFlag1 == "2"?"进行中":"已结束"}</label>
  434. <input type="checkbox" id="delFlag1" name="delFlag1" value="close" ${cmOrganizePromotion.delFlag1 == null?"":cmOrganizePromotion.delFlag1 == "0" ? "checked" : ""} />关闭
  435. </div>
  436. <div class="form-actions">
  437. <input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>
  438. <a href="${ctx}/weisha/cmOrganizePromotions/?type=1&organizeId=${cmOrganizePromotion.organizeId}"><input id="btnCancel" class="btn" type="button" value="返 回" /></a>
  439. </div>
  440. </form:form>
  441. <script type="text/javascript">
  442. $(function () {
  443. })
  444. //促销方式修改
  445. $("input:radio[name='mode']").click(function () {
  446. var promotionType = $("input[name='mode']:checked").val();
  447. if ("1" == promotionType) {
  448. $("#discountContent1").attr("style","display:inline");
  449. $("#discountContent2").attr("style","display:none");
  450. $("#discountContent3").attr("style","display:none");
  451. }else if ("2" == promotionType) {
  452. $("#discountContent1").attr("style","display:none");
  453. $("#discountContent2").attr("style","display:inline");
  454. $("#discountContent3").attr("style","display:none");
  455. } else {
  456. $("#discountContent1").attr("style","display:none");
  457. $("#discountContent2").attr("style","display:none");
  458. $("#discountContent3").attr("style","display:inline");
  459. }
  460. })
  461. //促销时效修改
  462. $("input:radio[name='status']").click(function () {
  463. var promotionStatus = $("input[name='status']:checked").val();
  464. var promotiondelFlag1 = $("input[name='delFlag1']:checked").val();
  465. if ("1" == promotionStatus) {
  466. $("#begin").attr("style","display:none");
  467. $("#end").attr("style","display:none");
  468. if (null == promotiondelFlag1) {
  469. $("#promotionStatus").text("进行中");
  470. $("#promotionStatus").attr("style", "display: inline;color:green");
  471. }
  472. }else if ("2" == promotionStatus) {
  473. $("#begin").attr("style","");
  474. $("#end").attr("style","");
  475. if (null == promotiondelFlag1) {
  476. updateStatus();
  477. }
  478. }
  479. })
  480. //促销日期修改
  481. $("#beginTime").blur(function () {
  482. var promotiondelFlag1 = $("input[name='delFlag1']:checked").val();
  483. if (null == promotiondelFlag1) updateStatus()
  484. });
  485. $("#endTime").blur(function () {
  486. var promotiondelFlag1 = $("input[name='delFlag1']:checked").val();
  487. if (null == promotiondelFlag1) updateStatus()
  488. });
  489. //促销状态修改
  490. $("input:checkbox[name='delFlag1']").click(function () {
  491. var promotiondelFlag1 = $("input[name='delFlag1']:checked").val();
  492. if (promotiondelFlag1 != null) {
  493. $("#promotionStatus").text("已关闭");
  494. $("#promotionStatus").attr("style", "display: inline;color:red");
  495. }else {
  496. var promotionStatus = $("input[name='status']:checked").val();
  497. if ("1" == promotionStatus) {
  498. $("#promotionStatus").text("进行中");
  499. $("#promotionStatus").attr("style", "display: inline;color:green");
  500. } else updateStatus()
  501. }
  502. })
  503. function updateStatus() {
  504. var beginTime = $("#beginTime").val();
  505. var beginMs = new Date(beginTime).getTime();
  506. var endTime = $("#endTime").val();
  507. var endMs = new Date(endTime).getTime();
  508. var nowMs = new Date().getTime();
  509. if (nowMs < beginMs) {
  510. $("#promotionStatus").text("未开始");
  511. $("#promotionStatus").attr("style", "display: inline;color:purple");
  512. } else if (nowMs > endMs) {
  513. $("#promotionStatus").text("已结束");
  514. $("#promotionStatus").attr("style", "display: inline;color:orange");
  515. } else {
  516. $("#promotionStatus").text("进行中");
  517. $("#promotionStatus").attr("style", "display: inline;color:green");
  518. }
  519. }
  520. /**
  521. * @param obj
  522. * jquery控制input只能输入数字
  523. */
  524. function onlynum(obj) {
  525. obj.value = obj.value.replace(/[^\d]/g, ""); //清除"数字"以外的字符
  526. }
  527. </script>
  528. </body>
  529. </html>