publishCoupon.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <style>
  2. .coupon_space input,.coupon_space select{
  3. display:inline-block;
  4. width:200px;
  5. padding:0 8px;
  6. height:26px;
  7. }
  8. .section{
  9. overflow:auto;
  10. }
  11. </style>
  12. <script>
  13. var houseInfo = {};
  14. var totalPage;
  15. var cId;
  16. var opText = "";
  17. var pageNo = 1;
  18. var membArr = [];
  19. var allUser = null;
  20. $(function(){
  21. cId = sessionStorage.couponId
  22. if(cId == 0){
  23. $("#identity").val("");
  24. $("#address").val("");
  25. $("#chargeRule").html("");
  26. $("#startDate").val("");
  27. $("#endDate").val("");
  28. $("#startTime").val("");
  29. $("#endTime").val("");
  30. $("#chargeType").html("");
  31. $("#charge").html("元");
  32. $("#describe").html("");
  33. }
  34. loadCoupon();
  35. getAllUser();
  36. });
  37. function loadCoupon(){
  38. $.post("system/getAllTypeList.do",{},function(resp){
  39. var typeList = resp.data;
  40. for(var i = 0; i <typeList.length;i++){
  41. var data = typeList[i];
  42. var line = "<option value="+data.id+">"+data.name+"</option>";
  43. $("#identity").append(line);
  44. }
  45. if(cId == 0){
  46. cId = typeList[0].id;
  47. }
  48. loadData();
  49. });
  50. }
  51. function loadData(){
  52. $.post("system/getCouponTypeDetail.do",{"id":cId},function(resp){
  53. var data = resp.data;
  54. if(resp.code == "ok"){
  55. $("#identity").val(data.id);
  56. $("#address").html(data.address);
  57. $("#startDate").val(data.startdate);
  58. $("#endDate").val(data.enddate);
  59. $("#startTime").val(data.starttime);
  60. $("#endTime").val(data.endtime);
  61. $("#describe").html(data.descp);
  62. if(data.type == 1){
  63. $("#chargeType").html("代金券");
  64. $("#chargeRule").html((data.money/100).toFixed(2));
  65. }else{
  66. $("#chargeType").html("按次优惠");
  67. $("#chargeRule").html(data.money);
  68. }
  69. $("#charge").html("元");
  70. if(data.type == 1){
  71. $("#charge").html("元");
  72. }else{
  73. $("#charge").html("次");
  74. }
  75. }else{
  76. alert("不可预知的错误发生了,请关闭后重试");
  77. }
  78. });
  79. }
  80. function changeName(){
  81. cId = $("#identity").val();
  82. loadData();
  83. }
  84. // function sendType(){
  85. // if($("#sendType").val() == 1){
  86. // $("#phoneText").show();
  87. // $("#phone").show();
  88. // }else{
  89. // $("#phoneText").hide();
  90. // $("#phone").hide();
  91. // }
  92. // }
  93. /**
  94. * 发放优惠券
  95. */
  96. function sendCoupon(){
  97. // var sTime = $("#startDate").val();
  98. // var startTime = sTime.replace(new RegExp("-","gm"),"/");
  99. // var startHm = (new Date(startTime)).getTime();
  100. // alert(startHm);
  101. var param={};
  102. param.title =$("#identity").find("option:selected").text();
  103. param.typeId =$("#identity").find("option:selected").val();
  104. if($("#chargeType").html() == "代金券"){
  105. param.type = 1;
  106. param.couponAmount = $("#chargeRule").html()*100;
  107. }else{
  108. param.type = 2;
  109. param.couponAmount = $("#chargeRule").html();
  110. }
  111. param.descp = $("#describe").html();
  112. param.timeS = $("#startTime").val();
  113. param.timeE = $("#endTime").val();
  114. // param.pushType =$("#sendType").val();
  115. param.areaLimit = $("#address").html();
  116. param.startTime = $("#startDate").val();
  117. param.endTime = $("#endDate").val();
  118. // if($("#sendType").val() == 1){
  119. // param.mobile = $("#phone").val();
  120. // }
  121. if(membArr.length == 0){
  122. alert("请选择发放目标");
  123. }else{
  124. var idList = "";
  125. for(var i = 0;i<membArr.length;i++){
  126. idList += membArr[i] + ","
  127. }
  128. param.ids = idList.substring(0,idList.length-1);
  129. $.post("system/pushCouponToMul.do",param,function(resp){
  130. var code = resp.code;
  131. if(code =="ok"){
  132. location.href="#/record";
  133. }else if(code == "error"){
  134. alert(resp.msg);
  135. }
  136. });
  137. }
  138. }
  139. /*选择发放目标*/
  140. function openSelectMemb(){
  141. getUser();
  142. $("#prePage").hide();
  143. $("#selectMembModel").modal('show');
  144. }
  145. /*搜索用户*/
  146. function searchUser(){
  147. getSelUser();
  148. pageNo = 1;
  149. $("#prePage").hide();
  150. getUser();
  151. }
  152. /*获取用户*/
  153. function getAllUser(){
  154. $.post("getUserAllList.do",{}, function(resp){
  155. allUser = resp.data;
  156. });
  157. }
  158. function getUser() {
  159. $.post("getUserList.do",{"page":pageNo,"mobile":$("#keyMobile").val()}, function(resp){
  160. $("#membData").empty();
  161. var listArray = resp.data.list;
  162. totalPage = resp.data.totalPage;
  163. for (var i=0;i<listArray.length;i++) {
  164. var item = listArray[i];
  165. if(item.nickname == null || item.nickname == ""){
  166. item.nickname = "";
  167. }else{
  168. item.nickname += "--";
  169. }
  170. var line = "<tr>"
  171. +"<td style=\"text-align:center;\"><input type=\"checkbox\" "+((membArr.indexOf(""+item.id) == -1)?"":"checked")+" value=\""+item.id+"\"></td>"
  172. +"<td>"+item.nickname+item.mobile+"</td>"
  173. +"</tr>"
  174. $("#membData").append(line);
  175. }
  176. });
  177. }
  178. /*获取已选择的用户*/
  179. function getSelUser(){
  180. $("#membData input[type=checkbox]").each(function(index,item){
  181. if($(this).prop("checked") && membArr.indexOf($(this).val()) == -1){
  182. membArr.push($(this).val());
  183. }
  184. if(!$(this).prop("checked") && membArr.indexOf($(this).val()) != -1){
  185. membArr.splice(membArr.indexOf($(this).val()),1);
  186. }
  187. });
  188. console.log(membArr);
  189. }
  190. /*改变页数*/
  191. function changePage(index){
  192. getSelUser();
  193. if(index == 1){
  194. pageNo -= 1;
  195. }else{
  196. pageNo += 1;
  197. }
  198. if(pageNo == 1){
  199. $("#prePage").hide();
  200. }else{
  201. $("#prePage").show();
  202. }
  203. if(pageNo == totalPage){
  204. $("#nextPage").hide();
  205. }else{
  206. $("#nextPage").show();
  207. }
  208. getUser();
  209. }
  210. /*清空选择的用户*/
  211. function clearSelected(){
  212. membArr = [];
  213. getUser();
  214. }
  215. /*选择全部*/
  216. function selectAll(){
  217. membArr = [];
  218. $("#membData input[type=checkbox]").prop("checked",true);
  219. for(var i = 0;i<allUser.length;i++){
  220. membArr.push(""+allUser[i].id);
  221. }
  222. }
  223. /*保存关闭*/
  224. function sureMemb(){
  225. getSelUser();
  226. $("#selectMembModel").modal('hide');
  227. $("#targetNum").html("已选择 "+membArr.length+" 个");
  228. }
  229. </script>
  230. <div class="section">
  231. <div class="add_item">
  232. <h4>优惠券发放</h4>
  233. </div>
  234. <div class="modal-header">
  235. <h4 class="modal-title" style="margin-left: 40px;">优惠券信息
  236. </h4>
  237. </div>
  238. <div class="modal-body coupon_space">
  239. <!-- <span style="width: 900px;height: 1px;color: #333"></span> -->
  240. <p style="margin-top: 10px"><span style="display:inline-block;vertical-align:middle;width: 80px">券名:</span><select onchange="changeName()" id="identity" type="text" class="form-control"></select> </P>
  241. <p style="margin-top: 20px"><span style="vertical-align:middle;display:inline-block;width: 80px;">描述:</span><span></span><input id="describe" type="text" class="form-control" style="width:420px;"></p>
  242. <p style="margin-top: 20px"><span style="display:inline-block;width: 80px;">优惠类型:</span>
  243. <span id="chargeType" style="width: 80px" onchange="changeType()"></span>
  244. <!-- <option value="1">代金券</option> -->
  245. <!-- <option value="2">按次优惠</option> -->
  246. <!-- </select> -->
  247. <span style="display:inline-block;width: 80px;margin-left: 200px">优惠额度:</span><span id="chargeRule" type="text"></span> <span id="charge">元</span>
  248. </p>
  249. <P style="margin-top: 20px"><span style="display:inline-block;width: 80px">使用地点:</span><span style="margin-left: 1px" id="address" type="text"></span></p>
  250. <p style="margin-top: 20px">
  251. <span style="display:inline-block;width: 80px;vertical-align:middle">有效期:</span><input class="form-control" id="startDate" type="date"> 至 <input class="form-control" id="endDate" type="date">
  252. </p>
  253. <p style="margin-top: 20px">
  254. <span style="display:inline-block;width: 80px;vertical-align:middle">使用时间:</span><input class="form-control" id="startTime" type="time"> 至 <input class="form-control" id="endTime" type="time">
  255. </p>
  256. <p style="margin-top: 20px"><span style="display:inline-block;width: 80px;vertical-align:middle">发放目标:</span>
  257. <!-- <select id="sendType" style="width: 80px"onchange="sendType()"> -->
  258. <!-- <option value="1">个人</option> -->
  259. <!-- <option value="2">所有人</option> -->
  260. <!-- </select> -->
  261. <img src="images/add.png" onclick="openSelectMemb()" style="width:24px;">
  262. <span id="targetNum">已选择 0 个</span>
  263. <!-- <span id="phoneText"style="display:inline-block;width: 80px;margin-left: 165px">手机号:</span><input id="phone" type="text"> -->
  264. </p>
  265. </div>
  266. <div class="modal-footer" style="text-align: center" >
  267. <button type="button" class="btn btn-default" data-dismiss="modal" onclick="returnPage()">取消
  268. </button>
  269. <button type="button" style="margin-left: 40px"class="btn btn-primary" onclick="sendCoupon()">
  270. 发放
  271. </button>
  272. </div>
  273. </div>
  274. <!--选择目标模态框 -->
  275. <div class="modal fade" id="selectMembModel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static" data-keyoard="false">
  276. <div class="modal-dialog modal-md">
  277. <div class="modal-content">
  278. <div class="modal-header">
  279. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
  280. &times;
  281. </button>
  282. <h4 class="modal-title">
  283. 选择发放目标
  284. </h4>
  285. </div>
  286. <div class="modal-body">
  287. <input type="text" id="keyMobile" class="form-control" style="width:510px;display:inline-block;"><button onclick="searchUser()" class="btn btn-default">搜索</button>
  288. <table class="table table-hover table-bordered">
  289. <thead>
  290. <tr>
  291. <th></th>
  292. <th>人员</th>
  293. </tr>
  294. </thead>
  295. <tbody id="membData">
  296. </tbody>
  297. </table >
  298. <p style="padding:0;text-align:center;margin-top:10px;">
  299. <button onclick="selectAll()" id="" class="btn btn-default btn-xs">选择全部用户</button>
  300. <button onclick="clearSelected()" id="" class="btn btn-default btn-xs">清空选择</button>
  301. <button onclick="changePage(1)" id="prePage" class="btn btn-default btn-xs">上一页</button>
  302. <button onclick="changePage(2)" id="nextPage" class="btn btn-default btn-xs">下一页</button>
  303. </p>
  304. </div>
  305. <div class="modal-footer" >
  306. <button type="button" class="btn btn-default" data-dismiss="modal" >关闭
  307. </button>
  308. <button type="button" class="btn btn-primary" onclick="sureMemb()">
  309. 保存
  310. </button>
  311. </div>
  312. </div><!-- /.modal-content -->
  313. </div>
  314. </div><!-- /.modal -->
  315. <script>
  316. $("#special span").click(function(){
  317. var mark = $(this).children('input').val();
  318. if(mark == 0){
  319. $(this).css({"background":"#41C7DB","color":"#fff"});
  320. $(this).children('input').val(1);
  321. }else if(mark == 1){
  322. $(this).css({"background":"#fff","color":"#333"});
  323. $(this).children('input').val(0);
  324. }
  325. });
  326. $(".textType label").click(function(){
  327. $(this).css({"background":"#41C7DB"}).siblings('label').css({"background":"#fff"});
  328. $(this).next('textarea').show().siblings('textarea').hide();
  329. });
  330. //实例化编辑器 -->
  331. var ue = UE.delEditor('editor');
  332. var mainHeight = $(window).height()-100+"px";
  333. $(".section").css({"height":mainHeight});
  334. </script>