deduction_cps_create.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. // 查询应用
  9. let appRet = http.ajax({
  10. url: '/app/all'
  11. });
  12. appRet.then((data) => {
  13. if (data.code === 200) {
  14. let html = '<option value=""></option>';
  15. for (let i in data.data) {
  16. html += '<option value="' + data.data[i].uid + '" class="che_' + data.data[i].uid + '">' + data.data[i].name + '</option>';
  17. }
  18. $('.app_uid').html(html);
  19. form.render();
  20. } else {
  21. $('.app-help').append('<span class="app-error">获取应用失败,刷新重试!</span>');
  22. }
  23. });
  24. form.on('submit(cps-save)', function (data) {
  25. let createLoading = layer.load();
  26. if (data.field.deduction_price.search(',') != -1) {
  27. layer.confirm('检测到扣量价格有","是否替换为以","分隔?', {
  28. icon: 3,
  29. title: '提示'
  30. }, function (index) {
  31. layer.close(index);
  32. $('.deduction_price').val(data.field.deduction_price.replace(/,/g, ","));
  33. layer.msg('已替换请再次确认!');
  34. });
  35. return false;
  36. }
  37. if (data.field.deduction_pro.search(',') != -1) {
  38. layer.confirm('检测扣量数量格有","是否替换为以","分隔?', {
  39. icon: 3,
  40. title: '提示'
  41. }, function (index) {
  42. layer.close(index);
  43. $('.deduction_pro').val(data.field.deduction_pro.replace(/,/g, ","));
  44. layer.msg('已替换请再次确认!');
  45. });
  46. return false;
  47. }
  48. let deductionPriceObg = [];
  49. if (data.field.deduction_price) {
  50. let priceArray = data.field.deduction_price.split(',');
  51. for (let i in priceArray) {
  52. let priceArrayItem = priceArray[i].split('-');
  53. deductionPriceObg.push({
  54. min_price: priceArrayItem[0],
  55. max_price: priceArrayItem[1],
  56. })
  57. }
  58. }
  59. let deductionProObg = [];
  60. if (data.field.deduction_pro) {
  61. let numberArray = data.field.deduction_pro.split(',');
  62. for (let i in numberArray) {
  63. let numberArrayItem = numberArray[i].split('-');
  64. deductionProObg.push({
  65. number: numberArrayItem[0],
  66. deduction: numberArrayItem[1],
  67. })
  68. }
  69. }
  70. if (deductionPriceObg.length !== deductionProObg.length) {
  71. layer.msg('扣量金额与扣量比例与对映不上!');
  72. return false;
  73. }
  74. let postData = data.field;
  75. postData.jdata = JSON.stringify({
  76. deduction_price: deductionPriceObg,
  77. deduction_number: deductionProObg,
  78. });
  79. postData.deduction_type = 'cps';
  80. let ret = http.ajax({
  81. url: '/deduction/create',
  82. data: postData
  83. });
  84. ret.then((data) => {
  85. layer.close(createLoading);
  86. if (data.code === 200) {
  87. layer.msg(data.message, {icon: 1, time: 1000}, function () {
  88. // 成功刷父页面
  89. window.parent.location.reload();
  90. // 成功关闭父窗口
  91. let index = parent.layer.getFrameIndex(window.name);
  92. parent.layer.close(index);
  93. });
  94. } else {
  95. layer.msg(data.message, {icon: 2, time: 1000});
  96. }
  97. });
  98. return false;
  99. });
  100. });