客户满意度调查和不再询问 him/her 的复选框

Customer satisfaction survey and checkbox to not ask him/her again

我正在使用 Sweet Alert 2 实现客户满意度模块。

几乎一切正常,唯一悬而未决的 activity 是控制客户何时决定不再看到满意度调查屏幕。

我们的想法是使用带有消息 "Do not ask me again." 的复选框和确认按钮,或者使用相同的复选框和取消按钮。

在同一客户操作中,我将显示消息并更新数据库列 table 作为标志 1 或 0。

目前开发的代码如下:

swal({
    title: 'Survey',
    html: 'Would you like to answer a customer survey?',
    type: 'question',
    showCancelButton: true,
    cancelButtonText: 'No',
    confirmButtonText: 'Yes',
    confirmButtonClass: 'btn btn-success',
    cancelButtonClass: 'btn btn-danger',
    buttonsStyling: true,
    input: 'checkbox',
    inputPlaceholder: 'Do not ask me again'

}).then(function(inputValue) {

    win = window.open(win, '_blank');

    if (win) {

        //Browser has allowed it to be opened
        win.focus();

        swal({
            html: 'The company thanks you for your participation',
            type: 'success'
        });

        // if the customer checked to not see the survey requisition again call a function that update the database (1 for ask again and 0 to not)
        if (inputValue) {
            customerSurvey(customerId, 0);
        }

    } else {

        swal({
            title: 'Atention!',
            html: 'Please, allow your browser to display popups window.',
            type: 'warning'
        });

    }

}, function (dismiss) {

    swal({
        //title: 'Information!',
        html: 'Thank you for your attention.',
        type: 'info'
    });

});

如您所见,当客户单击复选框和按钮 "Yes" 时,当第一个函数将 inputValue 作为参数时,它就按照我的期望工作。但是,我们如何处理 dismiss 时的第二个函数?

您可以使用全局变量并监听复选框何时更改并分配全局变量。然后可以在您解雇的功能中使用它。

var checkboxVal = false;
swal({
    title: 'Survey',
    html: 'Would you like to answer a customer survey?',
    type: 'question',
    showCancelButton: true,
    cancelButtonText: 'No',
    confirmButtonText: 'Yes',
    confirmButtonClass: 'btn btn-success',
    cancelButtonClass: 'btn btn-danger',
    buttonsStyling: true,
    input: 'checkbox',
    inputPlaceholder: 'Do not ask me again'
}).then(function (inputValue) {

    win = window.open(win, '_blank');

    if (win) {

        //Browser has allowed it to be opened
        win.focus();

        swal({
            html: 'The company thanks you for your participation',
            type: 'success'
        });

        // if the customer checked to not see the survey requisition again call a function that update the database (1 for ask again and 0 to not)
        if (inputValue) {
            customerSurvey(customerId, 0);
        }
    } else {
        swal({
            title: 'Atention!',
            html: 'Please, allow your browser to display popups window.',
            type: 'warning'
        });
    }
}, function (dismiss) {
    if (checkboxVal) {
        console.log("user has checked they do not want to view this popup again.");
        //handle your database call here
    }

    swal({
        //title: 'Information!',
        html: 'Thank you for your attention.',
        type: 'info'
    });
});

  /*
   *The following code handles when the checkbox has changed
   */
$('#swal2-checkbox').change(
    function () {
        if ($(this).is(':checked')) {
            checkboxVal = true;
        } else {
            checkboxVal = true;
        }
    });

这是一个有效的 jSfiddle

希望对您有所帮助,祝您好运!