jquery之鼠标失去焦点事件

时间:2021-08-10 04:06:41

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<jsp:include page="/jsp/common/header.jsp"></jsp:include>
<script src="${ctx }/js/hrt/hrtMinatoSingleGoods.js"></script>
<table class="queryTable" >
<tr>
<td class="queryTitle" width="80px">客户端</td>
<td class="queryContent">
<select id="client" class="easyui-combobox" style="width: 148px" panelHeight="auto" editable="false">
<option value="">请选择</option>
<option value="1" >pc</option>
<option value="2">m站 app</option>
</select>
</td>
<td class="queryTitle" width="80px">商品编码</td>
<td class="queryContent">
<input class="inputText" type="text" id="goodsNo">
</td>
<td class="queryBtnTd" colspan="2">
<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" onclick="doQuery()">查&nbsp;&nbsp;询</a>
</td>
</tr>
</table>

<table id="hrtMinatoSingleGoodsGrid"></table>

<!-- 添加凑单商品Div -->
<div id="addHrtMinatoSingleGoodsDiv" class="easyui-window" title="" iconCls="icon-edit" style="width:600px; height:200px;text-align:center; background: #fafafa;">
<div class="easyui-layout" fit="true">
<div region="center" border="false" style="background:#fff;border:1px solid #ccc;">
<form id="addForm" method="POST">
<table class="queryTable" width="100%" >
<tr>
<td class="queryTitle" width="100">商品编码</td>
<td class="queryContent" >
<input class="inputText" type="text" id="addGoodsNo">
<div id="addGoodsNoMsg" style="color:#F00;display:none" ></div>
</td>
</tr>
<tr>
<td class="queryTitle" width="100">客户端</td>
<td class="queryContent" >
<select id="addClient" class="easyui-combobox" style="width: 100px" panelHeight="auto" editable="false">
<option value="web" >web</option>
<option value="wap">wap</option>
<option value="app">app</option>
</select>
</td>
</tr>
<tr>
<td class="queryTitle" width="100">优先级</td>
<td class="queryContent" >
<input type="text" id="addGoodsOrder" min="1" precision="0" class="easyui-numberbox" style="width:100px"/>
</td>
</tr>
<tr>
<td class="queryTitle" width="100">商品描述</td>
<td class="queryContent" >
<input id="addGoodsNotes" class="inputText" style="width:200px"/>
</td>
</tr>
<tr>
<td class="queryTitle" width="100">商品标签</td>
<td class="queryContent" >
<input id="addMinatoGoodsCategoryId" class="easyui-combobox" style="width: 100px" panelHeight="auto" editable="false">
</td>
</tr>
</table>
</form>
</div>
<div region="south" border="false" style="text-align:center;height:30px;line-height:30px;">
<a class="easyui-linkbutton" iconCls="icon-ok" href="javascript:void(0);" onclick="saveHrtMinatoSingleGoods('add');">保存凑单商品</a>&nbsp;&nbsp;
<a class="easyui-linkbutton" iconCls="icon-cancel" href="javascript:void(0);" onclick="closeWin('addHrtMinatoSingleGoodsDiv');">取消</a>
</div>
</div>
</div>

<!-- 编辑凑单商品Div -->
<div id="updHrtMinatoSingleGoodsDiv" class="easyui-window" title="" iconCls="icon-edit" style="width:600px; height:200px;text-align:center; background: #fafafa;">
<div class="easyui-layout" fit="true">
<div region="center" border="false" style="background:#fff;border:1px solid #ccc;">
<form id="updForm" method="POST">
<input type="hidden" id="hrtMinatoSingleGoodsIdHidden" name="hrtMinatoSingleGoodsIdHidden" value="" />
<table class="queryTable" width="100%" >
<tr>
<td class="queryTitle" width="100">商品编码</td>
<td class="queryContent" >
<input class="inputText" type="text" id="updGoodsNo">
<div id="updGoodsNoMsg" style="color:#F00;display:none" ></div>
</td>
</tr>
<tr>
<td class="queryTitle" width="100">客户端</td>
<td class="queryContent" >
<select id="updClient" class="easyui-combobox" style="width: 100px" panelHeight="auto" editable="false">
<option value="web" >web</option>
<option value="wap">wap</option>
<option value="app">app</option>
</select>
</td>
</tr>
<tr>
<td class="queryTitle" width="100">优先级</td>
<td class="queryContent" >
<input type="text" id="updGoodsOrder" min="1" precision="0" class="easyui-numberbox" style="width:100px"/>
</td>
</tr>
<tr>
<td class="queryTitle" width="100">商品描述</td>
<td class="queryContent" >
<input id="updGoodsNotes" class="inputText" style="width:200px"/>
</td>
</tr>
<tr>
<td class="queryTitle" width="100">商品标签</td>
<td class="queryContent" >
<input id="updMinatoGoodsCategoryId" class="easyui-combobox" style="width: 100px" panelHeight="auto" editable="false">
</td>
</tr>
</table>
</form>
</div>
<div region="south" border="false" style="text-align:center;height:30px;line-height:30px;">
<a class="easyui-linkbutton" iconCls="icon-ok" href="javascript:void(0);" onclick="saveHrtMinatoSingleGoods('upd');">更新凑单商品</a>&nbsp;&nbsp;
<a class="easyui-linkbutton" iconCls="icon-cancel" href="javascript:void(0);" onclick="closeWin('updHrtMinatoSingleGoodsDiv');">取消</a>
</div>
</div>
</div>


$(function() {
createParentHiddenDom("frameName");
$('#addHrtMinatoSingleGoodsDiv').window('close');
$('#updHrtMinatoSingleGoodsDiv').window('close');
$("#hrtMinatoSingleGoodsGrid")
.datagrid(
{
url : appPath
+ '/page/hrtMinatoSingleGoods/getHrtMinatoSingleGoods',
height : 'full',
striped : true,
remoteSort : false,
pagination : true,
rownumbers : true,
singleSelect : false,
queryParams : getQueryParam(),
frozenColumns : [ [
{
field : 'ck',
checkbox : true
},
{
field : 'opt',
title : '操作',
width : 40,
align : 'center',
formatter : function(value, rowData,
rowIndex) {
var html = "<img class='op-enable' src='"
+ appPath
+ "/js/lib/jquery-easyui/themes/icons/pencil.png' onClick='opreateHrtMinatoSingleGoods(\""
+ rowData.id
+ "\")' title='编辑'/>";
return html;
}
} ] ],
columns : [ [ {
field : 'goodsNo',
title : '商品编号',
width : 100,
align : 'left',
sortable : true
}, {
field : 'productName',
title : '商品名称',
width : 200,
align : 'left',
sortable : true
}, {
field : 'ecPrice',
title : '商品价格',
width : 100,
align : 'left',
sortable : true
}, {
field : 'goodsNotes',
title : '商品描述',
width : 150,
align : 'left',
sortable : true
}, {
field : 'goodsOrder',
title : '优先级',
width : 100,
align : 'left',
sortable : true
}, {
field : 'mul',
title : '客户端',
width : 100,
align : 'left',
sortable : true
}, {
field : 'minatoGoodsCategoryName',
title : '商品标签',
width : 100,
align : 'left',
sortable : true
}, {
field : 'addTime',
title : '添加时间',
width : 150,
align : 'left',
sortable : true
}, ] ],
toolbar : [ {
id : 'btnadd',
text : '添加凑单商品',
iconCls : 'icon-add',
handler : function() {
// 清空表单
$('#addForm').form('clear');
// 设置客户端选中项
$('#addClient').combobox("select", 'web');
// 绑定商品编号失去焦点事件
goodNoBlur('add');
getMinatoSingleGoodsCategorys("add");
$('#addHrtMinatoSingleGoodsDiv').window({
title : '添加凑单商品',
iconCls : 'icon-add',
width : 450,
height : 250,
left : 550,
top : 150,
modal : true,
shadow : true,
collapsible : false,
minimizable : false,
maximizable : false
});
}
}, "-", {
id : 'btnPass',
text : '批量删除',
iconCls : 'icon-ok',
handler : function() {
deleteHrtMinatoSingleGoods();
}
} ]
});
});

/**
* 查询
*/
function doQuery() {
$("#hrtMinatoSingleGoodsGrid").datagrid('load', getQueryParam());
}

/*******************************************************************************
* 获得参数
*/
function getQueryParam() {
var HrtMinatoSingleGoods = new Object();
HrtMinatoSingleGoods.mul = $("#client").combobox(
"getValue");
if ($("#goodsNo").val()) {
HrtMinatoSingleGoods.goodsNo = $("#goodsNo").val();
}
return HrtMinatoSingleGoods;
}

/*******************************************************************************
* 显示凑单信息
*/
function opreateHrtMinatoSingleGoods(hrtMinatoSingleGoodsId) {
getMinatoSingleGoodsCategorys("upd");
doAjax({
url : appPath + '/page/hrtMinatoSingleGoods/opreateHrtMinatoSingleGoods/'
+ hrtMinatoSingleGoodsId,
type : 'post',
dataType : "json",
success : function(data) {
// 凑单商品Id
$("#hrtMinatoSingleGoodsIdHidden").val(data.id);
// 商品编号
$("#updGoodsNo").val(data.goodsNo);
// 客户端
$('#updClient').combobox("select", data.mul);
// 优先顺
$('#updGoodsOrder').val(data.goodsOrder);
// 商品描述
$("#updGoodsNotes").val(data.goodsNotes);
// 商品标签
$('#updMinatoGoodsCategoryId').combobox("select", data.minatoGoodsCategoryId);
$('#updHrtMinatoSingleGoodsDiv').window({
title : '修改凑单商品',
iconCls : 'icon-edit',
width : 450,
height : 250,
left : 550,
top : 150,
modal : true,
shadow : true,
collapsible : false,
minimizable : false,
maximizable : false
});
$('#updHrtMinatoSingleGoodsDiv').window('open');
// 绑定商品编号失去焦点事件
goodNoBlur('upd');
},
error : function(XMLHttpRequest, textStatus, errorThrown) {
$.messager.alert('提示信息', '抱歉,保存失败,' + textStatus, 'error');
}
});
}

/**
* 保存凑单商品(添加、更新)
*/
function saveHrtMinatoSingleGoods(type) {
if ($('#' + type + 'GoodsNo').val() == ""
|| $('#' + type + 'GoodsNoMsg').html() != "") {
$.messager.alert("提示", "请输入正确的商品编号!", "info");
return;
} else if (!$('#' + type + 'GoodsOrder').val()) {
$.messager.alert("提示", "请输入优先级!", "info");
return;
}
console.log($("#" + type + "MinatoGoodsCategoryId").combobox("getValue"));
if($("#" + type + "MinatoGoodsCategoryId").combobox("getValue")=="--请选择--"
|| $("#" + type + "MinatoGoodsCategoryId").combobox("getValue")=="0"){
$.messager.alert("提示", "请选择商品标签!", "info");
return;
}
// 商品编号
var goodsNo = $.trim($('#' + type + 'GoodsNo').val());
// 客户端
var client = $("#" + type + "Client").combobox("getValue");
// 优先级
var goodsOrder = $('#' + type + 'GoodsOrder').val();
// 商品描述
var goodsNotes = $.trim($('#' + type + 'GoodsNotes').val());
var hrtMinatoSingleGoods = new Object();
// 商品标签
var minatoGoodsCategoryId = $("#" + type + "MinatoGoodsCategoryId").combobox("getValue");
// 更新的场合,设置凑单商品Id
if (type == 'upd') {
hrtMinatoSingleGoods.id = $("#hrtMinatoSingleGoodsIdHidden").val();
}
hrtMinatoSingleGoods.goodsNo = goodsNo;
hrtMinatoSingleGoods.mul = client;
hrtMinatoSingleGoods.goodsOrder = goodsOrder;
hrtMinatoSingleGoods.goodsNotes = goodsNotes;
hrtMinatoSingleGoods.minatoGoodsCategoryId = minatoGoodsCategoryId;
doAjax({
url : appPath + "/page/hrtMinatoSingleGoods/saveHrtMinatoSingleGoods",
type : 'post',
data : hrtMinatoSingleGoods,
success : function(data) {
switch (data) {
case "ok":
if (type == 'add') {
$.messager.alert('提示信息', '保存成功', 'info');
} else {
$.messager.alert('提示信息', '更新成功', 'info');
}
break;
default:
$.messager.alert('提示信息', '抱歉,失败了', 'error');
break;
}
$('#' + type + 'HrtMinatoSingleGoodsDiv').window('close');
doQuery();
return;
},
error : function(XMLHttpRequest, textStatus, errorThrown) {
$.messager.alert('提示信息', '抱歉,保存失败,' + textStatus, 'error');
}
});
}

// 批量删除推荐商品
function deleteHrtMinatoSingleGoods() {
var selections = $("#hrtMinatoSingleGoodsGrid").datagrid('getSelections');
if (selections == null || selections == '') {
$.messager.alert('提示信息', '请选操作的记录', '');
return;
} else {
var hrtMinatoSingleGoodsIds = '';
for (var i = 0; i < selections.length; i++) {
hrtMinatoSingleGoodsIds += selections[i].id + ',';
}
hrtMinatoSingleGoodsIds = hrtMinatoSingleGoodsIds.substring(0,
hrtMinatoSingleGoodsIds.lastIndexOf(','));
$.messager
.confirm(
'提示信息',
"您确定批量删除凑单商品?",
function(r) {
if (r) {
doAjax({
url : appPath
+ "/page/hrtMinatoSingleGoods/deleteHrtMinatoSingleGoods",
type : 'post',
data : {"hrtMinatoSingleGoodsIds":hrtMinatoSingleGoodsIds},
success : function(data) {
switch (data) {
case "ok":
$.messager
.alert('提示信息', '删除成功', '');
break;
default:
$.messager.alert('提示信息', '抱歉,失败了',
'error');
break;
}
doQuery();
return;
},
error : function(XMLHttpRequest,
textStatus, errorThrown) {
$.messager.alert('提示信息', '抱歉,删除失败,'
+ textStatus, 'error');
}
});
}
});
}
}

/*******************************************************************************
* 绑定goodNo失去焦点后,查询商品编号事件
*/
function goodNoBlur(type) {
var goodsNo = $('#' + type + 'GoodsNo');
var goodsNoMsg = $('#' + type + 'GoodsNoMsg');
goodsNo.blur(function() {
if (goodsNo.val() == '') {
goodsNoMsg.html('');
return;
}
doAjax({
url : appPath + "/page/hrtMinatoSingleGoods/" + goodsNo.val()
+ "/checkGoodNo",
success : function(data) {
if (data == 'error') {
goodsNoMsg.css('display', 'inline');
goodsNoMsg.html('该商品编号不存在');
} else {
goodsNoMsg.css('display', 'none');
goodsNoMsg.html('');
}
}
});
});
}

function getMinatoSingleGoodsCategorys(type){
$("#"+type+"MinatoGoodsCategoryId").combobox({
url:appPath + "/page/hrtMinatoSingleGoods/getAllMinatoGoodsCategorys",
valueField:"id",
textField:"name"
});
$("#"+type+"MinatoGoodsCategoryId").combobox("select", '--请选择--');
}

/**
* 关闭窗口
*/
function closeWin(dlg) {
$('#' + dlg).window('close');
}