<%@ page contentType="text/html;charset=UTF-8" %>
<script>
$(document).ready(function() {
	$('#erpTable').bootstrapTable({
		 
		  //请求方法
               method: 'post',
               //类型json
               dataType: "json",
               contentType: "application/x-www-form-urlencoded",
               //显示检索按钮
	       		showSearch: true,
               //显示刷新按钮
               showRefresh: true,
               //显示切换手机试图按钮
               showToggle: true,
               //显示 内容列下拉框
    	       showColumns: true,
    	       //显示到处按钮
    	       showExport: true,
    	       //显示切换分页按钮
    	       showPaginationSwitch: true,
    	       //显示详情按钮
    	       detailView: true,
    	       	//显示详细内容函数
	           detailFormatter: "detailFormatter",
    	       //最低显示2行
    	       minimumCountColumns: 2,
               //是否显示行间隔色
               striped: true,
               //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）     
               cache: false,    
               //是否显示分页（*）  
               pagination: true,   
                //排序方式 
               sortOrder: "asc",  
               //初始化加载第一页，默认第一页
               pageNumber:1,   
               //每页的记录行数（*）   
               pageSize: 5,
               //可供选择的每页的行数（*）    
               pageList: [5,10, 25, 50, 100],
               //这个接口需要处理bootstrap table传递的固定参数,并返回特定格式的json数据  
               url: "${ctx}/sg/financial/erpCredit/data",
               //默认值为 'limit',传给服务端的参数为：limit, offset, search, sort, order Else
               //queryParamsType:'',   
               ////查询参数,每次调用是会带上这个参数，可自定义                         
               queryParams : function(params) {
               	var searchParam = $("#searchForm").serializeJSON();
               	searchParam.pageNo = params.limit === undefined? "1" :params.offset/params.limit+1;
               	searchParam.pageSize = params.limit === undefined? -1 : params.limit;
               	searchParam.orderBy = params.sort === undefined? "" : params.sort+ " "+  params.order;
                   return searchParam;
               },
               //分页方式：client客户端分页，server服务端分页（*）
               sidePagination: "server",
               contextMenuTrigger:"right",//pc端 按右键弹出菜单
               contextMenuTriggerMobile:"press",//手机端 弹出菜单，click：单击， press：长按。
               contextMenu: '#context-menu',
               onContextMenuItem: function(row, $el){
                   if($el.data("item") == "edit"){
                   		edit(row.id);
                   }else if($el.data("item") == "view"){
                       view(row.id);
                   } else if($el.data("item") == "delete"){
                        jp.confirm('确认要删除记录吗？', function(){
                       	jp.loading();
                       	jp.get("${ctx}/sg/financial/erpCredit/delete?id="+row.id, function(data){
                   	  		if(data.success){
                   	  			$('#erpTable').bootstrapTable('refresh');
                   	  			jp.success(data.msg);
                   	  		}else{
                   	  			jp.error(data.msg);
                   	  		}
                   	  	})
                   	   
                   	});
                      
                   } 
               },
              
               onClickRow: function(row, $el){
               },
               	onShowSearch: function () {
			$("#search-collapse").slideToggle();
		},
               columns: [{
		        checkbox: true
		       
		    }
			,{
		        field: 'itemId',
		        title: '项目定义编码',
		        sortable: true,
		        sortName: 'itemId'
		        ,formatter:function(value, row , index){

			   if(value == null || value ==""){
				   value = "-";
			   }
			   <c:choose>
				   <c:when test="${fns:hasPermission('sg:financial:erpCredit:edit')}">
				      return "<a href='javascript:edit(\""+row.id+"\")'>"+value+"</a>";
			      </c:when>
				  <c:when test="${fns:hasPermission('sg:financial:erpCredit:view')}">
				      return "<a href='javascript:view(\""+row.id+"\")'>"+value+"</a>";
			      </c:when>
				  <c:otherwise>
				      return value;
			      </c:otherwise>
			   </c:choose>

		        }
		       
		    }
			,{
		        field: 'itemName',
		        title: '项目名称',
		        sortable: true,
		        sortName: 'itemName'
		       
		    }
			,{
		        field: 'actualInvestment',
		        title: '实际投资',
		        sortable: true,
		        sortName: 'actualInvestment'
		       
		    }
			,{
		        field: 'transferAssets',
		        title: '移交生产的资产总值',
		        sortable: true,
		        sortName: 'transferAssets'
		       
		    }
                   ,{
                       field: 'consBuildingFee',
                       title: '建筑费',
                       sortable: true,
                       sortName: 'consBuildingFee'

                   }
                   ,{
                       field: 'consInstallFee',
                       title: '安装费',
                       sortable: true,
                       sortName: 'consInstallFee'

                   }
                   ,{
                       field: 'consTotalFee',
                       title: '施工费:合计',
                       sortable: true,
                       sortName: 'consTotalFee'

                   }
                   ,{
                       field: 'otherSupervisorFee',
                       title: '监理费',
                       sortable: true,
                       sortName: 'otherSupervisorFee'

                   }
                   ,{
                       field: 'otherDesignFee',
                       title: '设计费',
                       sortable: true,
                       sortName: 'otherDesignFee'

                   }
                   ,{
                       field: 'otherBeWorkFee',
                       title: '项目前期工作费',
                       sortable: true,
                       sortName: 'otherBeWorkFee'

                   }
                   ,{
                       field: 'otherBuildLoan',
                       title: '建设期贷款利息',
                       sortable: true,
                       sortName: 'otherBuildLoan'

                   }
                   ,{
                       field: 'otherLineDamages',
                       title: '线路施工赔偿费',
                       sortable: true,
                       sortName: 'otherLineDamages'

                   }
                   ,{
                       field: 'otherLegalManage',
                       title: '法人管理费',
                       sortable: true,
                       sortName: 'otherLegalManage'

                   }
                   ,{
                       field: 'otherTotalFee',
                       title: '其他费用:合计',
                       sortable: true,
                       sortName: 'otherTotalFee'

                   }
                   ,{
                       field: 'tenKvModel',
                       title: '10KV电缆、架空导线型号',
                       sortable: true,
                       sortName: 'tenKvModel'

                   }
                   ,{
                       field: 'tenKvUnit',
                       title: '单位',
                       sortable: true,
                       sortName: 'tenKvUnit'

                   }
                   ,{
                       field: 'tenKvLength',
                       title: '长度',
                       sortable: true,
                       sortName: 'tenKvLength'

                   }
                   ,{
                       field: 'tenKvLineLength',
                       title: '10KV线路长度（KM)',
                       sortable: true,
                       sortName: 'tenKvLineLength'

                   }
                   ,{
                       field: 'tenKvItsLine',
                       title: '其中：10KV线路',
                       sortable: true,
                       sortName: 'tenKvItsLine'

                   }
                   ,{
                       field: 'tenKvItesFhvFollow',
                       title: '其中：400V及以下',
                       sortable: true,
                       sortName: 'tenKvItesFhvFollow'

                   }
                   ,{
                       field: 'theInputTax',
                       title: '进项税额',
                       sortable: true,
                       sortName: 'theInputTax'

                   }
                   ,{
                       field: 'supplierName',
                       title: '供应商名称',
                       sortable: true,
                       sortName: 'supplierName'

                   }
                   ,{
                       field: 'cableTube',
                       title: '电缆管信息',
                       sortable: true,
                       sortName: 'cableTube'

                   }
		     ]
		
		});
		
		  
	  if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){//如果是移动端

		 
		  $('#erpTable').bootstrapTable("toggleView");
		}
	  
	  $('#erpTable').on('check.bs.table uncheck.bs.table load-success.bs.table ' +
                'check-all.bs.table uncheck-all.bs.table', function () {
            $('#remove').prop('disabled', ! $('#erpTable').bootstrapTable('getSelections').length);
            $('#view,#edit').prop('disabled', $('#erpTable').bootstrapTable('getSelections').length!=1);
        });
    	var str = "";
		$("#btnImport").click(function(){
			jp.open({
			    type: 2,
                area: [500, 200],
                auto: true,
			    title:"导入数据",
			    content: "${ctx}/tag/importExcel" ,
			    btn: ['确定', '关闭'],
				// btn1: function(index, layero){
				// 	  jp.downloadFile('${ctx}/sg/financial/erpCredit/import/template');
				//   },
			    btn1: function(index, layero){
						var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
						iframeWin.contentWindow.importExcel('${ctx}/sg/financial/erpCredit/import', function (data) {
                            // if (data.success) {
                            //     jp.success(data.msg);
                            //     jp.downloadFile('${ctx}/sg/financial/erpCredit/export');
                            //     refresh();
                            //     // if(data.flag){
                            //      //    jp.error("导入失败");
                            //      //    jp.openViewDialog(data.msg, "${ctx}/sg/financial/erpCredit/tips", '800px', '500px');
								// // }
                            // } else if (data.flag) {
                            //     jp.error("导入失败");
                            //     jp.openViewDialog(data.msg, "${ctx}/sg/financial/erpCredit/tips", '800px', '500px');
                            // } else if (data.noStatus) {
                            //     jp.error("导入失败");
                            //     top.layer.open({
                            //         type: 2,
                            //         area: ['800px', '500px'],
                            //         title: data.msg,
                            //         maxmin: true, //开启最大化最小化按钮
                            //         content: '${ctx}/sg/financial/erpCredit/tips1' ,
                            //         btn: ['继续操作', '停止操作'],
                            //         btn1: function(index1, layero){
                            //             jp.downloadFile('${ctx}/sg/financial/erpCredit/export');
                            //             jp.close(index1);
                            //         },
                            //         btn2: function(index1, layero){
                            //         	window.location.href="${ctx}/sg/financial/erpCredit/clearFileAllSession";
                            //             // jp.downloadFile('${ctx}/sg/financial/erpCredit/clearFileAllSession');
                            //             location.reload();
                            //             jp.close(index1);
                            //         }
                            //     });
                            // }else if (data.yesStatus){
                            //     jp.error(data.msg);
                            //     jp.downloadFile('${ctx}/sg/financial/erpCredit/exportYesStatus');
                            // }else {
                            //     jp.error(data.msg);
                            // }
                            // jp.close(index);
                            if (data.success) {
                                jp.success(data.msg);
                                jp.downloadFile('${ctx}/sg/financial/erpCredit/export','finalAccount');//给个name是为了能够在某些条件下下载两个文件
                                // refresh();
                                if(data.flag){
                                    jp.openViewDialog(data.msg, "${ctx}/sg/financial/erpCredit/tips", '800px', '500px');
                                }else if(data.yesStatus){
                                    jp.error(data.msg);
                                    // jp.alert(data.msg);
                                    jp.downloadFile('${ctx}/sg/financial/erpCredit/exportYesStatus','errorMsg');
                                }else if(data.noStatus){
                                    top.layer.open({
                                        type: 2,
                                        area: ['800px', '500px'],
                                        title: data.msg,
                                        maxmin: true, //开启最大化最小化按钮
                                        content: '${ctx}/sg/financial/erpCredit/tips1' ,
                                        btn: ['确定'],
                                        btn1: function(index1, layero){
                                            window.location.href="${ctx}/sg/financial/erpCredit/clearFileAllSession";
                                            // jp.downloadFile('${ctx}/sg/financial/erpCredit/clearFileAllSession');
                                            // location.reload();
                                            jp.close(index1);
                                        },
                                    });
                                }
                            }else {
                                jp.error(data.msg);
                                jp.alert(data.msg);
                            }
                            jp.close(index);
                        });//调用保存事件
                    return false;
				  },

				  btn2: function(index){
					  jp.close(index);
	    	       }
			});
            // getExport(flag,str)
		});
	  $("#export").click(function(){//导出Excel文件
			jp.downloadFile('${ctx}/sg/financial/erpCredit/exportList');
	  });
	  $("#search").click("click", function() {// 绑定查询按扭
		  $('#erpTable').bootstrapTable('refresh');
		});
	 
	 $("#reset").click("click", function() {// 绑定查询按扭
		  $("#searchForm  input").val("");
		  $("#searchForm  select").val("");
		   $("#searchForm  .select-item").html("");
		  $('#erpTable').bootstrapTable('refresh');
		});
		
				$('#beginInDate').datetimepicker({
					 format: "YYYY-MM-DD HH:mm:ss"
				});
				$('#endInDate').datetimepicker({
					 format: "YYYY-MM-DD HH:mm:ss"
				});
		
	});
		
  function getIdSelections() {
        return $.map($("#erpTable").bootstrapTable('getSelections'), function (row) {
            return row.id
        });
    }
  
  function deleteAll(){

		jp.confirm('确认要删除该记录吗？', function(){
			jp.loading();  	
			jp.get("${ctx}/sg/financial/erpCredit/deleteAll?ids=" + getIdSelections(), function(data){
         	  		if(data.success){
         	  			$('#erpTable').bootstrapTable('refresh');
         	  			jp.success(data.msg);
         	  		}else{
         	  			jp.error(data.msg);
         	  		}
         	  	})
		})
  }
  
    //刷新列表
  function refresh() {
      $('#erpTable').bootstrapTable('refresh');
  }
  function add(){
	  jp.openSaveDialog('新增记录', "${ctx}/sg/financial/erpCredit/form",'800px', '500px');
      // jp.openSaveDialog('新增记录', "${ctx}/sg/financial/erpCredit/tips",'800px', '500px');
  }
  
   function edit(id){//没有权限时，不显示确定按钮
       if(id == undefined){
	      id = getIdSelections();
	}
	jp.openSaveDialog('编辑记录', "${ctx}/sg/financial/erpCredit/form?id=" + id, '800px', '500px');
  }

  
 function view(id){//没有权限时，不显示确定按钮
      if(id == undefined){
             id = getIdSelections();
      }
        jp.openViewDialog('查看表单', "${ctx}/sg/financial/erpCredit/form?id=" + id, '800px', '500px');
 }
  
  
  
  
		   
  function detailFormatter(index, row) {
	  var htmltpl =  $("#testDataMain1ChildrenTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
	  var html = Mustache.render(htmltpl, {
			idx:row.id
		});
	  $.get("${ctx}/sg/financial/erpCredit/detail?id="+row.id, function(erpCredit){
    	var testDataMain1Child1RowIdx = 0, testDataMain1Child1Tpl = $("#testDataMain1Child1Tpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
		var data1 =  erpCredit.erpCreditChild1s;
		if(data1!=null){
			for (var i=0; i<data1.length; i++){
				// data1[i].dict = {};
				// data1[i].dict.isHave = jp.getDictLabel(${fns:toJson(fns:getDictList('yes_no'))}, data1[i].isHave, "-");
				addRow('#testDataMain1Child-'+row.id+'-1-List', testDataMain1Child1RowIdx, testDataMain1Child1Tpl, data1[i]);
				testDataMain1Child1RowIdx = testDataMain1Child1RowIdx + 1;
			}
		}
				
    	var testDataMain1Child2RowIdx = 0, testDataMain1Child2Tpl = $("#testDataMain1Child2Tpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
		var data2 =  erpCredit.erpCreditChild2s;
    	if(data2!=null){
			for (var i=0; i<data2.length; i++){
				// data2[i].dict = {};
				// data2[i].dict.isHave = jp.getDictLabel(${fns:toJson(fns:getDictList('yes_no'))}, data2[i].isHave, "-");
				addRow('#testDataMain1Child-'+row.id+'-2-List', testDataMain1Child2RowIdx, testDataMain1Child2Tpl, data2[i]);
				testDataMain1Child2RowIdx = testDataMain1Child2RowIdx + 1;
			}
		}
      })
     
        return html;
    }
  
	function addRow(list, idx, tpl, row){
		$(list).append(Mustache.render(tpl, {
			idx: idx, delBtn: true, row: row
		}));
	}
			
</script>
<script type="text/template" id="testDataMain1ChildrenTpl">//<!--
	<div class="tabs-container">
		<ul class="nav nav-tabs">
				<li class="active"><a data-toggle="tab" href="#tab-{{idx}}-1" aria-expanded="true">设备费</a></li>
				<li><a data-toggle="tab" href="#tab-{{idx}}-2" aria-expanded="true">材料费</a></li>
		</ul>
		<div class="tab-content">
				 <div id="tab-{{idx}}-1" class="tab-pane fade in active">
						<table class="ani table">
						<thead>
							<tr>
								<th width="14%">物料描述</th>
								<th width="4%">单位</th>
								<th width="4%">台数</th>
								<th width="6%">总容量(千伏安)</th>
								<th width="72%">入账金额(不含税价)</th>
							</tr>
						</thead>
						<tbody id="testDataMain1Child-{{idx}}-1-List">
						</tbody>
					</table>
				</div>
				<div id="tab-{{idx}}-2" class="tab-pane fade">
					<table class="ani table">
						<thead>
							<tr>
                                <th width="15%">物料描述</th>
                                <th width="85%">入账金额(不含税价)</th>
							</tr>
						</thead>
						<tbody id="testDataMain1Child-{{idx}}-2-List">
						</tbody>
					</table>
				</div>
		</div>//-->
	</script>
	<script type="text/template" id="testDataMain1Child1Tpl">//<!--
				<tr>
					<td>
						{{row.eqmMaterialDetails1}}
					</td>
					<td>
						{{row.eqmUnit}}
					</td>
					<td>
						{{row.eqmNumbers}}
					</td>
					<td>
						{{row.eqmTotalCapacity}}
					</td>
					<td>
						{{row.eqmBookedFee1}}
					</td>
				</tr>//-->
	</script>
	<script type="text/template" id="testDataMain1Child2Tpl">//<!--
				<tr>
					<td>
						{{row.eqmMaterialDetails2}}
					</td>
					<td>
						{{row.mtlBookedFee2}}
					</td>
				</tr>//-->
	</script>

