<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">

<head>
    <th:block th:include="include :: header('修改商品类目')"/>
    <th:block th:include="include :: select2-css"/>
</head>

<body>

<div class="main-content">
    <form class="form-horizontal" id="form-deptGoodsCategory-edit" th:object="${deptGoodsCategory}">
        <input id="deptGoodsCategoryId" name="deptGoodsCategoryId" type="hidden" th:field="*{deptGoodsCategoryId}"/>
        <input id="type" name="type" type="hidden" th:field="*{type}"/>

        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-6 control-label is-required">类目名称：</label>
                    <div class="col-sm-6">
                        <input name="goodsCategoryName" placeholder="请输入类目名称" class="form-control" type="text" maxlength="30"
                               th:field="*{goodsCategoryName}"
                               disabled>
                    </div>
                </div>
            </div>
            <div class="col-sm-6" th:if="*{type != 1}">
                <div class="form-group">
                    <label class="col-sm-6 control-label">服务类目：</label>
                    <div class="col-sm-6">
                        <div class="input-group">
                            <input class="form-control" type="text" onclick="selectServiceCategoryTree()" id="treeName" readonly="true" th:value="*{serviceCategoryName}">
                            <input type="hidden" id="treeId" name="serviceCategoryId" th:value="*{serviceCategoryId}">
                            <input type="hidden" id="serviceCategoryName" name="serviceCategoryName" th:value="*{serviceCategoryName}">
                            <span class="input-group-addon"><i class="fa fa-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-6 control-label is-required">一级分销扣点比例：</label>
                    <div class="col-sm-6">
                        <input name="oneRate" placeholder="请输入一级分销扣点比例" class="form-control" type="text" maxlength="12"
                               th:field="*{oneRate}"
                               required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-6 control-label is-required">PC一级分销扣点比例：</label>
                    <div class="col-sm-6">
                        <input name="pcOneRate" placeholder="请输入PC一级分销扣点比例" class="form-control" type="text" maxlength="12"
                               th:field="*{pcOneRate}"
                               required>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-6 control-label is-required">二级分销扣点比例：</label>
                    <div class="col-sm-6">
                        <input name="twoRate" placeholder="请输入二级分销扣点比例" class="form-control" type="text"
                               th:field="*{twoRate}"
                               maxlength="12" required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-6 control-label is-required">PC二级分销扣点比例：</label>
                    <div class="col-sm-6">
                        <input name="pcTwoRate" placeholder="请输入PC二级分销扣点比例" class="form-control" type="text"
                               th:field="*{pcTwoRate}"
                               maxlength="12" required>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-6 control-label is-required">三级分销扣点比例：</label>
                    <div class="col-sm-6">
                        <input name="threeRate" placeholder="请输入三级分销扣点比例" class="form-control" type="text" maxlength="12"
                               th:field="*{threeRate}"
                               required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-6 control-label is-required">PC三级分销扣点比例：</label>
                    <div class="col-sm-6">
                        <input name="pcThreeRate" placeholder="PC请输入三级分销扣点比例" class="form-control" type="text" maxlength="12"
                               th:field="*{pcThreeRate}"
                               required>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-6 control-label is-required">平台扣点比例：</label>
                    <div class="col-sm-6">
                        <input name="deptRate" placeholder="请输入平台扣点比例" class="form-control" type="text"
                               th:field="*{deptRate}"
                               maxlength="12" required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-6 control-label is-required">PC平台扣点比例：</label>
                    <div class="col-sm-6">
                        <input name="pcDeptRate" placeholder="请输入PC平台扣点比例" class="form-control" type="text"
                               th:field="*{pcDeptRate}"
                               maxlength="12" required>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-6 control-label is-required">平台固定扣金额：</label>
                    <div class="col-sm-6">
                        <input name="deptMoney" placeholder="请输入平台固定扣金额" class="form-control" type="text" maxlength="12"
                               th:field="*{deptMoney}"
                               required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-6 control-label is-required">PC平台固定扣金额：</label>
                    <div class="col-sm-6">
                        <input name="pcDeptMoney" placeholder="请输入PC平台固定扣金额" class="form-control" type="text" maxlength="12"
                               th:field="*{pcDeptMoney}"
                               required>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-6 control-label is-required">截留扣点：</label>
                    <div class="col-sm-6">
                        <input name="retainRate" placeholder="请输入截留扣点" class="form-control" type="text"
                               th:field="*{retainRate}"
                               maxlength="12" required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-6 control-label is-required">PC截留扣点：</label>
                    <div class="col-sm-6">
                        <input name="pcRetainRate" placeholder="请输入PC截留扣点" class="form-control" type="text"
                               th:field="*{pcRetainRate}"
                               maxlength="12" required>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-6 control-label is-required">截留金额：</label>
                    <div class="col-sm-6">
                        <input name="retainMoney" placeholder="请输入截留金额" class="form-control" type="text" maxlength="12"
                               th:field="*{retainMoney}"
                               required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-6 control-label is-required">PC截留金额：</label>
                    <div class="col-sm-6">
                        <input name="pcRetainMoney" placeholder="请输入PC截留金额" class="form-control" type="text" maxlength="12"
                               th:field="*{pcRetainMoney}"
                               required>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-6 control-label is-required">显示排序：</label>
                    <div class="col-sm-6">
                        <input class="form-control" type="text" name="categorySort" th:field="*{categorySort}" required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-6 control-label">是否热门类目：</label>
                    <div class="col-sm-6">
                        <select name="isHot" class="form-control m-b" th:field="*{isHot}" th:with="type=${@dict.getType('sys_user_sex')}">
                            <option th:text="否" th:value="0"/>
                            <option th:text="是" th:value="1"/>
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-6 control-label">热门名称：</label>
                    <div class="col-sm-6">
                        <input name="hotName" placeholder="请输入热门名称" class="form-control" type="text" maxlength="12"
                               th:field="*{hotName}">
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-6 control-label">简称：</label>
                    <div class="col-sm-6">
                        <input name="simpleGoodsCategoryName" placeholder="请输入简称" class="form-control" type="text"
                               maxlength="12"
                               th:field="*{simpleGoodsCategoryName}">
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-6 control-label">是否需要证书：</label>
                    <div class="col-sm-6">
                        <select name="isCert" class="form-control m-b" th:field="*{isCert}"  th:with="type=${@dict.getType('sys_user_sex')}">
                            <option th:text="否" th:value="0"/>
                            <option th:text="是" th:value="1"/>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-6 control-label">倒计时小时数：</label>
                    <div class="col-sm-6">
                        <input name="countdownHours" placeholder="请输入倒计时小时数" class="form-control" type="number" min="1" max="168"
                               th:field="*{countdownHours}">
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="row">
                <div class="col-sm-12">
                    <div class="form-group">
                        <label class="col-xs-3 control-label">PC保险设定：</label>
                        <div class="col-xs-9">
                            <label th:each="insurance:${pcInsurances}" class="check-box">
                                <input name="pcInsurance" type="checkbox" th:value="${insurance.id}" th:text="${insurance.insuranceName}" th:checked="${insurance.flag}">
                            </label>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="row">
                <div class="col-sm-12">
                    <div class="form-group">
                        <label class="col-xs-3 control-label">商城保险设定：</label>
                        <div class="col-xs-9">
                            <label th:each="insurance:${shopInsurances}" class="check-box">
                                <input name="shopInsurance" type="checkbox" th:value="${insurance.id}" th:text="${insurance.insuranceName}" th:checked="${insurance.flag}">
                            </label>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
            <div class="form-group">
                <label class="col-sm-3 control-label">热门类目图标：</label>
                <div class="col-sm-9">
                    <input type="text" name="cover" value="" hidden>
                    <input type="file" name="coverImg" id="coverImg" multiple class="file"/>
                </div>
            </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
            <div class="form-group">
                <label class="col-sm-3 control-label">热门类目图片：</label>
                <div class="col-sm-9">
                    <input type="text" name="categoryUrl" value="" hidden>
                    <input type="file" name="categoryUrlImg" id="categoryUrlImg" multiple class="file"/>
                </div>
            </div>
            </div>
        </div>
    </form>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<th:block th:include="include :: datetimepicker-js"/>

<script type="text/javascript">
    var prefix = ctx + "goods/deptcategory";

    $("#form-deptGoodsCategory-edit").validate({
        onkeyup: false,
        rules: {},
        messages: {},
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            var data = $("#form-deptGoodsCategory-edit").serializeArray();
            var pcInsuranceIds = $.form.selectCheckeds("pcInsurance");
            var shopInsuranceIds = $.form.selectCheckeds("shopInsurance");
            data.push({"name": "pcInsuranceIds", "value": pcInsuranceIds});
            data.push({"name": "shopInsuranceIds", "value": shopInsuranceIds});
            $.operate.saveTab(prefix + "/edit", data);
            $.modal.close();
        }
    }

    // 商品封面上传
    $('#categoryUrlImg').fileinput({
        language: 'zh',     //设置语言
        dropZoneEnabled: false,      //是否显示拖拽区域
        showPreview: false,
        uploadExtraData: {
            "name": "categoryUrlImg"
        },
        dropZoneTitle: "可以将图片拖放到这里",    //拖拽区域显示文字
        uploadUrl: ctx + 'tool/qiniu/dept/upload',  //上传路径
        allowedFileExtensions: ['jpg', 'png', 'gif', 'jpeg'],   //指定上传文件类型
        maxFileSize: 0,
        maxFileSize: 12048,   //上传文件最大值，单位kb
        uploadAsync: true,  //异步上传
        maxFileCount: 3    //上传文件最大个数。
    }).on("fileuploaded", function (event, data) { //异步上传成功后回调
        if (data.response.code === 0) {
            var imgUrl = $("input[name='categoryUrl']").val();
            if (imgUrl) {
                $("input[name='categoryUrl']").val(imgUrl + "," + data.response.url)
            } else {
                $("input[name='categoryUrl']").val(data.response.url)
            }
        } else {
            alert("上传失败!");
        }
    });

    // 商品封面上传
    $('#coverImg').fileinput({
        language: 'zh',     //设置语言
        dropZoneEnabled: false,      //是否显示拖拽区域
        showPreview: false,
        uploadExtraData: {
            "name": "coverImg"
        },
        dropZoneTitle: "可以将图片拖放到这里",    //拖拽区域显示文字
        uploadUrl: ctx + 'tool/qiniu/dept/upload',  //上传路径
        allowedFileExtensions: ['jpg', 'png', 'gif', 'jpeg'],   //指定上传文件类型
        maxFileSize: 0,
        maxFileSize: 12048,   //上传文件最大值，单位kb
        uploadAsync: true,  //异步上传
        maxFileCount: 1    //上传文件最大个数。
    }).on("fileuploaded", function (event, data) { //异步上传成功后回调
        if (data.response.code === 0) {
            var imgUrl = $("input[name='cover']").val();
            if (imgUrl) {
                $("input[name='cover']").val(imgUrl + "," + data.response.url)
            } else {
                $("input[name='cover']").val(data.response.url)
            }
        } else {
            alert("上传失败!");
        }
    });

    /*选择服务类目树*/
    function selectServiceCategoryTree() {
        var treeId = $("#treeId").val();
        var options = {
            title: '服务类目选择',
            width: "380",
            url: ctx + "goods/category/selectServiceCategoryTree",
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var body = $.modal.getChildFrame(index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        $("#serviceCategoryName").val(body.find('#treeName').val());
        $.modal.close(index);
    }

</script>
</body>
</html>