<!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 :: datetimepicker-css" />
    <th:block th:include="include :: jasny-bootstrap-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <div class="row">
            <div class="col-sm-1 col-sm-offset-10">
                <a class="btn btn-primary btn-rounded btn-sm" onclick="edit()" shiro:hasPermission="company:edit:submit">
                    <i class="fa fa-edit"></i>&nbsp;修改信息
                </a>

            </div>
        </div>
        <form class="form-horizontal m" id="form-company-edit" th:object="${sysCompany}">
            <input name="companyId" th:value="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">商户名称：</label>
                <div class="col-sm-8">
                    <input name="companyName" th:field="*{companyName}"  class="form-control" type="text" disabled="true" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">企业类型：</label>
                <div class="col-sm-8">
                    <select name="companyType" class="form-control m-b" th:with="type=${@dict.getType('company_type')}" disabled="true">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{companyType}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">详细地址：</label>
                <div class="col-sm-8">
                    <input name="detailAddress" th:field="*{detailAddress}" class="form-control" type="text" disabled="true">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">经度：</label>
                <div class="col-sm-8">
                    <input name="longitude" th:field="*{longitude}" class="form-control" type="text" disabled="true">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">纬度：</label>
                <div class="col-sm-8">
                    <input name="latitude" th:field="*{latitude}" class="form-control" type="text" disabled="true">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">企业法人：</label>
                <div class="col-sm-8">
                    <input name="legalPerson" th:field="*{legalPerson}" class="form-control" type="text" disabled="true">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">联系电话：</label>
                <div class="col-sm-8">
                    <input name="contactNumber" th:field="*{contactNumber}" class="form-control" type="text" disabled="true">
                </div>
            </div>
            <div class="form-group draggable">
                <label class="col-sm-3 control-label">成立日期：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="establishDate" th:value="${#dates.format(sysCompany.establishDate, 'yyyy-MM-dd')}"
                               class="form-control" placeholder="yyyy-MM-dd" type="text"  disabled="true">
                    </div>
                </div>
            </div>
            <div class="form-group">

                <label class="col-sm-3 control-label">统一社会信用代码：</label>
                <div class="col-sm-8">
                    <input name="unifiedSocialCreditCode" th:field="*{unifiedSocialCreditCode}" class="form-control" type="text" disabled="true">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">营业执照：</label>
                <div class="col-sm-8">
                    <div class="fileinput fileinput-new">
                        <input id="input-businessLicenseUrl" name="businessLicenseUrl" type="hidden"/>
                        <div class="fileinput-new thumbnail" style="max-width: 140px; max-height: 140px;" onclick="openImg(this)">
                            <img th:src="@{*{businessLicenseUrl}}" id="img-businessLicenseUrl" >
                        </div>
                        <div class="div-imgButton" style="display: none;">
                            <input type="file" accept="image/*" style="display: none" onchange="imgChange(this,'businessLicenseUrl')">
                            <a class="btn btn-primary btn-sm" onclick="upImg(this)" >
                                上传营业执照
                            </a>
                            <a  class="btn btn-white" onclick="clearImg('businessLicenseUrl')">清除</a>
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <input id="fmzFile" name="fmzFile" type="hidden"/>
                <label class="col-sm-3 control-label">商户封面：</label>
                <div class="col-sm-8">
                    <div class="fileinput fileinput-new">
                        <input id="input-defaultImgUrl" name="defaultImgUrl" type="hidden"/>
                        <div class="fileinput-new thumbnail" style="max-width: 140px; max-height: 140px;" onclick="openImg(this)">
                            <img th:src="@{*{defaultImgUrl}}" id="img-defaultImgUrl" >
                        </div>
                        <div class="div-imgButton" style="display: none;">
                            <input type="file" accept="image/*" style="display: none" onchange="imgChange(this,'defaultImgUrl')">
                            <a class="btn btn-primary btn-sm" onclick="upImg(this)" >
                                上传商户封面
                            </a>
                            <a  class="btn btn-white" onclick="clearImg('defaultImgUrl')">清除</a>
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">商户宣传图片：</label>
                <div class="col-sm-8">
                    <div class="fileinput fileinput-new">
                        <input id="input-propagandaImgUrl" name="propagandaImgUrl" type="hidden"/>
                        <div class="fileinput-new thumbnail" style="max-width: 140px; max-height: 140px;" onclick="openImg(this)">
                            <img th:src="@{*{propagandaImgUrl}}" id="img-propagandaImgUrl" >
                        </div>
                        <div class="div-imgButton" style="display: none;">
                            <input type="file" accept="image/*" style="display: none" onchange="imgChange(this,'propagandaImgUrl')">
                            <a class="btn btn-primary btn-sm" onclick="upImg(this)" >
                                上传宣传图片
                            </a>
                            <a  class="btn btn-white" onclick="clearImg('propagandaImgUrl')">清除</a>
                        </div>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">企业介绍：</label>
                <div class="col-sm-8">
                    <textarea name="companyIntroduce" class="form-control" disabled="true">[[*{companyIntroduce}]]</textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">主营业务：</label>
                <div class="col-sm-8">
                    <input name="primaryBusiness" th:field="*{primaryBusiness}" class="form-control" type="text" disabled="true">
                </div>
            </div>
        </form>
        <div id="div-button" class="row" style="display: none">
            <div class="col-sm-2 col-sm-offset-10">
                <a class="btn btn-primary  btn-sm" onclick="editUpdate()" >
                    <i class="fa fa-edit"></i>&nbsp;确定
                </a>
                <a class="btn btn-defult  btn-sm" onclick="reload()" >
                    <i class="fa fa-cancel"></i>&nbsp;取消
                </a>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "company/";
        $("#form-company-edit").validate({
            focusCleanup: true
        });
        $("input[name='establishDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        function edit(){
            $("#div-button").show();
            $(".div-imgButton").show();
            var forms = $("#form-company-edit");
            forms.each(function(index, form){
                for ( var i = 0; i < form.length; i++) {
                    var element = form.elements[i];
                    element.disabled = false;
                }
            });
        }
        function reload(){
            location.reload()
        }
        function editUpdate(){
            $.modal.confirm("提交修改信息将在审核后生效，是否确认",function(){
                var data = $("#form-company-edit").serialize()
                $.operate.save(prefix+"edit/submit",data,reload())
            })
        }

        function upImg(self){
            $(self).siblings("input").click()
        }
        function clearImg(name){
            $("#img-"+name).attr("src","")
            $("#input-"+name).val("")
        }
        function imgChange(self,name){
            if ($(self).val() == '') {
                return;
            }var data = new FormData();
            data.append('file', self.files[0]);
            $.modal.loading("正在上传，请稍后...");
            $.ajax({
                url:ctx+"common/upload",
                type:"post",
                data: data,
                cache: false,
                contentType: false,
                processData: false,
                dataType: 'json',
                success: function(result) {
                    if (result.code == web_status.SUCCESS) {
                        $("#img-"+name).attr("src",result.data.fileName)
                        $("#input-"+name).val(result.data.fileName)
                    } else {
                        $.modal.alertError(result.msg);
                    }
                    $.modal.closeLoading();
                },
                error:function(result) {
                    alert("上传失败")
                    $.modal.closeLoading();
                }
            });
        }
        function openImg(self){
            var img = $(self).children("img")
            layer.open({
                type: 1,
                title: false,
                shade: 0.0001,
                area: ['auto'],
                shadeClose: true,
                content: $(img)
            });
        }
    </script>
</body>
</html>