516 lines
12 KiB

  1. //一个页面的线路条数
  2. var pagesize = 10;
  3. //当前页数
  4. var currpage = 1;
  5. //线路id
  6. var line_id ="";
  7. //列表HTML
  8. var listHTML = '';
  9. var select_page = "1";
  10. //填坑
  11. var tiankeng = "";
  12. //从地址栏获取票种id(ticket_id)
  13. var ticket_id = getPar("ticket_id");
  14. var line_type = getPar("line_type");
  15. $(document).ready(function(){
  16. listHTML = $('#list').html();
  17. selectOnePage(1);
  18. });
  19. //根据票种id加载渠道商列表
  20. function selectOnePage(page){
  21. $.ajax({
  22. url:base_api+'lineManager/index.php', //请求地址
  23. data:{
  24. tp:"saleRule_getRuleList",
  25. ticket_id:ticket_id,
  26. line_type:line_type,
  27. current_page:page,
  28. page_size:pagesize
  29. },
  30. type: "post", //请求方式
  31. dataType: "json",
  32. async:false,
  33. success: function (data) {
  34. console.log(data);
  35. if(data.code == 0){
  36. totalpage = data.page.total_page;
  37. line_id = data.ticket_info.line_id;
  38. reloadData(data.station,data.ticket_info);
  39. if (totalpage == 0) {
  40. $('.pageDiv').hide();
  41. } else{
  42. createPage(currpage,totalpage);
  43. $('.pageDiv').show();
  44. }
  45. }else{
  46. ZZAlertInfo(data.info);
  47. }
  48. }
  49. });
  50. }
  51. function http_data(){
  52. $.ajax({
  53. url:base_api+'lineManager/index.php', //请求地址
  54. data:{
  55. tp:"saleRule_getRuleList",
  56. ticket_id:ticket_id,
  57. line_type:line_type,
  58. current_page:select_page,
  59. page_size:pagesize
  60. },
  61. type: "post", //请求方式
  62. dataType: "json",
  63. success: function (data) {
  64. console.log(data);
  65. if(data.code == 0){
  66. reloadData(data.station,data.ticket_info);
  67. }else{
  68. ZZAlertInfo(data.info);
  69. }
  70. }
  71. });
  72. }
  73. //替换列表数据
  74. function reloadData(data,index){
  75. var list = data;
  76. var newHTML = '';
  77. var temp = '<span>座位等级:</span>'
  78. + '<span style="margin-right: 40px;">'+index.seat_type_name+'</span>'
  79. + '<span>人群:</span>'
  80. + '<span style="margin-right: 40px;">'+index.human_type_name+'</span>'
  81. + '<span>零售价:</span>'
  82. + '<span style="margin-right: 40px;">'+index.cus_price+'</span>'
  83. + '<span>分销价:</span>'
  84. + '<span>'+index.prod_price+'</span>'
  85. $('#ticket_info').html(temp);
  86. for(var i=0;i<list.length;i++){
  87. var authority = "";
  88. var show_prod_price = "";
  89. var commision_flag = "";
  90. var font_color = "";
  91. if(list[i].sale_type=="177"){
  92. show_prod_price = list[i].prod_price;
  93. }else{
  94. show_prod_price = "-";
  95. }
  96. if(list[i].commision_flag=="1"){
  97. commision_flag = list[i].sale_rule;
  98. }else{
  99. commision_flag = "-";
  100. }
  101. if(list[i].authority_status=="0"){
  102. authority = "images/off.png";
  103. font_color = "#cccccc";
  104. }else{
  105. authority = "images/on.png";
  106. font_color = "#000000";
  107. }
  108. var tempHTML=listHTML;
  109. tempHTML=tempHTML.replace('[渠道商]',list[i].supplier_name);
  110. tempHTML=tempHTML.replace('#000000',font_color);
  111. tempHTML=tempHTML.replace('[销售方式]',list[i].sale_name);
  112. tempHTML=tempHTML.replace('[零售价]',list[i].cus_price);
  113. tempHTML=tempHTML.replace('[分销价]',show_prod_price);
  114. tempHTML=tempHTML.replace('[佣金规则]',commision_flag);
  115. tempHTML=tempHTML.replace('[oneCheckName]',list[i].supplier_id);
  116. tempHTML=tempHTML.replace('[supplier_id]',list[i].supplier_id);
  117. tempHTML=tempHTML.replace('images/off.png',authority);
  118. newHTML+=tempHTML;
  119. }
  120. $('#list').html(newHTML);
  121. }
  122. //创建分页控件
  123. function createPage(currpage,totalpage){
  124. $(".pageDiv").createPage({
  125. pageCount:totalpage,//总页数
  126. current:currpage,//当前页
  127. turndown:'true',//是否显示跳转框,显示为true,不现实为false,一定记得加上引号...
  128. backFn:function(p){
  129. select_page = p;
  130. $.ajax({
  131. url:base_api+'lineManager/index.php', //请求地址
  132. data:{
  133. tp:"saleRule_getRuleList",
  134. line_type:line_type,
  135. page_size:pagesize,
  136. current_page:p,
  137. ticket_id:ticket_id
  138. },
  139. type: "post",
  140. dataType: "json",
  141. async:false,
  142. success: function (data) {
  143. if(data.code == "0"){
  144. console.log(data);
  145. totalpage = data.page.total_page;
  146. reloadData(data.station,data.ticket_info);
  147. }else{
  148. ZZAlertInfo(data.info);
  149. }
  150. }
  151. });
  152. }
  153. });
  154. }
  155. //修改规则
  156. //function amend_regular(index){
  157. //
  158. // $.ajax({
  159. // url:base_api+'lineManager/index.php', //请求地址
  160. // data:{
  161. // tp:"saleRule_getRuleType"
  162. // },
  163. // type: "post", //请求方式
  164. // dataType: "json",
  165. //// async:false,
  166. // success: function (data) {
  167. // console.log(data);
  168. // if(data.code == 0){
  169. //
  170. // load_amend_base(data.saleType,data.define_type,data.back_commision_type,data.back_commision_method);
  171. //
  172. //
  173. // }else{
  174. // ZZAlertInfo(data.info);
  175. // }
  176. //
  177. // }
  178. // });
  179. //}
  180. //取消修改
  181. function cannel_amend(index){
  182. $(".amend_ticket_type").hide();
  183. }
  184. //复选框判断
  185. function select_checked(index) {
  186. //index=0最上面的全选 index=1表示的是下面所有的
  187. var cur_check = $('.ace_check')[0];
  188. var checkList = $('.ace_check');
  189. var checkCount = checkList.length - 1;
  190. var true_count = 0;
  191. for (var i = 1; i < checkList.length; i++) {
  192. if (index == '0') {
  193. checkList[i].checked = cur_check.checked;
  194. } else {
  195. if (checkList[i].checked == false) {
  196. cur_check.checked = false
  197. } else {
  198. true_count = true_count + 1;
  199. }
  200. }
  201. }
  202. //判断下面是否选中完
  203. if (checkCount == true_count) {
  204. cur_check.checked = true;
  205. }
  206. }
  207. //取复选框ticket_id
  208. function amend_regular(index){
  209. var ary = new Array();
  210. $('.ace_check').each(function(index, item) {
  211. if(this.checked && index != 0) {
  212. ary.push($(this).attr('name'));
  213. }
  214. });
  215. if(ary.length <= 0) {
  216. ZZAlertInfo('请勾选!!!');
  217. return;
  218. }
  219. var pro_str = ary.join(',');
  220. var data = {
  221. tp: "saleRule_getRuleBaseInfo",
  222. supplier_id: pro_str,
  223. ticket_id:ticket_id
  224. }
  225. $.ajax({
  226. url: base_api+'lineManager/index.php', //请求地址
  227. type: "post", //请求方式
  228. data: data,
  229. dataType: "json",
  230. success: function(data) {
  231. console.log(data);
  232. if(data.code == 0) {
  233. load_amend_base(data.saleType,data.define_type,data.back_commision_type,data.back_commision_method,data.base_info);
  234. }
  235. }
  236. });
  237. }
  238. //加载修改销售规则的基本信息
  239. function load_amend_base(data1,data2,data3,data4,data5){
  240. var saleType = "";
  241. var define_type = "";
  242. var back_commision_type = "";
  243. var back_commision_method = "";
  244. var authority_status = "";
  245. var choose_unit = "";
  246. if(data5.back_commision_method=="308"){
  247. choose_unit = "%";
  248. }else if(data5.back_commision_method=="335"){
  249. choose_unit = "元";
  250. }
  251. if(data5.authority_status=="0"){
  252. authority_status = "images/off.png";
  253. }else{
  254. authority_status = "images/on.png";
  255. }
  256. for(var i=0;i<data1.length;i++){
  257. saleType += '<option value="'+data1[i].type_id+'">'+data1[i].type_name+'</option>'
  258. }
  259. for(var i=0;i<data2.length;i++){
  260. define_type += '<option value="'+data2[i].type_id+'">'+data2[i].type_name+'</option>'
  261. }
  262. for(var i=0;i<data3.length;i++){
  263. back_commision_type += '<option value="'+data3[i].type_id+'">'+data3[i].type_name+'</option>'
  264. }
  265. for(var i=0;i<data4.length;i++){
  266. if(data4[i].type_id != 309){
  267. back_commision_method += '<option value="'+data4[i].type_id+'">'+data4[i].type_name+'</option>'
  268. }
  269. }
  270. $("#sale_type").html(saleType);
  271. $("#define_type").html(define_type);
  272. $("#back_commision_type").html(back_commision_type);
  273. $("#back_commision_method").html(back_commision_method);
  274. $("#sale_type").val(data5.sale_type);
  275. $("#is_rule").val(data5.commision_flag);
  276. $("#define_type").val(data5.commision_type);
  277. $("#authority_status").attr("src",authority_status);
  278. $("#back_commision_type").val(data5.back_commision_type);
  279. $("#back_commision_method").val(data5.back_commision_method);
  280. $("#unit").text(choose_unit);
  281. $("#sup_defind").text(data5.sale_rule);
  282. $("#prod_price").val(data5.prod_price);
  283. $("#back_commision_value").val(data5.back_commision_value);
  284. if(data5.sale_type=="177"){
  285. $("#prod").show();
  286. }else{
  287. $("#prod").hide();
  288. }
  289. if(data5.commision_flag=="1"){
  290. $("#define_type").show();
  291. $(".regulation").show();
  292. }else{
  293. $("#define_type").hide();
  294. $(".regulation").hide();
  295. }
  296. if(data5.commision_type=="304"){
  297. tiankeng = "chanping";
  298. $(".regulation").show();
  299. $(".regulation2").hide();
  300. }else{
  301. tiankeng = "qudao";
  302. $(".regulation").hide();
  303. $(".regulation2").show();
  304. }
  305. $(".amend_ticket_type").show();
  306. }
  307. //根据有无佣金规则显示、隐藏佣金规则
  308. function brokerage_type(index){
  309. if(tiankeng == "chanping"){
  310. if($(index).val()=="1"){
  311. $("#define_type").show();
  312. $(".regulation").show();
  313. }else{
  314. $("#define_type").hide();
  315. $(".regulation").hide();
  316. }
  317. }else{
  318. if($(index).val()=="1"){
  319. $("#define_type").show();
  320. $(".regulation2").show();
  321. }else{
  322. $("#define_type").hide();
  323. $(".regulation2").hide();
  324. }
  325. }
  326. }
  327. //根据销售规则显示、隐藏分销价
  328. function sell_type(index){
  329. if($(index).val()=="177"){
  330. $("#prod").show();
  331. }else{
  332. $("#prod").hide();
  333. }
  334. }
  335. //根据产品定义、渠道定义
  336. function definition(index){
  337. if($(index).val()=="304"){
  338. tiankeng = "chanping";
  339. $(".regulation").show();
  340. $(".regulation2").hide();
  341. }else{
  342. tiankeng = "qudao";
  343. $(".regulation").hide();
  344. $(".regulation2").show();
  345. }
  346. }
  347. //改变授权状态
  348. function choose_state(index){
  349. var supplier_id = $(index).attr("supplier_id");
  350. var status = "";
  351. var status_img = $(index).attr("src");
  352. if(status_img=="images/off.png"){
  353. status = "1";
  354. }else{
  355. status = "0";
  356. }
  357. $.ajax({
  358. url:base_api+'lineManager/index.php', //请求地址
  359. data:{
  360. tp:"saleRule_updateAuthorize",
  361. ticket_list:ticket_id,
  362. supplier_id:supplier_id,
  363. line_id:line_id,
  364. authority_status:status
  365. },
  366. type: "post", //请求方式
  367. dataType: "json",
  368. success: function (data) {
  369. console.log(data);
  370. if(data.code == 0){
  371. http_data();
  372. }else{
  373. ZZAlertInfo(data.info);
  374. }
  375. }
  376. });
  377. }
  378. //根据结算金额、销售金额改变单位
  379. function choose_unit(index){
  380. if($(index).val()=="308"){
  381. $("#unit").text("%");
  382. }else if($(index).val()=="335"){
  383. $("#unit").text("元");
  384. }
  385. }
  386. //保存修改
  387. function submit_amend(){
  388. var ary = new Array();
  389. $('.ace_check').each(function(index, item) {
  390. if(this.checked && index != 0) {
  391. ary.push($(this).attr('name'));
  392. }
  393. });
  394. if(ary.length <= 0) {
  395. ZZAlertInfo('请勾选!!!');
  396. return;
  397. }
  398. var pro_str = ary.join(',');
  399. var _sale_type = $("#sale_type").val();
  400. var _prod_price = "";
  401. var _cut_img = "";
  402. if($("#authority_status").attr("src")=="images/on.png"){
  403. _cut_img = "1";
  404. }else{
  405. _cut_img = "0";
  406. }
  407. if(_sale_type=="177"){
  408. _prod_price = $("#prod_price").val();
  409. }else{
  410. _prod_price = "0";
  411. }
  412. var _is_rule = $("#is_rule").val();
  413. var _define_type = $("#define_type").val();
  414. var _commision_type = $("#back_commision_type").val();
  415. var _commision_methed = $("#back_commision_method").val();
  416. var _back_value = $("#back_commision_value").val();
  417. var data = {
  418. tp: "saleRule_updateRule",
  419. supplier_list: pro_str,
  420. ticket_list: ticket_id,
  421. line_id: line_id,
  422. sale_type: _sale_type, //销售方式
  423. prod_price: _prod_price, //(分销价)
  424. is_rule: _is_rule, //是否有佣金规则 1:有,0:无
  425. authority_status: _cut_img, //授权开关 0:关 1:开
  426. define_type: _define_type, //佣金规则类型
  427. commision_type: _commision_type, //返佣类别
  428. commision_methed: _commision_methed, //返佣方式
  429. back_value: _back_value //值
  430. }
  431. $.ajax({
  432. url: base_api+'lineManager/index.php', //请求地址
  433. type: "post", //请求方式
  434. data: data,
  435. dataType: "json",
  436. success: function(data) {
  437. console.log(data);
  438. if(data.code == 0) {
  439. ZZAlertInfo("修改成功!");
  440. http_data();
  441. $(".amend_ticket_type").hide();
  442. }else{
  443. ZZAlertInfo(data.info);
  444. }
  445. }
  446. });
  447. }
  448. function cut_img(index){
  449. if($(index).attr("src")=="images/on.png"){
  450. $(index).attr("src","images/off.png")
  451. }else{
  452. $(index).attr("src","images/on.png")
  453. }
  454. }