<SCRIPT LANGUAGE="JavaScript">
<!--
var currentMoveObj = null;
var relLeft;
var relTop;
function f_mdown(obj)
{
currentMoveObj = obj;
currentMoveObj.style.position = "absolute";
relLeft = event.x - currentMoveObj.style.pixelLeft;
relTop = event.y - currentMoveObj.style.pixelTop;
}
window.document.onmouseup = function()
{
currentMoveObj = null;
}
function f_move(obj)
{
if(currentMoveObj != null)
{
currentMoveObj.style.pixelLeft=event.x-relLeft;
currentMoveObj.style.pixelTop=event.y-relTop;
}
}
//-->
function show(){
var d = document.getElementById("tanchu");
d.style.display="block";
}
function fclose()
{
document.getElementById("tanchu").style.display='none';
}
function checkFormat(obj)
{
var pat = /^[0-9]+/.?[0-9]{0,3}$/;
if(!pat.test(obj))
{
alert("格式为数字,小数位不得超过3位!");
return false;
}
return true;
}
// var oilArray=new Array("${devInSerialList}");
var oilArray=new Array();
function add()
{
if(r==1){
return false;
}
var div= document.getElementById("devId").value;
var devid=Number(div);
if(devid==0)
{
alert("设备ID不能为空!");
return false;
}
if(!checkFormat(devid))
{
document.getElementById("devId").value="";
return;
}
if(oilArray.length>0)
{
oilArray[oilArray.length]=devid;
}else{
oilArray[0]=devid;
}
showdev(oilArray);
scro.scrollTop=scro.scrollHeight;
document.getElementById("devId").value="";
}
function showdev(arr1)
{
var tb=document.getElementById("tb");
//while(tb.hasChildNodes())
while(tb.rows.length>0)
{
tb.deleteRow(0);
}
for(var j=0;j<arr1.length;j++)
{
var TR=tb.insertRow(j);
var TD1=TR.insertCell(0);
var TD2=TR.insertCell(1);
//TD1.innerHTML="<input type='text' style='width:80px' οnchange='changeoil(this)' οnblur='repeat("+j+")' id='"+j+"' size=10 value='"+arr1[j]+"'/>";
TD1.innerHTML=arr1[j];
TD2.innerHTML="<a href='javascript:del("+j+")'>删除</a>";
}
}
function del(o){
oilArray.splice(o,1);
showdev(oilArray);
}
var msg="";
function sub(){
if(r==1){
return false;
}
if(oilArray.length>0){
for(var j=0;j<oilArray.length;j++)
{
if(j<oilArray.length-1){
msg+=oilArray[j]+",";
}else{
msg+=oilArray[j];
}
}
//devInManager.devId(msg);
// devInManager.devId(oilArray);
devinaction.devArr(oilArray);
}else{
alert("设备ID不能为空");
}
fclose();
}
function changeoil(obj)
{
var nNum=obj.id;
var vNum=obj.value;
var n=new Number(nNum);
var v=new Number(vNum);
if(v==0)
{
alert("设备ID不能为空!");
obj.value=oilArray[n];
return;
}
if(!checkFormat(v))
{
obj.value=oilArray[n];
return;
}
oilArray[n]=v;
}
//去掉左右空格
String.prototype.trim=function(){
return this.replace(/(^/s*)|(/s*$)/g, '');
}
//判断设备id是否存在
function repeat(devId){
var dev=document.getElementById("devId").value;
for(var i=0;i<oilArray.length;i++){
if(dev==oilArray[i]){
alert("设备ID"+dev+"已经存在,请勿重复添加");
return false;
}
}
devInManager.devInSerialByDevId(dev,rep);
}
var r=0;
function rep(count){
if(count>0){
alert("此设备Id已存在,请重新输入");
r=1;
return false;
}else{
r=0;
}
}
//验证表单
function validate(){
var produceSerial=document.getElementById("produceSerial").value;//出场批次
var inPrice=document.getElementById("inPrice").value; //入库价格
var produceTime=document.getElementById("produceTime").value; //出场日期
var counter=document.getElementById("counter").value; //入库数量
var repareMonth=document.getElementById("repareMonth").value;//保修期
var remark=document.getElementById("remark").value; //备注
var reg=/^/d+((/.?/d+)|(/d*))$/; //验证价格
if(produceSerial==null||produceSerial.trim()==""){
alert("出厂批次不能为空");
return false;
}
if(inPrice==null||inPrice.trim()==""||!reg.test(inPrice)){
alert("入库价格不能为空或者格式不正确");
return false;
}
if(produceTime==null||produceTime.trim()==""){
alert("出厂日期不能为空");
return false;
}
// if(oilArray==null||oilArray.length==0){
// alert("设备id不能为空");
// return false;
// }
if(counter==null||counter.trim()==""||isNaN(counter)){
alert("入库数量不能为空或者格式不正确");
return false;
}
if(repareMonth==null||repareMonth.trim()==""||isNaN(repareMonth)){
alert("保修期不能为空或者格式不正确");
return false;
}
}
</SCRIPT>
</head>
<body>
<div id="tanchu" onMouseDown="f_mdown(this)"
onMouseMove="f_move(this)"
style="position: absolute; left: 226px; top: 30px; display: none; width: 400px; cursor: move;">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="10" height="24" class="tc_topl">
</td>
<td class="tc_topm">
<table width="98%" height="24" border="0" align="center"
cellpadding="0" cellspacing="0" style="margin: 0 auto;">
<tr>
<td align="left">
设备入库
</td>
<td align="right">
<div class="tlink" οnclick="fclose()"></div>
</td>
</tr>
</table>
</td>
<td width="6" height="24" class="tc_topr">
</td>
</tr>
<tr>
<td class="tc_midl">
</td>
<td align="left" valign="top" class="tc_mainbg">
<div id="scro" class="tc_mainx"
style="height: 225px; overflow: auto;">
<table>
<tr>
<td>
设备ID
</td>
<td>
操作
</td>
</tr>
</table>
<table id="tb"></table>
<table>
<tr>
<td>
设备ID:
</td>
<td>
<s:textfield name="devId" id="devId" value="" />
</td>
</tr>
<tr>
<td colspan="2">
<input type="button" value="增加" οnclick="add()"
οnmοuseοver="repeat('devId')" />
<input type="button" value="确定" οnclick="sub()" />
</td>
</tr>
</table>
</div>
<table width="95%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="5"></td>
</tr>
</table>
</td>
<td class="tc_midr"></td>
</tr>
<tr>
<td width="10" height="10" class="tc_botl"></td>
<td class="tc_botm"></td>
<td width="6" height="10" class="tc_botr"></td>
</tr>
</table>
</div>
<s:form action="sbgl/devInAction!devInAdd.action" method="post"
theme="simple">
<table>
<tr>
<td>
供应商:
</td>
<td>
<s:select list="devProvider" name="devInLists.providerid"
headerKey="0" headerValue="--请选择--" />
</td>
<td>
名称:
</td>
<td>
<s:select list="devNameList" name="devInLists.nameId"
headerKey="0" headerValue="--请选择--" />
</td>
</tr>
<tr>
<td>
出厂批次:
</td>
<td>
<s:textfield name="devInLists.produceSerial" id="produceSerial" />
</td>
<td>
入库价格:
</td>
<td>
<s:textfield name="devInLists.inPrice" id="inPrice" />
</td>
</tr>
<tr>
<td>
出厂日期:
</td>
<td>
<s:textfield name="devInLists.produceTime" id="produceTime"
οnclick="fPopCalendar(event,this,this)" οnselect="this.select()"
readonly="true" />
</td>
<td>
入库数量:
</td>
<td>
<s:textfield name="devInLists.counter" id="counter" />
</td>
</tr>
<tr>
<td>
设备ID:
</td>
<td>
<!--<s:textfield name="device" />-->
<input type="button" value="输入设备" οnclick="show()" />
</td>
<td>
保修期:
</td>
<td>
<s:textfield name="devInLists.repareMonth" id="repareMonth" />
(月)
</td>
</tr>
<tr>
<td>
备注:
</td>
<td colspan="3">
<s:textarea cols="55" rows="3" name="devInLists.remark"
id="remark" />
</td>
</tr>
<tr>
<td colspan="4">
<s:submit value="提交" οnclick="return validate()" />
<s:reset value="取消" />
</td>
</tr>
</table>
</s:form>
</body>