| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- /**
- * 菜单设置
- * */
- var rowData = {}
- var pidText = ''
- var treeGrid
- var config = {
- id: "tg1",
- width: "800",
- renderTo: "gridList",
- headerAlign: "left",
- headerHeight: "30",
- dataAlign: "left",
- indentation: "20",
- folderOpenIcon: "../public/treeGrid/images/folderOpen.gif",
- folderCloseIcon: "../public/treeGrid/images/folderClose.gif",
- defaultLeafIcon: "../public/treeGrid/images/defaultLeaf.gif",
- hoverRowBackground: "false",
- folderColumnIndex: "0",
- itemClick: "itemClickEvent",
- columns: [
- {
- headerText: "维修项目名称",
- dataField: "wxcenter",
- headerAlign: "center",
- handler: "customOrgName"
- },
- {
- headerText: "项目科室",
- dataField: "name",
- headerAlign: "center",
- handler: "customOrgName"
- },
- {
- headerText: "操作",
- headerAlign: "center",
- dataAlign: "center",
- width: "100",
- handler: "customLook"
- }
- ],
- data: []
- };
- $("#sc_btns").click(function() {
- gridList();
- });
- $(function() {
- $('.tool_bars').authorizeButton();
- treeGrid = new TreeGrid(config);
- gridList();
- });
- function itemClickEvent(id, index, data){
- jQuery("#currentRow").val(id + ", " + index + ", " + TreeGrid.json2str(data));
- }
- /*
- 通过指定的方法来自定义栏数据
- */
- function customOrgName(row, col){
- var name = row[col.dataField] || "";
- return name;
- }
- function customLook(row, col){
- return '<ul class="tool_downs">' +
- '<li><a class="aBtn" onclick="btn_edit(\''+row.id+'\',\''+row.P_ID+'\')">编辑</a></li>' +
- '<li><a class="aBtn" onclick="btn_delete(\'' + row.id + '\')">删除</a></li>' +
- '</ul>'
- }
- function gridList() {
- $.ajax({
- type: "get",
- url: huayi.config.callcenter_url + "/equipmentapi/api/WoRepairBase/getwxwpstimetree",
- async: true,
- dataType: 'json',
- data: {},
- success: function(data) {
- if (data.state.toLowerCase() == 'success') {
- var defaultDatas = getTreeData(data.data)
- config.data = getTreeData(data.data)
- treeGrid.show();
- }
- }
- });
-
- }
- function btn_add() {
- layer.open({
- type: 2,
- content: "template/addmaintainProject.html", //iframe的url,no代表不显示滚动条
- title: '新增维修项目时效',
- resize: false,
- area: ['80%', '90%'], //宽高
- });
- }
- function btn_edit(mid,pid) {
- if (pid!=="null") {
- pTxt = getTreePidText(pid,config.data)
- }else{
- pid = ''
- pTxt = ''
- }
-
- if(!mid) {
- layer.confirm('您还没有选择菜单', {
- icon: 7,
- btn: ['确定', '取消'],
- });
- return;
- }
- layer.open({
- type: 2,
- content: "template/addmaintainProject.html?isEdit=true&mid=" + mid + "&pid=" + pid + "&pTxt=" + pTxt, //iframe的url,no代表不显示滚动条
- title: '修改维修项目时效',
- resize: false,
- area: ['80%', '90%'], //宽高
- });
- }
- function btn_delete(mid) {
- if(!mid) {
- layer.confirm('您还没有选择菜单', {
- icon: 7,
- btn: ['确定', '取消'],
- });
- return;
- }
- layer.confirm('您确定要删除当前选项吗?', {
- icon: 7,
- btn: ['确定', '取消'],
- yes: function(index, layero) {
- $.get(huayi.config.callcenter_url + "equipmentapi/api/WoRepairBase/delewxwptimestabs", {
- id: mid,
- }, function(result) {
- result = JSON.parse(result);
- if(result.state.toLowerCase() == "success") {
- layer.msg("删除成功");
- location.reload()
- }
- })
- },
- });
- }
- function getTreeData (data) {
- var newData=[]
- data.forEach(function (ele) {
- newData.push({
- id: ele.id,
- P_ID: ele.pid,
- wxcenter: ele.wxcenter,
- name: ele.name,
- children: (ele.child && ele.child.length > 0) ? getTreeData(ele.child) : []
- })
- })
- return newData
- }
- function getTreePidText (pid,data) {
- var newData=[]
- var pidText
- for (var i=0;i<data.length;i++){
- if (data[i].id === pid) {
- pidText = data[i].wxcenter
- return pidText
- } else{
- getTreePidText(pid,data[i].children)
- }
- }
-
- }
|