| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- 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 loading = layer.msg('加载数据中...', {icon: 16, time: 0, shade: 0.3, shadeClose: false});
- // 查询应用
- 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);
- let uid = GetQueryString('uid');
- let postData = {uid: uid};
- let ret = http.ajax({
- url: '/deduction/detail',
- data: postData
- });
- ret.then((data) => {
- layer.close(loading);
- // 成功显示数据
- if (data.code === 200) {
- $('.deduction_method_' + data.data.deduction_method).attr('selected', 'selected');
- $('.deduction_rule_' + data.data.deduction_rule).attr('selected', 'selected');
- $('.che_' + data.data.app_uid).attr('selected', 'selected');
- $('.deduction_price').val(data.data.deduction_price);
- $('.deduction_pro').val(data.data.deduction_pro);
- $('.uid').val(data.data.uid);
- // 渲染form
- form.render();
- } else {
- layer.msg(data.message, {
- // 失败关闭父窗口
- icon: 2,
- time: 1000
- }, function () {
- let index = parent.layer.getFrameIndex(window.name);
- parent.layer.close(index);
- });
- }
- });
- 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,
- });
- let ret = http.ajax({
- url: '/deduction/modify',
- 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;
- });
- });
|