Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 

466 Zeilen
12 KiB

  1. //author:func
  2. //date:20161024
  3. //促销规则
  4. var current_page = "1";
  5. var page_size = "15";
  6. var line_id = '';
  7. var line_type = '';
  8. var ticket_id = '';
  9. var trHTML = '';
  10. window.onload = function() {
  11. line_type = getPar('line_type');
  12. ticket_id = getPar('ticket_id');
  13. line_id = getPar('line_id');
  14. trHTML = $('#tbody').html();
  15. httpTopInfo();
  16. httpFirstData();
  17. }
  18. //头部信息
  19. function httpTopInfo() {
  20. var param = {
  21. tp: "promotionRule_getPromotionBase",
  22. line_id: line_id,
  23. ticket_id: ticket_id
  24. }
  25. ZZLog(base_api + "lineManager/index.php" + JSON.stringify(param));
  26. $.ajax({
  27. type: "post",
  28. url: base_api + "lineManager/index.php",
  29. data: param,
  30. dataType: "json",
  31. success: function(res_data) {
  32. ZZLog(res_data);
  33. if(res_data['code'] != "0") {
  34. ZZAlertInfo(res_data['info']);
  35. } else {
  36. var base = res_data['base'];
  37. $('#seat_type').html(base['seat_type_name']);
  38. $('#crow').html(base['human_type_name']);
  39. $('#cus_price').html(base['cus_price']);
  40. $('#prod_price').html(base['prod_price']);
  41. }
  42. },
  43. error: function(e) {
  44. ZZLog(e);
  45. }
  46. });
  47. }
  48. //第一次加载列表
  49. function httpFirstData() {
  50. current_page = 1;
  51. var param = {
  52. tp: "promotionRule_getPromotionRuleList",
  53. page_size: page_size,
  54. current_page: current_page,
  55. line_id: line_id,
  56. ticket_id: ticket_id
  57. }
  58. ZZLog(base_api + "lineManager/index.php" + JSON.stringify(param));
  59. $.ajax({
  60. type: "post",
  61. url: base_api + "lineManager/index.php",
  62. data: param,
  63. dataType: "json",
  64. success: function(res_data) {
  65. ZZLog(res_data);
  66. if(res_data['code'] != "0") {
  67. ZZAlertInfo(res_data['info']);
  68. } else {
  69. setTableHTML(res_data);
  70. $('#tbody').show();
  71. //处理分页
  72. if(res_data['page']['total_count'] <= 0) {
  73. $('.pageDiv').hide();
  74. } else {
  75. $(".pageDiv").createPage({
  76. pageCount: res_data['page']['total_page'], //总页数
  77. current: current_page, //当前页
  78. turndown: 'true', //是否显示跳转框,显示为true,不现实为false,一定记得加上引号...
  79. backFn: function(p) {
  80. current_page = p;
  81. httpData();
  82. }
  83. });
  84. $('.pageDiv').show();
  85. }
  86. }
  87. },
  88. error: function(e) {
  89. ZZLog(e);
  90. }
  91. });
  92. }
  93. //请求
  94. function httpData() {
  95. var param = {
  96. tp: "promotionRule_getPromotionRuleList",
  97. page_size: page_size,
  98. current_page: current_page,
  99. line_id: line_id,
  100. ticket_id: ticket_id
  101. }
  102. ZZLog(base_api + "lineManager/index.php" + JSON.stringify(param));
  103. $.ajax({
  104. type: "post",
  105. url: base_api + "lineManager/index.php",
  106. data: param,
  107. dataType: "json",
  108. success: function(res_data) {
  109. ZZLog(res_data);
  110. if(res_data['code'] != "0") {
  111. ZZAlertInfo(res_data['info']);
  112. } else {
  113. setTableHTML(res_data);
  114. }
  115. },
  116. error: function(e) {
  117. ZZLog(e);
  118. }
  119. });
  120. }
  121. //设置表格HTML
  122. function setTableHTML(res_data) {
  123. var rule_list = res_data['rule_list'];
  124. var HTML = '';
  125. for(var i = 0, m = rule_list.length; i < m; i++) {
  126. var dict = rule_list[i];
  127. var tempHTML = trHTML;
  128. var objstr=JSON.stringify(dict);
  129. objstr=objstr.replace(/"/g,'&quot;');
  130. tempHTML = tempHTML.replace('[data-param]', objstr);
  131. tempHTML = tempHTML.replace('[promotion-id]', dict['promotion_id']);
  132. tempHTML = tempHTML.replace('[促销类型]', dict['discount_type_name']);
  133. tempHTML = tempHTML.replace('[促销内容]', "立减 " + dict['off_value'] + " 元");
  134. tempHTML = tempHTML.replace('[促销时间]', dict['discount_day_type_name']);
  135. tempHTML = tempHTML.replace('[促销渠道]', dict['supplier_name']);
  136. var imgstr = '';
  137. if(dict['is_onsale'] == "1") {
  138. imgstr = '<img data-is-onsale="' + dict['is_onsale'] + '" onclick="onOffLine(this)" style="width: 33px;height: 30px;cursor: pointer;" src="images/on.png" />';
  139. } else {
  140. imgstr = '<img data-is-onsale="' + dict['is_onsale'] + '" onclick="onOffLine(this)" style="width: 33px;height: 30px;cursor: pointer;" src="images/off.png" />'
  141. }
  142. tempHTML = tempHTML.replace('[上线]', imgstr);
  143. HTML += tempHTML;
  144. }
  145. $('#tbody').html(HTML);
  146. }
  147. //上下线
  148. function onOffLine(obj) {
  149. var _promotion_id = $(obj).closest('tr').attr('data-promotion-id');
  150. var _status = $(obj).attr('data-is-onsale');
  151. _status = _status == 1 ? "stop" : "start";
  152. var param = {
  153. tp: "promotionRule_ruleStatus",
  154. status: _status,
  155. promotion_id: _promotion_id
  156. }
  157. ZZLog(base_api + "lineManager/index.php" + JSON.stringify(param));
  158. $.ajax({
  159. type: "post",
  160. url: base_api + "lineManager/index.php",
  161. data: param,
  162. dataType: "json",
  163. success: function(res_data) {
  164. ZZLog(res_data);
  165. if(res_data['code'] != "0") {
  166. ZZAlertInfo(res_data['info']);
  167. } else {
  168. var imgstr = '';
  169. var is_onsale = '';
  170. if(_status == 'stop') {
  171. imgstr = 'images/off.png';
  172. is_onsale = 0;
  173. } else {
  174. imgstr = 'images/on.png';
  175. is_onsale = 1;
  176. }
  177. $(obj).attr('src', imgstr);
  178. $(obj).attr('data-is-onsale', is_onsale);
  179. }
  180. },
  181. error: function(e) {
  182. ZZLog(e);
  183. }
  184. });
  185. }
  186. //删除规则
  187. function delRule(obj) {
  188. var _promotion_id = $(obj).closest('tr').attr('data-promotion-id');
  189. var param = {
  190. tp: "promotionRule_delPromotion",
  191. promotion_id: _promotion_id
  192. }
  193. ZZLog(base_api + "lineManager/index.php" + JSON.stringify(param));
  194. $.ajax({
  195. type: "post",
  196. url: base_api + "lineManager/index.php",
  197. data: param,
  198. dataType: "json",
  199. success: function(res_data) {
  200. ZZLog(res_data);
  201. if(res_data['code'] != "0") {
  202. ZZAlertInfo(res_data['info']);
  203. } else {
  204. httpData();
  205. }
  206. },
  207. error: function(e) {
  208. ZZLog(e);
  209. }
  210. });
  211. }
  212. //弹出添加促销层
  213. function addRegular(obj) {
  214. var param = {
  215. tp: "promotionRule_getRuleBaseInfo",
  216. line_id: line_id,
  217. ticket_id: ticket_id,
  218. line_type: line_type
  219. }
  220. ZZLog(base_api + "lineManager/index.php" + JSON.stringify(param));
  221. $.ajax({
  222. type: "post",
  223. url: base_api + "lineManager/index.php",
  224. data: param,
  225. dataType: "json",
  226. success: function(res_data) {
  227. ZZLog(res_data);
  228. if(res_data['code'] != "0") {
  229. ZZAlertInfo(res_data['info']);
  230. } else {
  231. setAddDivHTML(res_data);
  232. $(".add_promotion_type").show();
  233. }
  234. },
  235. error: function(e) {
  236. ZZLog(e);
  237. }
  238. });
  239. }
  240. //加载添加DIV 的数据
  241. function setAddDivHTML(res_data) {
  242. //促销类型
  243. var discount_type = res_data['discount_type'];
  244. var promotion_typeHTML = '<option value="">请选择</option>';
  245. for(var i = 0, m = discount_type.length; i < m; i++) {
  246. var dict = discount_type[i];
  247. var tempHTML = '<option value="' + dict['id'] + '">' + dict['type_name'] + '</option>';
  248. promotion_typeHTML += tempHTML;
  249. }
  250. $('select[name="promotion_type"]').html(promotion_typeHTML);
  251. //促销时间
  252. var discount_time = res_data['discount_time'];
  253. var promotion_timeHTML = '';
  254. for(var i = 0, m = discount_time.length; i < m; i++) {
  255. var dict = discount_time[i];
  256. var tempHTML = '<label style="margin-right: 20px;">' +
  257. '<input name="promotion_time" type="radio" checked="checked" value="' + dict['id'] + '" />' +
  258. '<span>' + dict['type_name'] + '</span>' +
  259. '</label>';
  260. promotion_timeHTML += tempHTML;
  261. }
  262. $('#promotion_time').html(promotion_timeHTML);
  263. //促销渠道
  264. var promotion_channel = res_data['channel_list'];
  265. var promotion_channelHTML = '<label style="margin-right: 20px;">' +
  266. '<input type="checkbox" onclick="chooseAllChannel(this)" name="channelAll" value="" />' +
  267. '<span style="margin-right: 15px;">全选</span>' +
  268. '</label>';
  269. for(var i = 0, m = promotion_channel.length; i < m; i++) {
  270. var dict = promotion_channel[i];
  271. var tempHTML = '<label style="margin-right: 20px;">' +
  272. '<input type="checkbox" name="channel" value="' + dict['channel_id'] + '" />' +
  273. '<span style="margin-right: 15px;">' + dict['supplier_name'] + '</span>' +
  274. '</label>';
  275. promotion_channelHTML += tempHTML;
  276. }
  277. $('#promotion_channel').html(promotion_channelHTML);
  278. }
  279. //添加保存
  280. function saveAdd(obj) {
  281. var _discount_type = $('select[name="promotion_type"]').val(); //促销类型
  282. if(""==_discount_type.trim()){
  283. ZZAlertInfo('请选择促销类型');
  284. return;
  285. }
  286. var _discount_price = $('#promotion_price').val(); // 促销内容 立减元
  287. if(""==_discount_price.trim()){
  288. ZZAlertInfo('请填写促销内容');
  289. return;
  290. }
  291. var _discount_time = $('input[name="promotion_time"]:checked').val(); //促销时间
  292. if(""==_discount_time.trim()){
  293. ZZAlertInfo('请选择促销时间');
  294. return;
  295. }
  296. var _discount_channel = '',
  297. _channel_arr = [];
  298. $('input[name="channel"]').each(function(index, domEle) {
  299. if(domEle.checked) {
  300. _channel_arr.push($(this).val());
  301. }
  302. })
  303. _discount_channel = _channel_arr.join(',');
  304. if(""==_discount_channel.trim()){
  305. ZZAlertInfo('请选择促销渠道');
  306. return;
  307. }
  308. var param = {
  309. tp: "promotionRule_addPromotionRule",
  310. line_id: line_id,
  311. ticket_id: ticket_id,
  312. discount_type: _discount_type,
  313. off_value: _discount_price,
  314. discount_day_type: _discount_time,
  315. channel_id: _discount_channel
  316. }
  317. ZZLog(base_api + "lineManager/index.php" + JSON.stringify(param));
  318. $.ajax({
  319. type: "post",
  320. url: base_api + "lineManager/index.php",
  321. data: param,
  322. dataType: "json",
  323. success: function(res_data) {
  324. ZZLog(res_data);
  325. if(res_data['code'] != "0") {
  326. ZZAlertInfo(res_data['info'])
  327. } else {
  328. $('.add_promotion_type').hide();
  329. httpData();
  330. }
  331. },
  332. error: function(e) {
  333. ZZLog(e);
  334. }
  335. });
  336. }
  337. //修改规则
  338. var _datajson=null;
  339. function updateRule(obj){
  340. var datajson=$(obj).closest('tr').attr('data-param');
  341. datajson=JSON.parse(datajson);
  342. _datajson=datajson;
  343. var param = {
  344. tp: "promotionRule_getRuleBaseInfo",
  345. line_id: line_id,
  346. ticket_id: ticket_id,
  347. line_type: line_type
  348. }
  349. ZZLog(base_api + "lineManager/index.php" + JSON.stringify(param));
  350. $.ajax({
  351. type: "post",
  352. url: base_api + "lineManager/index.php",
  353. data: param,
  354. dataType: "json",
  355. success: function(res_data) {
  356. ZZLog(res_data);
  357. if(res_data['code'] != "0") {
  358. ZZAlertInfo(res_data['info']);
  359. } else {
  360. setUpdateDiv(res_data);
  361. $('.update_promotion_type').show();
  362. }
  363. },
  364. error: function(e) {
  365. ZZLog(e);
  366. }
  367. });
  368. }
  369. function setUpdateDiv(res_data){
  370. var _channel_name=_datajson['supplier_name'];
  371. $('#update_promotion_channel').children().find('span').text(_channel_name);
  372. $('.update_type').html(_datajson['discount_type_name']);
  373. $('#update_promotion_price').val(_datajson['off_value']);
  374. //促销时间
  375. var discount_time = res_data['discount_time'];
  376. var promotion_timeHTML = '';
  377. for(var i = 0, m = discount_time.length; i < m; i++) {
  378. var dict = discount_time[i];
  379. var cstr='';
  380. if(dict['id']==_datajson['discount_day_type']){
  381. cstr='<input name="update_promotion_time" type="radio" checked="checked" value="' + dict['id'] + '" />';
  382. }else{
  383. cstr='<input name="update_promotion_time" type="radio" value="' + dict['id'] + '" />';
  384. }
  385. var tempHTML = '<label style="margin-right: 20px;">' +
  386. cstr +
  387. '<span>' + dict['type_name'] + '</span>' +
  388. '</label>';
  389. promotion_timeHTML += tempHTML;
  390. }
  391. $('#update_promotion_time').html(promotion_timeHTML);
  392. }
  393. //保存修改
  394. function saveUpdate(obj){
  395. var _off_value=$('#update_promotion_price').val();
  396. var _discount_time = $('input[name="update_promotion_time"]:checked').val(); //促销时间
  397. var _promotion_id=_datajson['promotion_id']
  398. if(""==_promotion_id.trim()){
  399. ZZAlertInfo('缺少唯一id');
  400. return;
  401. }
  402. if(""==_off_value.trim()){
  403. ZZAlertInfo('请输入促销内容');
  404. $('#update_promotion_price').focus();
  405. return;
  406. }
  407. if(""==_discount_time.trim()){
  408. ZZAlertInfo('请选择促销时间');
  409. return;
  410. }
  411. var param={
  412. tp:"promotionRule_updatePromotion",
  413. promotion_id:_promotion_id,
  414. off_value:_off_value,
  415. discount_day_type:_discount_time
  416. }
  417. ZZLog(base_api+"lineManager/index.php"+JSON.stringify(param));
  418. $.ajax({
  419. type:"post",
  420. url:base_api+"lineManager/index.php",
  421. data:param,
  422. dataType:"json",
  423. success:function(res_data){
  424. ZZLog(res_data);
  425. if(res_data['code']!="0"){
  426. ZZAlertInfo(res_data['info']);
  427. }else{
  428. }
  429. },error:function(e){
  430. ZZLog(e);
  431. }
  432. });
  433. }
  434. //全选
  435. function chooseAllChannel(obj) {
  436. $(obj).closest('#promotion_channel').children().find('input[name="channel"]').attr('checked', obj.checked);
  437. $(obj).closest('#promotion_channel').children().find('input[name="channel"]').prop('checked', obj.checked);
  438. }
  439. //取消添加
  440. function cannelAdd(obj) {
  441. $(".add_promotion_type").hide();
  442. }
  443. //取消修改
  444. function cannelAmend(obj) {
  445. $(".add_promotion_type").hide();
  446. }
  447. //取消添加
  448. function cannelUpdate(obj) {
  449. $(".update_promotion_type").hide();
  450. }
  451. //取消修改
  452. function cannelUpdate(obj) {
  453. $(".update_promotion_type").hide();
  454. }