zero-buy.page.js 1.7 KB
require('admin/activity.page.css');

const $alert = $('#alert-modal');
const $confirm = $('#confirm-modal');

// $('#alert-modal').modal('show')

function bindEvent() {
    const editStatusFn = function(id, status) {
        return $.ajax({
            method: 'post',
            url: '/admin/activity/zerobuy/editStatus',
            data: {
                id,
                status
            }
        });
    };

    const editFn = function() {
        window.open('/admin/activity/zerobuy/edit?id=' +
            $(this).parent().data('id'), '_blank');
    };

    const switchFn = function() {
        let $this = $(this);
        let status = $this.hasClass('btn-switch-open') ? 1 : 0;

        editStatusFn($this.data('id'), status).then(res => {
            if (res.code === 200) {
                location.reload();
            } else {
                $alert.find('.modal-text').text(res.message);
                $alert.modal('show');
            }
        });
    };

    const exportFn = function() {

    };

    let publishId;
    const publishFn = function() {
        editStatusFn(publishId, 2).then(res => {
            if (res.code === 200) {
                location.reload();
            } else {
                $alert.find('.modal-text').text(res.message);
                $alert.modal('show');
            }
        });
    };


    $('.btn-edit').on('click', editFn);
    $('.btn-switch-open').on('click', switchFn);
    $('.btn-switch-close').on('click', switchFn);
    $('.btn-export').on('click', exportFn);
    $('.btn-publish').on('click', function() {
        publishId = $(this).data('id');
        $confirm.modal('show');
    });
    $('.sure-publish-btn').on('click', publishFn);
}


bindEvent();