<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('商品分类列表')"/>
    <th:block th:include="include :: bootstrap-fileinput-css" />
    <style>
        .layui-layer-btn0, .layui-layer-btn1 {
            font-size: 12px;
            font-weight: normal;
            margin: 0 3px;
            margin-right: 7px;
            margin-left: 7px;
            padding: 0 15px;
            color: #fff;
            border: 1px solid #0064b6;
            background: #0071ce;
            border-radius: 3px;
            display: inline-block;
            height: 30px;
            line-height: 30px;
            text-align: center;
            vertical-align: middle;
            background-repeat: no-repeat;
            text-decoration: none;
            outline: none;
            -moz-box-sizing: content-box;
            -webkit-box-sizing: content-box;
            box-sizing: content-box;
        }
        .layui-layer-btn1 {
            color: #404a58;
            border: 1px solid #c0c4cd;
            background: #fff;
            border-radius: 3px;
            margin-left: 0;
        }
        .layui-layer-btn0:hover {
            color: #fff;
        }
        #addClassify {
            display: none;
            width: 540px;
            padding-top: 20px;
        }
        #addClassify .selectClassify {
            display: flex;
            align-items: center;
            padding: 0 20px;
        }
        #addClassify .selectClassify label {
            display: flex;
            margin-right: 20px;
            align-items: center;
        }
        #addClassify .selectClassify label input {
            margin: 0;
            margin-right: 2px;
        }
        .shadeCss,.layui-layer-shade {
            background-color: rgb(0, 0, 0, 0.5) !important;
        }
        .selectClassifyOne {
            display: flex;
            align-items: center;
            margin-top: 12px;
            padding: 0 20px;
        }
        .selectClassifyOne span {
            width: 90px;
        }
        .bottomBtn {
            margin-top: 20px;
            text-align: right;
            padding: 10px 15px 12px;
            background: #f0f4f7;
            border-top: 1px #c7c7c7 solid;
        }
        .kv-hidden {
            display: none !important;
        }
    </style>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="role-form">
                <div class="select-list">
                    <ul>
                        <li>
                            名称：<input type="text" name="tagName"/>
                        </li>
                        <li>
                            类型：<select name="tagType" th:with="type=${@dict.getType('zhengzai_store_cert_type')}">
                            <option value="">全部</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" id="button-open-10" shiro:hasPermission="goblin:extag:add">
                <i class="fa fa-plus"></i> 新增
            </a>
<!--            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="goblin:extag:rmv">-->
<!--                <i class="fa fa-remove"></i> 删除-->
<!--            </a>-->
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
        <div id="addClassify">
            
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-fileinput-js" />
<script th:inline="javascript">
    var rmvFlg = [[${@permission.hasPermi('goblin:category:rmv')}]];
    var prefix = ctx + "goblin/category";
    let rowId = '';
    let modalDom = `<div class="selectClassify">
                <span>分类选择：</span>
                <label>
                    <input type="radio" checked value="1" id="optionsRadios1" name="optionsRadios"><span>一级</span></label>
                <label>
                    <input type="radio" value="2" id="optionsRadios1" name="optionsRadios"><span>二级</span></label>
                <label>
                    <input type="radio" value="3" id="optionsRadios1" name="optionsRadios"><span>三级</span></label>
            </div>
            <input type="hidden" id="typeValue" value="1">
            <div class="selectClassifyOne">
                <span>一级分类：</span>
                <input class="form-control" id="firstTypeIpt" type="text">
                <select class="form-control" name="tagType" id="firstTypeSelect" style="display: none;">
                    <option value="">全部</option>
                </select>
            </div>
            <div class="selectClassifyOne selectClassifyOne2" style="display: none;">
                <span>二级分类：</span>
                <input class="form-control" id="secondTypeIpt" type="text">
                <select class="form-control" name="tagType" id="secondTypeSelect">
                    <option value="">全部</option>
                </select>
            </div>
            <div class="selectClassifyOne selectClassifyOne3" style="display: none;">
                <span>三级分类：</span>
                <input class="form-control" id="threeIpt" type="text">
            </div>
            <div class="gitPic">
                <img id="viewImg" src="" alt="" style="max-height:150px;margin-top: 12px;margin-left: 12px;">
                <div class="ibox-content" style="border: none;padding-bottom: 0;">
                    <div class="form-group">
                        <div class="file-loading">
                            <input id="fileinput" type="file" name="file" data-browse-on-zone-click="true" data-theme="fas">
                        </div>
                    </div>
                </div>
            </div>
            <div class="bottomBtn">
                <a src="javascript:;" class="layui-layer-btn0 paddings" onclick="yes(1,2)">确定</a>
                <a class="layui-layer-btn1 layui-layer-btn1" onclick="closeModal()">取消</a>
            </div>`
    $(function () {
        $("#fileinput").fileinput({
            'theme': 'explorer-fas',
            'uploadUrl': 'https://devplatform.zhengzai.tv/platform/basicServices/alOss/upload',
            "uploadExtraData": {
                "pathName" : "banner",
                "buckType" : 1
            },
            autoReplace: true,
            showCaption: false,
            showPreview: false,
            showRemove: false,
            showUpload: false,
            showCancel: false,
            showClose: false,
            autoReplace: true,
            dropZoneTitle: "请上传文件",
            maxFileCount: 1
        }).on("filebatchselected", function (event, files) {         //默认上传
            $(this).fileinput("upload");
        })
        .on("fileuploaded", function (event, data) {       //上传回调事件
            showPicture = 'https://img.zhengzai.tv/' + data.response.data.ossPath;
            $("#viewImg").attr('src', showPicture)
        })
        var options = {
            url: prefix + "/list",
            removeUrl: prefix + "/rmv/{id}",
            sortName: "mid",
            modalName: "商品分类",
            // onCheck: onCheck,
            columns: [{
                radio: true
            },
                {
                    field: 'fname',
                    title: '一级分类'
                },
                {
                    field: 'sname',
                    title: '二级分类'
                },
                {
                    field: 'tname',
                    title: '二级分类'
                },
                {
                    field: 'fcounts',
                    title: '关联商品数量'
                }]
        };
        $.table.init(options);
    });
    $("#button-open-10").click(function(){
        $('#addClassify').append(modalDom)
        $("#fileinput").fileinput({
            'theme': 'explorer-fas',
            'uploadUrl': 'https://devplatform.zhengzai.tv/platform/basicServices/alOss/upload',
            "uploadExtraData": {
                "pathName" : "banner",
                "buckType" : 1
            },
            autoReplace: true,
            showCaption: false,
            showPreview: false,
            showRemove: false,
            showUpload: false,
            showCancel: false,
            showClose: false,
            autoReplace: true,
            dropZoneTitle: "请上传文件",
            maxFileCount: 1
        }).on("filebatchselected", function (event, files) {         //默认上传
            $(this).fileinput("upload");
        })
        .on("fileuploaded", function (event, data) {       //上传回调事件
            showPicture = 'https://img.zhengzai.tv/' + data.response.data.ossPath;
            $("#viewImg").attr('src', showPicture)
        })
        $("input[name=optionsRadios]").on('change', function (e) {
            console.log(e.target.value)
            let num = e.target.value;
            $("#typeValue").val(num);
            if (num == 1) {
                $(".selectClassifyOne2").hide();
                $(".selectClassifyOne3").hide();
                $(".selectClassifyOne").show();
                $("#firstTypeSelect").hide();
                $("#firstTypeIpt").show();
            } else if (num == 2) {
                $(".selectClassifyOne2").show();
                $("#secondTypeSelect").hide();
                $("#secondTypeIpt").show();
                $(".selectClassifyOne").show();
                $("#firstTypeSelect").show();
                $("#firstTypeIpt").hide();
                $(".selectClassifyOne3").hide();
                filterSelect ('', 2)
            } else {
                $(".selectClassifyOne").show();
                $("#firstTypeSelect").show();
                $("#firstTypeIpt").hide();
                $(".selectClassifyOne2").show();
                $("#secondTypeSelect").show();
                $("#secondTypeIpt").hide();
                $(".selectClassifyOne3").show();
                filterSelect ('', 2)
            }
        })
        $("#firstTypeSelect").on('change', function (e) {
            console.log(e)
            filterSelect (e.target.value, 3)
        })
        layer.open({
            type: 1,
            shade: true,
            title: '创建分类', //不显示标题
            content: $('#addClassify'), //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
            cancel: function(res){
                console.log(res, '111')
                $("#addClassify").empty()
                // layer.msg('捕获就是从页面已经存在的元素上，包裹layer的结构', {time: 5000, icon:6});
            }
        });
    })
    
    // function onCheck (row, $element) {
    //     console.log(row, $element)
    //     rowId = row.fcateId;
    // }
    function yes() {
        let name = ''
        let type = $("#typeValue").val();
        let catePid = '';
        if (type == 1) {
            name = $("#firstTypeIpt").val();
        } else if (type == 2) {
            name = $("#secondTypeIpt").val();
            catePid = $("#firstTypeSelect").val();
        } else {
            name = $("#threeIpt").val();
            catePid = $("#secondTypeSelect").val();
        }
        let data = {
            catePid,
            grade: type,
            icon: $("#viewImg").attr('src'),
            name,
            neIsbn: 0
        }
        $.ajax({
            type: 'post',
            url: '/goblin/category/addSave',
            data,
            success: function (res) {
                console.log(res, 'res')
                $("pull-right button[type=refresh]").click();
                closeModal ();
            }
        })
        
    }
    function closeModal () {
        $("#addClassify").empty()
        // $("#firstTypeIpt").val('');
        // $("#secondTypeIpt").val('');
        // $("#threeIpt").val('');
        // $("#threeIpt").attr('src', '');
        // $("#firstTypeSelect").empty().append('<option value="">全部</option>')
        // $("#secondTypeSelect").empty().append('<option value="">全部</option>')
        // $("input[name=optionsRadios value=1]").attr('checked')
        $(".layui-layer-close1").click();
    }
    
    // $("input[name=optionsRadios]").on('change', function (e) {
        
    // })
    function filterSelect (parentsId, num) {
        console.log('这个没触发')
        let data = {
            cateId: parentsId,
            grade: num - 1
        }
        $.ajax({
            type: 'post',
            url: '/goblin/category/filter',
            data,
            success: function(res) {
                console.log(res, 'res')
                const { data } = res;
                let str = '';
                data.forEach(item => {
                    console.log(item)
                    str += `<option value="${item.cateId}">${item.name}</option>`
                })
                if (!parentsId) {
                    $("#firstTypeSelect").empty().append('<option value="">全部</option>');
                    $("#firstTypeSelect").append(str);
                } else {
                    $("#secondTypeSelect").empty().append('<option value="">全部</option>');
                    $("#secondTypeSelect").append(str);
                }
            }
        })
    }
    function del(id, status, notice) {
        $.modal.confirm(notice, function() {
            $.ajax({
                type: 'put',
                url: '/stone/item/change/status',
                data: {
                    itemId: id,
                    status
                },
                success:function(e) {
                    layer.msg("操作成功！")
                    $("button[name=refresh]").click()
                }
            })
        });
    }
</script>
</body>
</html>