<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改工位参数')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-SubStation-editParam" th:object="${tBdSubstation}">
        <input name="ID" th:field="*{ID}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label">工位序号：</label>
            <div class="col-sm-8">
                <input id="StationID" name="StationID" th:field="*{StationID}" class="form-control" readonly="readonly">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">工位名称：</label>
            <div class="col-sm-8">
                <input name="StationName" th:field="*{StationName}" class="form-control" readonly="readonly">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">工位代码：</label>
            <div class="col-sm-8">
                <input id="StationCode" name="StationCode" th:field="*{StationCode}" class="form-control" readonly="readonly">
            </div>
        </div>
<!--        <div class="form-group">-->
<!--            <label class="col-sm-3 control-label">工位类型：</label>-->
<!--            <div class="col-sm-8">-->
<!--                <select name="StationType" class="form-control m-b" th:field="*{StationType}">-->
<!--                    <option th:each="st:${stationtype}" th:value="${st.ID}" th:text="${st.typeName}"></option>-->
<!--                </select>-->
<!--            </div>-->
<!--        </div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label">系统数据表：</label>
            <div class="col-sm-8">
                <input id="TableName" name="TableName" th:field="*{TableName}" class="form-control" readonly="readonly">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">参数个数：</label>
            <div class="col-sm-8">
                <input id="paraCount" name="paraCount" th:field="*{paraCount}" class="form-control" readonly="readonly">
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var prefix = ctx + "nanjing/StationParameterNotes";
    $("#form-SubStation-editParam").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            var formData = new FormData();
            var para = new Array();
            formData.append("stationID",$("#StationID").val());
            formData.append("stationCode",$("#StationCode").val());
            formData.append("tableName",$("#TableName").val());
            $("input[name='para']").each(function(){
                para.push($(this).val());
            });
            formData.append("paras",para);
            $.ajax({
                type: "post",
                url: prefix + "/editParmSave",
                data: formData,
                contentType: false,
                processData: false,
                dataType: "json",
                success: function (result) {
                    // console.log(result.msg);
                    if (result.code == web_status.SUCCESS){
                        alert(result.msg);
                        $.modal.close();
                    }else{
                        alert(result.msg);
                    }
                }
            });
        }
    }

    $(function() {
        var paramCount = $('#paraCount').val();
        // console.log(paramCount);
        var i =0;
        while(i<paramCount) {
            i++;
            createELm(i);
        }
    });

    //根据参数个数生成元素
    function createELm(num) {
        var formid = document.getElementById("form-SubStation-editParam");
        var doc = document.createElement("div");
        doc.setAttribute("class","form-group");
        formid.appendChild(doc);
        // var doc = document.getElementById("parameter");
        //添加lable
        var elm = document.createElement("label");
        elm.innerText="参数"+num+":";
        elm.setAttribute("class","col-sm-3 control-label");
        doc.appendChild(elm);
        //添加div
        var div1 = document.createElement("div");
        div1.setAttribute("class","col-sm-8");
        doc.appendChild(div1);
        // 在div中添加txt
        var txt = document.createElement("input");
        var name = "Para"+num;
        txt.setAttribute("name","para");
        txt.setAttribute("class","form-control");
        div1.appendChild(txt);
        //换行
        // var br = document.createElement("br");
        // doc.after(br);
        //填充参数数据
        var formData = new FormData();
        formData.append("stationID",$('#StationID').val());
        formData.append("para",name);
        $.ajax({
                type: "post",
                url: ctx + "nanjing/StationParameterNotes/getParamData",
                data: formData,
                contentType: false,
                processData: false,
                dataType: "json",
                success: function (result) {
                    // console.log(result.msg);
                    if (result.code == web_status.SUCCESS){
                        txt.value = result.msg;
                    }else{
                        txt.value = "";
                    }
                }
        });
    }
</script>
</body>
</html>