<%@ 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>
    .layui-form-checkbox[lay-skin=primary] i {
        border-radius: 50px;
        width: 18px;
        height: 18px;
        line-height: 18px;
        margin-top: 3px;
    }

    .layui-form-checkbox[lay-skin=primary] span {
        color: black;
        margin-top: 3px;
        font-size: 14px;
    }
</style>
<body>
<div class="big_box">
    <div class="left_div">
        <h1 class="h2">吊牌</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="吊牌">
            <p>材质</p>
            <div>
                <input type="radio" name="kindValue" lay-filter="kindValue" value="3" title="300克铜版纸" checked>
                <input type="radio" name="kindValue" lay-filter="kindValue" value="4" title="600克铜版纸">
                <!-- <input type="radio" name="kind3Value" lay-filter="kindValue3" value="5" title="800克铜版纸"> -->
            </div>
            <div class="tagOther">
                <p>
                    尺寸(CM/厘米) <span style="font-size: 14px; color: red">输入格式: 长 * 宽</span>
                    <span class="addOrCutTags">
<%--							<button type="button" title="点击添加尺寸" class="layui-btn layui-btn-primary layui-btn-sm button" onclick="AddInputTags()"><i class="layui-icon">组合</i></button>--%>
							<button type="button" title="点击移除尺寸" class="layui-btn layui-btn-primary layui-btn-sm button" onclick="CutInputTags()"><i
                                    class="layui-icon">单张</i></button>
						</span>
                </p>
                <div class="qt">
                    <div class="layui-form-item" id="fatherDivTags">
                        <input type="text" name="size" placeholder="格式:长*宽" id="size" class="layui-input" autocomplete="off">
                    </div>
                </div>
                <p>
                    数量(张) <span class="switchCount">
						<input type="checkbox" name="switchCount" class="Count" lay-filter="switchCount" title="自定义数量"></span>
                </p>
                <div class="count">
                    <div class="layui-form-item">
                        <select name="count" id="zjCount" 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>
                </div>
                <div class="mqCount" style="display:none">
                    <div class="layui-form-item">
                        <select name="count" id="mqCount" class="select">
                            <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>
                </div>
                <div class="diyCount" style="display: none">
                    <div class="layui-form-item">
                        <input type="text" name="count" id="count" placeholder="请输入整数" class="layui-input" autocomplete="off">
                    </div>
                </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-input-block">
                    <input type="radio" name="craftQie" lay-filter="craftQie" la value="直角打孔" title="直角打孔" checked>
                    <input type="radio" name="craftQie" lay-filter="craftQie" value="异形模切" title="异形模切">
                    |&nbsp;&nbsp;&nbsp;
                    <input type="radio" name="craftMo" lay-filter="craftMo" la value="双面覆哑膜" title="双面覆哑膜" checked>
                    <input type="radio" name="craftMo" lay-filter="craftMo" value="不覆膜" title="不覆膜">
                    |&nbsp;&nbsp;&nbsp;
                    <input type="checkbox" class="tang" name="craftTang" lay-filter="switch" value="单面烫金" title="单面烫金" lay-skin="primary">
                    <input type="checkbox" class="tang" name="craftTang" lay-filter="switch" value="双面烫金" title="双面烫金" lay-skin="primary">
                </div>
            </div>

            <div id="tag" style="display: none">
                <%@include file="tag.jsp" %>
            </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="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>
<script src="../../js/carousel.js" charset="utf-8"></script>
<%@include file="/views/copyResult.jsp" %>
<script>
    //用来判断是删除 还是增加按钮 以便count值进行计算
    var countTags = 0;

    function AddInputTags() {
        if (countTags > 0) {
            return false;
        }
        countTags++;
        var fatherDivTags = document.getElementById("fatherDivTags");

        //创建input
        var input = document.createElement("input");
        input.type = "text";
        input.setAttribute('class', 'layui-input');
        input.name = "size" + countTags;
        input.placeholder = "格式:长*宽";
        input.autocomplete = "off";
        input.setAttribute('class', 'layui-input size2');
        fatherDivTags.appendChild(input);
    }

    function CutInputTags() {
        countTags = 0;
        $(".size2").remove();
    }

    layui.use(['table', 'form'], function () {
        var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
        var table = layui.table;

        form.on('checkbox(switch)', function (data) {
            // 压痕压点线只能选一个
            var tangLen = $(".tang:checked").length;
            if (tangLen > 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;
            }
        })

        // 默认禁用600克
        $("#tag").find(":input").attr("disabled", true);
        form.on('radio(kindValue)', function (kindValueData) {
            if (kindValueData.value == '3') {
                $(".switchCount").show();
                $(".count").show();
                $(".diyCount").hide();
                $(".count").find(":input").attr("disabled", false);
                $(".diyCount").find(":input").attr("disabled", true);
                $("#selectCount").attr("disabled", false);

                $(".tagOther").show();
                $(".tagOther").find(":input").attr("disabled", false);
                $("#tag").hide();
                $("#tag").find(":input").attr("disabled", true);

                form.render();
            } else {
                $('input[class = Count]').prop('checked', false);
                $(".switchCount").hide();
                $(".diyCount").show();
                $(".count").hide();
                $(".diyCount").find(":input").attr("disabled", false);
                $(".count").find(":input").attr("disabled", true);
                $("#selectCount").attr("disabled", true);

                $(".tagOther").hide();
                $(".tagOther").find(":input").attr("disabled", true);
                $("#tag").show();
                $("#tag").find(":input").attr("disabled", false);

                $(".craftSheng").hide();
                form.render();
            }
        })

        $("#mqCount").attr("disabled", true);
        var craftQie;
        form.on('radio(craftQie)', function (data) {
            // 选中工艺标识
            craftQie = data.value;
            // 自定义数量没选中
            if (data.value == "直角打孔") {
                if (!choose) {
                    $(".mqCount").hide();
                    $(".count").show();
                    $("#mqCount").attr("disabled", true);
                    $("#zjCount").attr("disabled", false);
                }
            } else {
                if (!choose) {
                    $(".count").hide();
                    $(".mqCount").show();
                    $("#zjCount").attr("disabled", true);
                    $("#mqCount").attr("disabled", false);
                }
            }

            form.render();
        })

        // 自定义数量是否选中标识
        var choose;
        // 自定义少数量
        form.on('checkbox(switchCount)', function (data) {
            if (data.elem.checked) {
                choose = true;
                $(".diyCount").show();
                $(".count").hide();
                $(".mqCount").hide();
                $(".diyCount").find(":input").attr("disabled", false);
                $("#mqCount").attr("disabled", true);
                $("#zjCount").attr("disabled", true);
            } else {
                choose = false;
                if (craftQie == "直角打孔") {
                    $(".count").show();
                    $("#zjCount").attr("disabled", false);
                } else {
                    $(".mqCount").show();
                    $("#mqCount").attr("disabled", false);
                }
                $(".diyCount").hide();
                $(".diyCount").find(":input").attr("disabled", 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 wangwang = $("#wangwang").val();
            if(wangwang == ""){
                layer.msg("请填写客户旺旺号！",{offset:['300px','300px']},function(){});
                return false;
            } */
            // 选中‘自定义数量’
            if ($('input[name="switchCount"]:checked').length != 0) {
                if ($("#count").val() < 10000 || $("#count").val() % 1000 != 0) {
                    layer.msg("自定义数量需要大于10000 且是1000的整数倍", {offset: ['300px', '300px']}, function () {
                    });
                    return false;
                }
            }
            var kindValue = $('input[name="kindValue"]:checked').val();
            var craftQie = $('input[name="craftQie"]:checked').val();
            var craftMo = $('input[name="craftMo"]:checked').val();
            var craftTang = $('input[name="craftTang"]:checked').val();
            var size = $("#size").val();
            var arr = [];
            arr.push(craftMo);
            if (craftTang) {
                arr.push(craftTang);
            }
            if ((kindValue == 3 || kindValue == 0)) {
                if (craftQie == "异形模切") {
                    if ((size.split("*")[0] > 21 || size.split("*")[1] > 21)) {
                        layer.msg("【吊牌300克】尺寸不能超过21*21 cm", {offset: ['300px', '300px']}, function () {
                        });
                        return false;
                    }
                    $("#proTypeValue").val("吊牌");
                    $("input[name='kindValue']:checked").val(3);
                    if ((size.split("*")[0] <= 9 && size.split("*")[1] <= 5.4) || (size.split("*")[0] <= 5.4 && size.split("*")[1] <= 9)) {
                        if (craftTang) {
                            if (craftTang == "单面烫金") {
                                $("#proTypeValue").val(3);
                            }
                        } else {
                            if ((size.split("*")[0] < 3 || size.split("*")[1] < 3)) {
                                $("#proTypeValue").val(3);
                                $("input[name='kindValue']:checked").val(0);
                            }
                        }
                        form.render();
                    }
                } else if (craftQie == "直角打孔") {
                    $("#proTypeValue").val("吊牌");
                    $("input[name='kindValue']:checked").val(3);
                }
            }
            var number = $("#number").val();
            kindValueData = {
                0: "300克铜版纸",
                3: "300克铜版纸",
                4: "600克铜版纸"
            };
            $("input[name='craft']:checked").each(function () {
                if (!$(this).is("disabled")) {
                    if ($(this).val() == "抠图") {
                        arr.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 craftList = "";
                    if ($('input[name="kindValue"]:checked').val() == "4") {
                        craftQie = ""
                        var size1 = $(".size1").val();
                        size = $("#diySize").val();
                        if (size1) {
                            size = size + '厘米，' + size1
                        }
                        if ((size.split("*")[0] < 3 || size.split("*")[1] < 3)) {
                            layer.msg("[ 吊牌600克 ] 尺寸小于 3cm 请单独报价", {offset: ['300px', '300px']}, function () {
                            });
                            return false;
                        }
                        number = $("#numberTag").val();
                        arr = []
                        arr = $('input[name="kind2Value"]:checked').val();
                    } else if ($('input[name="kindValue"]:checked').val() == "3") { //  && craftQie == "异形模切"
                        var size2 = $(".size2").val();
                        size = $("#size").val();
                        if (size2) {
                            size = size + '厘米，' + size2
                        }
                    }
                    var span_result = '吊牌 - ' + kindValueData[kindValue] + ' - ' + size + '厘米\n' + "工艺： " + craftQie + ', ' + arr + "\n";
                    craftList += craftQie;
                    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 += '配送吊绳\n包邮，免费设计呢~（偏远地区需补邮费）'
                    if (window.parent.system_isGai) {
                        span_result += "\n\n亲 现在下单可以参加淘宝活动8.5折折扣哦!"
                    }
                    addLog(span_result);
                    $("#span_result").val(span_result);

                    var count = "";
                    if ($("input[name='switchCount']:checked").val() == undefined) {
                        count = $("#zjCount option:selected").val();
                    } else {
                        count = $("#count").val();
                    }
                    craftList += arr;
                    if ($("input[name='size1']").css("display") == "block") {
                        size = size.replace("厘米，");
                    }
                    getRemark($("#proTypeValue").val(), size, count + "个", kindValueData[kindValue], number, craftList, "");
                    //计算完自动复制文本
                    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>