<%@ 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>
    .p {
        color: green;
        font-weight: 400;
    }
</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="18">
            <p>
                款式
            </p>
            <%--            <input type="radio" name="kindValue" lay-filter="kindValue" value="0" title="短铆钉">--%>
            <input type="radio" name="kindValue" lay-filter="kindValue" value="1" title="长铆钉" checked="checked">
            <input type="radio" name="kindValue" lay-filter="kindValue" value="2" title="普通中柄（卡扣）">
            <input type="radio" name="kindValue" lay-filter="kindValue" value="3" title="筷子柄">
            <input type="radio" name="kindValue" lay-filter="kindValue" value="4" title="团扇">
            <input type="radio" name="kindValue" lay-filter="kindValue" value="5" title="o柄">
            <input type="radio" name="kindValue" lay-filter="kindValue" value="6" title="竹柄扇">
            <p>
                规格
            </p>
            <div class="layui-form-item kind1">
                <select name="kind2Value" id="kind2Value" lay-filter="kind2Value" class="select">
                    <option value="0">15*16</option>
                    <option value="1">16*17</option>
                    <option value="2">17*18</option>
                    <option value="3">17*19</option>
                    <option value="4">18*19</option>
                    <option value="5">19*20</option>
                    <option value="6">19*21</option>
                </select>
            </div>
            <div class="layui-form-item kind2" style="display:none">
                <select name="kind2Value" id="kind3Value" lay-filter="kind2Value" class="select">
                    <option value="0">15*15</option>
                    <option value="1">16*16</option>
                    <option value="2">17*17</option>
                    <option value="3">18*18</option>
                    <option value="4">19*19</option>
                    <option value="5">20*20</option>
                </select>
            </div>
            <div class="layui-form-item kind3" style="display:none">
                <select name="kind2Value" id="kind4Value" lay-filter="kind2Value" class="select">
                    <option value="0">20*28</option>
                    <option value="1">24*33</option>
                    <option value="2">22*34</option>
                </select>
            </div>
            <div class="layui-form-item kind4" style="display:none">
                <select name="kind2Value" id="kind5Value" lay-filter="kind2Value" class="select">
                    <option value="0">花瓶竹柄扇(190*207)</option>
                    <option value="1">四瓣竹柄扇(204*204)</option>
                    <option value="2">皇冠竹柄扇(183*207)</option>
                    <option value="3">芭蕉竹柄扇(280*212)</option>
                    <option value="4">正圆竹柄扇(205*205)</option>
                    <option value="5">千叶竹柄扇(171*222)</option>
                    <option value="6">海棠竹柄扇(207*203)</option>
                    <option value="7">苹果竹柄扇(204*204)</option>
                    <option value="8">宝相花竹柄扇(212*212)</option>
                    <option value="9">蝴蝶竹柄扇(212*167)</option>
                </select>
            </div>
            <p>
                数量(个)
            </p>
            <div class="layui-form-item" id="normal">
                <select name="count" id="count" lay-filter="count" 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 id="tsCount" style="display: none;">
                <select name="count1" id="count1" lay-filter="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>
                </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="normalCraft">
                <input type="checkbox" name="craft" id="mq" lay-filter="switch" value="异形" title="异形" checked/>
            </div>
            <div class="tsCraft" style="display: none;">
                <input type="checkbox" name="craft" lay-filter="switch" value="双面一样" title="双面一样"></div>
            <hr>
            <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>
            <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>
<script src="../../js/carousel.js" charset="utf-8"></script>
<%@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({});

        // form.on('checkbox(switch)', function (data) {
        //     if (!data.elem.checked && data.value == "异形") {
        //         layer.msg('不能取消 [异形] 工艺！', {offset: ['300px', '300px']}, function () {
        //         });
        //         $('#mq').prop('checked', true);
        //         form.render('checkbox');
        //         return false;
        //     }
        // })
        $(".kind2").find(":input").attr("disabled", true);
        $(".kind3").find(":input").attr("disabled", true);
        $(".kind4").find(":input").attr("disabled", true);
        // 没切换款式的时候默认禁用其它的下拉框,（防止提交表单）
        $(".kind2").find(":input").attr("disabled", true);
        form.on('radio(kindValue)', function (data) {
            $(".kind2").hide();
            $(".kind2").find(":input").attr("disabled", true);
            $(".kind1").hide();
            $(".kind1").find(":input").attr("disabled", true);
            $(".kind3").hide();
            $(".kind3").find(":input").attr("disabled", true);
            $(".kind4").hide();
            $(".kind4").find(":input").attr("disabled", true);
            $("#tsCount").hide();
            $("#normal").hide();
            $(".tsCraft").hide();
            $(".tsCraft").find(":input").attr("disabled", true);
            $(".normalCraft").hide();
            $(".normalCraft").find(":input").attr("disabled", true);
            let countHtml = ` <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>`;
            if (data.value == '3') {
                $(".kind2").show();
                $(".kind2").find(":input").attr("disabled", false);
                $("#normal").show();
                $(".normalCraft").show();
                $(".normalCraft").find(":input").attr("disabled", false);
            } else if (data.value == '4') {
                $("#tsCount").show();
                $(".kind3").show();
                $(".kind3").find(":input").attr("disabled", false);

            } else if (data.value == '6') {
                $(".kind4").show();
                $(".kind4").find(":input").attr("disabled", false);
                $("#normal").show();
                $(".normalCraft").show();
                $(".normalCraft").find(":input").attr("disabled", false);
                countHtml = `<option value="10">10</option>
                    <option value="100">100</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="6000">6000</option>
                    <option value="7000">7000</option>
                    <option value="8000">8000</option>
                    <option value="9000">9000</option>
                    <option value="10000">10000</option>`
            } else {
                $(".kind1").show();
                $(".kind1").find(":input").attr("disabled", false);
                $("#normal").show();
                $(".normalCraft").show();
                $(".normalCraft").find(":input").attr("disabled", false);
            }
            $("#count").empty().append(countHtml);
            form.render();
            getProductImage()
        });

        function getProductImage() {

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

            $("#carousel").empty();
            let data = {proTypeValue: "18", kindValue}
            let remark = "";
            let html = "";
            $.ajax({
                url: "${pageContext.request.contextPath}/getImgs",
                type: "GET",
                data,
                //dataType : "json",
                success: function (result) {
                    for (let i = 0; i < result.length; i++) {
                        // 只留一个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").empty().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('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 fanKind = $('input[name="kindValue"]:checked').val();
            var kindData = {
                0: "短铆钉",
                1: "长铆钉",
                2: "普通中柄（卡扣）",
                3: "筷子柄",
                4: "团扇",
                5: "o柄",
                6: "竹柄扇"
            };
            if (fanKind == 3) {
                var kind2Data = {
                    0: "15*15",
                    1: "16*16",
                    2: "17*17",
                    3: "18*18",
                    4: "19*19",
                    5: "20*20"
                };
            } else if (fanKind == 4) {
                var kind2Data = {
                    0: "20*28",
                    1: "24*33",
                    2: "21.5*34"
                }
            } else if (fanKind == 6) {
                var kind2Data = {
                    0: "花瓶竹柄扇(190*207)",
                    1: "四瓣竹柄扇(204*204)",
                    2: "皇冠竹柄扇(183*207)",
                    3: "芭蕉竹柄扇(280*212)",
                    4: "正圆竹柄扇(205*205)",
                    5: "千叶竹柄扇(171*222)",
                    6: "海棠竹柄扇(207*203)",
                    7: "苹果竹柄扇(204*204)",
                    8: "宝相花竹柄扇(212*212)",
                    9: "蝴蝶竹柄扇(212*167)"
                }
            } else {
                var kind2Data = {
                    0: "15*16",
                    1: "16*17",
                    2: "17*18",
                    3: "17*19",
                    4: "18*19",
                    5: "19*20",
                    6: "19*21"
                };
            }

            var kind = kindData[$('input[name="kindValue"]:checked').val()];
            var kind2 = "";
            if (fanKind == 3) {
                kind2 = kind2Data[$("#kind3Value option:selected").val()];
            } else if (fanKind == 4) {
                kind2 = kind2Data[$("#kind4Value option:selected").val()];
            } else {
                kind2 = kind2Data[$("#kind2Value option:selected").val()];
            }
            var count = "";
            if ($('input[name="kindValue"]:checked').val() == 4) {
                count = $("#count1 option:selected").val();
            } else {
                count = $("#count option:selected").val();
            }
            var number = $("#number").val();
            var craft = [$('input[name="craft"]:checked').val()];
            $.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;
                    if (kind2 == "20*28") {
                        kind = "小团扇";
                    } else if (kind2 == "24*33") {
                        kind = "大团扇"
                    } else if (kind2 == "21.5*34") {
                        kind = "芭蕉扇";
                    }
                    let arr = [];
                    $("input[name='craft']:checked").each(function () {
                        if (!$(this).is("disabled")) {
                            if ($(this).val() == "抠图") {
                                arr.push($(this).val() + $("input[name='cropNumber']").val());
                                return;
                            }
                            arr.push($(this).val())
                        }
                    })
                    var span_result = '扇子 - ' + kind + "-" + kind2 + 'cm - ' + '(同款内容)\n';
                    if (arr.length > 0) {
                        span_result += "工艺：" + arr.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);


                    getRemark("扇子", kind2, 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>