<%@ 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" id="kindForm">
            <input type="hidden" name="proTypeValue" id="proTypeValue" class="layui-input" value="19">
            <div class="layui-form-item">
                <input type="radio" lay-filter="kind" name="kind" value="常用种类" title="常规" checked="checked">
                <input type="radio" lay-filter="kind" name="kind" value="少数量" title="少数量（自来稿件）">
            </div>
            <div class="normal">
                <p>
                    封面
                </p>
                <div class="layui-form-item">
                    <input type="radio" name="kindValue" class="kindValue" value="0" title="250克哑膜" checked="checked">
                </div>
                <p>
                    内页
                </p>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <input type="radio" name="kind2Value" class="kind2Value" value="0" title="157克合板" checked="checked">
                        <input type="radio" name="kind2Value" class="kind2Value" value="1" title="160克合板">
                        <input type="radio" name="kind2Value" class="kind2Value" value="2" title="200克合板">
                    </div>
                </div>
                <p>
                    装订
                </p>
                <div class="layui-form-item">
                    <input type="radio" name="kind3Value" class="kind3Value" value="0" title="骑马钉" checked="checked">
                    <!-- <input type="radio" name="kind3Value" class="kind3Value" value="1" title="胶装">  -->
                </div>
                <p>
                    尺寸(CM/厘米) <span style="font-size:14px;color:red">输入格式: 长 * 宽</span>
                    <input type="checkbox" name="craft" class="craft" value="设计" title="含设计">
                </p>
                <div class="layui-form-item">
                    <input type="text" placeholder="格式:长*宽" name="size" id="size" class="layui-input" autocomplete="off">
                </div>
                <p>
                    封面P数 <span style="font-size:14px;color:green">（固定P数）</span>
                </p>
                <div class="layui-form-item">
                    <input type="text" value="4" readonly class="layui-input">
                </div>
                <p>
                    内页P数 <span style="font-size:14px;color:red">请输入4的整数倍</span>
                </p>
                <div class="layui-form-item">
                    <input type="text" placeholder="请输入4的整数倍" autocomplete="off" name="pcount" id="pcount" class="layui-input">
                </div>
                <p>
                    数量(本)
                </p>
                <div class="layui-form-item">
                    <input type="text" placeholder="请输入整数" autocomplete="off" name="count" class="layui-input">
                </div>
            </div>
            <div class="less" style="display:none">
                <p>
                    封面
                </p>
                <div class="layui-form-item">
                    <input type="radio" name="kindValue" value="1" title="250克铜版纸">
                    <%--						<input type="radio" name="kindValue" value="2" title="皮纹纸">--%>
                </div>
                <p>
                    内页
                </p>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <input type="radio" name="kind2Value2" value="3" title="157克铜版纸" checked>
                        <input type="radio" name="kind2Value2" value="4" title="70克双胶纸">
                    </div>
                </div>
                <p>
                    装订
                </p>
                <div class="layui-form-item">
                    <input type="radio" name="kind3Value3" value="0" title="骑马钉" checked>
                    <input type="radio" name="kind3Value3" value="1" title="胶装">
                </div>
                <p>
                    印色
                </p>
                <div class="layui-form-item">
                    <input type="radio" name="craftShua" value="0" title="彩色" checked>
                    <input type="radio" name="craftShua" value="1" title="单色">
                </div>
                <p>
                    尺寸(CM/厘米)
                    <!-- <span class="switchSize">
                        <input type="checkbox" name="switchSize" class="Size" lay-filter="switchSize" title="自定义尺寸">
                    </span>
                    <span style="font-size:14px;color:red">输入格式: 长 * 宽</span>
                    <div class="diySize" style="display:none">
                        <input type="text" name="size" placeholder="格式:长*宽" class="layui-input" autocomplete="off">
                    </div>-->
                </p>
                <div class="size">
                    <select name="size" id="sizeLess" class="select">
                        <option value="28.5*21">28.5 * 21 cm</option>
                    </select>
                </div>
                <p>
                    封面P数 <span style="font-size:14px;color:green">（固定P数）</span>
                </p>
                <div class="layui-form-item">
                    <input type="text" value="4" readonly class="layui-input">
                </div>
                <p>
                    内页P数 <span style="font-size:14px;color:red"></span>
                </p>
                <div class="layui-form-item">
                    <input type="text" placeholder="请输入内页P数" autocomplete="off" name="pcount" id="lessPcount" class="layui-input">
                </div>
                <p>
                    数量(本)
                </p>
                <div class="layui-form-item">
                    <input type="text" placeholder="请输入整数" autocomplete="off" name="count" class="layui-input" id="count1">
                </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>
            <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>
    layui.use(['table', 'form'], function () {
        var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
        var table = layui.table;


        //输入框的值改变时触发
        $("#lessPcount").on("input", function (e) {
            //获取input输入的值
            if (e.delegateTarget.value > 36 && $('input[name="kind3Value3"]:checked').val() != "1") {
                layer.msg('内页超过36P装订方式请选择【胶装】!', {offset: ['300px', '300px']}, function () {
                });
            }
        });

        var kind;
        // 没选按钮时候默认禁用少数量（防止提交表单）
        $(".less").find(":input").attr("disabled", true);
        form.on('radio(kind)', function (kindData) {
            kind = kindData.value;
            if (kindData.value == "常用种类") {
                // 切换按钮的时候,重置kind品种
                $("#kindForm")[0].reset();
                // 切换为品种单选框
                $(".normal").show();
                $(".normal").find(":input").attr("disabled", false);
                $(".less").hide();
                $(".less").find(":input").attr("disabled", true);
            } else {
                // 少数量、专版打印的时候，切换为品种下拉框
                $(".less").show();
                $(".less").find(":input").attr("disabled", false);
                $(".normal").hide();
                $(".normal").find(":input").attr("disabled", true);
                $('input[class = craft]').prop('checked', false);
            }
            form.render();//必须写
        })

        // 自定义少数量
        /* form.on('checkbox(switchSize)', function(data) {
            if (data.elem.checked) {
                $(".diySize").show();
                $(".size").hide();
                $(".diySize").find(":input").attr("disabled", false);
                $(".size").find(":input").attr("disabled", true);
            }else{
                $(".size").show();
                $(".diySize").hide();
                $(".size").find(":input").attr("disabled", false);
                $(".diySize").find(":input").attr("disabled", true);
                // 恢复标准的时候会被禁用，加这个解决
                form.render();
            }
        }) */

        // 点击计算，计算价格
        form.on('submit(acount_btn)', function (data) {
            var kindValue = $('input[name="kindValue"]:checked').val();
            var kind2Value = $('input[name="kind2Value"]:checked').val();
            var kind3Value = $('input[name="kind3Value"]:checked').val();
            var kindData = {
                0: "250克哑膜",
                1: "250克铜版纸",
                2: "皮纹纸"
            }, kind2Data = {
                0: "157克合板",
                1: "160克合板",
                2: "200克合板",
                3: "157克铜版纸",
                4: "70克双胶纸"
            }, kind3Data = {
                0: "骑马钉",
                1: "胶装"
            }, caratShuaData = {
                0: "彩色",
                1: "单色"
            };
            var size = $("#size").val();
            var pcount = $("#pcount").val();
            var number = $("#number").val();
            if (kind == "少数量") {
                var pcount = $("#lessPcount").val();
                var size = $("#sizeLess option:checked").val();
                var kind2Value = $('input[name="kind2Value2"]:checked').val();
                var kind3Value = $('input[name="kind3Value3"]:checked').val();
                var craftShua = $('input[name="craftShua"]:checked').val();
                //获取input输入的值
                if (pcount > 36 && $('input[name="kind3Value3"]:checked').val() != "1") {
                    layer.msg('内页超过36P装订方式请选择【胶装】!', {offset: ['300px', '300px']}, function () {
                    });
                    return false;
                }
                if (kindValue == 0) {
                    layer.msg('请选择封面!', {offset: ['300px', '300px']}, function () {
                    });
                    return false;
                }

            }

            if ($('input[name="kind"]:checked').val() == "常用种类") {
                if (!size) {
                    layer.msg('请填写尺寸！', {offset: ['300px', '300px']}, function () {
                    });
                    return false;
                }
                if ((size.split("*")[0] > 21 || size.split("*")[1] > 28.5) && (size.split("*")[0] > 28.5 || size.split("*")[1] > 21)) {
                    layer.msg("尺寸超过 28.5*21 cm 请单独报价", {offset: ['300px', '300px']}, function () {
                    });
                    return false;
                }
            }
            if (kind != "少数量") {
                if (pcount % 4 != 0) {
                    layer.msg('内页P数需为 4 的整数倍！', {offset: ['300px', '300px']}, function () {
                    });
                    return false;
                }
                // 200克合板只有36P价格（含封面4P）
                if (kind2Value == 2) {
                    if (pcount > 32) {
                        layer.msg('200克合板内页P数大于 32P 请单独报价！', {offset: ['300px', '300px']}, function () {
                        });
                        return false;
                    }
                } else {
                    if (pcount > 48) {
                        layer.msg('157、160克内页P数大于 48P 请单独报价！', {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 kind = kindData[kindValue];
                    var kind2 = kind2Data[kind2Value];
                    var kind3 = kind3Data[kind3Value];
                    var craft = caratShuaData[craftShua];
                    let arr = []
                    $("input[name='craft']:checked").each(function () {
                        if (!$(this).is("disabled")) {
                            if ($(this).val() == "抠图") {
                                arr.push($(this).val() + $("input[name='cropNumber']").val());
                                return;
                            }
                        }
                    })
                    if ($('input[name="kind"]:checked').val() == "少数量") {
                        var span_result = '画册（自来稿件） - 封面:' + kind + ' - 内页:' + kind2 + ' - ' + kind3 + ' - ' + [craft] + ' - ' + size + ' CM -(同款内容)\n' + "封面P数 :4\n" + "内页P数 :" + pcount + '\n';
                    } else {
                        var span_result = '画册 - 封面:' + kind + ' - 内页:' + kind2 + ' - ' + kind3 + ' - ' + size + ' CM -(同款内容)\n' + "封面P数 :4\n" + "内页P数 :" + pcount + '\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 ($("input[name='craft']:checked").val() == "设计") {
                        span_result += "，（包含设计费）";
                    }
                    if (window.parent.system_isGai) {
                        span_result += "\n\n亲 现在下单可以参加淘宝活动8.5折折扣哦!"
                    }
                    addLog(span_result);
                    $("#span_result").val(span_result);

                    var count = "";
                    if ($(".less").css("display") == "none") {
                        count = $("input[name='count']").val();
                    } else {
                        count = $("#count1").val();
                    }
                    var medol = $("input[name='kind2Value']:checked").attr("title");
                    medol = medol.replace("合版", "");
                    kind = "250克铜版纸-" + pcount + "P封面覆哑膜" + medol + "内页骑马钉";
                    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>