materialChoose.js 6.7 KB
Newer Older
doc_wei's avatar
doc_wei 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
var rowId = "";

layui.config({
	base: basePath, 
	version: skyeyeVersion
}).extend({
    window: 'js/winui.window'
}).define(['window', 'table', 'jquery', 'winui', 'form', 'tableCheckBoxUtil', 'fsCommon', 'fsTree'], function (exports) {
	winui.renderColor();
	var index = parent.layer.getFrameIndex(window.name);
	var $ = layui.$,
		form = layui.form,
		table = layui.table,
		fsTree = layui.fsTree,
		fsCommon = layui.fsCommon,
		tableCheckBoxUtil = layui.tableCheckBoxUtil;
		
	var checkType = '1';//商品选择类型:1.单选;2.多选
	
	if(!isNull(parent.productCheckType)){
		checkType = parent.productCheckType;
	}
	
	//设置提示信息
	var s = "商品选择规则:";
	if(checkType == "1"){
		s += '1.单选,双击指定行数据即可选中;';
	}else{
		s += '1.多选;';
		//显示保存按钮
		$("#saveCheckBox").show();
	}
	s += '如没有查到要选择的商品,请检查商品信息是否满足当前规则。';
	$("#showInfo").html(s);
	
	/********* tree 处理   start *************/
	//初始商品分类类型
    var materialCategoryType;
    fsTree.render({
		id: "materialCategoryType",
doc_wei's avatar
doc_wei 已提交
41
		url: flowableBasePath + "materialcategory008?userToken=" + getCookie('userToken') + "&loginPCIp=",
doc_wei's avatar
doc_wei 已提交
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
		checkEnable: false,
		loadEnable: false,//异步加载
		showLine: false,
		showIcon: true,
		expandSpeed: 'fast',
		clickCallback: zTreeOnClick
	}, function(id){
		materialCategoryType = $.fn.zTree.getZTreeObj(id);
		//加载商品列表
		initTable();
	});
	
	//节点点击事件
	function zTreeOnClick(event, treeId, treeNode) {
		categoryId = treeNode.id == 0 ? '' : treeNode.id;
		refreshTable();
	}
	
	$("body").on("input", "#name", function(){
		searchZtree(materialCategoryType, $("#name").val());
	});
	//ztree查询
	var hiddenNodes = [];
	function searchZtree(ztreeObj, ztreeInput) {
		//显示上次搜索后隐藏的结点
		ztreeObj.showNodes(hiddenNodes);
		function filterFunc(node) {
			var keyword = ztreeInput;
			//如果当前结点,或者其父结点可以找到,或者当前结点的子结点可以找到,则该结点不隐藏
			if(searchParent(keyword, node) || searchChildren(keyword, node.children)) {
				return false;
			}
			return true;
		};
		//获取不符合条件的叶子结点
		hiddenNodes = ztreeObj.getNodesByFilter(filterFunc);
		//隐藏不符合条件的叶子结点
		ztreeObj.hideNodes(hiddenNodes);
	}
	/********* tree 处理   end *************/
	//树节点选中的商品类型id
	var categoryId = "";
	function initTable(){
		if(checkType == '2'){
			//初始化值
			var ids = [];
			$.each(parent.productMationList, function(i, item){
				ids.push(item.productId);
			});
			tableCheckBoxUtil.setIds({
				gridId: 'messageTable',
				fieldName: 'productId',
				ids: ids
			});
			tableCheckBoxUtil.init({
				gridId: 'messageTable',
				filterId: 'messageTable',
				fieldName: 'productId'
			});
		}
			
		table.render({
		    id: 'messageTable',
		    elem: '#messageTable',
		    method: 'post',
doc_wei's avatar
doc_wei 已提交
107
		    url: flowableBasePath + 'material010',
doc_wei's avatar
doc_wei 已提交
108 109 110 111 112 113 114 115 116 117 118 119 120 121
		    where: getTableParams(),
			even: true,
		    page: true,
		    limits: [8, 16, 24, 32, 40, 48, 56],
		    limit: 8,
		    cols: [[
		    	{ type: checkType == '1' ? 'radio' : 'checkbox'},
		        { title: systemLanguage["com.skyeye.serialNumber"][languageType], type: 'numbers'},
		        { field: 'productName', title: '商品名称', align: 'left', width: 150, templet: function(d){
			        	return '<a lay-event="details" class="notice-title-click">' + d.productName + '</a>';
			    }},
		        { field: 'productModel', title: '型号', align: 'left', width: 150 },
		        { field: 'categoryName', title: '所属类型', align: 'left', width: 100 },
		        { field: 'typeName', title: '商品来源', align: 'left', width: 100 },
122
		        { field: 'createTime', title: systemLanguage["com.skyeye.createTime"][languageType], align: 'center', width: 150 }
doc_wei's avatar
doc_wei 已提交
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
		    ]],
		    done: function(res, curr, count){
		    	matchingLanguage();
		    	if(checkType == '1'){
			    	$('#messageTable').next().find('.layui-table-body').find("table" ).find("tbody").children("tr").on('dblclick',function(){
						var dubClick = $('#messageTable').next().find('.layui-table-body').find("table").find("tbody").find(".layui-table-hover");
						dubClick.find("input[type='radio']").prop("checked", true);
						form.render();
						var chooseIndex = JSON.stringify(dubClick.data('index'));
						var obj = res.rows[chooseIndex];
						parent.productMation = obj;
						
						parent.refreshCode = '0';
						parent.layer.close(index);
					});
					
					$('#messageTable').next().find('.layui-table-body').find("table" ).find("tbody").children("tr").on('click',function(){
						var click = $('#messageTable').next().find('.layui-table-body').find("table").find("tbody").find(".layui-table-hover");
						click.find("input[type='radio']").prop("checked", true);
						form.render();
					})
		    	}else{
		    		//多选
		    		//设置选中
		    		tableCheckBoxUtil.checkedDefault({
						gridId: 'messageTable',
						fieldName: 'productId'
					});
		    	}
		    }
		});
		
		table.on('tool(messageTable)', function (obj) {
	        var data = obj.data;
	        var layEvent = obj.event;
	        if (layEvent === 'details') { //详情
	        	details(data);
	        }
	    });
		
		form.render();
	}
	
	//详情
	function details(data){
		rowId = data.productId;
		_openNewWindows({
			url: "../../tpl/material/materialdetails.html", 
			title: systemLanguage["com.skyeye.detailsPageTitle"][languageType],
			pageId: "materialdetails",
			area: ['90vw', '90vh'],
			callBack: function(refreshCode){
			}});
	}
	
	//保存按钮-多选才有
	$("body").on("click", "#saveCheckBox", function(){
		var selectedData = tableCheckBoxUtil.getValue({
			gridId: 'messageTable'
		});
doc_wei's avatar
doc_wei 已提交
183
		AjaxPostUtil.request({url: flowableBasePath + "material013", params: {ids: selectedData.toString()}, type: 'json', callback: function(json){
doc_wei's avatar
doc_wei 已提交
184 185 186 187 188
   			if(json.returnCode == 0){
   				parent.productMationList = [].concat(json.rows);
 	   			parent.layer.close(index);
 	        	parent.refreshCode = '0';
   			}else{
doc_wei's avatar
doc_wei 已提交
189
   				winui.window.msg(json.returnMessage, {icon: 2, time: 2000});
doc_wei's avatar
doc_wei 已提交
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
   			}
   		}});
	});
	
	
	$("body").on("click", "#formSearch", function(){
		refreshTable();
	});
	
	 $("body").on("click", "#reloadTable", function(){
    	loadTable();
    });
    
    function loadTable(){
    	table.reload("messageTable", {where: getTableParams()});
    }
    
    function refreshTable(){
    	table.reload("messageTable", {page: {curr: 1}, where: getTableParams()});
    }

	function getTableParams(){
		return {
			materialName: $("#materialName").val(), 
    		model: $("#model").val(), 
    		categoryId: categoryId, 
    		typeNum: $("#typeNum").val()
		};
	}
	
    exports('materialChoose', {});
});