productPool.js 3.89 KB
var $ = require('jquery'),
	common = require('../common/common');

	var g = new common.grid({
		el: "#product-pool",
		hash: false,
		parms: function () {
			return {
				id: common.util.__input('search-id'),
				poolName: common.util.__input('search-name')
			};
		},
		columns: [
			{display: "商品池编号", name: "id"},
			{display: "商品池名称", name: "poolName"},
			{display: "说明", name: "comment"},
			{display: "SKN个数", name: "total"},
			{
				display: "操作", name: "", render: function (item) {
					return '<a class="btn btn-info detail" data-index="' + item.__index + '">详情</a>';
				}
			}

		]
	});

	g.init('/market/productPool/queryProductPoolPage');

	var Bll = {
		toast:function(url) {
			//var e = new common.edit("#baseform", {bucket: "productPool"});


			common.dialog.confirm("添加商品池",
				common.util.__template($("#template").html(), {}),
				function() {
					common.util.__ajax({
						url:url,
						data:{
							poolName: $("#poolName").val(),
							comment: $("#comment").val(),
							producttype:$("#producttype").val(),
							productSkns:$("#sknVal").val().replace("[", "").replace("]", "")
						}
					},function() {
						g.reload();
					});
				});

			common.edit.ajaxfileupload("#productSkn",{
				params: {
			        type: "productPool",
			        __type: "batch-import"
			    },
				onComplete:function(res){
					$("#sknVal").val(JSON.stringify(res.data.productSkn));
					//console.log($("#sknVal").val().replace("[", "").replace("]", ""));
				}
			});

			//e.init();

			new common.dropDown({el: "#producttype"});
		},
		detailtoast:function(obj) {
             common.dialog({
                title:"商品池详情",
                content:'<div id="faGrid" style="height: 600px;overflow:auto;"></div>',
                button:[{value:"添加", callback:function() {
                	var e = new common.edit("#base-form");

					common.dialog.confirm("添加商品池记录",
						common.util.__template($("#template1").html(), 
							{
								poolId:obj.id,
								producttype:grid.rows[0].producttype
							}),
						function() {
							e.submit("/market/productPool/addProductPoolDetailBo",function(option){
								//option.data;
								
								option.success=function(){
									grid.reload();
								};
								option.error=function(){
								}
							});
						});

					e.init();
					return false;
                }}]
             });
             var grid = new common.grid({
                el:"#faGrid",
				hash: false,
                parms: function() {
                	return {id: obj.id};
                },
                columns:[
                    {display:"ID", name:"id"},
                    {display:"SKN",name:"productskn"},
                    {display:"名称", name:""},
                    {display:'品牌', name: "brandName"},
                    {display: '分类',name: "sortName"},
                    {display: '操作', name: "", render: function(item) {
                    	return '<a class="btn btn-info delbtn" data-index="' + item.__index + '">删除</a>';
                    }}
                ]
             });
             grid.init('/market/productPool/queryProductPoolDetailPage');
             $(document).on('click', '.delbtn', function() {
             	var item = grid.rows[$(this).data("index")];
             	common.dialog.confirm("警告",
             		"确认删除?",
             		function() {
             			common.util.__ajax({
				 			url:'/market/productPool/deleteProductPoolDetailBo',
				 			data:{id:item.id}
				 		},function(res) {
				 			grid.reload();
				 		});
             		});
             });
		}
	};

	$("#add-pool").on('click', function() {
		Bll.toast("/market/productPool/addProductPoolBo");
	});

	$(document).on("click", ".detail", function() {
		var item=g.rows[$(this).data("index")];
	    Bll.detailtoast(item);
	});

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