<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>爱加</title>
<script th:include="sys/common/metaCSS" th:remove="tag"></script> 
<script th:include="sys/common/metaJS" th:remove="tag"></script> 
<script src="sys/js/My97DatePicker/WdatePicker.js" th:src="@{/static/sys/js/My97DatePicker/WdatePicker.js}"></script>
</head>
<style>
	.tablelink{margin-right:10px;}
	.stylecss{
	      color: red;
	}
	.select_width{
	     width: 220px;
	}
	.date_width{
	     width: 150px;
	}
</style>
<body>
<div class="place">
	<span>位置：</span>
	<ul class="placeul">
		<li><a href="#">库存管理</a></li>
		<li><a href="#">所有配件</a></li>
	</ul>
</div>
<div class="rightinfo">
	<form id="seachform" th:action="@{/sys/fx/partsAllList.html}" method="post">
	  <input type="hidden" name="reportType" id="reportType" />
	<ul class="seachform">
		<li>
		  <label>配件名称</label>
		  <input name="name" type="text" class="scinput" th:value="${search.get('LIKE_name')}"/>
	    </li>
	    <li>
		  <label>备注</label>
		  <input name="remarks" type="text" class="scinput" th:value="${search.get('LIKE_remarks')}"/>
	    </li>
	    <li>
			<label>所有商户</label>
			<select class="scinput select_width"  name="orgCode"   style="width: 150px;" >
				<option value="">全部</option>
				<option th:each="item:${poslist}"  th:selected="${search.get('EQ_orgCode') eq item.orgCode ? true : false}" th:value="${item.orgCode}">[[${item.unitName}]]</option>
			</select>
		</li>
		<li>
			<input type="button" class="scbtn" value="查询" />
		</li>
		<li>
			<ul class="toolbar">
				<a href="javascript:;" onclick="partsAdd('')">
					<li class="click"><span><img th:src="@{/static/sys/images/t01.png}"></span>添加</li>
				</a>
			</ul>
		</li>
	</ul>
	</form>
	
	<ul class="seachform">
		<li>
			<input type="button" id="button" class="scbtn" value="导出配件" />
		</li>
	</ul>
	
	<table class="tablelist">
		<thead>
		    <tr>
		        <th>现商户</th>
		        <th>现商户名称</th>
		    	<th>配件名称</th>
		    	<th>配件颜色</th>
		        <th>已收货(现商户)</th>
		        <th>待收货(现商户)</th>
		        <th>待收货<t style="color: red">(退回)</t></th>
		        <th>更变时间</th> 
		        <th>备注</th> 
		        <th>操作</th> 
		    </tr>
		</thead>
		<tbody>
			<tr th:each="item:${list}" >
					<td th:text="${item.posCode}"></td>
					<td th:text="${item.merchant.unitName}"></td>
					<td th:text="${item.name}"></td>
					<td th:text="${item.partsColor}"></td>
					<td th:text="${item.sellNum}"></td>
					<td>[[${item.sellWaitNum}]] </td>
					<td>[[${item.returnWaitNum}]] </td>		
					<td th:text="${#calendars.format(item.updateTime,'yyyy-MM-dd HH:mm')}" ></td>  
					<td th:text="${item.remarks}"></td>
					<td>  
						<a href="javascript:;"  th:onclick="'addpartsnum(\''+${item.id}+'\',\''+${item.sellNum}+'\',\''+${item.name}+'\')'"  class="tablelink">增加库量</a>
						<a href="javascript:;"  th:onclick="'cutpartsnum(\''+${item.id}+'\',\''+${item.sellNum}+'\',\''+${item.name}+'\')'"  class="tablelink">减除库量</a>
						<a href="javascript:;"  th:onclick="'matchparts(\''+${item.id}+'\',\''+${item.sellNum}+'\',\''+${item.name}+'\')'"  class="tablelink ">分配</a>
					</td>  
					
			</tr>
		</tbody>
	</table>
	
	
	
	<div id="lowermerchants" style="display: none; width: 100%;height: 100%;" >
		<div id="match_title" style="margin-left:23px;font-size:10pt;line-height: 34px;color: red"></div>
		<input id="match_id" type="hidden" value="" />
		<input id="match_sellnum" type="hidden" value="" />
		
		<div style="width: 100%;margin-bottom: 10px">
			<ul class="forminfo">
				<li style="margin-bottom:3px">
					<label>配件名称：<b></b></label>
					<input disabled="disabled" type="text" id="match_name" class="dfinput fl"/>
				</li>
				<li style="margin-bottom:3px">
					<label>分配数量：<b></b></label>
					<input type="number" id="match_num" value="1" class="dfinput fl"/>
				</li>
				<li style="margin-bottom:3px">
					<label>快递单号：<b></b></label>
					<input type="text" id="match_emsnumber" class="dfinput fl"/>
				</li>
				<li style="margin-bottom:3px">
					<label>快递地址：<b></b></label>
					<input type="text" id="match_emsaddress" class="dfinput fl"  />
				</li>
				<li style="margin-bottom:3px">
					<label>联系人：<b></b></label>
					<input type="text" id="match_emsusername" class="dfinput fl"  />
				</li>
				<li style="margin-bottom:3px">
					<label>联系号码：<b></b></label>
					<input type="text" id="match_emstelephone" class="dfinput fl"  />
				</li>
			</ul>
		</div>
		<table class="tablelist" style="width:95%;margin-left: 5px">
			<thead>
			    <tr>
			        <th style="width: 100px;">勾选</th>
			        <th>商户账号</th>
			        <th>商户名称</th>
			    </tr>
			</thead>
			<tbody id="lmlist">
				<tr  th:each="item:${poslist}" >
					<td><input type="radio" th:value="${item.posCode}" calss="imeiradio" name="lm" ></td>
					<td th:text="${item.posCode}" ></td>
					<td th:text="${item.unitName}" ></td>
				</tr>
			</tbody>
		</table>
		<div style=" bottom: 30px;position: fixed;right: 50px">
			<input type="button" class="scbtn savematchparts" value="确定分配" />
		</div>
	</div>
	
	
	<div id="addpartsnum" style="display: none; width: 100%;height: 100%;" >
		<div id="addparts_title" style="margin-left:23px;font-size:10pt;line-height: 34px;color: red"></div>
		<div id="addparts_id" style="margin-left:23px;font-size:10pt;line-height: 34px;color: red"></div>
		<div style="width: 100%;margin-bottom: 10px">
			<ul class="forminfo">
				<li style="margin-bottom:3px">
					<label>配件名称：<b></b></label>
					<input disabled="disabled" type="text" id="addparts_name" class="dfinput fl"/>
				</li>
				<li style="margin-bottom:3px">
					<label>入库数量：<b></b></label>
					<input type="number" id="addparts_num" class="dfinput fl"/>
				</li>
				<li style="margin-bottom:3px">
					<label>快递单号：<b></b></label>
					<input type="text" id="addparts_emsnumber" class="dfinput fl"/>
				</li>
				<li style="margin-bottom:3px">
					<label>快递地址：<b></b></label>
					<input type="text" id="addparts_emsaddress" class="dfinput fl"  />
				</li>
				<li style="margin-bottom:3px">
					<label>联系人：<b></b></label>
					<input type="text" id="addparts_emsusername" class="dfinput fl"  />
				</li>
				<li style="margin-bottom:3px">
					<label>联系号码：<b></b></label>
					<input type="text" id="addparts_emstelephone" class="dfinput fl"  />
				</li>
			</ul>
		</div>
		<div style=" bottom: 30px;position: fixed;right: 50px">
			<input type="button" class="scbtn addmatchparts" value="确定入库" />
		</div>
	</div>
	
	
	<div id="cutpartsnum" style="display: none; width: 100%;height: 100%;" >
		<div id="cutparts_title" style="margin-left:23px;font-size:10pt;line-height: 34px;color: red"></div>
		<div id="cutparts_id" style="margin-left:23px;font-size:10pt;line-height: 34px;color: red"></div>
		<div id="cutparts_sellnum" style="margin-left:23px;font-size:10pt;line-height: 34px;color: red"></div>
		
		<div style="width: 100%;margin-bottom: 10px">
			<ul class="forminfo">
				<li style="margin-bottom:3px">
					<label>配件名称：<b></b></label>
					<input disabled="disabled" type="text" id="cutparts_name" class="dfinput fl"/>
				</li>
				<li style="margin-bottom:3px">
					<label>减库数量：<b></b></label>
					<input type="number" id="cutparts_num" class="dfinput fl"/>
				</li>
				<li style="margin-bottom:3px">
					<label>快递单号：<b></b></label>
					<input type="text" id="cutparts_emsnumber" class="dfinput fl"/>
				</li>
				<li style="margin-bottom:3px">
					<label>快递地址：<b></b></label>
					<input type="text" id="cutparts_emsaddress" class="dfinput fl"  />
				</li>
				<li style="margin-bottom:3px">
					<label>联系人：<b></b></label>
					<input type="text" id="cutparts_emsusername" class="dfinput fl"  />
				</li>
				<li style="margin-bottom:3px">
					<label>联系号码：<b></b></label>
					<input type="text" id="cutparts_emstelephone" class="dfinput fl"  />
				</li>
			</ul>
		</div>
		<div style=" bottom: 30px;position: fixed;right: 50px">
			<input type="button" class="scbtn cutmatchparts" value="确定减库" />
		</div>
	</div>
	


	<!-- 分页 -->
	<div class="pagin">
    	<div class="message">共<i class="blue">[[${page.rowCnt}]]</i>条记录，当前显示第&nbsp;<i class="blue">[[${page.pageNo }]]&nbsp;</i>页</div>
    	<div th:utext='${listNavigatHtml}' th:remove="tag" ></div>
   	</div>
</div>
</body>
<script type="text/javascript">
	$(function (){
		
		$(".savematchparts").click(function () {
			var matchnum=$("#match_num").val();
			if(matchnum<=0){
				parent.layer.msg("请输入正确的分配数量",{icon:3});
				return;
			}
			if(matchnum>$("#match_sellnum").val()){
				parent.layer.msg("分配数量已超出可分配的数量",{icon:3});
				return;
			}
			var poscode=$(".imeiradio,input[type='radio']:checked").val();
			if(poscode==undefined){
				parent.layer.msg("请选择分配商户",{icon:3});
				return;
			}
			$.ajax({
				url : "[[${sysUrl}]]/sys/fx/matchParts",
				type : "post",
				data : {
					id:$("#match_id").val(),
					matchNum:matchnum,
					posCode:poscode,
					emsNumber:$("#match_emsnumber").val(),
					emsAddress:$("#match_emsaddress").val(),
					emsUsername:$("#match_emsusername").val(),
					emsTelephone:$("#match_emstelephone").val()
					},
				dataType : "json",
				success : function(data) {
					if(data.meta.success){
						parent.layer.msg("分配成功",{icon:1});
				    	setTimeout(function(){
				    		location.reload();
						},500);
					}else{
						alert("分配异常，请刷新后重试...")
					}
				}
			});
		});
		
		
		$(".addmatchparts").click(function () {
			var matchnum=$("#addparts_num").val();
			if(matchnum<=0){
				parent.layer.msg("请输入正确的数量",{icon:3});
				return;
			}
			$.ajax({
				url : "[[${sysUrl}]]/sys/fx/addParts",
				type : "post",
				data : {
					id:$("#addparts_id").val(),
					matchNum:matchnum,
					emsNumber:$("#addparts_emsnumber").val(),
					emsAddress:$("#addparts_emsaddress").val(),
					emsUsername:$("#addparts_emsusername").val(),
					emsTelephone:$("#addparts_emstelephone").val()
					},
				dataType : "json",
				success : function(data) {
					if(data.meta.success){
						parent.layer.msg("增库成功",{icon:1});
				    	setTimeout(function(){
				    		location.reload();
						},500);
					}else{
						alert("增库异常，请刷新后重试...")
					}
				}
			});
		});
		
		
		$(".cutmatchparts").click(function () {
			var matchnum=$("#cutparts_num").val();

			if(matchnum<=0){
				parent.layer.msg("请输入正确的数量",{icon:3});
				return;
			}
			
			if($("#cutparts_sellnum").val()<matchnum){
				parent.layer.msg("减库的数量不能超过已收货的数量",{icon:3});
				return;
			}

			$.ajax({
				url : "[[${sysUrl}]]/sys/fx/cutParts",
				type : "post",
				data : {
					id:$("#cutparts_id").val(),
					matchNum:matchnum,
					emsNumber:$("#cutparts_emsnumber").val(),
					emsAddress:$("#cutparts_emsaddress").val(),
					emsUsername:$("#cutparts_emsusername").val(),
					emsTelephone:$("#cutparts_emstelephone").val()
					},
				dataType : "json",
				success : function(data) {
					if(data.meta.success){
						parent.layer.msg("减库成功",{icon:1});
				    	setTimeout(function(){
				    		location.reload();
						},500);
					}else{
						alert("减库异常，请刷新后重试...")
					}
				}
			});
		});
		
		
		
	})
	
	
	
	function matchparts(id,sellNum,name){
			$("#match_title").html("可分配配件最大数量："+sellNum);
			$("#match_name").val(name);
			$("#match_id").val(id);
			$("#match_sellnum").val(sellNum);
			$("#match_num").val(sellNum)
	        layer.open({
	            type: 1,
	            title: '分配配件',
	            shadeClose: false,
	            shade: 0.8,
	            area: ['50%', '60%'],
	            offset: '100px',
	            content: $("#lowermerchants")
		     });
	};
	
	
	function addpartsnum(id,sellNum,name){
		$("#addparts_title").html("&nbsp;");
		$("#addparts_name").val(name);
		$("#addparts_id").val(id);
        layer.open({
            type: 1,
            title: '增加配件',
            shadeClose: false,
            shade: 0.8,
            area: ['50%', '60%'],
            offset: '100px',
            content: $("#addpartsnum")
	     });
	};
	
	
	function cutpartsnum(id,sellNum,name){
		$("#cutparts_title").html("当前可减库配件数量："+sellNum);
		$("#cutparts_name").val(name);
		$("#cutparts_id").val(id);
		$("#cutparts_sellnum").val(sellNum);
        layer.open({
            type: 1,
            title: '减库配件',
            shadeClose: false,
            shade: 0.8,
            area: ['50%', '60%'],
            offset: '100px',
            content: $("#cutpartsnum")
	     });
	};


	function partsAdd(id){
		layer.open({
		    type: 2,
		    title: '编辑设备',
		    closeBtn: 1, //不显示关闭按钮
		    shift: 0.8,
		    area: ['50%', '80%'],
		    offset: '100px',
		    content: '[[${sysUrl}]]/sys/fx/partsAdd.html'
		});
	}


	
	
	
</script>

<script type="text/javascript">
$("#button").on('click',function(){
	document.getElementById("seachform").action = "[[${sysUrl}]]/sys/fx/exportParts";
	$("#seachform").submit();
	document.getElementById("seachform").action = "[[${sysUrl}]]/sys/fx/deviceAllList.html";
});
</script>

</html>