<%@ 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>
    #craft_layout .layui-form-select .layui-edge {
        right: 20px;
    }
</style>
<body>
<div class="big_box">
    <div class="left_div">
        <h1 class="h1">彩色信封</h1>
        <hr>
        <form class="layui-form">
            <input type="hidden" name="proTypeValue" id="proTypeValue" class="layui-input" value="9">
            <p>
                材质
            </p>
            <div class="layui-form-item" style="display:none;">
                <div class="layui-input-block">
                    <input type="radio" name="kindValue" lay-filter="k" class="kindValue" value="0" title="120克双胶纸">
                    <input type="radio" name="kindValue" lay-filter="k" class="kindValue" value="10" title="120克牛皮纸">
                    <input type="radio" name="kindValue" lay-filter="k" class="kindValue" value="1" title="100克双胶纸">
                    <input type="radio" name="kindValue" lay-filter="k" class="kindValue" value="11" title="100克牛皮纸">
                </div>
            </div>
            <div class="layui-form-item" style="display:none;">
                <div class="layui-input-block">
                    <input type="radio" name="kindValue" lay-filter="k" class="kindValue" value="2" title="140克珠光冰白彩色信封">
                    <input type="radio" name="kindValue" lay-filter="k" class="kindValue" value="3" title="200克珠光冰白彩色信封">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="radio" name="kindValue" lay-filter="k" class="kindValue" value="4" title="250克高端珠光冰白烫金信封">
                    <input type="radio" name="kindValue" lay-filter="k" class="kindValue" value="12" title="300克铜版纸信封">
                </div>
            </div>
            <p>
                规格
            </p>
            <div class="layui-form-item first">
                <select name="kind2Value" class="select kind2Value firstKind2Value">
                    <option value="0">3号（中/西封）--成品17.6*12.5CM</option>
                    <option value="1">5号（中/西封）--成品22*11CM</option>
                    <option value="2">6号（中/西封）--成品23*12CM</option>
                    <option value="3">7号（中/西封）--成品22.9*16.2CM</option>
                    <option value="4">8号（中/西封）--成品25*16.2CM</option>
                    <option value="5">9号（中式） --成品32.4*22.9CM</option>
                    <option value="6">9号（西式） --成品32.4*22.9CM</option>
                </select>
            </div>
            <div class="layui-form-item second" style="display:none;">
                <select name="kind2Value" class="select kind2Value secondKind2Value">
                    <option value="0">1号信封 (16.5*10cm)</option>
                    <option value="1">2号信封 (17.5*11cm)</option>
                    <option value="2">3号信封 (B6号 17.6*12.5cm)</option>
                    <option value="3">5号信封 (DL号 22*11cm)</option>
                    <option value="4">6号信封 (ZL号 23*12cm)</option>
                    <option value="5">7号信封 (C5号 22.9*16.2cm)</option>
                    <option value="6">8号信封 (增值税票专用 25*16.2cm)</option>
                    <option value="7">9号信封 (C4号 32.4*22.9cm)</option>
                </select>
            </div>
            <div class="layui-form-item third" style="display:none;">
                <select name="kind2Value" class="select kind2Value thirdKind2Value" lay-filter="testId">
                    <option value="0">9*6cm</option>
                    <option value="1">10*7cm</option>
                    <option value="2">12*8cm</option>
                    <option value="3">15*8cm</option>
                    <option value="4">17*9cm</option>
                    <option value="5">19*9cm</option>
                    <option value="6">21*11cm</option>
                    <option value="7">22*12cm</option>
                </select>
            </div>
            <div class="pageColor" style="display:none;">
                <p>
                    纸张颜色
                </p>
                <div class="layui-form-item color1">
                    <select class="select color11">
                        <option value="白金">白金</option>
                        <option value="米金">米金</option>
                        <option value="湖蓝">湖蓝</option>
                        <option value="紫红">紫红</option>
                        <option value="金黄">金黄</option>
                        <option value="金铜">金铜</option>
                        <option value="炭黑">炭黑</option>
                        <option value="墨绿">墨绿</option>
                    </select>
                </div>
                <div class="layui-form-item color2">
                    <select class="select color22">
                        <option value="红色">红色</option>
                        <option value="宝蓝">宝蓝</option>
                        <option value="金色">金色</option>
                        <option value="黑卡">黑卡</option>
                    </select>
                </div>
            </div>
            <p>
                数量（个）
            </p>
            <div class="layui-form-item" id="otherCount" style="display:none;">
                <select name="count" class="select" id="count">
                    <option value="200">200</option>
                    <option value="500">500</option>
                    <option value="1000">1000</option>
                    <option value="3000">3000</option>
                    <option value="5000">5000</option>
                </select>
            </div>
            <div class="layui-form-item" id="thirdCount">
                <select name="count" class="select" id="count1">
                    <option value="100">100</option>
                    <option value="200">200</option>
                    <option value="300">300</option>
                    <option value="500">500</option>
                    <option value="1000">1000</option>
                    <option value="2000">2000</option>
                    <option value="3000">3000</option>
                    <option value="5000">5000</option>
                    <option value="10000">10000</option>
                </select>
            </div>
            <p>
                款数
            </p>
            <div class="layui-form-item">
                <input type="text" placeholder="请输入整数" autocomplete="off" name="number" id="number" value="1"
                       class="layui-input" lay-verify="number">
            </div>
            <p>
                客户旺旺
            </p>
            <div class="layui-form-item">
                <input type="text" placeholder="请输入客户旺旺号" autocomplete="off" name="wangwang" id="wangwang"
                       class="layui-input">
            </div>
            <p>工艺</p>
            <div id="craft_layout">
                烫金工艺：
                <input type="checkbox" name="craft" lay-filter="switch" value="烫金" title="烫金">
                <div class="layui-inline" style="width: 100px">
                    <select name="craft" class="select" id="craftNum">
                        <option value="1处">1处</option>
                        <option value="2处">2处</option>
                        <option value="3处">3处</option>
                    </select>
                </div>
                <div class="layui-inline" style="width: 100px" id="craftColor">
                    <select name="craft" class="select">
                        <option value="金色">金色</option>
                        <option value="黑色">黑色</option>
                        <option value="红色">红色</option>
                        <option value="蓝色">蓝色</option>
                        <option value="银色">银色</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item" id="craft_mo">
                覆膜工艺：
                <input type="checkbox" name="craft" lay-filter="switch" value="覆哑膜" title="覆哑膜" checked>
            </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>
            <div class="layui-form-item">
                <button class="layui-btn" lay-submit="" lay-filter="acount_btn" id="queryCondBtn">计算</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" style="margin-left:50px;">
        <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({});

        // 监听回车键，如果敲了回车，调用点击‘计算’
        $(document).keydown(function (e) {
            if (e.keyCode === 13) {
                $("#queryCondBtn").trigger("click");
            }
        });

        form.on('checkbox(switch)', function (data) {

            let craft_list = [];
            let kindV = $("input[name='kindValue']:checked").val();

            $("input[name='craft']:checked").each(function () {
                if (!$(this).is(':disabled')) {
                    craft_list.push($(this).val());
                }
            });
            if (kindV == 12 && !craft_list.includes("覆哑膜")) {
                $(data.elem).prop("checked", true);
                layer.msg("覆膜工艺无法取消", {offset: ['300px', '300px']}, function () {
                });
                form.render();
                return false;
            }

        })
        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();
        })
        // 隐藏的默认禁用
        $(".color2").hide();
        $(".second").find(":input").attr("disabled", true);
        form.on('radio(k)', function (data) {
            var level = data.value;//被点击的radio的value值

            var html = " ";
            var remark = " ";
            // 清空轮播图
            $("#carousel").empty();
            $("#remark").empty();
            $.ajax({
                url: "${pageContext.request.contextPath}/getImgs",
                type: "GET",
                data: {
                    proTypeValue: $("#proTypeValue").val(),
                    kindValue: level
                },
                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
                        });
                    }
                }
            });
            $(".first").hide();
            $(".first").find(":input").attr("disabled", true);
            $(".second").hide();
            $(".second").find(":input").attr("disabled", true);
            $(".third").hide();
            $(".third").find(":input").attr("disabled", true);
            $("#otherCount").hide();
            $("#otherCount").find(":input").attr("disabled", true);
            $("#craft_mo").hide();
            $("#craft_mo").find(":input").attr("disabled", true);
            $("#thirdCount").hide();
            $("#thirdCount").find(":input").attr("disabled", true);
            $(".pageColor").hide();
            $(".pageColor").find(":input").attr("disabled", true);
            if (level == 2 || level == 3) {
                $(".second").show();
                $(".second").find(":input").attr("disabled", false);
                $("#otherCount").show();
                $("#thirdCount").find(":input").attr("disabled", false);
            } else if (level == 4 || level == 12) {
                $(".third").show();
                $(".third").find(":input").attr("disabled", false);
            } else {
                $(".first").show();
                $(".first").find(":input").attr("disabled", false);
            }
            // 高端珠白冰白烫金信封
            if (level == 4) {
                // 数量
                $("#thirdCount").show();
                $("#thirdCount").find(":input").attr("disabled", false);

                $(".pageColor").show();
                $(".pageColor").find(":input").attr("disabled", false);
                $(".color2").find(":input").attr("disabled", true);
                form.on('select(testId)', function (data) {
                    if (data.value == 0) {
                        $(".color1").show();
                        $(".color1").find(":input").attr("disabled", false);
                        $(".color2").hide();
                        $(".color2").find(":input").attr("disabled", true);
                    } else {
                        // $(".color2").show();
                        // $(".color2").find(":input").attr("disabled", false);
                        // $(".color1").hide();
                        // $(".color1").find(":input").attr("disabled", true);
                    }
                })
            } else if (level == 12) {
                $("#craft_mo").show();
                $("#craft_mo").find(":input").attr("disabled", false);
                $("#otherCount").show();
                $("#otherCount").find(":input").attr("disabled", false);
            } else {
                // 数量
                $("#otherCount").show();
                $("#otherCount").find(":input").attr("disabled", false);

            }

            // 点击计算，计算价格
            form.on('submit(acount_btn)', function (data) {
                $.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 kindData = {
                            0: "120克双胶纸",
                            10: "120克牛皮纸",
                            1: "100克双胶纸",
                            11: "100克牛皮纸",
                            2: "140克珠光冰白彩色信封",
                            3: "200克珠光冰白彩色信封",
                            4: "250克高端珠光冰白烫金信封",
                            12: "300克铜版纸信封"
                        };
                        // 第二排
                        if (level == 2 || level == 3) {
                            var kind2Data = {
                                0: "1号封",
                                1: "2号封",
                                2: "3号封",
                                3: "5号封",
                                4: "6号封",
                                5: "7号封",
                                6: "8号（增票专用）",
                                7: "9号封"
                            };
                            var kind2 = kind2Data[$(".secondKind2Value").val()];
                        }
                        // 第三排
                        else if (level == 4 || level == 12) {
                            var kind2Data = {
                                0: "5号西式信封22*11cm",
                                1: "卡套定制款  9.4*6.4cm"
                            };
                            var kind2 = $(".thirdKind2Value").val();
                            // 判断规格选颜色
                            if (level == 4) {
                                if (kind2 == 0) {
                                    var color = $(".color11").val()
                                } else {
                                    var color = $(".color22").val()
                                }
                            }
                            kind2 = $(".thirdKind2Value option:selected").text();
                        }
                        // 第一排
                        else {
                            var kind2Data = {
                                0: "3号（中/西封）成品17.6*12.5CM",
                                1: "5号（中/西封）成品22*11CM",
                                2: "6号（中/西封）成品23*12CM",
                                3: "7号（中/西封）成品22.9*16.2CM",
                                4: "8号（中/西封）成品25*16.2CM",
                                5: "9号（中式）成品32.4*22.9CM",
                                6: "9号（西式）成品32.4*22.9CM"
                            };
                            var kind2 = kind2Data[$(".firstKind2Value").val()];
                        }
                        var kind = kindData[$('input[name="kindValue"]:checked').val()];
                        var number = $("#number").val();
                        let craft_list = [];
                        if (color == null) color = ""
                        $("input[name='craft']:checked").each(function () {
                                if (!$(this).is(':disabled')) {
                                    if ($(this).val() == "烫金") {
                                        craft_list.push($(this).val() + $("#craftNum option:selected").val() + $("#craftColor option:selected").val());
                                    } else if ($(this).val() == "抠图") {
                                        craft_list.push($(this).val() + $("input[name='cropNumber']").val());
                                        return;
                                    } else {
                                        craft_list.push($(this).val());
                                    }
                                }
                            }
                        );


                        var span_result = kind + '\n' + kind2 + ' - ' + color + ' (同款内容)\n';
                        if (craft_list.length > 0) {
                            span_result += "工艺:" + craft_list.join(",") + '\n'
                        }
                        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);

                        var count = "";
                        if ($("#otherCount").css("display") == "none") {
                            count = $("#count1 option:selected").val();
                        } else {
                            count = $("#count option:selected").val();
                        }
                        var size = "";
                        if (level == 2 || level == 3) {
                            var secondKind2Value = $(".secondKind2Value option:selected").val();
                            if (secondKind2Value == "0") {
                                size = "16.5*10";
                            } else if (secondKind2Value == "1") {
                                size = "17.5*11";
                            } else if (secondKind2Value == "2") {
                                size = "17.6*12.5";
                            } else if (secondKind2Value == "3") {
                                size = "22*11";
                            } else if (secondKind2Value == "4") {
                                size = "23*12";
                            } else if (secondKind2Value == "5") {
                                size = "22.9*16.2";
                            } else if (secondKind2Value == "6") {
                                size = "25*16.2";
                            } else {
                                size = "32.4*22.9";
                            }
                            kind += "-" + kind2;
                        } else if (level == 4 || level == 12) {
                            var thirdKind2Value = $(".thirdKind2Value option:selected").val();
                            size = $(".thirdKind2Value option:selected").text()

                        } else {
                            var sizeIndex = kind2.indexOf("品");
                            size = kind2.substring(sizeIndex + 1, kind2.length);
                            size = size.replace("CM", "");
                            kind += "-" + kind2.substring(0, sizeIndex - 1);
                        }

                        getRemark("彩色信封", size, count + "个", kind, number, "", "");
                        //计算完自动复制文本
                        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>