guochao-option.page.js 1.49 KB
require('admin/coupon-option.page.css');
require('bootstrap-daterangepicker');
require('bootpag/lib/jquery.bootpag.min');

function bindEditPageEvent() {

    function packInfo() {
        let resData = {};
        let error;

        $('.form-imput').each(function() {

            let $this = $(this);
            let val = $this.val();
            let data = $this.data();

            if (!val && !error) {
                error = data.empty || `请填写${data.type}`;
            }
            resData[data.type] = val;
        });

        if (error) {
            alert(error);// eslint-disable line
            return;
        }


        resData.place = $('input[name=place]:checked').val();
        return resData;
    }

    function radioInit() {
        let place = parseInt($('#place').val());

        if (place) {
            $($('input[name=place]')[1]).attr('checked', true);
        } else {
            $($('input[name=place]')[0]).attr('checked', true);
        }
    }

    radioInit();


    $('.btn-save').on('click', function() {
        let info = packInfo();

        if (!info || window.saveing) {
            return;
        }

        window.saveing = true;

        $.ajax({
            method: 'post',
            url: '/admin/api/guochao/update',
            contentType: 'application/json',
            data: JSON.stringify(info)
        }).then(() => {
            window.saveing = false;
            alert('保存成功');
        });
    });
}

(function() {
    bindEditPageEvent();
}());