<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
 <%@include file="/views/common.jsp"%>
</head>
<!-- 便签纸 -->
<style>
.select{
	width:100px;
	margin-top:5px;
	display:inline-block;
}
</style>
<body>
	<div class="big_box">
		<div class="left_div">
			<h1 class="h1">便签本/联单</h1>
			<hr>
			<form  class="layui-form">
				<div class="layui-form-item">
			      	<input type="radio" lay-filter="kind" name="notePaperKind" value="联单" title="联单" checked="checked">
			      	<input type="radio" lay-filter="kind" name="notePaperKind" value="稿纸/便签本/票本(每本100张)" title="稿纸 / 便签本 / 票本(每本100张)">
			      	<!-- <input type="radio" lay-filter="kind" name="notePaperKind" value="彩胶纸" title="彩胶纸"> -->
			      	<input type="radio" lay-filter="kind" name="notePaperKind" value="红头文件" title="红头文件(每本100张)">
			      	<input type="radio" lay-filter="kind" name="notePaperKind" value="彩色信纸(单面彩色印刷)" title="彩色信纸(单面彩色印刷)">
			    </div>
			</form>
			<form class="layui-form" id="kindValueForm">
				<p>材质</p>
				<div class="kind1">
					<input type="radio" lay-filter="kindValue" name="kind2Value" value="0" title="二联单（50份100张）">
					<input type="radio" lay-filter="kindValue" name="kind2Value" value="1" title="三联单（30份90张）">
					<input type="radio" lay-filter="kindValue" name="kind2Value" value="2" title="四联单（25份100张）">
				</div>
				<div class="kind2" style="display:none">
					<input type="radio" name="kind2Value" value="3" title="60克双胶">
					<input type="radio" name="kind2Value" value="4" title="70克双胶">
					<input type="radio" name="kind2Value" value="5" title="80克双胶">
				</div>
				<div class="kind3" style="display:none">
					<input type="radio" name="70克彩胶" value="6" title="70克彩胶" checked="checked">
					<div>
						<input type="radio" name="craftMo" value="单面" title="单面" checked="checked">
						<input type="radio" name="craftMo" value="双面" title="双面">
					</div>
					<p>
					颜色
					</p>
					<div class="layui-form-item">
						<select id="color" class="select">
							<option value="粉红色">粉红色</option>
							<option value="浅黄">浅黄</option>
							<option value="浅蓝">浅蓝</option>
						</select>
					</div>
					<p>
						尺寸(CM/厘米)
					</p>
					<div class="layui-form-item">
						<select name="size" class="select">
							<option value="28.5*21">28.5 x 21 cm</option>
						</select>
					</div>
				</div>
				<div class="kind4" style="display:none">
					<input type="radio" name="80克双胶" value="7" title="80克双胶" checked="checked">
					<p>
						尺寸(CM/厘米)
					</p>
					<div class="layui-form-item">
						<select name="size" class="select">
							<option value="29.7*21">29.7 x 21 cm</option>
						</select>
					</div>
				</div>
				<div class="kind5" style="display:none">
					<input type="radio" name="kind2Value" class="noFifty" value="4" title="70克双胶">
					<input type="radio" name="kind2Value" class="hundred" value="5" title="80克双胶">
					<p>
						规格
					</p>
					<input type="radio" name="kind1Value" lay-filter="kind1Value" value="0" title="每本50张">
					<input type="radio" name="kind1Value" lay-filter="kind1Value" value="1" title="每本100张">
				</div>
			</form>
			<form class="layui-form">
				<input type="hidden" name="proTypeValue" id="proTypeValue" class="layui-input" value="16">
				<div class="size">
					<p>
						尺寸(CM/厘米)   <span style="font-size:14px;color:red">输入格式: 长 * 宽</span>
					</p>
					<div class="layui-form-item">
						<input type="text" placeholder="格式:长*宽" name="size" id="size" class="layui-input" autocomplete="off">
					</div>
				</div>
				<p>数量(本)</p>
				<div class="layui-form-item">
					<div class="layui-input-block">
						<input type="text" name="count" autocomplete="off" class="layui-input" placeholder="数量">
					</div>
				</div>
				<p>款数</p>
				<div class="layui-form-item">
					<div class="layui-input-block">
						<input type="text" name="number" id="number" autocomplete="off" class="layui-input" value="1">
					</div>
				</div>
				<p>
					客户旺旺
				</p>
				<div class="layui-form-item">
					<input type="text" placeholder="请输入客户旺旺号" autocomplete="off" name="wangwang" id="wangwang" class="layui-input">
				</div>
				<div class="kind1">
					<p>
						工艺
					</p>
					<input type="checkbox" name="craft" class="craft" lay-filter="switch" value="垫板" title="垫板">
					<input type="checkbox" name="craft" class="craft" lay-filter="switch" value="封皮" title="封皮">
					<input type="checkbox" name="craft" class="craft" lay-filter="switch" value="彩色" title="彩色">
				</div>
				<div class="kind2" style="display: none;">
					<p>工艺</p>
					<input type="checkbox" name="craft" class="craft" lay-filter="switch" value="垫板" title="垫板">
					<input type="checkbox" name="craft" class="craft" lay-filter="switch" value="封皮" title="封皮">
				</div>
				<div class="layui-input-block">
					<input type="checkbox" name="craft" lay-filter="ui_craft" value="抠图" title="抠图">
					<div class="layui-inline crop" style="display:none;width: 80px">
						<input class="layui-input" type="text" name="cropNumber">
					</div>
				</div>
				<hr>
				<hr class="layui-bg-orange">
				<div class="layui-form-item">
					<button class="layui-btn" lay-submit="" lay-filter="acount_btn">计算</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
				<h2>计算结果-<button type="button" class="layui-btn layui-btn-primary layui-btn-sm copyResult" onclick="copyResult()">点击复制</button></h2>
				<div>
					<textarea rows="11" cols="75"  id="span_result" readonly="readonly"></textarea>
					<%@include file="../acountExpressFee.jsp"%>
				</div>
				<!--<h2>下单备注-<button type="button" class="layui-btn layui-btn-primary layui-btn-sm copyResult" onclick="copyBz()">点击复制</button></h2>
				<div>
					<textarea rows="5" cols="75" id="bz_result" readonly="readonly"></textarea>
				</div>-->
				<div >
					<table class="layui-hide" id="priceTable" lay-filter="priceTable"></table>
				</div>
			</form>
		</div>
		<div class="right_div">
			<div class="layui-carousel" id="test1" >
				<div carousel-item id="carousel"></div>
				<br>
				<div id="remark" style="font-size:20px;color:red"></div>
			</div> 
		</div>
	</div>
</body>
<%@include file="/views/copyResult.jsp"%>
<script>
	layui.use(['table','form','carousel'], function(){    
	    var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
	    var carousel = layui.carousel;
	    var table = layui.table;
	    
	  	//建造实例
	    ins = carousel.render({});
	    
	 	// 没切换“联单”的时候默认禁用其它的下拉框,（防止提交表单）
		$(".kind2").find(":input").attr("disabled", true); 
		$(".kind3").find(":input").attr("disabled", true); 
		$(".kind4").find(":input").attr("disabled", true); 
	 	// 选择材质种类--默认联单
		form.on('radio(kind)', function(kindData) {
	    	var html   = " ";
			var remark = " ";
			// 清空轮播图
			$("#carousel").empty();
			$("#remark").empty();
			$.ajax({
				url:"${pageContext.request.contextPath}/getImgs",
				type:"GET",
				data:{
					proTypeValue : $("#proTypeValue").val(),
					kindValue : kindData.value
				},
				//dataType : "json",
				success : function(result) {
					for (let i = 0; i < result.length; i++) {
						// 只留一个remark
						remark = "";
						html += '<div><img style="width:'+result[0].imgWidth+'px" src="' +result[i].imgUrl+ '"></div>';
						remark += '<div><span>' +result[i].remark+ '<span/></div>';
				    }  
					$("#carousel").append(html);
					// 如果没有说明，就不显示null
					if(remark.indexOf("null") < 0){
						$("#remark").append(remark);
					}
					if(result.length == 0){
						document.getElementById("test1").style.display = "none";   //隐藏
					}else{
						document.getElementById("test1").style.display = "block";   //显示
						ins.reload({
							elem: '#test1', 
							width: result[0].imgWidth,  //设置容器宽度
					        height: result[0].imgHeight
			            });
					}
				}
			});
			
			
			$("#kindValueForm")[0].reset();
			// 产品种类的值
		 	kind = kindData.value
			
			if(kind == "联单"){
				$("#proTypeValue").val("16");
				$(".size").show();
				$(".size").find(":input").attr("disabled", false);
				$(".kind1").show();
				$(".kind1").find(":input").attr("disabled", false); 
				$(".kind2").hide();
				$(".kind2").find(":input").attr("disabled", true); 
				$(".kind3").hide();
				$(".kind3").find(":input").attr("disabled", true); 
				$(".kind4").hide();
				$(".kind4").find(":input").attr("disabled", true); 
				$(".kind5").hide();
				$(".kind5").find(":input").attr("disabled", true);
				$('input[class = craft]').eq(0).prop('checked', true);
				$('input[class = craft]').eq(1).prop('checked', true);
			}else if(kind == "稿纸/便签本/票本(每本100张)"){
				$("#proTypeValue").val("16");
				$(".size").show();
				$(".size").find(":input").attr("disabled", false); 
				$(".kind2").show();
				$(".kind2").find(":input").attr("disabled", false); 
				$(".kind1").hide();
				$(".kind1").find(":input").attr("disabled", true); 
				$(".kind3").hide();
				$(".kind3").find(":input").attr("disabled", true); 
				$(".kind4").hide();
				$(".kind4").find(":input").attr("disabled", true);
				$(".kind5").hide();
				$(".kind5").find(":input").attr("disabled", true);
			}else if(kind == "彩胶纸"){
				$("#proTypeValue").val("16");
				$(".size").hide();
				$(".size").find(":input").attr("disabled", true); 
				$(".kind3").show();
				$(".kind3").find(":input").attr("disabled", false); 
				$(".kind1").hide();
				$(".kind1").find(":input").attr("disabled", true); 
				$(".kind2").hide();
				$(".kind2").find(":input").attr("disabled", true); 
				$(".kind4").hide();
				$(".kind4").find(":input").attr("disabled", true); 
				$(".kind5").hide();
				$(".kind5").find(":input").attr("disabled", true);
			}else if(kind == "红头文件"){
				$("#proTypeValue").val("16");
				$(".size").hide();
				$(".size").find(":input").attr("disabled", true); 
				$(".kind4").show();
				$(".kind4").find(":input").attr("disabled", false); 
				$(".kind1").hide();
				$(".kind1").find(":input").attr("disabled", true); 
				$(".kind2").hide();
				$(".kind2").find(":input").attr("disabled", true); 
				$(".kind3").hide();
				$(".kind3").find(":input").attr("disabled", true);
				$(".kind5").hide();
				$(".kind5").find(":input").attr("disabled", true);
			}else if(kind == "彩色信纸(单面彩色印刷)"){
				$("#proTypeValue").val("彩色信纸");
				$(".size").show();
				$(".size").find(":input").attr("disabled", false);
				$(".kind5").show();
				$(".kind5").find(":input").attr("disabled", false); 
				$(".kind1").hide();
				$(".kind1").find(":input").attr("disabled", true); 
				$(".kind2").hide();
				$(".kind2").find(":input").attr("disabled", true); 
				$(".kind3").hide();
				$(".kind3").find(":input").attr("disabled", true); 
				$(".kind4").hide();
				$(".kind4").find(":input").attr("disabled", true); 
			}
		 	form.render();//必须写
		}); 
	 	
	 	// 判断是否有 【70克双胶】
		form.on('radio(kind1Value)', function(kind1ValueData) {
			// 选择【每本50张】的时候禁用70克双胶，切换成80克双胶
	    	if(kind1ValueData.value == "0"){
	    		$(".noFifty").attr("disabled", true);
	    		$('input[class = hundred]').prop('checked', true);
	    		$(".hundred").attr("disabled", false);// 加这个让按钮取消禁用模式
	    	}else{
	    		var size = $("#size").val();
	    		if ((size.split("*")[0] > 21 || size.split("*")[1] > 14) && (size.split("*")[0] > 14 || size.split("*")[1] > 21)) {
					$(".noFifty").attr("disabled", true);
    	    		$('input[class = hundred]').prop('checked', true);
    	    		$(".hundred").attr("disabled", false);// 加这个让按钮取消禁用模式
				}else{
    				$(".noFifty").attr("disabled", false);
    			}
	    	}
	    	form.render('radio');
		})
		
		//输入框的值改变时触发
    	$("#size").on("input",function(e){
    		var size = e.delegateTarget.value;
    		kind1Value = $('input[name="kind1Value"]:checked').val()
    		//获取input输入的值
    		if(kind1Value == "1"){
    			// 输入尺寸大于21
    			if(size > 21){
    				$(".noFifty").attr("disabled", true);
    	    		$('input[class = hundred]').prop('checked', true);
    	    		$(".hundred").attr("disabled", false);// 加这个让按钮取消禁用模式
    			}else{
    				$(".noFifty").attr("disabled", false);
    			}
    			// 尺寸第一位小于21，第二位不符合
    			if(size.indexOf("*") != -1){
    				if ((size.split("*")[0] > 21 || size.split("*")[1] > 14) && (size.split("*")[0] > 14 || size.split("*")[1] > 21)) {
    					$(".noFifty").attr("disabled", true);
        	    		$('input[class = hundred]').prop('checked', true);
        	    		$(".hundred").attr("disabled", false);// 加这个让按钮取消禁用模式
    				}else{
        				$(".noFifty").attr("disabled", false);
        			}
    			}
    			form.render('radio');
        	}
    	});
		//工艺选择 -- 增加皮的种类
		form.on('checkbox(switch)', function(data) {
			if(data.value==='封皮'){
				$('input[class = craft]').eq(0).prop('checked', true);
				form.render();
			}

		});
		form.on('checkbox(ui_craft)', function (data) {
			let craft_list = [];
			let kindValue = $('input[name="kindValue"]:checked').val();
			craft_list.push($("select[name='craft'] option:selected").val());
			$("input[name='craft']:checked").each(function () {
				if (!$(this).is(':disabled')) {
					craft_list.push($(this).val());
				}
			});

			if (data.value == '抠图') {
				$(".crop").hide();
				$(".crop").find("input").prop("disabled", true)
				if (data.elem.checked) {
					$(".crop").show();
					$(".crop").find("input").prop("disabled", false)
				}
			}
			form.render();
		})
	  	//点击计算，计算价格
		form.on('submit(acount_btn)', function(data) {
			var notePaperKind = $('input[name="notePaperKind"]:checked').val();
			var kindData={
				0 :"二联单（50份100张）",1 :"三联单（30份90张）",2 :"四联单（25份100张）",
				3 :"60克双胶",4 :"70克双胶",5 :"80克双胶",
				6 :"70克彩胶",7 :"80克双胶"
			},kind1Data={
				0 :"每本50张",1 :"每本100张",
			};
			if(notePaperKind == "彩胶纸"){
				var kindValue = 6
				var craft 	  = $('input[name="craftMo"]:checked').val();
				var size   	  = "28.5 x 21"
				var color 	  = $("#color").val();
			}else if(notePaperKind == "红头文件"){
				var kindValue = 7
				var size   	  = "29.7 x 21"
				var craft 	  = ""
				var color 	  = ""
			}else if(notePaperKind == "联单"){
				var kindValue = $('input[name="kind2Value"]:checked').val();
				var size   	  = $("#size").val();
				var craft 	  = [];
				$("input:checkbox[name='craft']:checked").each(function(i) {
					// 没有被禁用的工艺加到arr中
					if(!$(this).is(':disabled')){
						craft.push($(this).val());
					}
				});
				var color 	  = ""
				if ((size.split("*")[0] > 42 || size.split("*")[1] > 28.5) && (size.split("*")[0] > 28.5 || size.split("*")[1] > 42)) {
					layer.msg("联单尺寸超过42*28.5 cm请单独报价",{offset:['300px','300px']},function(){});
					return false;
				}
			}else if(notePaperKind == "稿纸/便签本/票本(每本100张)"){
				var kindValue = $('input[name="kind2Value"]:checked').val();
				var size   	  = $("#size").val();
				var craft 	  = [];
				$("input:checkbox[name='craft']:checked").each(function(i) {
					// 没有被禁用的工艺加到arr中
					if(!$(this).is(':disabled')){
						craft.push($(this).val());
					}
				});
				var color 	  = ""
				if ((size.split("*")[0] > 28.5 || size.split("*")[1] > 21) && (size.split("*")[0] > 21 || size.split("*")[1] > 28.5)) {
					layer.msg("稿纸/便签本/票本尺寸超过28.5 * 21 cm请单独报价",{offset:['300px','300px']},function(){});
					return false;
				}
			}else if(notePaperKind == "彩色信纸(单面彩色印刷)"){
				var kind1Value = $('input[name="kind1Value"]:checked').val();
				var kindValue = $('input[name="kind2Value"]:checked').val();
				var size   	  = $("#size").val();
				var craft 	  = ""
				var color 	  = ""
				if ((size.split("*")[0] < 10 || size.split("*")[1] < 7) && (size.split("*")[0] < 7 || size.split("*")[1] < 10)) {
					layer.msg("联单尺寸不能小于10*7 cm",{offset:['300px','300px']},function(){});
					return false;
				}
				if ((size.split("*")[0] > 21 || size.split("*")[1] > 28.5) && (size.split("*")[0] > 28.5 || size.split("*")[1] > 21)) {
					layer.msg("彩色信纸尺寸不能超过21*28.5 cm",{offset:['300px','300px']},function(){});
					return false;
				}
			}
			var number 	= $("#number").val();
			var kind   	= [kindData[kindValue]];
			if(!size){
				layer.msg('请填写尺寸！',{offset:['300px','300px']},function(){});
				return false;
			}
			if (!kindValue) {
				layer.msg('请选择材料！', {
					offset : [ '300px', '300px' ]
				}, function() {
				});
				return false;
			}
			$("input[name='craft']:checked").each(function () {
				if (!$(this).is("disabled")) {
					if ($(this).val() == "抠图") {
						craft.push($(this).val() + $("input[name='cropNumber']").val());
						return;
					}
				}
			})
			$.ajax({
				url : "${path}/getThanSum",
				type : "GET",
				data : $(".big_box form").serialize(),
				success : function(result) {
					if(result.code == 100){
						layer.msg(result.msg,{offset:['300px','300px']},function(){});
						return false;
					}
					var data = result.data.proList;
					var span_result = notePaperKind + ' - ' + kind +'-' + [kind1Data[kind1Value]] +' -' + craft +'- ' + color + size +' 厘米 -(同款内容)\n' + '款数 : ' + number + '\n';
					if(notePaperKind == "红头文件" || notePaperKind == "彩胶纸"){
						if(number > 1){
							for (let i = 0; i < data.length; i++) {
								span_result += number + '款 各' + data[i].count + "张，共" + data[i].price + "元" + '\n'
								data[i].number = number;
					        }   
						}else{
							for (let i = 0; i < data.length; i++) {
								span_result += number + '款 ' + data[i].count + "张，共" + data[i].price + "元" + '\n'
								data[i].number = number;
					        }   
						}
					}else{
						if(number > 1){
							for (let i = 0; i < data.length; i++) {
								span_result += number + '款 各' + data[i].count + "本，共" + data[i].price + "元" + '\n'
								data[i].number = number;
					        }   
						}else{
							for (let i = 0; i < data.length; i++) {
								span_result += number + '款 ' + data[i].count + "本，共" + data[i].price + "元" + '\n'
								data[i].number = number;
					        }   
						}
					}
					
					span_result += '包邮，免费设计呢~（偏远地区需补邮费）'
                        if(window.parent.system_isGai){
                            span_result +="\n\n亲 现在下单可以参加淘宝活动8.5折折扣哦!"
                        }
	    			addLog(span_result);
                    $("#span_result").val(span_result);
					
					kind[0] = kind[0].replace("（","");
					kind[0] = kind[0].replace("）","");
					var count = $("input[name='count']").val();
					if(notePaperKind.indexOf("稿纸/便签本/票本") >= 0){
						notePaperKind = "便签本";
					}else if(notePaperKind.indexOf("红头文件") >= 0){
						size = "29.7*21";
					}
					getRemark(notePaperKind, size, count+"本", kind, number, craft, "");
					//计算完自动复制文本
					var e=document.getElementById("span_result");//对象是content
					if (e.value != "") {
						e.select();//选择对象
						document.execCommand("Copy");//执行浏览器复制命令
					}
					//生成表格
					table.render({
						elem : '#priceTable',
						even : true, //隔行变色
						data : data, // 赋值已知数据
						width : 500,
						cols : [ [ 
							{
								field : 'number',
								width : '12%',
								align : "center",
								title : '款数'
							},{
								field : 'count',
								width : '16%',
								align : "center",
								title : '数量'
							},{
								field : 'price',
								width : '16%',
								align : "center",
								title : '报价'
							},{
								field : 'wangwang',
								align : "center",
								width : '16%',
								title : '折扣价'
							},{
								field : 'wangwang',
								align : "center",
								width : '19%',
								title : '跳楼价'
							},{
								field : 'weight',
								width : '21%',
								align : "center",
								title : '重量（kg）'
							}
						] ],
						done: function () {
			            }
					});
				}
			});
			return false;
		})
	});
</script>
</html>