upload-excel.page.js 2.22 KB
require('admin/user.page.css');
require('bootpag/lib/jquery.bootpag.min');

const _ = require('lodash');

function bind_delete_user() {
    const deleteFn = function() {
        const userId = $(this).data('id');

        $.ajax({
            method: 'post',
            url: '/admin/api/user/deleteInfoUser',
            data: {
                userId
            }
        })
        .then(() => {
            location.reload();
        });
    };

    $(document).on('click', '.btn-delete-user', deleteFn);
}

function bind_table_pagination(list) {
    const $ul = $('.user-list');
    let html = '';

    _.each(list, item => {
        html += `
                    <tr class="even pointer">
                        <td class="">${item.id}</td>
                        <td class=""><img src="${item.head_url}" style="width: 50px;height: 50px;border-radius: 50px;"></td>
                        <td class=""><img src="${item.img_url}" style="width: 50px;height: 50px;"></td>
                        <td class="">${item.name}</td>
                        <td class="">${item.tag}</td>
                        <td class="">${item.style}</td>
                        <td class="">${item.career}</td>
                        <td class="">${item.skns_1 || ''} || ${item.skns_2 || ''}</td>
                        <td class="">${item.interest}</td>
                        <td class="">${item.desc}</td>
                    </tr>`;
    });

    $ul.html(html);
}

function bind_export_user_list() {
    let uploadFn = function() {
        let $form = $('#uploadForm')[0];
        let formData = new FormData($form);

        formData.append('actId', $(this).data('id'));

        console.log($form);
        if ($form) {
            $.ajax({
                url: '/api/excel/loady100file',
                data: formData,
                method: 'POST',
                cache: false,
                processData: false,
                contentType: false,
                success: function(res) {
                    console.log(res.data);
                    bind_table_pagination(res.data);
                }
            });
        }
    };

    $('.btn-upload-excel').on('click', uploadFn);
}



(function() {
    bind_delete_user();
    bind_export_user_list();
}());