assetManageChoose.js 5.0 KB
Newer Older
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 41 42 43 44 45 46 47 48 49 50

var rowId = "";

layui.config({
	base: basePath, 
	version: skyeyeVersion
}).extend({
    window: 'js/winui.window'
}).define(['window', 'table', 'jquery', 'winui', 'form', 'tableCheckBoxUtil'], function (exports) {
	winui.renderColor();
	var index = parent.layer.getFrameIndex(window.name);
	var $ = layui.$,
		form = layui.form,
		table = layui.table,
		tableCheckBoxUtil = layui.tableCheckBoxUtil;

	// 选择类型,默认单选,true:多选,false:单选
	var assetCheckType = isNull(parent.adminAssistantUtil.assetCheckType) ? false : parent.adminAssistantUtil.assetCheckType;

	// 设置提示信息
	var s = '资产选择规则:';
	if(assetCheckType){
		s += '1.多选;如没有查到要选择的资产,请检查资产信息是否满足当前规则。';
		// 多选保存的资产对象信息
		var checkAssetMation = [].concat(parent.adminAssistantUtil.checkAssetMation);
		// 初始化值
		var ids = [];
		$.each(checkAssetMation, function(i, item) {
			ids.push(item.id);
		});
		tableCheckBoxUtil.setIds({
			gridId: 'messageTable',
			fieldName: 'id',
			ids: ids
		});
		tableCheckBoxUtil.init({
			gridId: 'messageTable',
			filterId: 'messageTable',
			fieldName: 'id'
		});
	} else {
		s += '双击要选择的数据即可选中';
		$("#saveCheckBox").hide();
	}
	$("#showInfo").html(s);
	
	table.render({
	    id: 'messageTable',
	    elem: '#messageTable',
	    method: 'post',
doc_wei's avatar
doc_wei 已提交
51
	    url: sysMainMation.admBasePath + 'asset001',
52 53 54 55 56 57
	    where: getTableParams(),
		even: true,
	    page: true,
	    limits: getLimits(),
	    limit: getLimit(),
	    cols: [[
58 59
	    	{ type: assetCheckType ? 'checkbox' : 'radio', fixed: 'left'},
	        { title: systemLanguage["com.skyeye.serialNumber"][languageType], fixed: 'left', type: 'numbers' },
doc_wei's avatar
doc_wei 已提交
60
			{ field: 'name', title: '资产名称', width: 120 },
61 62 63
			{ field: 'assetImg', title: '图片', align: 'center', width: 60, templet: function (d) {
				return '<img src="' + systemCommonUtil.getFilePath(d.assetImg) + '" class="photo-img" lay-event="assetImg">';
			}},
doc_wei's avatar
doc_wei 已提交
64 65 66
			{ field: 'typeId', title: '资产类型', width: 100, templet: function(d) {
				return sysDictDataUtil.getDictDataNameByCodeAndKey("ADM_ASSET_TYPE", d.typeId);
			}},
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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
			{ field: 'numberPrefix', title: '资产编号前缀', width: 140 },
			{ field: 'readPrice', title: '参考价', width: 80 },
		]],
	    done: function(res) {
	    	matchingLanguage();

			initTableSearchUtil.initAdvancedSearch(this, res.searchFilter, form, "请输入资产名称", function () {
				table.reloadData("messageTable", {page: {curr: 1}, where: getTableParams()});
			});
			if (assetCheckType) {
				// 设置选中
				tableCheckBoxUtil.checkedDefault({
					gridId: 'messageTable',
					fieldName: 'id'
				});
			} else {
				$('#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.adminAssistantUtil.checkAssetMation = 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();
				});
			}
	    }
	});

	table.on('tool(messageTable)', function (obj) {
		var data = obj.data;
		var layEvent = obj.event;
		if (layEvent === 'assetlistdetails') { // 详情
			assetlistdetails(data);
		} else if (layEvent === 'assetImg') { // 图片预览
			systemCommonUtil.showPicImg(systemCommonUtil.getFilePath(data.assetImg));
		}
	});

	// 详情
	function assetlistdetails(data) {
		rowId = data.id;
		_openNewWindows({
			url: "../../tpl/assetManage/assetManageDetails.html",
			title: systemLanguage["com.skyeye.detailsPageTitle"][languageType],
			pageId: "assetManageDetails",
			area: ['90vw', '90vh'],
W
weizhiqiang 已提交
122
			callBack: function (refreshCode) {
123 124 125 126 127
			}});
	}
	
	// 保存
	$("body").on("click", "#saveCheckBox", function() {
doc_wei's avatar
doc_wei 已提交
128
		var selectedData = tableCheckBoxUtil.getValueList({
129 130 131 132 133 134
			gridId: 'messageTable'
		});
		if (selectedData.length == 0) {
			winui.window.msg("请选择资产", {icon: 2, time: 2000});
			return false;
		}
doc_wei's avatar
doc_wei 已提交
135 136 137
		parent.adminAssistantUtil.checkAssetMation = [].concat(selectedData);
		parent.layer.close(index);
		parent.refreshCode = '0';
138 139 140 141 142 143 144
	});

	form.render();
	$("body").on("click", "#reloadTable", function() {
    	loadTable();
    });
    
W
weizhiqiang 已提交
145
    function loadTable() {
146 147 148
    	table.reloadData("messageTable", {where: getTableParams()});
    }
    
W
weizhiqiang 已提交
149
	function getTableParams() {
doc_wei's avatar
doc_wei 已提交
150
		return $.extend(true, {}, initTableSearchUtil.getSearchValue("messageTable"));
151 152 153 154
	}
	
    exports('assetManageChoose', {});
});