goods.limitcategory.Index.js 5.52 KB
webpackJsonp([45],[
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	/**
	 * Created by yoho on 2016/6/28.
	 */
	'use strict';
	var $ = __webpack_require__(1),
	    common = __webpack_require__(2);

	var renderHd = false;//加载表格头部
	var tabTree = new common.tabTree("#sort");
	tabTree.init();
	//分类Id
	new common.dropDown({
	    el: "#SortId", ajax: "fuzzySearchProductSortIds"
	});
	//分类级别
	new common.dropDown({
	    el: "#SortLevel", ajax: "searchAllSortLevel"
	});
	var Bll = {
	    dataList: [],
	    searchList: {},
	    selectSort: function () {
	        var select = tabTree.getAddress();
	        if (select[0].id) {
	            Bll.searchList.sortNameId = select[select.length - 1].id;
	        }
	    },
	    getDataList: function () {
	        Bll.selectSort();
	        common.util.__ajax({
	            url: "/product/queryProductSortRefundAllReferdSortInfo",
	            async: false,
	            data: Bll.searchList
	        }, function (res) {
	            Bll.dataList = res.data;
	        }, true);
	    },
	    reload: function () {
	        renderHd = false;
	        Bll.getDataList();
	        g.init(Bll.dataList);
	    }
	};
	/**
	 * 列表
	 */
	var g = new common.grid({
	    el: "#basicTable",
	    columns: [
	        {
	            display: '',
	            name: 'foler',
	            render: function (item) {
	                var html = "", top = true, isRefundExchange = 1;
	                if (!renderHd) {
	                    html += $('#tableHdTemp').html();
	                    init(item);
	                    renderHd = true;
	                } else {
	                    init(item)
	                }
	                return html;
	                function init(item) {
	                    if (top) {
	                        html += "<div id='category_id_" + item.id + "' class='level-wrap clearfix'>";
	                        top = false;
	                    } else {
	                        html += "<div id='category_id_" + item.id + "' class='level-wrap clearfix level_" + item.sortLevel + "' style='display: none'>";
	                    }
	                    html += common.util.__template2($('#tableTemp2').html(), item);
	                    if (item.subList.length>0) {//如果有子集
	                        for (var i = 0; i < item.subList.length; i++) {
	                            init(item.subList[i]);
	                        }
	                    }
	                    html += "</div>";
	                }
	            }
	        }
	    ]
	});
	Bll.getDataList();
	g.init(Bll.dataList);

	//打开层级类目
	$(document).on('click', '.folder', function () {
	    var $wrap = $(this).parent();
	    if (!$(this).hasClass('open')) {
	        var isfont = $(this).data('name');
	        if(isfont==0){
	            $wrap.find('.level-wrap .operate a').hide();
	        }

	        if ($wrap.find('> .level-wrap').size() > 0) {
	            var position = $(this).css("background-position");
	            var a = position.substring(0, position.indexOf("px"));
	            $wrap.find('> .level-wrap').show().find(".folder").css("background-position", (parseInt(a) + 36) + "px");
	            $(this).addClass('open');
	        }
	    } else {
	        $(this).removeClass('open');
	        if ($wrap.find('.level-wrap').size() > 0) {
	            $wrap.find('.level-wrap').hide().find(".folder").removeClass('open').css("background-position", "12px center");
	        }
	    }
	});

	//切换状态重载列表
	$('input[name="state"]').on('change', function () {
	    $(this).parent().addClass('current').siblings().removeClass('current');
	    g.reload();
	});

	$(document).on('change', '#categoryName', function () {
	    $(this).removeClass("error")
	});

	/**
	 * 监控筛选项
	 */
	$(document).on('change', '#SortId', function () {
	    if ($(this).val() == -1) {
	        Bll.searchList.sortId = ""
	    } else {
	        Bll.searchList.sortId = $(this).val() ? $(this).val() : "";
	    }

	});
	$(document).on('change', '#SortLevel', function () {
	    if ($(this).val() == -1) {
	        Bll.searchList.sortLevel = ""
	    } else {
	        Bll.searchList.sortLevel = $(this).val() ? $(this).val() : "";
	    }
	});

	/**
	 * 筛选按钮
	 */
	$(document).on('click', "#filter-btn", function () {
	    Bll.reload();
	});
	//导出
	$(document).on('click', '#export-btn', function () {
	    Bll.selectSort();
	    var queryConf = JSON.stringify(Bll.searchList);
	    window.open("/ajax/down?queryConf=" + queryConf + "&type=productSortRefundExchangeExport");
	});
	/**
	 * 开启
	 */
	$(document).on('click', ".close-category", function () {
	    var id = $(this).parent().data('id');
	    common.dialog.confirm("警告",
	        "开启后关联商品会一并开启,请谨慎操作!",
	        function () {
	            common.util.__ajax({
	                url: '/product/closeProductSortRefundExchange',
	                data: {
	                    param: id
	                }
	            }, function () {
	                Bll.reload();
	            }, true);
	        });
	});
	/**
	 * 关闭
	 */
	$(document).on('click', ".open-category", function () {
	    var id = $(this).parent().data('id');
	    common.dialog.confirm("警告",
	        "关闭后关联商品会一并关闭,请谨慎操作!",
	        function () {
	            common.util.__ajax({
	                url: '/product/openProductSortRefundExchange',
	                data: {
	                    param: id
	                }
	            }, function () {
	                Bll.reload();
	            }, true);
	        });
	});

/***/ }
]);