123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- /**
- * 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(){
- rationOprObj.initParam();
- mkRationItemSpread();
- });
- var rationOprObj = {
- initParam : function() {
- var me = this, rationLibName = getQueryString("repository");//获取定额库参数
- if (rationLibName) {
- params.realLibName = rationLibName;
- me.getRationTree();
- } else{
- params = JSON.parse(getQueryString("params"));
- me.getRationTree();
- }
- },
- getRationTree: function(){
- var me = this;
- $.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) {
- me.createRationTree(result.data);
- }
- },
- error:function(err){
- alert(err.responseText.error)
- }
- })
- },
- createRationTree: function(sourceData){
- var treeArr = tree_Data_Helper.buildTreeNodeDirectly(sourceData);
- treeObj = $.fn.zTree.init($("#treeDemo"), setting, treeArr);
- }
- }
- function addRootNode(){
- var rawNode = {ParentID: -1, NextSiblingID: -1, name: "新增节点"};
- addNewNode(rawNode, function(err, rst){
- if (!(err)) {
- var newNodes = [], isSilent = false;
- newNodes.push({ rationRepId: rst.data.rationRepId, ID: rst.data.ID, ParentID:-1, NextSiblingID:-1, name:"新增节点",isParent:true, items:[]});
- if (treeObj) {
- treeObj.addNodes(null, -1, newNodes, isSilent);
- } else {
- treeObj = $.fn.zTree.init($("#treeDemo"), setting, newNodes);
- }
- }
- });
- }
- //--------------------------------------------------------树处理事件
- 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:"请输入章节名称",items:[]});
- }
- 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 addNewNode(rawNode, callback) {
- $.ajax({
- type:"POST",
- url:"api/createNewNode",
- data:{"rationLibName":params.realLibName,"rawNodeData": JSON.stringify(rawNode)},
- dataType:"json",
- cache:false,
- timeout:1000,
- success: function(result,textStatus,status){
- callback(false, result);
- },
- error:function(err){
- callback(err);
- }
- })
- };
- //保存新增的节点
- 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().items;
- 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);
- }
|