// https://gitee.com/cshaptx4869/sku-table
layui.use(['jquery','layer', 'form'], function () {
    var $ = layui.jquery,
        layer = layui.layer,
        form = layui.form;
    let productId = $('#fairy-sku-table').data('id');
    let productTypeId = $('#fairy-sku-table').data('type');
    let multiSpec = $('#fairy-sku-table').data('multi');
    let option = [];
    option['onlyMode'] = $('#fairy-is-attribute').data('only') >= 0 ? $('#fairy-is-attribute').data('only') : '';
    let skuTableObj = renderSku(productId ? productId : 0, productTypeId, multiSpec, option)

    form.on('submit(submit)', function (data) {
        //获取表单数据
        console.log(data.field);

        if (skuTableObj.getMode() === 0) {
            //单规格
            layer.alert(JSON.stringify(data.field), {title: '提交的数据'});
        } else {
            //多规格
            var state = Object.keys(data.field).some(function (item, index, array) {
                return item.startsWith('skus');
            });
            state ? layer.alert(JSON.stringify(data.field), {title: '提交的数据'}) : layer.msg('sku表数据不能为空', {icon: 5, anim: 6});
        }

        return false;
    });
});