<%@ page import="com.lightinit.hsdataplatform.dictionary.*" %>
<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@ page isELIgnored="false" %>
<%
    String basePath = request.getContextPath();
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<jsp:include page="../../../common/admin/modal_content_pre.jsp"><jsp:param name="modal_title" value="发布" /> </jsp:include>
<form id="formPublish" action="<%=basePath%>/admin/microapp_publish/doPublish.action"enctype="multipart/form-data"  method="post" class="form-horizontal">
    <input type="hidden" name="id" value="${resource.id}" />
    <div id="div">
        <ul class="nav nav-tabs" role="tablist">
            <li role="presentation" class="active"><a href="#baseInfo" aria-controls="baseInfo" role="tab" data-toggle="tab">基本信息</a></li>
            <li role="presentation"><a href="#publish" aria-controls="publish" role="tab" data-toggle="tab">发布渠道</a></li>
        </ul>
        <div class="tab-content">
            <div role="tabpanel" class="tab-pane active" id="baseInfo">
            <div class="form-group">
                <label  class="col-md-3 col-sm-3 control-label">微应用名称：</label>
                <div class="col-md-7 col-sm-7">
                    <p class="form-control-static"> ${resource.resourceName}</p>
                </div>
                <span class="field-validation-valid help-block"></span>
            </div>
            <div class="form-group">
                <label  class="col-md-3 col-sm-3 control-label">微应用标示：</label>
                <div class="col-md-7 col-sm-7">
                    <p class="form-control-static"> ${resource.resourceIdentity}</p>
                </div>
                <span class="field-validation-valid help-block"></span>
            </div>
            <div class="form-group">
                <label class="col-md-3 col-sm-3 control-label">微应用简介：</label>
                <div class="col-md-7 col-sm-7">
                    <p class="form-control-static"> ${resource.resourceSummary}</p>
                </div>
                <span class="field-validation-valid help-block"></span>
            </div>
            <%--<div class="form-group">--%>
                <%--<label  class="col-md-3 col-sm-3 control-label">注册日期：</label>--%>
                <%--<div class="col-md-7 col-sm-7">--%>
                    <%--<div class="input-group date">--%>
                        <%--<span class="input-group-addon">--%>
                            <%--<span class="glyphicon glyphicon-calendar"></span>--%>
                        <%--</span>--%>
                    <%--</div>--%>
                <%--</div>--%>
                <%--<span class="field-validation-valid help-block"></span>--%>
            <%--</div>--%>
            <div class="form-group">
                <label  class="col-md-3 col-sm-3 control-label">所属单位：</label>
                <div class="col-md-7 col-sm-7">


                    <p class="form-control-static">  ${dic.provider}</p>

                </div>
                <span class="field-validation-valid help-block"></span>
            </div>
            <div class="form-group">
                <label  class="col-md-3 col-sm-3 control-label">服务方式：</label>
                <div class="col-md-7 col-sm-7">
                    <p class="form-control-static">${microapp.serviceMethod}</p>
                </div>
                <span class="field-validation-valid help-block"></span>
            </div>
            <div class="form-group">
                <label  class="col-md-3 col-sm-3 control-label">服务渠道：</label>
                <div class="col-md-7 col-sm-7">
                    <p class="form-control-static">${microapp.serviceChannel}</p>
                </div>
                <span class="field-validation-valid help-block"></span>
            </div>
            <div class="form-group">
                <label  class="col-md-3 col-sm-3 control-label">演示地址：</label>
                <div class="col-md-7 col-sm-7">
                    <p class="form-control-static">  ${microapp.demoUrl}</p>
                </div>
                <span class="field-validation-valid help-block"></span>
            </div>
            <div class="form-group">
                <label  class="col-md-3 col-sm-3 control-label">访问URL：</label>
                <div class="col-md-7 col-sm-7">
                    <p class="form-control-static">${microapp.url}</p>
                </div>
                <span class="field-validation-valid help-block"></span>
            </div>
            <div class="form-group">
                <label  class="col-md-3 col-sm-3 control-label">页面截图：</label>
                <div class="col-md-7 col-sm-7">
                    <p class="form-control-static">${screenshot == null ? "" : screenshot}</p>
                </div>
                <span class="field-validation-valid help-block"></span>
            </div>
            <div class="form-group">
                <label  class="col-md-3 col-sm-3 control-label">服务类型：</label>
                <div class="col-md-7 col-sm-7">
                    <p class="form-control-static">${resource.openType}</p>
                </div>
                <span class="field-validation-valid help-block"></span>
            </div>
            <div class="form-group">
                <label  class="col-md-3 col-sm-3 control-label">主题分类：</label>
                <div class="col-md-7 col-sm-7">

                            <p class="form-control-static">${dic.themename}</p>

                </div>
                <span class="field-validation-valid help-block"></span>
            </div>

            <div class="form-group">
                <label  class="col-md-3 col-sm-3 control-label"><span style="color: red">*</span>服务标签：</label>
                <div class="col-md-7 col-sm-7">
                    <input type="text" name="dataTag" class="form-control" >
                        <span class="field-validation-valid help-block"></span>
                </div>

            </div>
            <div class="form-group">
                <label class="col-md-3 col-sm-3 control-label"><span style="color: red">*</span>资源图片：</label>
                <div class="col-md-7 col-sm-7">
                    <input type="file" name="imgResource" onchange="fileChange()"/>
                    <input type="hidden" id="resourceImg" name="resourceImg">
                    <span class="field-validation-valid help-block"></span>
                </div>

            </div>
        </div>

        <div  role="tabpanel" class="tab-pane" id="publish" >
            <div class="form-group">
                <label for="publishChannel" class="col-sm-2 control-label">发布渠道</label>
                <div class="col-md-7 col-sm-7">
                    <input type="checkbox" id="publishChannel" name="publishChannel" <c:if test="${fn:contains(publishInfo.publishChannel,'开放平台')}">checked</c:if>
                           value="<%=DicPublishChannel.OPEN%>"/><%=DicPublishChannel.OPEN%>
                    <input type="checkbox" name="publishChannel" <c:if test="${fn:contains(publishInfo.publishChannel,'共享平台')}">checked</c:if>
                           value="<%=DicPublishChannel.SHARE%>" style="margin-left: 50px;"/><%=DicPublishChannel.SHARE%>
                </div>
                <span class="field-validation-valid help-block"></span>
            </div>
            <div class="form-group">
                <label  class="col-sm-2 control-label">共享平台</label>
            </div>
            <div class="form-group">
                <label for="shareType" class="col-sm-2 control-label">共享类型</label>
                <div class="col-md-7 col-sm-7">
                    <input type="text" id="shareType" name="shareType" class="form-control"
                           value=" ${resource.shareType}" disabled/>
                </div>
                <span class="field-validation-valid help-block"></span>
            </div>
            <div class="form-group">
                <label for="shareCondition" class="col-sm-2 control-label">共享条件</label>
                <div class="col-md-7 col-sm-7">
                    <input type="text" id="shareCondition" name="shareCondition" class="form-control"/>
                </div>
                <span class="field-validation-valid help-block"></span>
            </div>
            <div class="form-group">
                <label  class="col-sm-2 control-label">开放平台</label>
            </div>
            <div class="form-group">
                <label for="openType" class="col-sm-2 control-label">开放类型</label>
                <div class="col-md-7 col-sm-7">
                    <input type="text" id="openType" name="openType" class="form-control"
                           value="${resource.openType}" disabled/>
                </div>
                <span class="field-validation-valid help-block"></span>
            </div>
            <div class="form-group">
                <label for="openCondition" class="col-sm-2 control-label">开放条件</label>
                <div class="col-md-7 col-sm-7">
                    <input type="text" id="openCondition" name="openCondition" class="form-control"/>
                </div>
                <span class="field-validation-valid help-block"></span>
            </div>
            <div class="form-group">
                <table id="testaaa" class="table table-hover  table-condensed table-bordered "
                           align="center">
                        <thead>
                        <tr>
                            <td>计费方式</td>
                            <td>套餐名称</td>
                            <td>套餐价格</td>
                            <td>购买限制</td>
                            <td>使用限制</td>
                            <td>生效日期</td>
                            <td>失效日期</td>
                            <td>操作</td>
                        </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
            </div>
            <button onclick="aclick()" type="button" class="btn btn-sm btn-primary btn-position"><i class="fa fa-plus"></i>定价</button>
   <br>
    </div>
    </div>
    </div>
</form>
<%--====================================定价====================================--%>
<form id="settingForm" style="display: none" class="form-horizontal">
<div id="aa" >

    <div class="form-group">
        <label for="chargeMethod" class="col-md-3 col-sm-3 control-label"><span style="color: red;">*</span>计费方式0：</label>
        <div class="col-md-7 col-sm-7">
            <select id="chargeMethod" name="chargeMethod" class="form-control">
                <option value="<%=DicPublishSettingChargeMethod.FREE%>">
                    <%=DicPublishSettingChargeMethod.FREE%>
                </option>
                <option value="<%=DicPublishSettingChargeMethod.BY_NUMBER_OF_TIMES%>">
                    <%=DicPublishSettingChargeMethod.BY_NUMBER_OF_TIMES%>
                </option>
                <option value="<%=DicPublishSettingChargeMethod.BY_TIME%>">
                    <%=DicPublishSettingChargeMethod.BY_TIME%>
                </option>
            </select>
            <span class="help-block"></span>
        </div>
    </div>
    <div class="form-group">
        <label for="packageName" class="col-md-3 col-sm-3 control-label"><span style="color: red;">*</span>套餐名称：</label>
        <div class="col-md-7 col-sm-7">
            <input type="text" id="packageName" name="packageName" class="form-control" />
            <span class="help-block"></span>
        </div>
    </div>
    <div class="form-group">
        <label for="packagePrice" class="col-md-3 col-sm-3 control-label"><span style="color: red;">*</span>套餐价格：</label>
        <%-- <div class="col-md-3 col-sm-3>
             <input type="text" id="dataTag3" name="dataTag" class="form-control" />
             <span class="help-block"></span>
         </div>--%>
        <div class="col-sm-3">
            <input type="text" id="packagePrice" name="packagePrice" class="form-control"/>
            <span class="help-block"></span>
        </div>
        <div class="col-sm-3">
            <input type="text" id="packageMonths" name="packageMonths" class="form-control"/>
            <span class="help-block"></span>
        </div>
    </div>
    <div class="form-group">
        <label for="selfCost" class="col-sm-3 control-label">套餐成本：</label>
        <div class="col-sm-8">
            <input type="text" id="selfCost" name="selfCost" class="form-control"/>
            <span class="help-block"></span>
        </div>
    </div>
    <div class="form-group">
        <label for="buyTimesLimit" class="col-sm-3 control-label">购买次数限制：</label>
        <div class="col-sm-8">
            <select id="buyTimesLimit" name="buyTimesLimit" class="form-control">
                <%--TODO 暂时先做成下拉--%>
                <option value="0" selected="selected">无限制</option>
                <option value="1">限制一次</option>
            </select>
            <%-- <input type="radio" name="buyTimesLimit" value="无限次" />无限次
                 <input type="radio" name="buyTimesLimit" value="仅一次" />仅一次--%>
        </div>
    </div>
    <div class="form-group">
        <label for="useTimesLimit" class="col-sm-3 control-label">使用限制：</label>
        <div class="col-sm-8">
            <input type="text" id="useTimesLimit" name="useTimesLimit" class="form-control"/>
        </div>
    </div>
    <div class="form-group">
        <label for="effectiveDate" class="col-sm-3 control-label">生效日期：</label>
        <div class="input-group date col-sm-8">
            <input type="text" id="effectiveDate" name="effectiveDate" class="form-control"/>
            <span class="input-group-addon">
                <span class="glyphicon glyphicon-calendar"></span>
            </span>
        </div>
    </div>
    <div class="form-group">
        <label for="expiriedDate" class="col-sm-3 control-label">失效日期：</label>
        <div class="input-group date col-sm-8">
            <input type="text" id="expiriedDate" name="expiriedDate" class="form-control"/>
            <span class="input-group-addon">
                <span class="glyphicon glyphicon-calendar"></span>
            </span>
        </div>
    </div>
    <div class="form-group">
        <label for="description" class="col-sm-3 control-label">套餐说明：</label>
        <div class="col-sm-8">
            <input type="text" id="description" name="description" class="form-control"/>
        </div>
    </div>
    <div class="form-group">
        <div class="col-md-9 col-sm-9 control-label"></div>
        <div class="col-md-3 col-sm-3">
            <input type="button"  class="btn btn-primary" value="确定" onclick="btnSave()"/>
            <span class="help-block"></span>
        </div>
    </div>
</div>
</form>
<jsp:include page="../../../common/admin/modal_content_post.jsp"></jsp:include>
<jsp:include page="../../../common/admin/modal_footer_pre.jsp"></jsp:include>
<button type="button" class="btn btn-default" data-dismiss="modal"><i class="fa fa-close"></i>取消</button>
<button type="button" id="btnSave" class="btn btn-primary"><i class="fa fa-check"></i>保存</button>
<button type="button" onclick="btnSubmit()"class="btn btn-sm btn-primary m-r-sm"><i class="fa fa-check"></i>提交</button>
<jsp:include page="../../../common/admin/modal_footer_post.jsp"></jsp:include>
<script type="text/javascript">
    $('#myTabs a').click(function (e) {
        /*e.preventDefault()*/
        $(this).tab('show')
    })
    function aclick() {
        $('#settingForm input').clearInputs();
       $('#div').hide();
    $('#settingForm').show();
    }
    var count=0;
    function btnSave() {
        if ($.trim($('#chargeMethod').val()) != '免费') {
            var isValid = $.getJqObj("#settingForm").valid();
            if (!isValid) {
                return;
            }
        } else {
            if ($.trim($('#packageName').val()) == '') {
                $.showFormFieldValidationResult({form: "#settingForm", field: "packageName", msg: "不能为空"});
                return;
            }
        }
        $('#settingForm').hide();
        $('#div').show();

        var tables=$('#testaaa');
        var addtr="<tr >" +
            "<td>" + $('#chargeMethod').val() + "</td>" +
            "<td>" + $('#packageName').val() + "</td>" +
            "<td><span>" + $("#packagePrice").val() + "</span>元/<span>" + $("#packageMonths").val() + "</span>月</td>" +
            "<td>" + $("#buyTimesLimit option:selected").html()+ "</td>" +
            "<td>" + $("#useTimesLimit").val() + "</td>" +
            "<td>" + $("#effectiveDate").val() + "</td>" +
            "<td>" + $("#expiriedDate").val() + "</td>" +
            "<td><input type='hidden' name='publishSettingList["+count+"].id'/>" +
            "<input type='hidden' name='settingList["+count+"].chargeMethod' value='" + $('#chargeMethod').val() + "'/>" +
            "<input type='hidden' name='settingList["+count+"].packageName' value='" +  $("#packageName").val() + "'/>" +
            "<input type='hidden' name='settingList["+count+"].packagePrice' value='" + $("#packagePrice").val() + "'/>" +
            "<input type='hidden' name='settingList["+count+"].packageMonths' value='" + $("#packageMonths").val() + "'/>" +
            "<input type='hidden' name='settingList["+count+"].selfCost' value='" + $("#selfCost").val() + "'/>" +
            "<input type='hidden' name='settingList["+count+"].buyTimesLimit' value='" + $("#buyTimesLimit").val()  + "'/>" +
            "<input type='hidden' name='settingList["+count+"].useTimesLimit' value='" +  $("#useTimesLimit").val() + "'/>" +
            "<input type='hidden' name='settingList["+count+"].effectiveDate' value='" +  $("#effectiveDate").val()  + "'/>" +
            "<input type='hidden' name='settingList["+count+"].expiriedDate' value='" +  $("#expiriedDate").val() + "'/>" +
            "<input type='hidden' name='settingList["+count+"].description' value='" + $("#description").val() + "'/>" +
            "<a onclick='toEdit(this)'>修改</a>|<a onclick='toDelete(this)'>删除</a></td>" +
            "</tr>";
        tables.append(addtr)
        count++;
    }
    function toDelete(tr){
        $(tr).parent().parent().remove();
    }
    function toEdit(tr) {

        $(tr).parent().parent().remove();
        $('#settingForm input').clearInputs();
        $('#settingForm').show();
        $('#div').hide();
        $("#chargeMethod").val($(tr).parent().parent().children("td:eq(0)").html());
        $("#packageName").val($(tr).parent().parent().children("td:eq(1)").html());
        $("#packagePrice").val($(tr).parent().parent().children('td:eq(2)').children('span:eq(0)').html());
        $("#packageMonths").val($(tr).parent().parent().children('td:eq(2)').children('span:eq(1)').html());
        if($(tr).parent().parent().children("td:eq(3)").html() =='无限制'){        /*此处写死，不好*/
            $("#buyTimesLimit").val(0);
        }else{
            $("#buyTimesLimit").val(1);
        }
        $("#useTimesLimit").val($(tr).parent().parent().children("td:eq(4)").html());
        $("#effectiveDate").val($(tr).parent().parent().children("td:eq(5)").html());
        $("#expiriedDate").val($(tr).parent().parent().children("td:eq(6)").html());
        $("#description").val($(tr).parent().parent().children("td:last").children("input:last").val());
        $("#selfCost").val($(tr).parent().parent().children('td:last').children('input:eq(5)').val());
    }
    $("#btnSave").click(function() {

        $('#formPublish').append('<input type="hidden" name="publishState" value="<%=DicDataPublishState.DRAFT%>">')

        
        $("#formPublish").ajaxSubmitCloseRefresh();
    });

    $(".input-group.date").datetimepicker({
        format: "YYYY-MM-DD",
        locale: "zh-cn"
    });

    function btnSubmit() {
        $('#formPublish').append('<input type="hidden" name="publishState" value="<%=DicDataPublishState.PENDING%>">')
        $('#formPublish').ajaxSubmitCloseRefresh();

    }
    $("#formPublish").validate({
        rules: {
            dataTag: "required",
            imgResource:"required"
        }
    });
    $("#settingForm").validate({
        rules: {
            packageName: "required",
            packagePrice:"required",
            packageMonths:"required"
        }
    });
    function fileChange() {
        $("#resourceImg").val("111");
    }

</script>