operations.activitytemplate.Product.js 6.69 KB
webpackJsonp([99],[
/* 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: '',
	            type: 'checkbox',
	            render: function (item) {
	                var htmlContent = "";
	                if(iList.length == 0 ){
	                    htmlContent = "<input type='checkbox'  class='wqt_checkbox' data-index='"+item.__index+"'>";
	                }else{
	                    $.each(iList,function(n,value) {
	                        if(item.id == value){
	                            htmlContent = "<input type='checkbox' checked='checked'  class='wqt_checkbox' data-index='"+item.__index+"'>";
	                            return false
	                        }else{
	                            htmlContent = "<input type='checkbox'  class='wqt_checkbox'data-index='"+item.__index+"'>";
	                        }
	                    })
	                }
	                return htmlContent;
	            }
	        },
	        {
	            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');
	            g.reload();
	        }
	    }
	});

	//编辑
	$(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();
	});

	//批量删除
	$(document).on("click","#batchDel",function(){
	    var len = iList.length;
	    if (len <= 0) {
	        common.util.__tip('请选择需要删除的数据', 'warning');
	        return;
	    }
	    var data = {
	        ids: iList.join(",")
	    };
	    common.dialog.confirm("温馨提示","你确定删除吗?",function() {
	    common.util.__ajax({
	        url: "/activityTemplate/batchDelProducts",
	        data: data
	    }, function () {
	        iList.splice(0,iList.length);
	        g.reload();
	    });
	    });
	});

	/*
	 *可通用于翻页勾选
	 * 将checkbox选中存入一个数组,勾选push,取消remove
	  * 进入页面判断id是否在数组中存在,如果存在,checked
	 */
	var iList = [];
	$(document).on("change", ".wqt_checkbox", function () {
	    var checked = $(this).prop("checked");
	    var index = $(this).data("index");
	    var val = g.rows[index];
	    var index_;
	    if(checked){
	        iList.push(val['id']);
	    }else{
	        index_ =  $.inArray(val['id'],iList);
	        iList.splice(index_,1);
	    }
	    console.log("iList:"+iList);
	});
	/**
	 * 全选事件
	 */
	$(g.grid).on("change", ".wqt_all", function() {
	    $(".wqt_checkbox").each(function () {
	        var checked = $(this).prop("checked");
	        var index = $(this).data("index");
	        var index_;
	        var val = g.rows[index];
	        if (checked) {
	            index_ = $.inArray(val['id'], iList);
	            if (index_ < 0) {
	                iList.push(val['id']);
	            }

	        } else {
	            index_ = $.inArray(val['id'], iList);
	            iList.splice(index_, 1);
	        }
	    });
	    console.log("iList:"+iList);
	});

	/** 清空 */
	$(document).on("click", "#clearProduct", function() {
	    console.log(id);
	    common.dialog.confirm("温馨提示","你确定要清空所有商品吗?",function() {
	        common.util.__ajax({
	            url: "/activityTemplate/delProductByTemplateId",
	            data: {
	                templateId: id 
	            }
	        }, function () {
	            g.reload(1);
	        });
	    });
	});


/***/ }
]);