cmHeheCouponForm.jsp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  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. <style>
  9. .formCheck{
  10. margin-left: 20px !important;
  11. }
  12. </style>
  13. <script type="text/javascript">
  14. $(document).ready(function() {
  15. //$("#name").focus();
  16. $("#inputForm").validate({
  17. submitHandler: function(form){
  18. var productType = $("input[name='productType']:checked").val() * 1;
  19. if (productType === 2 && imageList.length <= 0) {
  20. alertx("请先添加商品");
  21. return false;
  22. }
  23. var couponType = $("#couponType").val() * 1;
  24. if (couponType === 2 && userList.length <= 0) {
  25. alertx("请先添加用户");
  26. return false;
  27. }
  28. if (imageList.length > 0) {
  29. var productInfo = JSON.stringify(imageList);
  30. $('#productInfo').val(productInfo);
  31. }
  32. if (userList.length > 0) {
  33. var userInfo = JSON.stringify(userList);
  34. $("#userInfo").val(userInfo);
  35. }
  36. var couponAmount = $("#couponAmount").val()*1;
  37. var touchPrice = $("#touchPrice").val()*1;
  38. var noThresholdFlag = $("#noThresholdFlag").val() * 1;
  39. if (noThresholdFlag === 0 && couponAmount >= touchPrice) {
  40. alertx("优惠券金额必须小于优惠条件金额");
  41. return false;
  42. }
  43. var startNowFlag = $("#startNowFlag").val() * 1;
  44. var permanentFlag = $("#permanentFlag").val() * 1;
  45. var startTime = $("#startTime").val();
  46. var endTime = $("#endTime").val();
  47. if (startNowFlag === 1 && startTime == '') {
  48. startTime = new Date().format("yyyy-MM-dd hh:mm");
  49. }
  50. if (permanentFlag === 0 && startTime >= endTime) {
  51. alertx("下架时间不能早于上架时间");
  52. return false;
  53. }
  54. loading('正在提交,请稍等...');
  55. form.submit();
  56. },
  57. errorContainer: "#messageBox",
  58. errorPlacement: function(error, element) {
  59. $("#messageBox").text("输入有误,请先更正。");
  60. if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
  61. error.appendTo(element.parent().parent());
  62. } else {
  63. error.insertAfter(element);
  64. }
  65. }
  66. });
  67. });
  68. Date.prototype.format = function(fmt) {
  69. var o = {
  70. "M+" : this.getMonth()+1, //月份
  71. "d+" : this.getDate(), //日
  72. "h+" : this.getHours(), //小时
  73. "m+" : this.getMinutes(), //分
  74. "s+" : this.getSeconds(), //秒
  75. "q+" : Math.floor((this.getMonth()+3)/3), //季度
  76. "S" : this.getMilliseconds() //毫秒
  77. };
  78. if(/(y+)/.test(fmt)) {
  79. fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
  80. }
  81. for(var k in o) {
  82. if(new RegExp("("+ k +")").test(fmt)){
  83. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
  84. }
  85. }
  86. return fmt;
  87. }
  88. /**
  89. * @param obj
  90. * jquery控制input只能输入数字
  91. */
  92. function onlynum(obj) {
  93. obj.value = obj.value.replace(/[^\d]/g, ""); //清除"数字"以外的字符
  94. }
  95. </script>
  96. </head>
  97. <body>
  98. <ul class="nav nav-tabs">
  99. <li><a href="${ctx}/hehe/cmHeheCoupon/?couponType=${cmHeheCoupon.couponType}">优惠券列表</a></li>
  100. <li class="active"><a href="${ctx}/hehe/cmHeheCoupon/form?id=${cmHeheCoupon.id}&couponType=${cmHeheCoupon.couponType}">${not empty cmHeheCoupon.id?'编辑':'添加'}${cmHeheCoupon.couponType eq 1?'活动':cmHeheCoupon.couponType eq 2?'专享':cmHeheCoupon.couponType eq 3?'新人':cmHeheCoupon.couponType eq 4?'好友邀请':'好友消费'}券</a></li>
  101. </ul><br/>
  102. <form:form id="inputForm" modelAttribute="cmHeheCoupon" action="${ctx}/hehe/cmHeheCoupon/save" method="post" class="form-horizontal">
  103. <form:hidden path="id"/>
  104. <form:hidden path="productInfo"/>
  105. <form:hidden path="userInfo"/>
  106. <form:hidden path="couponType"/>
  107. <sys:message content="${message}"/>
  108. <form:hidden path="noThresholdFlag"/>
  109. <form:hidden path="startNowFlag"/>
  110. <form:hidden path="permanentFlag"/>
  111. <form:hidden path="receiveFlag"/>
  112. <div class="control-group">
  113. <label class="control-label"><font color="red">*</font>优惠券名称:</label>
  114. <div class="controls">
  115. <form:input path="name" htmlEscape="false" maxlength="30" placeholder="30个汉字以内" class="input-xlarge required"/>
  116. </div>
  117. </div>
  118. <div class="control-group">
  119. <label class="control-label"><font color="red">*</font>优惠券金额:</label>
  120. <div class="controls">
  121. <input type="number" id="couponAmount" name="couponAmount" value="${cmHeheCoupon.couponAmount}" min="0" required> 元
  122. </div>
  123. </div>
  124. <div class="control-group">
  125. <label class="control-label"><font color="red">*</font>优惠条件:</label>
  126. <div class="controls">
  127. 订单商品总额满
  128. <input type="number" id="touchPrice" name="touchPrice" value="${cmHeheCoupon.touchPrice}" min="0" required> 元
  129. <input type="checkbox" id="noThresholdFlag" name="noThresholdFlag" class="formCheck" value="${cmHeheCoupon.noThresholdFlag eq 1?1:0}"
  130. ${cmHeheCoupon.noThresholdFlag eq 1 ? "checked" : ""} onclick="changeCondition('noThresholdFlag','touchPrice')" />无门槛
  131. <input id="touchPriceTemp" type="hidden" value="${cmHeheCoupon.touchPrice}">
  132. </div>
  133. </div>
  134. <div class="control-group">
  135. <label class="control-label"><font color="red">*</font>上架时间:</label>
  136. <div class="controls">
  137. <input id="startTime" name="startTime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate required"
  138. value="<fmt:formatDate value="${cmHeheCoupon.startTime}" pattern="yyyy-MM-dd HH:mm"/>"
  139. onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',isShowClear:false});"/>
  140. <input type="checkbox" id="startNowFlag" name="startNowFlag" class="formCheck" value="${cmHeheCoupon.startNowFlag eq 1?1:0}" ${cmHeheCoupon.startNowFlag eq 1 ? "checked" : ""} onclick="changeCondition('startNowFlag','startTime')" />立即上架
  141. <input id="startTimeTemp" type="hidden" value="${cmHeheCoupon.startTime}">
  142. </div>
  143. </div>
  144. <div class="control-group">
  145. <label class="control-label"><font color="red">*</font>下架时间:</label>
  146. <div class="controls">
  147. <input id="endTime" name="endTime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate required"
  148. value="<fmt:formatDate value="${cmHeheCoupon.endTime}" pattern="yyyy-MM-dd HH:mm"/>"
  149. onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',isShowClear:false});"/>
  150. <input type="checkbox" id="permanentFlag" name="permanentFlag" class="formCheck" value="${cmHeheCoupon.permanentFlag eq 1?1:0}" ${cmHeheCoupon.permanentFlag eq 1 ? "checked" : ""}
  151. onclick="changeCondition('permanentFlag','endTime')" />永久
  152. <input id="endTimeTemp" type="hidden" value="${cmHeheCoupon.endTime}">
  153. </div>
  154. </div>
  155. <div class="control-group">
  156. <label class="control-label"><font color="red">*</font>领取期限:</label>
  157. <div class="controls">
  158. <input type="number" id="receivePeriod" name="receivePeriod" onkeyup="onlynum(this)" value="${cmHeheCoupon.receivePeriod}" min="1" required> 天
  159. <input type="checkbox" id="receiveFlag" name="receiveFlag" class="formCheck" value="${cmHeheCoupon.receiveFlag eq 1?1:0}" ${cmHeheCoupon.receiveFlag eq 1 ? "checked" : ""} onclick="changeCondition('receiveFlag','receivePeriod')" />同上下架时间
  160. <input id="receivePeriodTemp" type="hidden" value="${cmHeheCoupon.receivePeriod}">
  161. </div>
  162. </div>
  163. <div class="control-group">
  164. <label class="control-label"><font color="red">*</font>使用期限:</label>
  165. <div class="controls">
  166. <input type="number" id="usePeriod" name="usePeriod" value="${cmHeheCoupon.usePeriod}" min="1" onkeyup="onlynum(this)" required> 天
  167. </div>
  168. </div>
  169. <div class="control-group">
  170. <label class="control-label"><font color="red">*</font>优惠商品:</label>
  171. <div class="controls">
  172. <form:radiobutton path="productType" value="1" label="全商城商品" onclick="productShow()" checked ="${empty cmHeheCoupon.productType ? true:false}"/>
  173. <form:radiobutton path="productType" value="2" label="指定商品" onclick="productShow()"/>
  174. </div>
  175. </div>
  176. <div class="productData" hidden="hidden">
  177. <div class="control-group">
  178. <input class="btn" id="productDel" style="width: 50px" onclick="productBatchDeletion()" value="删除"/>&nbsp;&nbsp;&nbsp;&nbsp;
  179. <input class="btn btn-primary" style="width: 70px" onclick="batchSaveProductSort()" value="一键排序"/>&nbsp;&nbsp;&nbsp;&nbsp;
  180. <input class="btn btn-primary" style="width: 50px" onclick="productShowSelect()" value="添加"/>
  181. <br><br>
  182. <table id="productTable" class="table table-striped table-bordered table-condensed" hidden="hidden">
  183. <thead>
  184. <tr>
  185. <th style="width:20px;"><input class="check-all" type="checkbox" onclick="clickAllSelect(this,1);"/> 全选
  186. </th>
  187. <th>商品图片</th>
  188. <th>商品名称</th>
  189. <th>供应商</th>
  190. <th>状态</th>
  191. <th>排序</th>
  192. <th>添加时间</th>
  193. <th>操作</th>
  194. </tr>
  195. </thead>
  196. <tbody id="productTbody"></tbody>
  197. </table>
  198. </div>
  199. </div>
  200. <c:if test="${cmHeheCoupon.couponType eq 2}">
  201. <div class="control-group">
  202. <label class="control-label"><font color="red">*</font>用户列表:</label>
  203. </div>
  204. <div class="userData">
  205. <div class="control-group">
  206. <input class="btn" id="userDel" style="width: 50px" onclick="userBatchDeletion()" value="删除"/>&nbsp;&nbsp;&nbsp;&nbsp;
  207. <input class="btn btn-primary" style="width: 50px" onclick="userShowSelect()" value="添加"/>
  208. <br><br>
  209. <table id="userTable" class="table table-striped table-bordered table-condensed" hidden="hidden">
  210. <thead>
  211. <tr>
  212. <th style="width:20px;"><input class="check-all" type="checkbox" onclick="clickAllSelect(this,2);"/> 全选
  213. </th>
  214. <th>微信昵称</th>
  215. <th>手机号</th>
  216. <th>身份</th>
  217. <th>添加时间</th>
  218. <th>操作</th>
  219. </tr>
  220. </thead>
  221. <tbody id="userTbody"></tbody>
  222. </table>
  223. </div>
  224. </div>
  225. </c:if>
  226. <div class="form-actions">
  227. <input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;
  228. <input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
  229. </div>
  230. </form:form>
  231. <script>
  232. function changeCondition(flag, name) {
  233. var obj = $("#" + flag);
  234. var val = obj.val();
  235. if (val === '1') {
  236. obj.val(0);
  237. val = '0';
  238. } else {
  239. obj.val(1);
  240. val = '1';
  241. }
  242. var inputObj = $("#" + name);
  243. // 临时数据
  244. var tempObj = $("#" + name + "Temp");
  245. if (name.indexOf("Time") !== -1) {
  246. //修改时间
  247. if (val === '1') {
  248. inputObj.attr('onclick', '');
  249. inputObj.removeClass('required');
  250. } else {
  251. inputObj.attr('onclick', "WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',isShowClear:false})");
  252. inputObj.addClass('required');
  253. }
  254. }else {
  255. if (val === '1') {
  256. inputObj.attr('readonly', true);
  257. inputObj.attr('required', false);
  258. } else {
  259. inputObj.attr('readonly', false);
  260. inputObj.attr('required', true);
  261. }
  262. }
  263. if (val === '1') {
  264. tempObj.val(inputObj.val());
  265. inputObj.val('');
  266. } else {
  267. inputObj.val(tempObj.val());
  268. tempObj.val('');
  269. }
  270. }
  271. var productIds = '';
  272. var imageList = [];
  273. var userIds = '';
  274. var userList = [];
  275. $(function () {
  276. <c:forEach items="${productList}" var="product" varStatus="index">
  277. imageList.push({
  278. id: "${product.id}",
  279. productId: "${empty product.productId ? "":product.productId}",
  280. image: "${product.image}",
  281. productName: "${product.productName}",
  282. shopName: "${product.shopName}",
  283. sort: "${product.sort}",
  284. status: "${product.status}",
  285. addTime: "<fmt:formatDate value="${product.addTime}" pattern="yyyy-MM-dd HH:mm:ss"/>"
  286. });
  287. </c:forEach>
  288. <c:forEach items="${userList}" var="user" varStatus="index">
  289. userList.push({
  290. userId: "${user.userId}",
  291. nickName: "${user.nickName}",
  292. mobile: "${user.mobile}",
  293. userIdentity: "${user.userIdentity}",
  294. addTime: "<fmt:formatDate value="${user.addTime}" pattern="yyyy-MM-dd HH:mm:ss"/>"
  295. });
  296. </c:forEach>
  297. if (imageList.length > 0) {
  298. $('#productTable').show();
  299. batchSaveProductSort();
  300. }
  301. if (userList.length > 0) {
  302. $('#userTable').show();
  303. batchSaveUserSort();
  304. }
  305. initInputDisplay();
  306. productShow();
  307. });
  308. //商品添加
  309. function productShowSelect() {
  310. var url = "${ctx}/hehe/cmHeheCoupon/toAddProduct?productIds=" + productIds;
  311. var title = '';
  312. title = "选择商品";
  313. top.$.jBox("iframe:" + url, {
  314. iframeScrolling: 'yes',
  315. width: $(top.document).width() - 400,
  316. height: $(top.document).height() - 160,
  317. persistent: true,
  318. title: title,
  319. buttons: {"确定": '1', "取消": '-1'},
  320. submit: function (v, h, f) {
  321. //确定
  322. var $jboxFrame = top.$('#jbox-iframe');
  323. var $mainFrame = top.$('#mainFrame');
  324. if ('1' == v && 1 == $jboxFrame.size() && 1 == $mainFrame.size()) {
  325. var items = $jboxFrame[0].contentWindow.getCheckedItems();
  326. console.log(items);
  327. console.log(items[0]);
  328. for (var i = 0; i < items.length; i++) {
  329. console.log(items[i]);
  330. imageList.push(items[i]);
  331. $('#productTable').show();
  332. $("#productDel").removeAttr("disabled");
  333. batchSaveProductSort();
  334. };
  335. }
  336. return true;
  337. }
  338. });
  339. }
  340. //用户添加
  341. function userShowSelect() {
  342. var url = "${ctx}/hehe/cmHeheCoupon/toAddUser?userIds=" + userIds;
  343. var title = '';
  344. title = "选择用户";
  345. top.$.jBox("iframe:" + url, {
  346. iframeScrolling: 'yes',
  347. width: $(top.document).width() - 400,
  348. height: $(top.document).height() - 160,
  349. persistent: true,
  350. title: title,
  351. buttons: {"确定": '1', "取消": '-1'},
  352. submit: function (v, h, f) {
  353. //确定
  354. var $jboxFrame = top.$('#jbox-iframe');
  355. var $mainFrame = top.$('#mainFrame');
  356. if ('1' == v && 1 == $jboxFrame.size() && 1 == $mainFrame.size()) {
  357. var items = $jboxFrame[0].contentWindow.getCheckedItems();
  358. console.log(items);
  359. console.log(items[0]);
  360. for (var i = 0; i < items.length; i++) {
  361. console.log(items[i]);
  362. userList.push(items[i]);
  363. $('#userTable').show();
  364. $("#userDel").removeAttr("disabled");
  365. batchSaveUserSort();
  366. };
  367. }
  368. return true;
  369. }
  370. });
  371. }
  372. function initInputDisplay() {
  373. var noThresholdFlag = $("#noThresholdFlag").val();
  374. var startNowFlag = $("#startNowFlag").val();
  375. var permanentFlag = $("#permanentFlag").val();
  376. var receiveFlag = $("#receiveFlag").val();
  377. if (noThresholdFlag === '') {
  378. $("#noThresholdFlag").val(0);
  379. noThresholdFlag = '0';
  380. }
  381. if (startNowFlag === '') {
  382. $("#startNowFlag").val(0);
  383. startNowFlag = '0';
  384. }
  385. if (permanentFlag === '') {
  386. $("#permanentFlag").val(0);
  387. permanentFlag = '0';
  388. }
  389. if (receiveFlag === '') {
  390. $("#receiveFlag").val(0);
  391. receiveFlag = '0';
  392. }
  393. if (noThresholdFlag === '1') {
  394. $("#touchPrice").attr('readonly', true);
  395. $("#touchPrice").attr('required', false);
  396. } else {
  397. $("#touchPrice").attr('readonly', false);
  398. $("#touchPrice").attr('required', true);
  399. }
  400. if (receiveFlag === '1') {
  401. $("#receivePeriod").attr('readonly', true);
  402. $("#receivePeriod").attr('required', false);
  403. } else {
  404. $("#receivePeriod").attr('readonly', false);
  405. $("#receivePeriod").attr('required', true);
  406. }
  407. if (startNowFlag === '1') {
  408. $("#startTime").attr('onclick', '');
  409. $("#startTime").removeClass('required');
  410. } else {
  411. $("#startTime").attr('onclick', "WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',isShowClear:false})");
  412. $("#startTime").addClass('required');
  413. }
  414. if (permanentFlag === '1') {
  415. $("#endTime").attr('onclick', '');
  416. $("#endTime").removeClass('required');
  417. } else {
  418. $("#endTime").attr('onclick', "WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',isShowClear:false})");
  419. $("#endTime").addClass('required');
  420. }
  421. }
  422. /**
  423. * 一键排序
  424. */
  425. function batchSaveProductSort() {
  426. imageList.sort(sort);
  427. productInsertHtml(imageList);
  428. }
  429. /**
  430. * 一键排序
  431. */
  432. function batchSaveUserSort() {
  433. userInsertHtml(userList);
  434. }
  435. //根据sort值 从小到大排序
  436. function sort(a, b) {
  437. return a.sort - b.sort;
  438. }
  439. //相关图片列表数据
  440. function appendProduct(data, index) {
  441. var html = '<tr id ="ai' + index + '">' +
  442. '<td>' +
  443. '<input class="product-check-item" type="checkbox" name="info" value="' + index + '"/>' + (index + 1) +
  444. '</td>' +
  445. '<td>' +
  446. '<img src="' + data.image + '" width="60px" border="none" title="启用">' +
  447. '</td>' +
  448. '<td>' +
  449. data.productName +
  450. '</td>' +
  451. '<td>' +
  452. data.shopName +
  453. '</td>' +
  454. '<td>' +
  455. (data.status == 1 ? (
  456. '<font color="green">已启用</font>&nbsp;&nbsp;&nbsp;' +
  457. '<a href="javascript:void(0);" onclick="updateStatus(0,' + index + ');" >' +
  458. '停用</a>'
  459. ) : (
  460. '<font color="red">已停用</font>&nbsp;&nbsp;&nbsp;' +
  461. '<a href="javascript:void(0)" onclick="updateStatus(1,' + index + ');">' +
  462. '启用</a>'
  463. )) +
  464. '</td>' +
  465. '</td>' +
  466. '<td>' +
  467. '<input name="sort" style="width:50px;" value="' + data.sort + '" onkeyup="onlynum(this)" onchange="changeSort(' + index + ',this)"></td>' +
  468. '</td>' +
  469. '<td>' +
  470. (data.addTime == '' ? (
  471. '<fmt:formatDate value="<%=new Date()%>" pattern="yyyy-MM-dd HH:mm:ss"/>'
  472. ) : (
  473. data.addTime
  474. )) +
  475. '</td>' +
  476. '<td>' +
  477. '<a href="javascript:;" onclick="productDelete(' + index + ')">删除</a>' +
  478. '</td>' +
  479. '</tr>';
  480. return html;
  481. }
  482. //相关用户列表数据
  483. function appendUser(data, index) {
  484. var html = '<tr id ="ai' + index + '">' +
  485. '<td>' +
  486. '<input class="user-check-item" type="checkbox" name="info" value="' + index + '"/>' + (index + 1) +
  487. '</td>' +
  488. '<td>' +
  489. data.nickName +
  490. '</td>' +
  491. '<td>' +
  492. data.mobile +
  493. '</td>' +
  494. '<td>' +
  495. (data.userIdentity === 1 ? '普通用户':'分销者') +
  496. '</td>' +
  497. '<td>' +
  498. (data.addTime == '' ? (
  499. '<fmt:formatDate value="<%=new Date()%>" pattern="yyyy-MM-dd HH:mm:ss"/>'
  500. ) : (
  501. data.addTime
  502. )) +
  503. '</td>' +
  504. '<td>' +
  505. '<a href="javascript:;" onclick="userDelete(' + index + ')">删除</a>' +
  506. '</td>' +
  507. '</tr>';
  508. return html;
  509. }
  510. function productInsertHtml(list) {
  511. var html = '';
  512. productIds = '';
  513. list.forEach(function (item, index) {
  514. html += appendProduct(item, index);
  515. productIds += "," + item.productId;
  516. });
  517. $("#productTbody").html(html);
  518. }
  519. function userInsertHtml(list) {
  520. var html = '';
  521. userIds = '';
  522. list.forEach(function (item, index) {
  523. html += appendUser(item, index);
  524. userIds += "," + item.userId;
  525. });
  526. $("#userTbody").html(html);
  527. }
  528. function changeSort(index, sortThis) {
  529. var sort = sortThis.value;
  530. if (sort <= 0) {
  531. }
  532. var image = imageList[index];
  533. image.sort = sort;
  534. }
  535. function updateStatus(status, index) {
  536. var image = imageList[index];
  537. confirmx(status == 0 ? '确定停用吗?' : '确定启用吗?', function () {
  538. image.status = status;
  539. batchSaveProductSort();
  540. })
  541. }
  542. function clickAllSelect(ckb, type) {
  543. var isChecked = ckb.checked;
  544. if (type === 1) {
  545. $(".product-check-item").attr('checked', isChecked);
  546. } else {
  547. $(".user-check-item").attr('checked', isChecked);
  548. }
  549. }
  550. /**
  551. * 商品删除操作
  552. */
  553. function productDelete(index) {
  554. return confirmx("确定删除吗?", function () {
  555. var image = imageList[index];
  556. if (image.productId != '') {
  557. productIds = productIds.replace(image.productId,"");
  558. }
  559. imageList.splice(index, 1);
  560. productInsertHtml(imageList);
  561. if (imageList.length == 0) {
  562. $('#productTable').hide();
  563. $("#productDel").attr("disabled", "disabled");
  564. }
  565. });
  566. }
  567. /**
  568. * 用户删除操作
  569. */
  570. function userDelete(index) {
  571. return confirmx("确定删除吗?", function () {
  572. var user = userList[index];
  573. if (user.userId != '') {
  574. userIds = userIds.replace(user.userId,"");
  575. }
  576. userList.splice(index, 1);
  577. userInsertHtml(userList);
  578. if (userList.length == 0) {
  579. $('#userTable').hide();
  580. $("#userDel").attr("disabled", "disabled");
  581. }
  582. });
  583. }
  584. /**
  585. * 批量删除商品
  586. */
  587. function productBatchDeletion() {
  588. var index = -1;
  589. var i = 1;
  590. return confirmx("确定删除吗?", function () {
  591. $('input[name="info"]:checked').each(function () {
  592. var thisIndex = $(this).val();
  593. if (index >= 0 && index < thisIndex) {
  594. thisIndex = thisIndex - i;
  595. i++;
  596. } else {
  597. index = thisIndex;
  598. }
  599. var image = imageList[thisIndex];
  600. if (image.productId != '') {
  601. productIds = productIds.replace(image.productId, "");
  602. }
  603. imageList.splice(thisIndex, 1);
  604. productInsertHtml(imageList);
  605. if (imageList.length == 0) {
  606. $('#productTable').hide();
  607. $("#productDel").attr("disabled", "disabled");
  608. }
  609. });
  610. });
  611. }
  612. /**
  613. * 批量删除用户
  614. */
  615. function userBatchDeletion() {
  616. var index = -1;
  617. var i = 1;
  618. return confirmx("确定删除吗?", function () {
  619. $('input[name="info"]:checked').each(function () {
  620. var thisIndex = $(this).val();
  621. if (index >= 0 && index < thisIndex) {
  622. thisIndex = thisIndex - i;
  623. i++;
  624. } else {
  625. index = thisIndex;
  626. }
  627. var user = userList[thisIndex];
  628. if (user.userId != '') {
  629. userIds = userIds.replace(user.userId, "");
  630. }
  631. userList.splice(thisIndex, 1);
  632. userInsertHtml(userList);
  633. if (userList.length == 0) {
  634. $('#userTable').hide();
  635. $("#userDel").attr("disabled", "disabled");
  636. }
  637. });
  638. });
  639. }
  640. function productShow() {
  641. var productType = $("input[name='productType']:checked").val();
  642. if (productType == 2){
  643. $(".productData").show();
  644. }else {
  645. $(".productData").hide();
  646. }
  647. }
  648. </script>
  649. </body>
  650. </html>