define(function (require, exports, module) { //引入业务类基类 var BaseBiz = require('apps/rht/base/rhtBiz'); var service = require('./bas0405service'); var Add = require('./Add'); var selectedTreeNode; /** * 定义业务类对象 * @param vm 界面相关ViewModule */ function Biz(vm) { //继承第一步,构造继承 BaseBiz.call(this, vm); } //继承第二步,方法继承 inherits(Biz, BaseBiz); /** * @description 点击【增加】按钮 */ function btnAddClick() { if(selectedTreeNode == null) { Store.messager.err('请选择父节点!'); return false; } if(selectedTreeNode.islast == '1') { Store.messager.err('末级地区不能添加子地区!'); return false; } add = new Add(selectedTreeNode, 0); add.callback = function () { clearSel(); initTree($('#areaTree')); } add.open(); }; /** * @description 点击【编辑】按钮 */ function btnEditClick() { if(selectedTreeNode == null) { Store.messager.err('请选择一个节点!'); return false; } if(selectedTreeNode.areacode == '*') { return false; } add = new Add(selectedTreeNode, 1); add.callback = function () { clearSel(); initTree($('#areaTree')); } add.open(); }; /** * @description 点击【删除】按钮 */ function btnDelClick() { if(selectedTreeNode == null) { Store.messager.err('请选择一个节点!'); return false; } if(selectedTreeNode.isParent) { Store.messager.err('要删除的节点存在下级节点,不能删除!'); return false; } Store.messager.confirm('确认要删除节点吗?', function (isOK) { //点击【取消】跳出 if (!isOK) { return true; } else { //点击【确定】删除 var ret = service.DeleteArea(selectedTreeNode.areacode); if(ret.result != 1) { Store.messager.err('删除失败!' + ret.message); return false; } clearSel(); initTree($('#areaTree')); } }); }; /** * @description 点击树时 * @param {*} e * @param {*} treeId 树ID * @param {*} treeNode 节点ID */ function onNodeTreeClick(e, treeId, treeNode) { selectedTreeNode = treeNode; var ret = service.GetChildArea(selectedTreeNode.areacode); $('#childArea').datagrid({ data: ret.data }); }; /** * @description 清除选中信息和子区域信息 * @param {*} treeObj */ function clearSel() { selectedTreeNode = null; $('#childArea').datagrid({ data: [] }); } /** * @description 初始化树状列表 * @param {*} treeObj 树对象 */ function initTree(treeObj) { //树选项 var treeSetting = { view: { selectedMulti: false //允许多选 }, // check: { // enable: true, //允许勾选 // chkboxType: { // "Y": "s", // "N": "s" // } //父节点与子节点勾选关系 // }, data: { simpleData: { enable: true //使用简单JSON构建树 } }, callback: { onClick: onNodeTreeClick, //单击时响应事件 } }; //调用插件获取组织信息并组装为树的节点信息 var areaTreeInfo = service.GetAreaTree(); var zTreeNodes = []; if (areaTreeInfo.result != 1) { Store.MESSAGER.err(areaTreeInfo.message); } else { for (var i = 0, len = areaTreeInfo.data.length; i <= len - 1; i++) { zTreeNodes.push({ id: areaTreeInfo.data[i].id, //节点ID pId: areaTreeInfo.data[i].pid, //父节点ID areacode: areaTreeInfo.data[i].areacode, //地区编码 areaname: areaTreeInfo.data[i].areaname, //地区名称 name: areaTreeInfo.data[i].areacode + '-' + areaTreeInfo.data[i].areaname, //节点显示信息 islast: areaTreeInfo.data[i].islast, //是否末级 remark: areaTreeInfo.data[i].remark, //备注 open: true //是否展开 }); }; }; //创建树 $.fn.zTree.init(treeObj, treeSetting, zTreeNodes); }; /** * @description 初始化完毕 */ Biz.prototype.initCompleted = function () { $('#childArea').datagrid({ columns:[[ {field:'areacode',title:'地区编码',width:100}, {field:'areaname',title:'地区名称',width:100}, {field:'islast',title:'是否末级',width:100, formatter: function(value,row,index){ if (row.islast == '1'){ return '是'; } else { return '否'; } } }, {field:'remark',title:'备注',width:100} ]], striped:true, ctrlSelect:true }); //对页面中的元素进行事件绑定 var btnAdd = document.getElementById('btnAdd'); var btnEdit = document.getElementById('btnEdit'); var btnDel = document.getElementById('btnDel'); btnAdd.addEventListener('click', btnAddClick, false); btnEdit.addEventListener('click', btnEditClick, false); btnDel.addEventListener('click', btnDelClick, false); //初始化组织树 initTree($('#areaTree')); }; return Biz; });