cmHeheDiscountForm.jsp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. <%@ page import="java.util.Date" %>
  2. <%@ page contentType="text/html;charset=UTF-8" %>
  3. <%@ include file="/WEB-INF/views/include/taglib.jsp"%>
  4. <html>
  5. <head>
  6. <title>内部优惠管理</title>
  7. <meta name="decorator" content="default"/>
  8. <script type="text/javascript">
  9. $(document).ready(function() {
  10. //$("#name").focus();
  11. $("#inputForm").validate({
  12. submitHandler: function(form){
  13. if (imageList.length > 0) {
  14. var productInfo = JSON.stringify(imageList);
  15. $('#productInfo').val(productInfo);
  16. }
  17. if (userList.length > 0) {
  18. var userInfo = JSON.stringify(userList);
  19. $("#userInfo").val(userInfo);
  20. }
  21. loading('正在提交,请稍等...');
  22. form.submit();
  23. },
  24. errorContainer: "#messageBox",
  25. errorPlacement: function(error, element) {
  26. $("#messageBox").text("输入有误,请先更正。");
  27. if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
  28. error.appendTo(element.parent().parent());
  29. } else {
  30. error.insertAfter(element);
  31. }
  32. }
  33. });
  34. });
  35. /**
  36. * @param obj
  37. * jquery控制input只能输入数字
  38. */
  39. function onlynum(obj) {
  40. obj.value = obj.value.replace(/[^\d]/g, ""); //清除"数字"以外的字符
  41. }
  42. function changeDiscount(){
  43. var discount = Number($("#discount").val()).toFixed(2);
  44. if (discount > 100 || discount <= 0) {
  45. $.jBox.tip("请输入0-100之间的数字", 'info');
  46. $("#discount").val('');
  47. }
  48. }
  49. </script>
  50. </head>
  51. <body>
  52. <ul class="nav nav-tabs">
  53. <li><a href="${ctx}/hehe/cmHeheDiscount/">内部优惠列表</a></li>
  54. <li class="active"><a href="${ctx}/hehe/cmHeheDiscount/form?id=${cmHeheDiscount.id}">${not empty cmHeheDiscount.id?'编辑':'添加'}</a></li>
  55. </ul><br/>
  56. <form:form id="inputForm" modelAttribute="cmHeheDiscount" action="${ctx}/hehe/cmHeheDiscount/save" method="post" class="form-horizontal">
  57. <form:hidden path="id"/>
  58. <form:hidden path="productInfo"/>
  59. <form:hidden path="userInfo"/>
  60. <sys:message content="${message}"/>
  61. <div class="control-group">
  62. <label class="control-label"><font color="red">*</font>标题:</label>
  63. <div class="controls">
  64. <form:input path="title" htmlEscape="false" maxlength="30" placeholder="30个汉字以内" class="input-xlarge required"/>
  65. </div>
  66. </div>
  67. <div class="control-group">
  68. <label class="control-label"><font color="red">*</font>折扣率:</label>
  69. <div class="controls">
  70. <form:input path="discount" htmlEscape="false" onkeyup="onlynum(this)" onchange="changeDiscount()" class="input-xlarge digits required"/> %
  71. </div>
  72. </div>
  73. <div class="control-group">
  74. <label class="control-label"><font color="red">*</font>状态:</label>
  75. <div class="controls">
  76. <form:select path="status" class="input-medium required">
  77. <form:option value="1" label="启用"/>
  78. <form:option value="0" label="停用"/>
  79. </form:select>
  80. </div>
  81. </div>
  82. <div class="control-group">
  83. <label class="control-label"><font color="red">*</font>优惠商品:</label>
  84. <div class="controls">
  85. <form:radiobutton path="productType" value="1" label="全商城商品" onclick="productShow()" checked="${empty cmHeheDiscount.productType ? true:false}"/>
  86. <form:radiobutton path="productType" value="2" label="指定商品" onclick="productShow()" />
  87. </div>
  88. </div>
  89. <div class="productData" hidden="hidden">
  90. <div class="control-group">
  91. <input class="btn" id="productDel" style="width: 50px" onclick="productBatchDeletion()" value="删除"/>&nbsp;&nbsp;&nbsp;&nbsp;
  92. <input class="btn btn-primary" style="width: 70px" onclick="batchSaveProductSort()" value="一键排序"/>&nbsp;&nbsp;&nbsp;&nbsp;
  93. <input class="btn btn-primary" style="width: 50px" onclick="productShowSelect()" value="添加"/>
  94. <br><br>
  95. <table id="productTable" class="table table-striped table-bordered table-condensed" hidden="hidden">
  96. <thead>
  97. <tr>
  98. <th style="width:20px;"><input class="check-all" type="checkbox" onclick="clickAllSelect(this,1);"/> 全选
  99. </th>
  100. <th>商品图片</th>
  101. <th>商品名称</th>
  102. <th>供应商</th>
  103. <th>状态</th>
  104. <th>排序</th>
  105. <th>添加时间</th>
  106. <th>操作</th>
  107. </tr>
  108. </thead>
  109. <tbody id="productTbody"></tbody>
  110. </table>
  111. </div>
  112. </div>
  113. <div class="control-group">
  114. <label class="control-label"><font color="red">*</font>用户列表:</label>
  115. </div>
  116. <div class="userData">
  117. <div class="control-group">
  118. <input class="btn" id="userDel" style="width: 50px" onclick="userBatchDeletion()" value="删除"/>&nbsp;&nbsp;&nbsp;&nbsp;
  119. <input class="btn btn-primary" style="width: 50px" onclick="userShowSelect()" value="添加"/>
  120. <br><br>
  121. <table id="userTable" class="table table-striped table-bordered table-condensed" hidden="hidden">
  122. <thead>
  123. <tr>
  124. <th style="width:20px;"><input class="check-all" type="checkbox" onclick="clickAllSelect(this,2);"/> 全选
  125. </th>
  126. <th>微信昵称</th>
  127. <th>手机号</th>
  128. <th>身份</th>
  129. <th>添加时间</th>
  130. <th>操作</th>
  131. </tr>
  132. </thead>
  133. <tbody id="userTbody"></tbody>
  134. </table>
  135. </div>
  136. </div>
  137. <div class="form-actions">
  138. <input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;
  139. <input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
  140. </div>
  141. </form:form>
  142. <script>
  143. var productIds = '';
  144. var imageList = [];
  145. var userIds = '';
  146. var userList = [];
  147. $(function () {
  148. <c:forEach items="${productList}" var="product" varStatus="index">
  149. imageList.push({
  150. id: "${product.id}",
  151. productId: "${empty product.productId ? "":product.productId}",
  152. image: "${product.image}",
  153. productName: "${product.productName}",
  154. shopName: "${product.shopName}",
  155. sort: "${product.sort}",
  156. status: "${product.status}",
  157. addTime: "<fmt:formatDate value="${product.addTime}" pattern="yyyy-MM-dd HH:mm:ss"/>"
  158. });
  159. </c:forEach>
  160. debugger
  161. <c:forEach items="${userList}" var="user" varStatus="index">
  162. userList.push({
  163. userId: "${user.userId}",
  164. nickName: "${user.nickName}",
  165. mobile: "${user.mobile}",
  166. userIdentity: "${user.userIdentity}",
  167. addTime: "<fmt:formatDate value="${user.addTime}" pattern="yyyy-MM-dd HH:mm:ss"/>"
  168. });
  169. </c:forEach>
  170. if (imageList.length > 0) {
  171. $('#productTable').show();
  172. batchSaveProductSort();
  173. }
  174. if (userList.length > 0) {
  175. $('#userTable').show();
  176. batchSaveUserSort();
  177. }
  178. productShow();
  179. });
  180. //商品添加
  181. function productShowSelect() {
  182. var url = "${ctx}/hehe/cmHeheDiscount/toAddProduct?productIds=" + productIds;
  183. var title = '';
  184. title = "选择商品";
  185. top.$.jBox("iframe:" + url, {
  186. iframeScrolling: 'yes',
  187. width: $(top.document).width() - 400,
  188. height: $(top.document).height() - 160,
  189. persistent: true,
  190. title: title,
  191. buttons: {"确定": '1', "取消": '-1'},
  192. submit: function (v, h, f) {
  193. //确定
  194. var $jboxFrame = top.$('#jbox-iframe');
  195. var $mainFrame = top.$('#mainFrame');
  196. if ('1' == v && 1 == $jboxFrame.size() && 1 == $mainFrame.size()) {
  197. var items = $jboxFrame[0].contentWindow.getCheckedItems();
  198. console.log(items);
  199. console.log(items[0]);
  200. for (var i = 0; i < items.length; i++) {
  201. console.log(items[i]);
  202. imageList.push(items[i]);
  203. $('#productTable').show();
  204. $("#productDel").removeAttr("disabled");
  205. batchSaveProductSort();
  206. };
  207. }
  208. return true;
  209. }
  210. });
  211. }
  212. //用户添加
  213. function userShowSelect() {
  214. debugger
  215. var url = "${ctx}/hehe/cmHeheDiscount/toAddUser?userIds=" + userIds;
  216. var title = '';
  217. title = "选择用户";
  218. top.$.jBox("iframe:" + url, {
  219. iframeScrolling: 'yes',
  220. width: $(top.document).width() - 400,
  221. height: $(top.document).height() - 160,
  222. persistent: true,
  223. title: title,
  224. buttons: {"确定": '1', "取消": '-1'},
  225. submit: function (v, h, f) {
  226. //确定
  227. var $jboxFrame = top.$('#jbox-iframe');
  228. var $mainFrame = top.$('#mainFrame');
  229. if ('1' == v && 1 == $jboxFrame.size() && 1 == $mainFrame.size()) {
  230. var items = $jboxFrame[0].contentWindow.getCheckedItems();
  231. console.log(items);
  232. console.log(items[0]);
  233. for (var i = 0; i < items.length; i++) {
  234. console.log(items[i]);
  235. userList.push(items[i]);
  236. $('#userTable').show();
  237. $("#userDel").removeAttr("disabled");
  238. batchSaveUserSort();
  239. };
  240. }
  241. return true;
  242. }
  243. });
  244. }
  245. /**
  246. * 一键排序
  247. */
  248. function batchSaveProductSort() {
  249. imageList.sort(sort);
  250. productInsertHtml(imageList);
  251. }
  252. /**
  253. * 一键排序
  254. */
  255. function batchSaveUserSort() {
  256. userInsertHtml(userList);
  257. }
  258. //根据sort值 从小到大排序
  259. function sort(a, b) {
  260. return a.sort - b.sort;
  261. }
  262. //相关图片列表数据
  263. function appendProduct(data, index) {
  264. var html = '<tr id ="ai' + index + '">' +
  265. '<td>' +
  266. '<input class="product-check-item" type="checkbox" name="info" value="' + index + '"/>' + (index + 1) +
  267. '</td>' +
  268. '<td>' +
  269. '<img src="' + data.image + '" width="60px" border="none" title="启用">' +
  270. '</td>' +
  271. '<td>' +
  272. data.productName +
  273. '</td>' +
  274. '<td>' +
  275. data.shopName +
  276. '</td>' +
  277. '<td>' +
  278. (data.status == 1 ? (
  279. '<font color="green">已启用</font>&nbsp;&nbsp;&nbsp;' +
  280. '<a href="javascript:void(0);" onclick="updateStatus(0,' + index + ');" >' +
  281. '停用</a>'
  282. ) : (
  283. '<font color="red">已停用</font>&nbsp;&nbsp;&nbsp;' +
  284. '<a href="javascript:void(0)" onclick="updateStatus(1,' + index + ');">' +
  285. '启用</a>'
  286. )) +
  287. '</td>' +
  288. '</td>' +
  289. '<td>' +
  290. '<input name="sort" style="width:50px;" value="' + data.sort + '" onkeyup="onlynum(this)" onchange="changeSort(' + index + ',this)"></td>' +
  291. '</td>' +
  292. '<td>' +
  293. (data.addTime == '' ? (
  294. '<fmt:formatDate value="<%=new Date()%>" pattern="yyyy-MM-dd HH:mm:ss"/>'
  295. ) : (
  296. data.addTime
  297. )) +
  298. '</td>' +
  299. '<td>' +
  300. '<a href="javascript:;" onclick="productDelete(' + index + ')">删除</a>' +
  301. '</td>' +
  302. '</tr>';
  303. return html;
  304. }
  305. //相关用户列表数据
  306. function appendUser(data, index) {
  307. var html = '<tr id ="ai' + index + '">' +
  308. '<td>' +
  309. '<input class="user-check-item" type="checkbox" name="info" value="' + index + '"/>' + (index + 1) +
  310. '</td>' +
  311. '<td>' +
  312. data.nickName +
  313. '</td>' +
  314. '<td>' +
  315. data.mobile +
  316. '</td>' +
  317. '<td>' +
  318. (data.userIdentity === 1 ? '普通用户':'分销者') +
  319. '</td>' +
  320. '<td>' +
  321. (data.addTime == '' ? (
  322. '<fmt:formatDate value="<%=new Date()%>" pattern="yyyy-MM-dd HH:mm:ss"/>'
  323. ) : (
  324. data.addTime
  325. )) +
  326. '</td>' +
  327. '<td>' +
  328. '<a href="javascript:;" onclick="userDelete(' + index + ')">删除</a>' +
  329. '</td>' +
  330. '</tr>';
  331. return html;
  332. }
  333. function productInsertHtml(list) {
  334. var html = '';
  335. productIds = '';
  336. list.forEach(function (item, index) {
  337. html += appendProduct(item, index);
  338. productIds += "," + item.productId;
  339. });
  340. $("#productTbody").html(html);
  341. }
  342. function userInsertHtml(list) {
  343. var html = '';
  344. userIds = '';
  345. list.forEach(function (item, index) {
  346. html += appendUser(item, index);
  347. userIds += "," + item.userId;
  348. });
  349. $("#userTbody").html(html);
  350. }
  351. function changeSort(index, sortThis) {
  352. var sort = sortThis.value;
  353. if (sort <= 0) {
  354. }
  355. var image = imageList[index];
  356. image.sort = sort;
  357. }
  358. function updateStatus(status, index) {
  359. var image = imageList[index];
  360. confirmx(status == 0 ? '确定停用吗?' : '确定启用吗?', function () {
  361. image.status = status;
  362. batchSaveProductSort();
  363. })
  364. }
  365. function clickAllSelect(ckb, type) {
  366. var isChecked = ckb.checked;
  367. if (type === 1) {
  368. $(".product-check-item").attr('checked', isChecked);
  369. } else {
  370. $(".user-check-item").attr('checked', isChecked);
  371. }
  372. }
  373. /**
  374. * 商品删除操作
  375. */
  376. function productDelete(index) {
  377. return confirmx("确定删除吗?", function () {
  378. var image = imageList[index];
  379. if (image.productId != '') {
  380. productIds = productIds.replace(image.productId,"");
  381. }
  382. imageList.splice(index, 1);
  383. productInsertHtml(imageList);
  384. if (imageList.length == 0) {
  385. $('#productTable').hide();
  386. $("#productDel").attr("disabled", "disabled");
  387. }
  388. });
  389. }
  390. /**
  391. * 用户删除操作
  392. */
  393. function userDelete(index) {
  394. return confirmx("确定删除吗?", function () {
  395. var user = userList[index];
  396. if (user.userId != '') {
  397. userIds = userIds.replace(user.userId,"");
  398. }
  399. userList.splice(index, 1);
  400. userInsertHtml(userList);
  401. if (userList.length == 0) {
  402. $('#userTable').hide();
  403. $("#userDel").attr("disabled", "disabled");
  404. }
  405. });
  406. }
  407. /**
  408. * 批量删除商品
  409. */
  410. function productBatchDeletion() {
  411. var index = -1;
  412. var i = 1;
  413. return confirmx("确定删除吗?", function () {
  414. $('input[name="info"]:checked').each(function () {
  415. var thisIndex = $(this).val();
  416. if (index >= 0 && index < thisIndex) {
  417. thisIndex = thisIndex - i;
  418. i++;
  419. } else {
  420. index = thisIndex;
  421. }
  422. var image = imageList[thisIndex];
  423. if (image.productId != '') {
  424. productIds = productIds.replace(image.productId, "");
  425. }
  426. imageList.splice(thisIndex, 1);
  427. productInsertHtml(imageList);
  428. if (imageList.length == 0) {
  429. $('#productTable').hide();
  430. $("#productDel").attr("disabled", "disabled");
  431. }
  432. });
  433. });
  434. }
  435. /**
  436. * 批量删除用户
  437. */
  438. function userBatchDeletion() {
  439. var index = -1;
  440. var i = 1;
  441. return confirmx("确定删除吗?", function () {
  442. $('input[name="info"]:checked').each(function () {
  443. var thisIndex = $(this).val();
  444. if (index >= 0 && index < thisIndex) {
  445. thisIndex = thisIndex - i;
  446. i++;
  447. } else {
  448. index = thisIndex;
  449. }
  450. var user = userList[thisIndex];
  451. if (user.userId != '') {
  452. userIds = userIds.replace(user.userId, "");
  453. }
  454. userList.splice(thisIndex, 1);
  455. userInsertHtml(userList);
  456. if (userList.length == 0) {
  457. $('#userTable').hide();
  458. $("#userDel").attr("disabled", "disabled");
  459. }
  460. });
  461. });
  462. }
  463. function productShow() {
  464. var productType = $("input[name='productType']:checked").val();
  465. if (productType == 2){
  466. $(".productData").show();
  467. }else {
  468. $(".productData").hide();
  469. }
  470. }
  471. </script>
  472. </body>
  473. </html>