category.Index.js 3.14 KB
webpackJsonp([15],[
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	/*
	 *@time: 2016/1/26
	 *@author: chenglong
	 */


	var $ = __webpack_require__(1);
	var common=__webpack_require__(2);
	    //列表展示效果

	    var $toggleTd = $('.toggle-td');

	    $toggleTd.click(function () {

	        var $this = $(this),
	            $thisNext = $this.closest('tr').nextAll(),
	            thisVal = $(this).closest('tr').attr('data-val');

	        if ($this.closest('tr').attr('data-status') === 'close') {

	            $thisNext.filter(function (index) {

	                return $(this).attr('data-parent') === thisVal;

	            }).removeClass('hidden');

	            $this.closest('tr').attr('data-status', 'open').find('.toggle-td').find('span')
	                .removeClass('glyphicon-folder-close').addClass('glyphicon-folder-open');

	        } else {

	            $thisNext.filter(function (index) {

	                var thisR = $(this).attr('data-parent') === thisVal;

	                if (thisR && $(this).attr('data-status') === 'open') {
	                    $(this).find('.toggle-td').trigger('click');
	                }

	                return thisR;

	            }).addClass('hidden');

	            $this.closest('tr').attr('data-status', 'close').find('.toggle-td').find('span')
	                .removeClass('glyphicon-folder-open').addClass('glyphicon-folder-close');
	        }

	    });

	    //列表编辑

	    var $table = $('.toggle-table');

	    $table.click(function (event) {

	        var $target = $(event.target),
	            id;

	        //编辑
	        if ($target.hasClass('edit-class-btn')) {

	        } else if ($target.hasClass('open-close-btn')) {

	            var status;

	            if ($target.attr('data-status') === '1') {
	                status = 0;
	            } else if ($target.attr('data-status') === '0') {
	                status = 1;
	            }

	            console.log(status);

	            $.ajax({
	                type: 'POST',
	                dataType: 'json',
	                url: status?"/erpproduct/sorter/open":"/erpproduct/sorter/close",
	                data: {
	                    param: $target.closest('td').attr('data-id')
	                }
	            }).then(function (data) {

	                console.log(data);

	                if (data.code === 200) {

	                    $target.attr('data-status', status);
	                    if ($target.hasClass('btn-danger')) {
	                        $target.text('开启');
	                        $target.removeClass('btn-danger')
	                            .addClass('btn-success').closest('td').prev('td').text('关闭');
	                        common.util.__tip("关闭成功!",'success');
	                    } else {
	                        $target.text('关闭');
	                        $target.removeClass('btn-success')
	                            .addClass('btn-danger').closest('td').prev('td').text('开启');
	                        common.util.__tip("开启成功!",'success');
	                    }

	                }
	            });

	            event.preventDefault();
	        }
	    });




/***/ }
]);