<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<script type="text/javascript">
    var str = ''
    layui.use(['table','form','layedit', 'laydate'], function(){
        var table = layui.table //生产数据表格
        ,form = layui.form;
        form.render();//表格渲染
        table.render({
        elem: '#longtable'
        ,title: '税金处理'
        ,id:'checktable'
        ,limit:Number.MAX_VALUE
        ,cols: [[ //生产表头
            {field:'itemName',title:'项目名称'}
            ,{field:'unitType',title:'税额扣减',edit: 'text'}

        ]]
        ,data:[ //数据导入
        <c:if test="${ not empty list}">
        <c:forEach items="${list}" var="data" varStatus="index">
        {
            "id":"${data.id}",
            "unitType": "${data.unitType}",
            "itemName": "${data.itemName}"
        },
        </c:forEach>
        </c:if>
        ]
        ,page: false
        ,done: function(res, curr, count){
            for(var p in res.data){
                str = str+res.data[p].id+',';
            }
         }
        });

        table.on('edit(longtable)', function(obj){ //注：edit是固定事件名，test是table原始容器的属性 lay-filter="对应的值"
            var field = obj.field;
            if(field == 'unitType'){
               var value = obj.value;
               if(isNaN(value)){ //判断输入是否是数字
                    layer.msg('请输入有效数字',{icon: 5,offset:['40%','40%']});
                     return false;
               }
            }
        });
    });
    function updateProject(){
        var nameString = "";
        $('table tr').each(function () {
            var unitType = $(this).find('td:eq(1)').text();
            if(unitType == ''){
                unitType = null
            }
            nameString += unitType+",";
        })
        var unitTypes = nameString.substring(5,nameString.length);
        var ids = str.substring(0,str.length-1);
         $.ajax({
            type:"post",
            url:"${ctx}/project/withhold",
            data:{'ids':ids,'unitTypes':unitTypes},
            success:function(result){
                layer.msg(result.msg, {icon: 6,offset:['38%','38%']},function () {
                parent.location.reload();
        });
    }
    });
}



</script>