<%@ 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;
    }

    .ji .layui-form-select .layui-edge {
        right: 20px;
    }
</style>
<body>
<div class="big_box">
    <div class="left_div">
        <h1 class="h1">插卡</h1> <span style="color:red;font-weight:700;"></span>
        <hr>
        <form class="layui-form">
            <input type="hidden" name="proTypeValue" id="proTypeValue" class="layui-input" value="3">
            <p>
                品种
            </p>
            <div class="layui-form-item">
                <select name="kindValue" id="kindValue" class="select" lay-filter="setKind" lay-verify="required">
                    <option></option>
                </select>
            </div>
            <p>
                尺寸（厘米）<span style="font-size:14px;color:red">输入格式: 长 * 宽</span>
            </p>

            <div class="layui-form-item size2">
                <input type="text" name="size" placeholder="格式:长*宽" autocomplete="off" class="layui-input size22 size">
            </div>

            <div class="layui-form-item size1" style="display:none">
                <select name="size" class="select size11">
                    <option value="3*3">3*3（厘米）</option>
                    <option value="3.5*3.5">3.5*3.5（厘米）</option>
                    <option value="4*4">4*4（厘米）</option>
                    <option value="4.5*4.5">4.5*4.5（厘米）</option>
                    <option value="5*5">5*5（厘米）</option>
                </select>
            </div>
            <div class="layui-form-item ui_size" style="display:none">
                <select name="size" class="size">
                    <option value="3.5*3.5">3.5*3.5（厘米）</option>
                    <option value="4*4">4*4（厘米）</option>
                    <option value="5*5">5*5（厘米）</option>
                </select>
            </div>
            <p>
                数量(个)
            </p>
            <div class="layui-form-item ui_normal">
                <select name="count" class="select">
                    <option value="200">200</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>
                    <option value="20000">20000</option>
                    <option value="30000">30000</option>
                </select>
            </div>
            <div class="layui-form-item ui_wq" style="display: none;">
                <select name="count" class="select">
                    <option value="200">200</option>
                    <option value="500">500</option>
                    <option value="1000">1000</option>
                    <option value="2000">2000</option>
                    <option value="3000">3000</option>
                    <!-- <option value="4000">4000</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 class="layui-form-item ui_normal">
                <input type="radio" name="craftQie" class="moqie" value="模切" lay-skin="primary" title="模切"
                       checked="checked">
            </div>
            <div class="layui-form-item auto" style="display: none;">
                <input type="radio" name="craftauto" value="击凸" lay-skin="primary" title="击凸" checked>
                <input type="radio" name="craftauto" value="压凹" lay-skin="primary" title="压凹">
            </div>
            <div class="ui_wq" style="display: none;">
                <input type="radio" name="craftQie" class="moqie" value="模切" lay-skin="primary" title="模切"
                       checked="checked">
                <input type="radio" name="craftTang" value="单面烫金" lay-skin="primary" title="单面烫金" checked="checked">
                <br/>
                <input type="radio" name="craftShua" value="无" lay-skin="primary" title="无" checked="checked">
                <input type="radio" name="craftShua" value="银铝箔纸" lay-skin="primary" title="银铝箔纸">
                <input type="radio" name="craftShua" value="金铝箔纸" lay-skin="primary" title="金铝箔纸">
            </div>
            <div class="layui-input-block ji" style="display: none">
                <input type="checkbox" class="craft" name="craft" lay-filter="craft" value="击凸" title="击凸">
                <input type="checkbox" class="craft" name="craft" lay-filter="craft" value="压凹" title="压凹">
                <div class="layui-inline " style="width: 110px;display: none">
                    <select class="select" name="ji_color">
                        <option value="无色">无色</option>
                        <option value="有色">有色</option>
                    </select>
                </div>
            </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">计算</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="13" 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({});
        //一访问页面就调用
        $.ajax({
            url: "${pageContext.request.contextPath}/getKindsByPro",
            type: "GET",
            data: {
                proTypeValue: 3
            },
            dataType: "json",
            success: function (result) {
                $.each(result, function (index, item) {
                    //哑金哑银凹凸插卡
                    if (index == 9) {
                        $('#kindValue').append(new Option("哑金插卡", index));//往下拉菜单里添加元素
                        $('#kindValue').append(new Option("哑银插卡", 14));//往下拉菜单里添加元素
                    }
                    //亮金亮银凹凸插卡
                    else if (index == 10) {
                        $('#kindValue').append(new Option("亮金插卡", index));//往下拉菜单里添加元素
                        $('#kindValue').append(new Option("亮银插卡", 15));//往下拉菜单里添加元素
                    } else {
                        $('#kindValue').append(new Option(item, index));//往下拉菜单里添加元素
                    }
                });
                layui.form.render("select");
            }
        });
        form.on('checkbox(craft)', function (data) {
            if (data.value == '击凸' || data.value == '压凹') {
                if ($(data.elem).is(":checked")) {
                    $("select[name='ji_color']").parent().show();
                    $("select[name='ji_color']").prop("disabled", false);
                } else {
                    $("select[name='ji_color']").parent().hide();
                    $("select[name='ji_color']").prop("disabled", true);
                }
            }

        })
        form.on('select(setKind)', function (data) {
            var html = " ";
            var remark = " ";
            // 清空轮播图
            $("#carousel").empty();
            $("#remark").empty();
            let kindValue = $("#kindValue").val();
            if (kindValue == 14) {
                kindValue = 9;
            }
            if (kindValue == 15) {
                kindValue = 10;
            }
            let prams = {
                proTypeValue: $("#proTypeValue").val(),
                kindValue: kindValue
            }
            $.ajax({
                url: "${pageContext.request.contextPath}/getImgs",
                type: "GET",
                data: prams,
                success: function (result) {
                    for (let i = 0; i < result.length; i++) {
                        // 只留一个remark
                        remark = "";
                        html += '<div><img style="width:100%;height: 100%;object-fit: contain" 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
                        });
                    }
                }
            });
            $(".auto").find(":input").attr("disabled", true);
            $(".auto").hide();
            $(".ji").hide();
            $(".ji").find(":input").attr("disabled", true);
            if (data.value == 7) {
                $(".ui_wq").find(":input").attr("disabled", false);
                $(".ui_wq").show();
                $(".ui_normal").find(":input").attr("disabled", true);
                $(".ui_normal").hide();
            } else {
                $(".ui_normal").find(":input").attr("disabled", false);
                $(".ui_normal").show();
                $(".ui_wq").find(":input").attr("disabled", true);
                $(".ui_wq").hide();
            }
            if (data.value == 9 || data.value == 10 || data.value == 14 || data.value == 15) {
                $(".auto").find(":input").attr("disabled", false);
                $(".auto").show();
            }
            if (data.value == 1) {
                $(".size1").find(":input").attr("disabled", false);
                $(".size1").show();
                $(".size2").hide();
                $(".size2").find(":input").attr("disabled", true);
                $(".ui_size").hide();
                $(".ui_size").find(":input").attr("disabled", true);
            } else if (data.value == 12) {//400克旋转插卡
                $(".ui_size").show();
                $(".ui_size").find(":input").attr("disabled", false);
                $(".size2").hide();
                $(".size2").find(":input").attr("disabled", true);
                $(".size1").hide();
                $(".size1").find(":input").attr("disabled", true);
            } else {
                $(".size2").show();
                $(".size2").find(":input").attr("disabled", false);
                $(".size1").hide();
                $(".size1").find(":input").attr("disabled", true);
                $(".ui_size").hide();
                $(".ui_size").find(":input").attr("disabled", true);
            }
            if (data.value == '0') {
                $(".ji").show();
                $(".ji").find(":input").attr("disabled", false);
            }
            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 kind = $("#kindValue").val();
            var size = $(".size").val();
            if (kind == 1) {
                size = $(".size11 :checked").val();
            } else if (kind == 12) {
                size = $(".ui_size :checked").val();
            } else {
                if (!size) {
                    layer.msg('请填写尺寸！', {offset: ['300px', '300px']}, function () {
                    });
                    return false;
                }
                if ((size.split("*")[0] > 9 || size.split("*")[1] > 5.4) && (size.split("*")[0] > 5.4 || size.split("*")[1] > 9)) {
                    layer.msg("[ 插卡 ]尺寸不能超过9*5.4 cm !", {offset: ['300px', '300px']}, function () {
                    });
                    return false;
                }
            }
            let craftList = []
            var craftQie = $("input[name='craftQie']:checked").val();
            var craftauto = $("input[name='craftauto']:checked").val();
            var number = $("#number").val();
            craftList.push(craftQie);
            var kindData = {
                0: "异形插牌",
                1: "菱形单面直角插卡",
                2: "400g卡纸单面烫金",
                3: "400g铜板印刷+单面烫金效果",
                4: "哑金烫金单面插卡",
                5: "透明烫金插牌",
                7: "弯曲插卡",
                8: "400g卡纸双面烫金",
                9: "哑金插卡",
                10: "亮金插卡",
                11: "镭射银插卡",
                12: "400克旋转插卡单面烫金（烫银）",
                13: "350克铜版纸印刷+凹凸",
                14: "哑银插卡",
                15: "亮银插卡",
            };
            var kindValue = kindData[kind];
            $.ajax({
                url: "${pageContext.request.contextPath}/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;
                    if (kind == 7) {
                        craftQie += "," + $("input[name='craftTang']:checked").val();
                        craftList.push($("input[name='craftTang']:checked").val());
                        if ($("input[name='craftShua']:checked").val() != "无") {
                            craftQie += "," + $("input[name='craftShua']:checked").val();
                            craftList.push($("input[name='craftShua']:checked").val());
                        }
                    }
                    if (kind == 9 || kind == 10 || kind == 14 || kind == 15) {
                        craftQie += "," + craftauto;
                        craftList.push(craftauto);
                    }
                    if (kind == 0) {
                        $("input[name='craft']:checked").each(function () {
                            if (!$(this).is(':disabled')) {
                                if ($(this).val() == '击凸' || $(this).val() == '压凹') {
                                    craftList.push($("select[name='ji_color'] option:selected").val() + $(this).val());
                                } else if ($(this).val() == "抠图") {
                                    return;
                                } else {
                                    craftList.push($(this).val());
                                }
                            }
                        });
                    }
                    $("input[name='craft']:checked").each(function () {
                        if (!$(this).is("disabled")) {
                            if ($(this).val() == "抠图") {
                                craftList.push($(this).val() + $("input[name='cropNumber']").val());
                                return;
                            }
                        }
                    })
                    var span_result = '插卡 - ' + kindValue + ' - ' + size + "厘米 - (同款内容) " + '\n';
                    span_result += '工艺：' + craftList.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 = $("#count option:selected").val();
                    getRemark("插卡", size, count + "个", kindValue, number, craftQie, "");
                    //计算完自动复制文本
                    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）'
                            }
                        ]],
                    });
                }
            });
            return false;
        });
    })
    ;
</script>
</html>