<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript" src="angular.js" ></script>
<script>
var app=angular.module("myApp",[]);
app.controller("myCtrl", function($scope){
$scope.shops=[
{num:10011120,name:"iphoneX",count:99},
{num:10011121,name:"华为mate10",count:20},
{num:10011122,name:"vivoR12",count:55}
];
$scope.sub=function(){
var flag1=false;
var flag2=false;
var flag3=false;
if($scope.newNum ==""||$scope.newNum==null){
alert("编号不能为空");
flag1=false;
}else if(isNaN($scope.newNum)){
alert("编号必须为数字");
flag1=false;
}else if($scope.newNum.length !=8){
alert("编号必须为八位");
flag1=false;
}else{
flag1=true;
}
var flag=false;
for(index in $scope.shops){
if($scope.newName==$scope.shops[index].name){
flag=true;
}
}
if(flag){
alert("财产名不能重复");
flag2=false;
}else {
flag2=true;
}
if($scope.newCount==""||$scope.newCount==null){
alert("数量不能为空");
flag3=false;
}else if(isNaN($scope.newCount)){
alert("数量必须是数字");
flag3=false;
}else{
flag3=true;
}
if(flag1 && flag2 && flag3){
//添加
$scope.shops.push({num:$scope.newNum,
name:$scope.newName,
count:$scope.newCount});
}
}
//查询
$scope.select=function(){
var flag=false;
$scope.searchShow="";
for(index in $scope.shops){
if($scope.search==$scope.shops[index].name){
flag=true;
}
}
if($scope.search==null||$scope.search==""){
alert("输入框不能为空");
$scope.searchShow="";
}else if(flag){
alert("商品存在");
$scope.searchShow=$scope.search;
}else{
alert("商品不存在");
$scope.searchShow=null;
}
}
//show
$scope.fromShow=false;
$scope.show=function(){
if($scope.fromShow){
$scope.fromShow=false;
}else{
$scope.fromShow=true;
}
}
});
</script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<center>
<h3>资产登记</h3><br /><br />
资产搜索 <input type="text" ng-model="search"/><button ng-click="select()">搜索</button>
<table border="1" cellspacing="0" width="600px">
<thead>
<th>资产编号</th>
<th>资产名称</th>
<th>资产数量</th>
</thead>
<tbody ng-repeat="a in shops | filter:searchShow ">
<td align="center">{{a.num}}</td>
<td align="center">{{a.name}}</td>
<td align="center">{{a.count}}</td>
</tbody>
</table>
<br /><br />
<button ng-click="show()">添加财产</button><br /><br />
<form ng-show="fromShow">
资产编号 <input type="text" ng-model="newNum"/><br />
资产名称 <input type="text" ng-model="newName"/><br />
资产数量 <input type="text" ng-model="newCount"/><br />
<input type="button" value="资产录入" ng-click="sub()" />
</form>
</center>
</body>
</html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript" src="angular.js" ></script>
<script>
var app=angular.module("myApp",[]);
app.controller("myCtrl", function($scope){
$scope.shops=[
{num:10011120,name:"iphoneX",count:99},
{num:10011121,name:"华为mate10",count:20},
{num:10011122,name:"vivoR12",count:55}
];
$scope.sub=function(){
var flag1=false;
var flag2=false;
var flag3=false;
if($scope.newNum ==""||$scope.newNum==null){
alert("编号不能为空");
flag1=false;
}else if(isNaN($scope.newNum)){
alert("编号必须为数字");
flag1=false;
}else if($scope.newNum.length !=8){
alert("编号必须为八位");
flag1=false;
}else{
flag1=true;
}
var flag=false;
for(index in $scope.shops){
if($scope.newName==$scope.shops[index].name){
flag=true;
}
}
if(flag){
alert("财产名不能重复");
flag2=false;
}else {
flag2=true;
}
if($scope.newCount==""||$scope.newCount==null){
alert("数量不能为空");
flag3=false;
}else if(isNaN($scope.newCount)){
alert("数量必须是数字");
flag3=false;
}else{
flag3=true;
}
if(flag1 && flag2 && flag3){
//添加
$scope.shops.push({num:$scope.newNum,
name:$scope.newName,
count:$scope.newCount});
}
}
//查询
$scope.select=function(){
var flag=false;
$scope.searchShow="";
for(index in $scope.shops){
if($scope.search==$scope.shops[index].name){
flag=true;
}
}
if($scope.search==null||$scope.search==""){
alert("输入框不能为空");
$scope.searchShow="";
}else if(flag){
alert("商品存在");
$scope.searchShow=$scope.search;
}else{
alert("商品不存在");
$scope.searchShow=null;
}
}
//show
$scope.fromShow=false;
$scope.show=function(){
if($scope.fromShow){
$scope.fromShow=false;
}else{
$scope.fromShow=true;
}
}
});
</script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<center>
<h3>资产登记</h3><br /><br />
资产搜索 <input type="text" ng-model="search"/><button ng-click="select()">搜索</button>
<table border="1" cellspacing="0" width="600px">
<thead>
<th>资产编号</th>
<th>资产名称</th>
<th>资产数量</th>
</thead>
<tbody ng-repeat="a in shops | filter:searchShow ">
<td align="center">{{a.num}}</td>
<td align="center">{{a.name}}</td>
<td align="center">{{a.count}}</td>
</tbody>
</table>
<br /><br />
<button ng-click="show()">添加财产</button><br /><br />
<form ng-show="fromShow">
资产编号 <input type="text" ng-model="newNum"/><br />
资产名称 <input type="text" ng-model="newName"/><br />
资产数量 <input type="text" ng-model="newCount"/><br />
<input type="button" value="资产录入" ng-click="sub()" />
</form>
</center>
</body>
</html>