Нет описания

maintainProject.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /**
  2. * 菜单设置
  3. * */
  4. var rowData = {}
  5. var pidText = ''
  6. var treeGrid
  7. var config = {
  8. id: "tg1",
  9. width: "800",
  10. renderTo: "gridList",
  11. headerAlign: "left",
  12. headerHeight: "30",
  13. dataAlign: "left",
  14. indentation: "20",
  15. folderOpenIcon: "../public/treeGrid/images/folderOpen.gif",
  16. folderCloseIcon: "../public/treeGrid/images/folderClose.gif",
  17. defaultLeafIcon: "../public/treeGrid/images/defaultLeaf.gif",
  18. hoverRowBackground: "false",
  19. folderColumnIndex: "0",
  20. itemClick: "itemClickEvent",
  21. columns: [
  22. {
  23. headerText: "维修项目名称",
  24. dataField: "wxcenter",
  25. headerAlign: "center",
  26. handler: "customOrgName"
  27. },
  28. {
  29. headerText: "项目科室",
  30. dataField: "name",
  31. headerAlign: "center",
  32. handler: "customOrgName"
  33. },
  34. {
  35. headerText: "操作",
  36. headerAlign: "center",
  37. dataAlign: "center",
  38. width: "100",
  39. handler: "customLook"
  40. }
  41. ],
  42. data: []
  43. };
  44. $("#sc_btns").click(function() {
  45. gridList();
  46. });
  47. $(function() {
  48. $('.tool_bars').authorizeButton();
  49. treeGrid = new TreeGrid(config);
  50. gridList();
  51. });
  52. function itemClickEvent(id, index, data){
  53. jQuery("#currentRow").val(id + ", " + index + ", " + TreeGrid.json2str(data));
  54. }
  55. /*
  56. 通过指定的方法来自定义栏数据
  57. */
  58. function customOrgName(row, col){
  59. var name = row[col.dataField] || "";
  60. return name;
  61. }
  62. function customLook(row, col){
  63. return '<ul class="tool_downs">' +
  64. '<li><a class="aBtn" onclick="btn_edit(\''+row.id+'\',\''+row.P_ID+'\')">编辑</a></li>' +
  65. '<li><a class="aBtn" onclick="btn_delete(\'' + row.id + '\')">删除</a></li>' +
  66. '</ul>'
  67. }
  68. function gridList() {
  69. $.ajax({
  70. type: "get",
  71. url: huayi.config.callcenter_url + "/equipmentapi/api/WoRepairBase/getwxwpstimetree",
  72. async: true,
  73. dataType: 'json',
  74. data: {},
  75. success: function(data) {
  76. if (data.state.toLowerCase() == 'success') {
  77. var defaultDatas = getTreeData(data.data)
  78. config.data = getTreeData(data.data)
  79. treeGrid.show();
  80. }
  81. }
  82. });
  83. }
  84. function btn_add() {
  85. layer.open({
  86. type: 2,
  87. content: "template/addmaintainProject.html", //iframe的url,no代表不显示滚动条
  88. title: '新增维修项目时效',
  89. resize: false,
  90. area: ['80%', '90%'], //宽高
  91. });
  92. }
  93. function btn_edit(mid,pid) {
  94. if (pid!=="null") {
  95. pTxt = getTreePidText(pid,config.data)
  96. }else{
  97. pid = ''
  98. pTxt = ''
  99. }
  100. if(!mid) {
  101. layer.confirm('您还没有选择菜单', {
  102. icon: 7,
  103. btn: ['确定', '取消'],
  104. });
  105. return;
  106. }
  107. layer.open({
  108. type: 2,
  109. content: "template/addmaintainProject.html?isEdit=true&mid=" + mid + "&pid=" + pid + "&pTxt=" + pTxt, //iframe的url,no代表不显示滚动条
  110. title: '修改维修项目时效',
  111. resize: false,
  112. area: ['80%', '90%'], //宽高
  113. });
  114. }
  115. function btn_delete(mid) {
  116. if(!mid) {
  117. layer.confirm('您还没有选择菜单', {
  118. icon: 7,
  119. btn: ['确定', '取消'],
  120. });
  121. return;
  122. }
  123. layer.confirm('您确定要删除当前选项吗?', {
  124. icon: 7,
  125. btn: ['确定', '取消'],
  126. yes: function(index, layero) {
  127. $.get(huayi.config.callcenter_url + "equipmentapi/api/WoRepairBase/delewxwptimestabs", {
  128. id: mid,
  129. }, function(result) {
  130. result = JSON.parse(result);
  131. if(result.state.toLowerCase() == "success") {
  132. layer.msg("删除成功");
  133. location.reload()
  134. }
  135. })
  136. },
  137. });
  138. }
  139. function getTreeData (data) {
  140. var newData=[]
  141. data.forEach(function (ele) {
  142. newData.push({
  143. id: ele.id,
  144. P_ID: ele.pid,
  145. wxcenter: ele.wxcenter,
  146. name: ele.name,
  147. children: (ele.child && ele.child.length > 0) ? getTreeData(ele.child) : []
  148. })
  149. })
  150. return newData
  151. }
  152. function getTreePidText (pid,data) {
  153. var newData=[]
  154. var pidText
  155. for (var i=0;i<data.length;i++){
  156. if (data[i].id === pid) {
  157. pidText = data[i].wxcenter
  158. return pidText
  159. } else{
  160. getTreePidText(pid,data[i].children)
  161. }
  162. }
  163. }