deduction_cps_edit.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. layui.use(['form', 'jquery', 'madmin', 'mhttp', 'layer'], function () {
  2. let form = layui.form;
  3. let $ = layui.jquery;
  4. let layer = layui.layer;
  5. let admin = layui.madmin;
  6. let http = layui.mhttp;
  7. admin.getConfig();
  8. let loading = layer.msg('加载数据中...', {icon: 16, time: 0, shade: 0.3, shadeClose: false});
  9. // 查询应用
  10. let appRet = http.ajax({
  11. url: '/app/all'
  12. });
  13. appRet.then((data) => {
  14. if (data.code === 200) {
  15. let html = '<option value=""></option>';
  16. for (let i in data.data) {
  17. html += '<option value="' + data.data[i].uid + '" class="che_' + data.data[i].uid + '">' + data.data[i].name + '</option>';
  18. }
  19. $('.app_uid').html(html);
  20. let uid = GetQueryString('uid');
  21. let postData = {uid: uid};
  22. let ret = http.ajax({
  23. url: '/deduction/detail',
  24. data: postData
  25. });
  26. ret.then((data) => {
  27. layer.close(loading);
  28. // 成功显示数据
  29. if (data.code === 200) {
  30. $('.deduction_method_' + data.data.deduction_method).attr('selected', 'selected');
  31. $('.deduction_rule_' + data.data.deduction_rule).attr('selected', 'selected');
  32. $('.che_' + data.data.app_uid).attr('selected', 'selected');
  33. $('.deduction_price').val(data.data.deduction_price);
  34. $('.deduction_pro').val(data.data.deduction_pro);
  35. $('.uid').val(data.data.uid);
  36. // 渲染form
  37. form.render();
  38. } else {
  39. layer.msg(data.message, {
  40. // 失败关闭父窗口
  41. icon: 2,
  42. time: 1000
  43. }, function () {
  44. let index = parent.layer.getFrameIndex(window.name);
  45. parent.layer.close(index);
  46. });
  47. }
  48. });
  49. form.render();
  50. } else {
  51. $('.app-help').append('<span class="app-error">获取应用失败,刷新重试!</span>');
  52. }
  53. });
  54. form.on('submit(cps-save)', function (data) {
  55. let createLoading = layer.load();
  56. if (data.field.deduction_price.search(',') != -1) {
  57. layer.confirm('检测到扣量价格有","是否替换为以","分隔?', {
  58. icon: 3,
  59. title: '提示'
  60. }, function (index) {
  61. layer.close(index);
  62. $('.deduction_price').val(data.field.deduction_price.replace(/,/g, ","));
  63. layer.msg('已替换请再次确认!');
  64. });
  65. return false;
  66. }
  67. if (data.field.deduction_pro.search(',') != -1) {
  68. layer.confirm('检测扣量数量格有","是否替换为以","分隔?', {
  69. icon: 3,
  70. title: '提示'
  71. }, function (index) {
  72. layer.close(index);
  73. $('.deduction_pro').val(data.field.deduction_pro.replace(/,/g, ","));
  74. layer.msg('已替换请再次确认!');
  75. });
  76. return false;
  77. }
  78. let deductionPriceObg = [];
  79. if (data.field.deduction_price) {
  80. let priceArray = data.field.deduction_price.split(',');
  81. for (let i in priceArray) {
  82. let priceArrayItem = priceArray[i].split('-');
  83. deductionPriceObg.push({
  84. min_price: priceArrayItem[0],
  85. max_price: priceArrayItem[1]
  86. })
  87. }
  88. }
  89. let deductionProObg = [];
  90. if (data.field.deduction_pro) {
  91. let numberArray = data.field.deduction_pro.split(',');
  92. for (let i in numberArray) {
  93. let numberArrayItem = numberArray[i].split('-');
  94. deductionProObg.push({
  95. number: numberArrayItem[0],
  96. deduction: numberArrayItem[1],
  97. })
  98. }
  99. }
  100. if (deductionPriceObg.length !== deductionProObg.length) {
  101. layer.msg('扣量金额与扣量比例与对映不上!');
  102. return false;
  103. }
  104. let postData = data.field;
  105. postData.jdata = JSON.stringify({
  106. deduction_price: deductionPriceObg,
  107. deduction_number: deductionProObg,
  108. });
  109. let ret = http.ajax({
  110. url: '/deduction/modify',
  111. data: postData
  112. });
  113. ret.then((data) => {
  114. layer.close(createLoading);
  115. if (data.code === 200) {
  116. layer.msg(data.message, {icon: 1, time: 1000}, function () {
  117. // 成功刷父页面
  118. window.parent.location.reload();
  119. // 成功关闭父窗口
  120. let index = parent.layer.getFrameIndex(window.name);
  121. parent.layer.close(index);
  122. });
  123. } else {
  124. layer.msg(data.message, {icon: 2, time: 1000});
  125. }
  126. });
  127. return false;
  128. });
  129. });