| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- layui.use(['form', 'jquery', 'madmin', 'mhttp', 'layer'], function () {
- let form = layui.form;
- let $ = layui.jquery;
- let layer = layui.layer;
- let admin = layui.madmin;
- let http = layui.mhttp;
- admin.getConfig();
- // 查询应用
- let appRet = http.ajax({
- url: '/app/all'
- });
- appRet.then((data) => {
- if (data.code === 200) {
- let html = '<option value=""></option>';
- for (let i in data.data) {
- html += '<option value="' + data.data[i].uid + '" class="che_' + data.data[i].uid + '">' + data.data[i].name + '</option>';
- }
- $('.app_uid').html(html);
- form.render();
- } else {
- $('.app-help').append('<span class="app-error">获取应用失败,刷新重试!</span>');
- }
- });
- form.on('submit(cps-save)', function (data) {
- let createLoading = layer.load();
- if (data.field.deduction_price.search(',') != -1) {
- layer.confirm('检测到扣量价格有","是否替换为以","分隔?', {
- icon: 3,
- title: '提示'
- }, function (index) {
- layer.close(index);
- $('.deduction_price').val(data.field.deduction_price.replace(/,/g, ","));
- layer.msg('已替换请再次确认!');
- });
- return false;
- }
- if (data.field.deduction_pro.search(',') != -1) {
- layer.confirm('检测扣量数量格有","是否替换为以","分隔?', {
- icon: 3,
- title: '提示'
- }, function (index) {
- layer.close(index);
- $('.deduction_pro').val(data.field.deduction_pro.replace(/,/g, ","));
- layer.msg('已替换请再次确认!');
- });
- return false;
- }
- let deductionPriceObg = [];
- if (data.field.deduction_price) {
- let priceArray = data.field.deduction_price.split(',');
- for (let i in priceArray) {
- let priceArrayItem = priceArray[i].split('-');
- deductionPriceObg.push({
- min_price: priceArrayItem[0],
- max_price: priceArrayItem[1],
- })
- }
- }
- let deductionProObg = [];
- if (data.field.deduction_pro) {
- let numberArray = data.field.deduction_pro.split(',');
- for (let i in numberArray) {
- let numberArrayItem = numberArray[i].split('-');
- deductionProObg.push({
- number: numberArrayItem[0],
- deduction: numberArrayItem[1],
- })
- }
- }
- if (deductionPriceObg.length !== deductionProObg.length) {
- layer.msg('扣量金额与扣量比例与对映不上!');
- return false;
- }
- let postData = data.field;
- postData.jdata = JSON.stringify({
- deduction_price: deductionPriceObg,
- deduction_number: deductionProObg,
- });
- postData.deduction_type = 'cps';
- let ret = http.ajax({
- url: '/deduction/create',
- data: postData
- });
- ret.then((data) => {
- layer.close(createLoading);
- if (data.code === 200) {
- layer.msg(data.message, {icon: 1, time: 1000}, function () {
- // 成功刷父页面
- window.parent.location.reload();
- // 成功关闭父窗口
- let index = parent.layer.getFrameIndex(window.name);
- parent.layer.close(index);
- });
- } else {
- layer.msg(data.message, {icon: 2, time: 1000});
- }
- });
- return false;
- });
- });
|