<%@ 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> <span style="color:red;font-weight:700;">一卷起做（每卷最少500张）</span>
        <hr>
        <form class="layui-form">
            <input type="hidden" name="proTypeValue" id="proTypeValue" class="layui-input" value="2">
            <p>
                品类
            </p>
            <input type="radio" lay-filter="kind" name="kind" value="卷标" title="卷标" checked>
            <input type="radio" lay-filter="kind" name="kind" value="封口贴" title="封口贴">
            <p>
                材料
            </p>
            <div class="layui-form-item">
                <select name="kindValue" id="kindValue" lay-filter="kindValue" class="select">
                    <option value="0">格底铜板纸卷标</option>
                    <option value="1">格底PP合成纸</option>
                    <option value="2">8丝光白PVC</option>
                    <option value="3">5丝格底透明</option>
                    <option value="4">格底哑银 / 亮银</option>
                    <option value="5">格底银平光</option>
                    <option value="6">单防热敏纸（底纸白色）</option>
                    <option value="7">三防热敏纸（底纸蓝色）</option>
                </select>
            </div>
            <p>
                尺寸(CM/厘米) <span style="font-size:14px;color:red">输入格式: 长 * 宽</span>
            </p>
            <div class="layui-form-item roll">
                <input type="text" placeholder="格式:长*宽" name="size" id="size" class="layui-input" autocomplete="off">
            </div>
            <div class="layui-form-item sealant">
                <select name="size">
                    <option value="8*2">8*2cm</option>
                    <option value="9*2">9*2cm</option>
                    <option value="10*2">10*2cm</option>
                </select>
            </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>
            <!-- <p>规格</p>
            <div class="layui-form-item">
                <input type="radio" class="ui_zz" name="shuliang" lay-filter="switch" value="500" title="每卷500张" checked="checked"/>
                <input type="radio" class="ui_zz" name="shuliang" lay-filter="switch" value="1000" title="每卷1000张" />
                <input type="radio" class="ui_zz" name="shuliang" lay-filter="switch" value="2000" title="每卷2000张" />
            </div> -->
            <p>工艺</p>
            <div class="layui-form-item">
                <div class="layui-input-block check">
                    <span style="float:left;margin-top:10px">覆膜 ： </span>
                    <span class="roll">
                        <input type="checkbox" name="craft" class="fm" lay-filter="switch" value="覆膜" title="覆膜">
                        <input type="checkbox" name="craft" class="fm" lay-filter="switch" value="覆哑膜" title="覆哑膜">
                        <input type="checkbox" name="craft" class="fm" lay-filter="switch" value="大雪花镭射膜" title="大雪花镭射膜">
                    </span>
                    <span class="sealant">
                        <input type="checkbox" name="craft" class="fm" lay-filter="switch" value="覆亮膜" title="覆亮膜" checked>
                    </span>
                </div>
            </div>
            <div class="layui-form-item roll">
                <span style="float:left;margin-top:10px">白墨 ： </span>
                <input type="checkbox" class="yb" name="yinbai" lay-filter="switch" value="印白" title="印白">
            </div>
            <div class="layui-form-item roll">
                <span style="float:left;margin-top:10px">烫金 ： </span>
                <input type="checkbox" class="tang" name="craftTang" lay-filter="switch" value="烫金" title="烫金">
            </div>
            <div class="layui-form-item">
                <span style="float:left;margin-top:10px">卷芯 ： </span>
                <span class="roll">
                    <input type="radio" class="jc" name="jx" lay-filter="switch" value="7.5cm" title="7.5cm"
                           checked="checked"/>
                    <input type="radio" class="jc" name="jx" lay-filter="switch" value="4cm" title="4cm"/>
                    <input type="radio" class="jc" name="jx" lay-filter="switch" value="3cm" title="3cm"/>
                </span>
                <span class="sealant">
                    <input type="radio" class="jc" name="jx" lay-filter="switch" value="2.5cm" title="2.5cm"/>
                </span>
            </div>
            <div class="layui-form-item">
                <span style="float:left;margin-top:10px">出标方向 ： </span>
                <input type="radio" class="cb" name="cb" lay-filter="switch" value="上出标" title="上出标" checked="checked"/>
                <input type="radio" class="cb" name="cb" lay-filter="switch" value="下出标" title="下出标"/>
                <input type="radio" class="cb" name="cb" lay-filter="switch" value="左出标" title="左出标"/>
                <input type="radio" class="cb" name="cb" lay-filter="switch" value="右出标" title="右出标"/>
            </div>
            <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" 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 table = layui.table;
        var carousel = layui.carousel;

        ins = carousel.render({});
        $(".sealant").hide();
        $(".sealant").find("input").attr("disabled", true);
        $(".sealant").find("select").attr("disabled", true);
        $("input[name='yinbai']").attr("disabled", true);
        form.render()
        form.on('select(kindValue)', function (data) {
            // 中间三个可以印白
            if (data.value == 3 || data.value == 4 || data.value == 5) {
                $('.yb').removeAttr('disabled');
            } else {
                $('.yb').prop('disabled', 'disabled');
            }
            form.render();
            getImages(data.value)
        })
        getImages(0)

        function getImages(kindValue) {
            let kindValue2 = $("input[name='kind']:checked").val();
            let davaValue = {
                proTypeValue: $("#proTypeValue").val(),
                kindValue: kindValue,
                kind2Value: kindValue2
            }
            var html = " ";
            var remark = " ";
            // 清空轮播图
            $("#carousel").empty();
            $("#remark").empty();
            $.ajax({
                url: "${pageContext.request.contextPath}/getImgs",
                type: "GET",
                data: davaValue,
                success: function (result) {
                    for (let i = 0; i < result.length; i++) {
                        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);
                    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
                        });
                    }
                }
            });
        }

        form.on("radio(kind)", function (data) {
            let html = ` <option value="0">格底铜板纸卷标</option>
                    <option value="1">格底PP合成纸</option>
                    <option value="2">8丝光白PVC</option>
                    <option value="3">5丝格底透明</option>
                    <option value="4">格底哑银 / 亮银</option>
                    <option value="5">格底银平光</option>
                    <option value="6">单防热敏纸（底纸白色）</option>
                    <option value="7">三防热敏纸（底纸蓝色）</option>`
            $(".sealant").hide();
            $(".sealant").find("input").attr("disabled", true);
            $(".sealant").find("select").attr("disabled", true);
            $(".roll").hide();
            $(".roll").find("input").attr("disabled", true);
            if (data.value == "卷标") {
                $(".roll").show();
                $(".roll").find("input").attr("disabled", false);

                $("input[name='jx'][value='7.5cm']").click()
            }
            if (data.value == "封口贴") {
                html = ` <option value="0">格底铜板纸卷标</option>`
                $(".sealant").show();
                $(".sealant").find("input").attr("disabled", false);
                $(".sealant").find("select").attr("disabled", false);
                $("input[name='jx'][value='2.5cm']").click()
            }
            $("input[name='yinbai']").attr("disabled", true);
            $("#kindValue").empty().append(html);
            form.render()
            getImages(0)
        })

        form.on('checkbox(switch)', function (data) {
            // 亮膜哑膜只能选一个
            var moLen = $(".fm:checked:not(:disabled)").length;
            if (moLen > 1) {
                $(data.elem).next().attr("class", "layui-unselect layui-form-checkbox");
                $(data.elem).prop("checked", false);
                layer.msg('[覆膜 - 镭射膜]不能同时选择！', {offset: ['300px', '300px']}, {icon: 5});
                return false;
            }
        })
        //点击计算，计算价格
        form.on('submit(acount_btn)', function (data) {
            var kindData = {
                0: "格底铜板纸卷标", 1: "格底PP合成纸", 2: "8丝光白PVC",
                3: "5丝格底透明", 4: "格底哑银 / 亮银", 5: "格底银平光",
                6: "单防热敏纸（底纸白色）", 7: "三防热敏纸（底纸蓝色）"
            };
            var type = $("input[name='kind']:checked").val();
            var kind = kindData[$("#kindValue").val()];
            var size = $("#size").val();
            var number = $("#number").val();
            var count = $("input[name='count']").val();
            var craft = [];
            $("input:checkbox[name='craft']:checked").each(function (i) {
                if (!$(this).is(':disabled')) {
                    craft.push($(this).val());
                }
            });
            var yinbai = [];
            $("input:checkbox[name='yinbai']:checked").each(function (i) {
                if (!$(this).is(':disabled')) {
                    yinbai.push($(this).val());
                }
            });
            if (type == "封口贴") {
                size = $("select[name='size'] option:selected").val()
                if (count % 500 != 0) {
                    layer.msg("封口贴数量只能是500的倍数", {offset: ['300px', '300px']}, function () {
                    });
                    return false;
                }
            }
            if (type == "卷标") {
                if ((size.split("*")[0] > 42 || size.split("*")[1] > 38) && (size.split("*")[0] > 38 || size.split("*")[1] > 42)) {
                    layer.msg("卷装标签尺寸不能超过42*38 cm", {offset: ['300px', '300px']}, function () {
                    });
                    return false;
                }
                if ((size.split("*")[0] < 2 || size.split("*")[1] < 2)) {
                    layer.msg("卷装标签尺寸小于2*2 cm 请单独报价！", {offset: ['300px', '300px']}, function () {
                    });
                    return false;
                }
            }

            $.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 = "";
                    let craft_list = [];
                    if ($("#kindValue").val() == 0) {
                        jx = $("input[name='jx']:checked").val();
                        span_result = kind + ' - ' + size + ' 厘米 -卷芯直径' + $("input[name='jx']:checked:not(:disabled)").val() + '出标方向' + $("input[name='cb']:checked:not(:disabled)").val() + '(同款内容)\n' + '款数 : ' + number + '\n';
                    } else {
                        span_result = kind + ' - ' + size + ' 厘米 -(同款内容)\n' + '款数 : ' + number + '\n';
                    }
                    let fm = $("input[name='craft']:checked:not(:disabled)").val();
                    if (!!fm) {
                        craft_list.push(fm);
                    }
                    let yb = $("input[name='yinbai']:checked:not(:disabled)").val();
                    if (!!yb) {
                        craft_list.push(yb);
                    }
                    let craftTang = $("input[name='craftTang']:checked:not(:disabled)").val();
                    if (!!craftTang) {
                        craft_list.push(craftTang);
                    }
                    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);

                    if (yinbai != "") {
                        craft += yinbai;
                    }
                    if (craft != "") {
                        craft += "-";
                    }
                    craft += "卷芯直径" + $("input[name='jx']:checked").val() + "出标方向" + $("input[name='cb']:checked").val();
                    getRemark("卷装标签", 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>