<%@ page import="com.lightinit.hsdataplatformresdir.dictionary.DicPublishSettingChargeMethod" %>
<%@ page import="com.lightinit.hsdataplatformresdir.dictionary.DicBuyTimesLimit" %>
<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<%@ page isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String basePath = request.getContextPath();
%>
<jsp:include page="../../../common/admin/modal_content_pre.jsp">
    <jsp:param name="modal_title" value="定价发布"/>
</jsp:include>
<form id="publisResourceDetailFormId" action="<%=basePath%>/admin/datapublish_mgr/publishResourcePublic.action" method="post" enctype="multipart/form-data" role="form" class="form-horizontal">
    <input type='hidden'  id='param' name='param'/>
    <div id="publisResourceDiv">
        <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">
                <input type="hidden" name="id" value="${busiModel.id}"/>
                <div class="form-group">
                    <label class="col-md-3 col-sm-3 control-label">数据名称：</label>
                    <div class="col-md-7 col-sm-7" style="padding-top: 7px"  style="padding-top: 7px"> ${busiModel.resourceName}
                    </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" style="padding-top: 7px" style="padding-top: 7px">
                        ${busiModel.resourceSummary}
                    </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" style="padding-top: 7px">
                        ${busiModel.dataItem}
                    </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" style="padding-top: 7px">
                        没有赋值，需求不明确
                    </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" style="padding-top: 7px">
                        ${busiModel.belongToString}
                    </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" style="padding-top: 7px">
                        ${busiModel.catelogType}
                    </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" style="padding-top: 7px">
                        ${busiModel.dataTag}
                    </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" style="padding-top: 7px">
                        ${busiModel.dataFile}
                    </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" style="padding-top: 7px">
                       ${busiModel.demoFile}
                    </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" style="padding-top: 7px">
                        没有赋值，需求不明确
                    </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" style="padding-top: 7px">
                        <input type="file" name="ResourcePicture" id="ResourcePicture" />
                        <span class="help-block"></span>
                    </div>
                </div>
            </div>
            <%--/////////////////////发布渠道//////////////////////////////////////////////////////--%>
            <div role="tabpanel" class="tab-pane" id="publish">
                <div class="form-group">
                    <label class="col-md-3 col-sm-3 control-label">发布渠道：</label>
                    <input type="checkbox" name="publicChannel" style="margin:12px 12px 0px" value="共享平台"/>共享平台
                    <input type="checkbox" name="publicChannel" style="margin:12px 12px 0px" value="开放平台"/>开放平台
                </div>
                <div class="form-group">
                    <label class="col-md-3 col-sm-3 control-label">共享平台：</label>
                </div>
                <div class="form-group">
                    <label class="col-md-3 col-sm-3 control-label">共享类型：</label>
                    <div class="col-md-7 col-sm-7" style="padding-top: 7px">
                        ${busiModel.shareType}
                    </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" style="padding-top: 7px">
                        <input type="text" name="shareCondition" class="form-control"/>
                    </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>
                <div class="form-group">
                    <label class="col-md-3 col-sm-3 control-label">开放类型：</label>
                    <div class="col-md-7 col-sm-7" style="padding-top: 7px">
                        ${busiModel.openType}
                    </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" style="padding-top: 7px">
                        <input type="text" name="openCondition" class="form-control"/>
                    </div>
                    <span class="field-validation-valid help-block"></span>
                </div>
                <div>
                    <table id="fixedPriceTable" 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 class="modal-footer">
                    <button type="button" class="btn btn-primary"  onclick="showFiexedPriceModal()">定价</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-primary" onclick="fnSubmit()">提交</button>
            <button type="button" class="btn btn-info" onclick="fnStorage()">暂存</button>
            <button type="button" class="btn btn-default" data-dismiss="modal"><i class="fa fa-close"></i>取消</button>
        </div>
    </div>
</form>
<%--///////////////////////////////////////定价form////////////////////////////////////////////--%>
<form id="formAdd" class="form-horizontal">
    <div class="form-group" id="fiexedPriceModal" style="display:none">
        <div class="form-group">
            <label for="chargeMethod" class="col-sm-3 control-label">计费方式</label>
            <div class="col-sm-8">
                <input type="hidden" id="badge" name="badge" value="${publishSetting.badge}"/>
                <input type="hidden" id="editPublishSettingId" value="${publishSetting.id}">
                <select id="chargeMethod" name="chargeMethod" class="form-control">
                    <option value="<%=DicPublishSettingChargeMethod.FREE%>"
                            <c:if test="${publishSetting.chargeMethod eq DicPublishSettingChargeMethod.FREE}">selected="selected"</c:if>><%=DicPublishSettingChargeMethod.FREE%>
                    </option>
                    <option value="<%=DicPublishSettingChargeMethod.BY_NUMBER_OF_TIMES%>"
                            <c:if test="${publishSetting.chargeMethod eq DicPublishSettingChargeMethod.BY_NUMBER_OF_TIMES}">selected="selected"</c:if>><%=DicPublishSettingChargeMethod.BY_NUMBER_OF_TIMES%>
                    </option>
                    <option value="<%=DicPublishSettingChargeMethod.BY_TIME%>"
                            <c:if test="${publishSetting.chargeMethod eq DicPublishSettingChargeMethod.BY_TIME}">selected="selected"</c:if>><%=DicPublishSettingChargeMethod.BY_TIME%>
                    </option>
                </select>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label for="packageName" class="col-sm-3 control-label">套餐名称</label>
            <div class="col-sm-8">
                <input type="text" id="packageName" name="packageName" class="form-control"
                       value="${publishSetting.packageName}"/>
                <span class="help-block"></span>
            </div>
        </div>
        <div class="form-group">
            <label for="packagePrice" class="col-sm-3 control-label">套餐价格</label>
            <div class="col-md-8 col-sm-8">
                <div class="input-group">
                    <input type="text" id="packagePrice" name="packagePrice" class="NumDecText form-control"
                           value="${publishSetting.packagePrice}"/>
                    <span class="input-group-addon">元/</span>
                    <input type="text" id="packageMonths" name="packageMonths" class="form-control"
                           value="${publishSetting.packageMonths}" onkeyup="value=value.replace(/[^\d]/g,'')"/>
                    <span class="input-group-addon">月</span>
                </div>
                <span class="field-validation-valid help-block"></span>
            </div>
        </div>
        <div class="form-group">
            <label for="selfCost" class="col-sm-3 control-label">套餐成本</label>
            <div class="col-md-8 col-sm-8">
                <div class="input-group">
                    <input type="text" id="selfCost" name="selfCost" class="NumDecText form-control"
                           value="${publishSetting.selfCost}"/>
                    <span class="input-group-addon">元/月</span>
                </div>
                <span class="field-validation-valid 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">
                    <option value="0" selected="selected"><%=DicBuyTimesLimit.UNLIMITED%></option>
                    <option value="1"><%=DicBuyTimesLimit.UNLIMITED_ONE%></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label for="useTimesLimit" class="col-sm-3 control-label">使用限制</label>
            <div class="col-md-8 col-sm-8">
                <div class="input-group">
                    <input type="text" id="useTimesLimit" name="useTimesLimit" class="form-control"
                           value="${publishSetting.useTimesLimit}" onkeyup="value=value.replace(/[^\d]/g,'')"/>
                    <span class="input-group-addon">次</span>
                </div>
                <span class="help-block"></span>
            </div>
        </div>
        <div class="form-group">
            <label for="effectiveDate" class="col-md-3 col-sm-3 control-label">生效日期</label>
            <div class="col-md-8 col-sm-8">
                <div class="input-group date">
                    <input type="text" id="effectiveDate" name="effectiveDate" class="form-control"
                           value="<fmt:formatDate value="${publishSetting.effectiveDate}" pattern="yyyy-MM-dd"/>"/>
                    <span class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </span>
                </div>
                <span class="help-block"></span>
            </div>
        </div>
        <div class="form-group">
            <label for="expiriedDate" class="col-md-3 col-sm-3 control-label">失效日期</label>
            <div class="col-md-8 col-sm-8">
                <div class="input-group date">
                    <input type="text" id="expiriedDate" name="expiriedDate" class="form-control"
                           value="<fmt:formatDate value="${publishSetting.expiriedDate}" pattern="yyyy-MM-dd"/>"/>
                    <span class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </span>
                </div>
                <span class="help-block"></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"
                       value="${publishSetting.description}"/>
            </div>
        </div>
        <div class="modal-footer">
            <input type="button"  class="btn btn-primary" value="确定" onclick="hideFiexedPriceModal()"/>
            <input type="button"  class="btn btn-default" style="margin-left: 30px" value="返回" onclick="hideFiexedPriceModalBackToForm()"/>
        </div>
    </div>
</form>

<script type="text/javascript">
    var count=0;        /*用来作为list角标*/
    /*选择标签页*/
    $('#myTabs a').click(function (e) {
        $(this).tab('show')
    })

    function hideFiexedPriceModalBackToForm(){
        hideFiexedPriceModal();
        $('#fiexedPriceModal input').clearInputs();
        $('#fiexedPriceModal').hide();
        $('#publisResourceDiv').show();

    }
    function showFiexedPriceModal() {
        $('#fiexedPriceModal input').clearInputs(); //清空表单
        $.removeFormValidationStyle({form: "#formAdd"});//移除表单样式
        $('#fiexedPriceModal').show();
        $('#publisResourceDiv').hide();
    }

    /*表单验证*/
    $("#formAdd").validate({
        rules: {
            packageName:"required",
            packagePrice: "required",
            packageMonths: "required",
            selfCost: "required",
        }
    });
    $(".NumDecText").keyup(function () {
        $(this).val($(this).val().replace(/[^0-9.]/g, ''));
    }).bind("paste", function () {
        $(this).val($(this).val().replace(/[^0-9.]/g, '')); //粘贴的不是数字，则替换为''
        //或 return false; 禁用粘贴功能
    }).css("ime-mode", "disabled"); //CSS设置输入法不可用

    function hideFiexedPriceModal() {
        //简易的表单验证
        if ($.trim($('#chargeMethod').val()) != '免费') {
            var isValid = $.getJqObj("#formAdd").valid();
            if (!isValid) {
                return;
            }
        } else {
            if ($.trim($('#packageName').val()) == '') {
                $.showFormFieldValidationResult({form: "#formAdd", field: "packageName", msg: "不能为空"});
                return;
            }
        }


        $('#fiexedPriceModal').hide();
        $('#publisResourceDiv').show();
        var fiexedPriceTr = "<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='publishSettingList["+count+"].chargeMethod' value='" + $('#chargeMethod').val() + "'/>" +
            "<input type='hidden' name='publishSettingList["+count+"].packageName' value='" +  $("#packageName").val() + "'/>" +
            "<input type='hidden' name='publishSettingList["+count+"].packagePrice' value='" + $("#packagePrice").val() + "'/>" +
            "<input type='hidden' name='publishSettingList["+count+"].packageMonths' value='" + $("#packageMonths").val() + "'/>" +
            "<input type='hidden' name='publishSettingList["+count+"].selfCost' value='" + $("#selfCost").val() + "'/>" +
            "<input type='hidden' name='publishSettingList["+count+"].buyTimesLimit' value='" + $("#buyTimesLimit").val()  + "'/>" +
            "<input type='hidden' name='publishSettingList["+count+"].useTimesLimit' value='" +  $("#useTimesLimit").val() + "'/>" +
            "<input type='hidden' name='publishSettingList["+count+"].effectiveDate' value='" +  $("#effectiveDate").val()  + "'/>" +
            "<input type='hidden' name='publishSettingList["+count+"].expiriedDate' value='" +  $("#expiriedDate").val() + "'/>" +
            "<input type='hidden' name='publishSettingList["+count+"].description' value='" + $("#description").val() + "'/>" +
            "<a onclick='toEdit(this)'>修改</a>|<a onclick='toDelete(this)'>删除</a></td>" +
            "</tr>"
        $('#fixedPriceTable tbody').append(fiexedPriceTr);
        count++;
    }

    function toEdit(tr) {
        $(tr).parent().parent().remove();
        showFiexedPriceModal();
        $("#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() =='<%=DicBuyTimesLimit.UNLIMITED%>'){        /*此处写死，不好*/
            $("#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());

    }


    function toDelete(tr) {
        $(tr).parent().parent().remove();
    }

    function fnSubmit(){
        $('#param').val(1);
        $('#publisResourceDetailFormId').ajaxSubmitCloseRefresh();
    }
    function fnStorage(){
        $('#param').val(2);
        $('#publisResourceDetailFormId').ajaxSubmitCloseRefresh();
    }

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

    /*表单验证*/
    $('#publisResourceDetailFormId').validate({
        rules: {
            ResourcePicture: "required",
        }
    });
</script>
<%--///////////////////////////////////////--%>
<jsp:include page="../../../common/admin/modal_content_post.jsp"></jsp:include>
<%--
<jsp:include page="../../../common/admin/modal_footer_pre.jsp"></jsp:include>
<jsp:include page="../../../common/admin/modal_footer_post.jsp"></jsp:include>--%>
