goods.js 7.9 KB
Newer Older
G
gongfuxiang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
$(function()
{
    // 商品导航
    $('.goods-nav li a').on('click', function()
    {
        $('.goods-nav li a').removeClass('goods-nav-active');
        $(this).addClass('goods-nav-active');
    })

    // 规格列添加
    $('.specifications-nav-title-add').on('click', function()
    {
        if($('.specifications-table th.table-title').length >= 5)
        {
            Prompt('最多添加5列规格');
            return false;
        }

        // title
        var index = parseInt(Math.random()*1000001);
        html = '<th class="table-title table-title-'+index+'">';
        html += '<i class="am-close am-close-spin title-nav-remove" data-index="'+index+'">&times;</i>';
        html += '<input type="text" name="specifications_name_'+index+'" placeholder="规格名" />';
        html += '</th>';
        $('.title-start').before(html);

        // value
D
devil_gong 已提交
28
        html = '<td class="table-value table-value-'+index+'">';
G
gongfuxiang 已提交
29 30 31
        html += '<input type="text" name="specifications_value_'+index+'[]" placeholder="规格值" />';
        html += '</td>';
        $('.value-start').before(html);
G
goods  
gongfuxiang 已提交
32 33 34

        // 规格图片
        SpecImagesHandle();
G
gongfuxiang 已提交
35 36 37 38 39 40 41 42 43 44 45 46 47
    });

    // 规格列移除
    $('.specifications-table').on('click', '.title-nav-remove', function()
    {
        var index = $(this).data('index');
        $('.table-title-'+index).remove();
        $('.table-value-'+index).remove();

        if($('.specifications-table th.table-title').length <= 0)
        {
            $('.specifications-table tr.line-not-first').remove();
        }
G
goods  
gongfuxiang 已提交
48 49 50

        // 规格图片
        SpecImagesHandle();
G
gongfuxiang 已提交
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
    });

    // 添加一行规格值
    $('.specifications-line-add').on('click', function()
    {
        if($('.specifications-table th.table-title').length <= 0)
        {
            Prompt('请先添加规格');
            return false;
        }

        var html = $('.specifications-table').find('tbody tr:last').prop('outerHTML');
        if(html.indexOf('<!--operation-->') >= 0)
        {
            html = html.replace(/<!--operation-->/ig, '<span class="fs-12 cr-blue c-p m-r-5 line-copy">复制</span> <span class="fs-12 cr-red c-p line-remove">移除</span>');
        }
        $('.specifications-table').append(html);
        $('.specifications-table').find('tbody tr:last').addClass('line-not-first');

        // 值赋空
        $('.specifications-table').find('tbody tr:last').find('input').each(function(k, v)
        {
            $(this).attr('value', '');
        });
G
goods  
gongfuxiang 已提交
75 76 77

        // 规格图片
        SpecImagesHandle();
G
gongfuxiang 已提交
78 79 80 81 82 83 84 85 86 87 88
    });

    // 规格行复制
    $('.specifications-table').on('click', '.line-copy', function()
    {
        var $parent = $(this).parents('tr');
        $parent.find('input').each(function(k, v)
        {
            $(this).attr('value', $(this).val());
        });
        $parent.after($parent.prop('outerHTML'));
G
goods  
gongfuxiang 已提交
89 90 91

        // 规格图片
        SpecImagesHandle();
G
gongfuxiang 已提交
92 93 94 95 96 97
    });

    // 规格行移除
    $('.specifications-table').on('click', '.line-remove', function()
    {
        $(this).parents('tr').remove();
D
devil_gong 已提交
98 99 100 101 102 103

        if($('.specifications-table tbody tr').length <= 1)
        {
            $('.specifications-table th.table-title').remove();
            $('.specifications-table td.table-value').remove();
        }
G
goods  
gongfuxiang 已提交
104 105 106

        // 规格图片
        SpecImagesHandle();
D
devil_gong 已提交
107 108 109 110 111
    });

    // 规格首列事件
    $('.spec-images-tips').on('change', 'input', function()
    {
G
goods  
gongfuxiang 已提交
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
        // 规格图片
        SpecImagesHandle();
    });

    // 规格第一列输入事件
    $('.specifications-table tbody tr').on('change', 'td:eq(0) input', function()
    {
        // 规格图片
        SpecImagesHandle();
    });

    // 规格图片
    function SpecImagesHandle()
    {
        if($('.spec-images-tips input').prop('checked'))
D
devil_gong 已提交
127
        {
G
goods  
gongfuxiang 已提交
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
            var temp_spec_all = {}, spec_all = [];
            $('.specifications-table tbody tr').each(function(k, v)
            {
                var value = $(this).find('td:eq(0) input').val();
                temp_spec_all[value] = value;
            });
            spec_all = Object.keys(temp_spec_all);
            if(spec_all.length > 0)
            {
                for(var i in spec_all)
                {
                    var temp_class = 'spec-images-items-'+spec_all[i];
                    if($('ul.spec-images-list').find('.'+temp_class).length <= 0)
                    {
                        var html = '<li class="'+temp_class+'">';
                            html += '<input type="text" value="'+spec_all[i]+'" disabled="disabled" />'
                            html += '<ul class="plug-file-upload-view spec-images-view-'+spec_all[i]+'" data-form-name="spec_images[]" data-max-number="1" data-delete="0" data-dialog-type="images">';
                            html += '<li>';
                            html += '<input type="hidden" name="spec_images[]" value="" />';
                            html += '<img src="'+__image_host__+'/static/admin/default/images/default-images.png" />';
                            html += '</li>';
                            html += '</ul>';
                            html += '<div class="plug-file-upload-submit" data-view-tag="ul.spec-images-view-'+spec_all[i]+'">+上传图片</div>';
                            html += '</li>';
                        $('ul.spec-images-list').append(html);
                    }
                }
            }
D
devil_gong 已提交
156
        } else {
G
goods  
gongfuxiang 已提交
157
            $('ul.spec-images-list').html('');
D
devil_gong 已提交
158
        }
G
goods  
gongfuxiang 已提交
159
    }
G
gongfuxiang 已提交
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212

    // 手机详情添加
    $(document).on('click', '.content-app-items-add-sub', function()
    {
        var $content_tag = $('.content-app-items');

        var i = (($(this).attr('index') || null) == null) ? parseInt($content_tag.find('li').length) : parseInt($(this).attr('index'));
        var index = parseInt(Math.random()*1000001)+i;

        var images_name = $content_tag.data('images-name');
        var content_name = $content_tag.data('content-name');
        var images_text = $content_tag.data('images-text');
        var content_text = $content_tag.data('content-text');
        var delete_text = $content_tag.data('delete-text');
        var drag_sort_text = $content_tag.data('drag-sort-text');

        var html = '<li><div>';
            // 左侧
            html += '<div class="content-app-left">';
            html += '<label class="block">图片</label>';
            html += '<ul class="plug-file-upload-view goods-content-app-images-view-'+index+'" data-form-name="'+images_name+'_'+index+'" data-max-number="1" data-dialog-type="images">';
            html += '</ul>';
            html += '<div class="plug-file-upload-submit" data-view-tag="ul.goods-content-app-images-view-'+index+'">+上传图片</div>';
            html += '</div>';

            // 右侧
            html += '<div class="am-form-group content-app-right fr">';
            html += '<label>文本内容</label>';
            html += '<textarea rows="3" name="'+content_name+'_'+index+'" class="am-radius" placeholder="'+content_text+'" data-validation-message=""></textarea>';
            html += '</div>';
            html += '</div>';

            // 操作按钮
            html += '<i class="c-p fs-12 cr-red content-app-items-rem-sub">删除</i>';
            html += ' <i class="c-m fs-12 drag-sort-submit">拖拽排序</i>';
            html += '</li>';
        $content_tag.append(html);
        $content_tag.attr('index', index);
        $(this).attr('index', i+1);
    });

    // 手机详情删除
    $(document).on('click', '.content-app-items-rem-sub', function()
    {
        $(this).parent().remove();
    });

    // 拖拽
    $('ul.goods-photo-view').dragsort({ dragSelector: 'img', placeHolderTemplate: '<li class="drag-sort-dotted"></li>'});
    $('ul.content-app-items').dragsort({ dragSelector: 'i.drag-sort-submit', placeHolderTemplate: '<li class="drag-sort-dotted"></li>'});
    $('ul.goods-attribute-items').dragsort({ dragSelector: 'i.drag-sort-submit', placeHolderTemplate: '<li class="drag-sort-dotted"></li>'});

});