123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 |
- /**
- * Created by Syusuke on 2017/3/17.
- */
- function getQueryString(key){
- var reg = new RegExp("(^|&)"+key+"=([^&]*)(&|$)");
- var result = window.location.search.substr(1).match(reg);
- return result?decodeURIComponent(result[2]):null;
- }
- //---------------------------------------------------页面跳转
- var params = {}
- $("#dinge").click(function(){
- $(this).attr('href', "/rationLibEditor/rationLib" + "?params=" + JSON.stringify(params))
- })
- $("#gongliao").click(function(){
- $(this).attr('href', "/rationLibEditor/gongliao" + "?params=" + JSON.stringify(params))
- });
- //----------------------------------------------------页面初始化
- $(document).ready(function(){
- initParam();
- mkRationItemSpread();
- });
- function initParam(){
- var rationLibName = getQueryString("repository");//获取定额库参数
- if(rationLibName) {
- params.realLibName = LibName;
- getRationTree();
- } else{
- params = JSON.parse(getQueryString("params"));
- getRationTree();
- }
- }
- //---------------------------------------------------初始化章节树界面
- function getRationTree(){
- $.ajax({
- type:"POST",
- url:"api/getRationTree",
- data:{"rationLibName": params.realLibName},
- dataType:"json",
- cache:false,
- timeout:20000,
- success:function(result,textStatus,status){
- if(status.status == 200) createRationTree(result.data);//根据返回的全部定额章节对象,构架树。
- else{
- treeObj = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
- saveTempTree();
- }
- },
- error:function(err){
- alert(err.responseText.error)
- }
- })
- }
- //根据返回的节点集合构建树节点
- function createRationTree(obj){
- var treeArr;
- treeArr = makeNodes(obj);
- var maxIDNode = obj.reduce(function(a,b){
- return (a.id> b.id)?a:b;
- });
- newCount = maxIDNode.id;
- treeObj = $.fn.zTree.init($("#treeDemo"), setting, treeArr);
- }
- function makeNodes(obj){
- var arr=[];
- arr = obj.filter(function(x){
- return x.parentId==0
- })
- arr.forEach(function(x){
- x.id = x.sectionId;
- x.pId = x.parentId;
- x.nId = x.nextSiblingId;
- x.name = x.name;
- x.isParent = true
- x.lev = 0
- });
- arr = sortArray(arr);
- for(var i=0;i<arr.length;i++){
- var L1 = [];
- L1 = obj.filter(function(x){
- return x.parentId ==arr[i].id;
- });
- L1.forEach(function(x){
- x.id = x.sectionId;
- x.pId = x.parentId;
- x.nId = x.nextSiblingId;
- x.name = x.name;
- x.isParent = true
- x.lev = 1
- });
- L1=sortArray(L1);
- for(var j=0; j<L1.length;j++){
- var L2 = [];
- L2 =obj.filter(function(x){
- return x.parentId == L1[j].id;
- })
- L2.forEach(function(x){
- x.id = x.sectionId;
- x.pId = x.parentId;
- x.nId = x.nextSiblingId;
- x.name = x.name;
- x.isParent = false;
- x.lev = 2
- })
- L2=sortArray(L2)
- L1[j].children = L2;
- }
- arr[i].children = L1;
- }
- return arr;
- }
- function sortArray(arr){
- var a = [];
- for(var i=0;i<arr.length;i++)
- if (arr[i].nextSiblingId == -1)
- a.push(arr[i])
- for(; a.length < arr.length;){
- for(var j=0;j<arr.length;j++) {
- if (arr[j].nextSiblingId == a[0].sectionId)
- {a.unshift(arr[j]); break;}
- }
- }
- return a ;
- }
- //新建的定额库保存模板节点
- function saveTempTree(){
- var N = []
- for(i=0;i<zNodes.length;i++){
- var node ={}
- node.sectionId = zNodes[i].id;
- node.parentId = zNodes[i].pId;
- node.nextSiblingId = zNodes[i].nId;
- node.name =zNodes[i].name;
- N.push(node);
- }
- var rationTempTree = JSON.stringify(N)
- $.ajax({
- type:"POST",
- url:"api/saveTempRationTree",
- data:{"rationName":rationLibName,"rationTempTree":rationTempTree},
- dataType:"json",
- cache:false,
- timeout:1000,
- success:function(result,textStatus,status){},
- error:function(){}
- })
- }
- //--------------------------------------------------------树处理事件
- var newCount = 13;
- //新增树节点
- function addHoverDom(treeId, treeNode) {
- var sObj = $("#" + treeNode.tId + "_span");
- if (treeNode.editNameFlag || $("#addBtn_"+treeNode.tId).length>0||(treeNode.level==2)) return;
- var addStr = "<span class='button add' id='addBtn_" + treeNode.tId
- + "' title='add node' onfocus='this.blur();'></span>";
- sObj.after(addStr);
- var btn = $("#addBtn_"+treeNode.tId);
- if (btn) btn.bind("click", function(){
- var zTree = $.fn.zTree.getZTreeObj("treeDemo");
- if((treeNode.level==0)){
- var newNode = zTree.addNodes(treeNode, {id:(++newCount), pId:treeNode.id,nId:-1,isParent:true, name:"请输入章节名称",children:[]});
- }
- else{
- var newNode = zTree.addNodes(treeNode, {id:(++newCount), pId:treeNode.id,nId:-1,isParent:false, name:"请输入章节名称"});
- }
- saveNewSection(newNode[0]);
- var pnode = newNode[0].getPreNode()
- if(pnode){
- pnode.nId = newNode[0].id;
- saveNewSection(pnode);
- }
- return false;
- });
- };
- //保存新增的节点
- function saveNewSection(n){
- var sec={};
- sec.sectionId = n.id;
- sec.parentId = n.pId;
- sec.nextSiblingId = n.nId;
- sec.name = n.name;
- var section = JSON.stringify(sec);
- $.ajax({
- type:"POST",
- url:"api/addSection",
- data:{"rationLibName":params.realLibName,"rationSection":section},
- dataType:"json",
- cache:false,
- timeout:1000,
- success:function(result,textStatus,status){
- },
- error:function(){
- }
- })
- }
- //编辑树节点事件(添加节点到数据库)
- function onRename(e, treeId, treeNode, isCancel) {
- saveNewSection(treeNode);
- }
- function onRemove(e, treeId, treeNode) {
- var id = treeNode.id;
- var pNodes = treeNode.getParentNode().children;
- for(var i=0;i<pNodes.length;i++){
- if(pNodes[i].nId==id){
- pNodes[i].nId = -1;
- saveNewSection(pNodes[i]);
- }
- }
- $.ajax({
- type:"POST",
- url:"api/deleteSection",
- data:{"rationLibName":params.realLibName,"sectionID": treeNode.id},
- dataType:"json",
- cache:false,
- timeout:1000,
- success:function(result,textStatus,status){
- //if(result){
- // caseDeleteTreeNode(result.data)
- //}
- },
- error:function(){
- }
- })
- removeSection(id)
- $("#rationTbody").html("");
- $("#rationGLJTbody").html("");
- }
- //--------------------------------------------------------定额spreadjs
- var spSetting_ration = {
- spType:"Ration",
- header:[
- {headerName:"编码",headerWidth:120,data:"rationCode"},
- {headerName:"名称",headerWidth:400,data:"rationName"},
- {headerName:"单位",headerWidth:120,data:"unit"},
- {headerName:"基价",headerWidth:120,data:"basePrice"},
- {headerName:"显示名称(以%s表示参数)",headerWidth:450,data:"caption"},
- {headerName:"取费专业",headerWidth:120,data:"feeType"}
- ],
- view:{
- comboBox:[
- {row:-1,col:2,rowCount:-1,colCount:1}
- ],
- lockedCells:[
- {row:-1,col:3,rowCount:-1, colCount:1}
- ]
- }
- };
- var spSetting_rationGLJ = {
- spType:"RationGLJ",
- header:[
- {headerName:"编码",headerWidth:160},
- {headerName:"名称",headerWidth:400},
- {headerName:"单位",headerWidth:160},
- {headerName:"单位基价",headerWidth:160},
- {headerName:"定额消耗",headerWidth:160},
- {headerName:"类型",headerWidth:160},
- {headerName:"操作",headerWidth:130}
- ],
- view:{
- comboBox:[],
- lockedCells:[
- {row:-1,col:1,rowCount:-1, colCount:1},
- {row:-1,col:2,rowCount:-1, colCount:1},
- {row:-1,col:3,rowCount:-1, colCount:1},
- {row:-1,col:5,rowCount:-1, colCount:1},
- {row:-1,col:6,rowCount:-1, colCount:1}
- ]
- }
- };
- function mkRationItemSpread(){
- var rationSpread = $.fn.Spread.init($("#rationItemsSheet"),spSetting_ration);
- var rationGLJSpread = $.fn.Spread.init($("#rationGLJSheet"),spSetting_rationGLJ);
- }
|