<%--
  Created by IntelliJ IDEA.
  User: user
  Date: 2019/8/19
  Time: 15:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
    <title>修改</title>
    <link rel="stylesheet" href="${ctxp}/static/plugin/assets/layui/css/layui.css">
    <link rel="stylesheet" href="${ctxp}/static/plugin/assets/common.css"/>
    <script type="text/javascript" src="${ctxp}/static/plugin/assets/jquery-3.2.1.min.js"></script>
    <script src="${ctxp}/static/plugin/assets/layui/layui.js"></script>
</head>
<style>
    .layui-input{height: 28px;margin-top: 6px;line-height: 28px/*background: whitesmoke;*/}
    .layui-form-label { float: left;display: block;padding: 9px 15px;width: 100px;font-weight: 400;line-height: 20px;text-align: right;}
    .layui-table-view .layui-table {width:100%}
    .mydiv{padding: 5px 7px;border: whitesmoke;line-height: 98%;margin-top: 2px}
</style>
<body>
<c:if test="${ not empty list}">
    <c:forEach items="${list}" var="data" varStatus="index">
<form id="updateForm">
    <div class="layui-form-item" style="margin-top: 10px;">
        <input name="id" value="${data.id}" hidden>
        <div class="layui-inline">
            <label class="layui-form-label">*工程名称</label>
            <div class="layui-input-inline">
                <input type="text" id="projectName" name="projectName"  autocomplete="off" class="layui-input" value="${data.projectName}">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">*工程编号</label>
            <div class="layui-input-inline">
                <input type="text" id="projectNo" name="projectNo"  autocomplete="off" class="layui-input" value="${data.projectNo}">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">创建时间</label>
            <div class="layui-input-inline">
                <input style=" background: whitesmoke;" type="text" name="beginUpdate"  readonly="readonly"  placeholder="yyyy-MM-dd" autocomplete="off"
                       class="layui-input" value="<fmt:formatDate value="${data.createDate}" pattern="yyyy/MM/dd "/>">
            </div>
        </div>
    </div>
    <input style="display: none" id="inputId" name="ids" value="">
    <input style="display: none" id="inputUnits" name="units" value="">
</form>
<div style="margin: 20px;">
    <fieldset class="layui-elem-field layui-field-title">
        <legend style="font-size: 15px;">结算书信息</legend>
    </fieldset>
    <table class="layui-hide" id="updatetable" lay-filter="updatetable"></table>
</div>
<input id="updatebtn" type="button" onclick="updateProject()" style="display: none" />
<script>
    layui.use(['table','form','layedit', 'laydate'], function(){
        var table = layui.table
            ,form = layui.form
            ,laydate = layui.laydate;
        laydate.render({
            elem: '#beginUpdate'
        });
        laydate.render({
            elem: '#endUpdate'
        });
        //日期
        form.render();
        table.render({
            elem: '#updatetable'
            ,cols: [[
                {field:'xmmc',title:'结算书名称'}
                ,{field:'sgdw',title:'供应商',templet:function(d){
                        var updateXml= "<div contenteditable='true' class='mydiv1 mydiv'>"+d.sgds+"</div>"+
                            "<div style='display: none' class='mydiv2'>"+d.id+"</div>";
                        return updateXml;
                    }}
                ,{field:'xmlx',title:'结算书类型'}
                // ,{field:'xmbh',title:'结算书编号'}
                ,{field:'op',align:'center',title:"操作",templet:function(d){
                        ////对操作进行初始化
                        var xml = "<a  class='layui-btn layui-btn-xs' style='margin-top: 3px' onclick=\"view( '" + d.id +" ','" + d.type + "')\">编辑</a>";
                        return xml;
                    }}
            ]]
            ,data:[
                <c:if test="${ not empty data.wbsItems}">
               <c:forEach items="${data.wbsItems}" var="data1" varStatus="index">
                {
                    "id":"${data1.id}",
                    "type":"${data1.type}",
                    "xmmc": "${data1.itemName}",
                    "sgds": "${data1.unit}",
                    "xmlx":<c:if test="${data1.type eq '1'}">"架空线路"</c:if><c:if test="${data1.type eq '2'}">"电缆线路"</c:if><c:if test="${data1.type eq '3'}">"变电站工程"</c:if>,
                    <%--"xmbh":"${data1.itemNo}"--%>
                },
                </c:forEach>
                </c:if>
            ]
            ,page: true
        });
        table.on('tool(updatetable)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event == 'update'){
//		     alert(data.id);
            }
        });
    });
</script>
<script>
    function updateProject(){
        if ($("#projectName").val()==null||$("#projectName").val()==""){
            layer.msg("请输入工程名称",{icon:3});
            throw SyntaxError;
        }
        if($("#projectNo").val()==null||$("#projectNo").val()==""){
            layer.msg("请输入工程编号",{icon:3});
            throw SyntaxError;
        }
        var div_value =  $(".mydiv1");
        var nameString = "";
        for (var i = 0; i < div_value.length; i++) {
            nameString+=div_value[i].innerText+",";
        }
        var name = nameString.substring(0,nameString.length-1);


        var div_value2 = $(".mydiv2");
        var idString = "";
        for (var i = 0; i < div_value2.length; i++) {
            idString+=div_value2[i].innerText+",";
        }
        var id = idString.substring(0,idString.length-1);

        $("#inputId").val(id);
        $("#inputUnits").val(name);
        $.ajax({
            type:"post",
            url:"${ctx}/project/update",
            // data:JSON.stringify({id:newid2,type:xmmc2,fee:fyje2}),
            data:$('#updateForm').serialize(),
            success:function(result){
                layer.msg(result.msg, {icon: 6,offset:['38%','38%']},function () {
                    parent.location.reload();
                });
            }
        });
    }
    function view(id,type) {
        var url = '${ctx}/jkxl/list?id='+id+'&type='+type;
        parent.location.href=url;
    }
</script>
    </c:forEach>
</c:if>
</body>
</html>
