operations.activitytemplate.Product.js 3.7 KB
webpackJsonp([82],[
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	/**
	 * Created by ty on 2016/7/4.
	 * 模板商品管理
	 */

	var $ = __webpack_require__(1),
	    common = __webpack_require__(2);

	var id = $("#basicForm").data("id");

	/*下拉选择*/
	new common.dropDown({
	    el: "#brandId",
	    ajax: "brand",
	    hash: true,
	    params:function(){
	        return {userLimitFlag:true};
	    }
	});

	var tabTree = new common.tabTree("#sort");
	tabTree.init();


	var g = new common.grid({
	    el: '#product-list',
	    parms: function () {

	        var select = tabTree.getAddress();

	        return {
	            templateId: id,
	            productSkn: common.util.__input("productSkn"),
	            brandId: common.util.__input("brandId"),
	            maxSortId: select[0] ? select[0].id : "",
	            middleSortId: select[1] ? select[1].id : "",
	            smallSortId: select[2] ? select[2].id : "",
	            sortId: select[3] ? select[3].id : ""
	        };
	    },
	    columns: [
	        {
	            display: "ID",
	            name: "id"
	        },
	        {
	            display: "SKN",
	            name: "productSkn"
	        },
	        {
	            display: '操作',
	            render: function (item) {
	                var HtmArr = [];
	                HtmArr.push('&nbsp;&nbsp;&nbsp;排序<input type="text" class="number" value="'+ item.orderBy +'" id="orderBy'+ item.__index +'"/>');
	                HtmArr.push('&nbsp;&nbsp;&nbsp;<input type="checkbox" id="status'+ item.__index +'" '+ (item.status?"checked":"") +'>');
	                HtmArr.push('启用&nbsp;&nbsp;&nbsp;');
	                HtmArr.push('<a data-index="'+ item.__index +'" class="btn btn-primary btn-xs edit">修改</a>');
	                HtmArr.push('<a data-index="'+ item.__index +'" class="btn btn-danger btn-xs del">删除</a>');
	                return HtmArr.join('');
	            }
	        }
	    ]
	});

	g.init("/activityTemplate/getProductListByCondition");

	common.edit.ajaxfileupload("#uploadBox", {
	    params: {
	        type: "activityProduct",
	        __type: "batch-import",
	        args:id
	    },
	    valid_extensions: ['xls', 'xlsx'],
	    onComplete: function (response) {
	        if (response.status && response.code == 200) {
	            common.util.__tip(response.message, 'success');
	            g.reload();
	        }
	        else {
	            common.util.__tip(response.message, 'warning');
	        }
	    }
	});

	//编辑
	$(document).on("click", ".edit", function () {
	    var index = $(this).data("index");
	    var item = g.rows[index];
	    var status = $("#status" + index).prop("checked") ? 1 : 0;
	    var isRecommend = item.isRecommend ? 1 : 0;
	    common.util.__ajax({
	        url: "/activityTemplate/updateProduct",
	        data: {
	            id:item.id,
	            isRecommend:isRecommend,
	            orderBy:$("#orderBy"+index).val(),
	            status: status
	        }
	    }, function () {
	        g.reload();
	    });
	});

	//删除
	$(document).on("click", ".del", function () {
	    var index = $(this).data("index");
	    var item = g.rows[index];
	    common.dialog.confirm("温馨提示","你确定删除吗?",function() {
	        common.util.__ajax({
	            url: "/activityTemplate/delOneProduct",
	            data: {
	                id: item.id
	            }
	        }, function () {
	            g.reload();
	        });
	    });
	});

	$(document).on("click", "#filter-btn", function () {
	    g.reload(1);
	});

	//输入限制
	$(document).on("keyup",".number", function () {
	    $(this).val($(this).val().replace(/\D/g, ''));
	});

	$(document).on("click", "#chooseFile", function () {
	    $("#uploadBox").click();
	});

/***/ }
]);