cfd64ae951f42989a132440949b7b8e663a7dd4f.svn-base 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <template>
  2. <div class="tree" :style="{'height':height + 'px','width':width == 0 ? 250 : width + 'px'}">
  3. <el-tree
  4. :data="treeData"
  5. :show-checkbox="showCheckbox"
  6. @check-change="handleCheckChange"
  7. :props="treeProps"
  8. :expand-on-click-node="false"
  9. @node-click="nodeClick"
  10. node-key="id"
  11. :default-expanded-keys="tableDefaultExpandedKeys"
  12. ></el-tree>
  13. </div>
  14. </template>
  15. <script>
  16. import request from '@util/gw_ajax_request.js';
  17. import {dateFormat} from "@util/gw_date";
  18. import {getTrees} from "@util/gw_formatTree.js";
  19. import {getYearList} from '@api/jcOneMapApi'
  20. export default {
  21. components: {},
  22. props: ['pid', 'type', 'pidNodes', 'height', 'width', 'showCheckbox'],
  23. data() {
  24. return {
  25. treeData: [],
  26. code: '45',
  27. tableDefaultExpandedKeys: ['001', '002', '003', '006'],
  28. treeProps: {
  29. label: "pnm",
  30. children: "children",
  31. // disabled: false,
  32. expandOnClickNode: false,
  33. first: true,
  34. },
  35. checkedData: [],
  36. changedData: [],
  37. yearList: [],
  38. year: ''
  39. };
  40. },
  41. mounted: function () {
  42. if (this.width === undefined) {
  43. this.width = '250';
  44. }
  45. if (this.height === undefined) {
  46. this.height = '550';
  47. }
  48. this.getYearlists();
  49. },
  50. computed: {
  51. userId: function () {
  52. return localStorage.getItem("userid")
  53. ? localStorage.getItem("userid")
  54. : "1098101939614724096";
  55. }
  56. },
  57. methods: {
  58. getYearlists() {
  59. getYearList().then(res => {
  60. this.yearList = res.data;
  61. let lastItemIndex = this.yearList.length - 1
  62. this.year = this.yearList[lastItemIndex].year
  63. })
  64. },
  65. // 节点点击事件
  66. nodeClick: function (data) {
  67. var _self = this;
  68. _self.$emit("provTreeSelectChange", {
  69. 'id': data.id,
  70. 'pid': data.pid,
  71. 'pnm': data.pnm
  72. });
  73. },
  74. // 递归获取选中的元素id
  75. getCheckedNode: function (data) {
  76. if (data.children == null || data.disabled || data.children.length === 0) {
  77. return;
  78. }
  79. data.children.forEach((element, index) => {
  80. this.checkedData.push({
  81. 'id': element.id,
  82. 'pnm': element.pnm,
  83. });
  84. this.getCheckedNode(element);
  85. });
  86. },
  87. // 递归获取改变的元素id
  88. getChangedNode: function (data) {
  89. if (data.children == null || data.disabled || data.children.length === 0) {
  90. return;
  91. }
  92. data.children.forEach((element, index) => {
  93. this.changedData.push({
  94. 'id': element.id,
  95. 'pnm': element.pnm,
  96. });
  97. this.getChangedNode(element);
  98. });
  99. },
  100. // 选中或取消事件
  101. handleCheckChange: function (data, checked, indeterminate) {
  102. let _self = this;
  103. // 如果是选中
  104. if (checked) {
  105. // 如果没有被禁用
  106. if (!data.disabled) {
  107. _self.checkedData.push({
  108. 'id': data.id,
  109. 'pnm': data.pnm
  110. });
  111. _self.getCheckedNode(data);
  112. }
  113. } else {
  114. // 取消选中
  115. let newCheckedData = [];
  116. _self.checkedData.forEach((element, index) => {
  117. if (element.id == data.id || element.engId == data.engId) {
  118. // 不做操作
  119. } else {
  120. newCheckedData.push(element);
  121. }
  122. });
  123. _self.checkedData = newCheckedData;
  124. // 被改变的元素,先清空一下
  125. _self.changedData = [];
  126. // 只获取明确被取消的元素id和下级id
  127. if (!indeterminate) {
  128. _self.changedData.push({
  129. 'id': data.id,
  130. 'pnm': data.pnm,
  131. });
  132. _self.getChangedNode(data)
  133. } else {
  134. _self.changedData.push({
  135. 'id': data.id,
  136. 'pnm': data.pnm,
  137. });
  138. }
  139. }
  140. this.$emit('treeCheckedDataChange', {
  141. 'newCheckedArray': _self.checkedData,
  142. 'changedItem': _self.changedData,
  143. 'newStatus': checked
  144. });
  145. },
  146. //根据用户id获取左侧树
  147. getLeftTreeData() {
  148. var _self = this;
  149. request.get('/dc/organization/base/getAllNode', {
  150. params: {
  151. 'userId': this.userId,
  152. 'orgType': this.type,
  153. 'year': this.year
  154. }
  155. }).then((res) => {
  156. let data = res.data
  157. data.forEach(ele => {
  158. // if(ele.pid == null || ele.pid == ''){
  159. // ele.pid = '001'
  160. // }
  161. if (ele.sttm == null || ele.sttm == '') {
  162. ele.sttm = ''
  163. } else {
  164. ele.sttm = dateFormat(ele.sttm, 'yy-MM-dd');
  165. }
  166. if (ele.entm == null || ele.entm == '') {
  167. ele.entm = ''
  168. } else {
  169. ele.entm = dateFormat(ele.entm, 'yy-MM-dd');
  170. }
  171. });
  172. // 处理最低节点增加上层节点
  173. _self.addUpNode(data);
  174. })
  175. },
  176. //处理最低节点增加上层节点
  177. async addUpNode(data) {
  178. // 1.先获取所有id组成的数组并满足id的长度小于12的(12是最低节点)
  179. // 2.如果都是最低节点,那么就加上上层节点
  180. let arr = data.map(v => {
  181. return v.id
  182. }).filter(
  183. (v, i) => v.length < 12
  184. );
  185. let ids = data.map(v => {
  186. return v.pid
  187. }).join();
  188. if (arr.length == 0 && ids.length != 0) {
  189. await request.get('/dc/organization/base/getAllNodeById', {
  190. params: {
  191. 'id': ids,
  192. 'year': this.year
  193. }
  194. }).then((res) => {
  195. let dataUp = res.data;
  196. dataUp.forEach((item, index) => {
  197. item.disabled = true
  198. })
  199. data = data.concat(dataUp)
  200. }).catch((err) => {
  201. })
  202. }
  203. this.treeData = await getTrees(data)
  204. console.log(JSON.stringify(this.treeData))
  205. },
  206. },
  207. watch: {
  208. type(val) {
  209. if (val) {
  210. this.getLeftTreeData()
  211. }
  212. },
  213. year(val) {
  214. if (val) {
  215. this.getLeftTreeData();
  216. this.$emit('changeYear', val);
  217. }
  218. }
  219. }
  220. };
  221. </script>
  222. <style scoped>
  223. .tree {
  224. overflow-y: auto;
  225. overflow-x: auto;
  226. }
  227. .el-tree {
  228. min-width: 100%;
  229. display: inline-block !important;
  230. }
  231. /*滚动条样式*/
  232. .tree::-webkit-scrollbar {
  233. width: 8px;
  234. height: 8px;
  235. }
  236. /*正常情况下滑块的样式*/
  237. .tree::-webkit-scrollbar-thumb {
  238. background-color: rgba(0, 0, 0, .05);
  239. border-radius: 10px;
  240. -webkit-box-shadow: inset 1px 1px 0 rgba(0, 0, 0, .1);
  241. }
  242. /*鼠标悬浮在该类指向的控件上时滑块的样式*/
  243. .tree:hover::-webkit-scrollbar-thumb {
  244. background-color: rgba(0, 0, 0, .2);
  245. border-radius: 10px;
  246. -webkit-box-shadow: inset 1px 1px 0 rgba(0, 0, 0, .1);
  247. }
  248. /*鼠标悬浮在滑块上时滑块的样式*/
  249. .tree::-webkit-scrollbar-thumb:hover {
  250. background-color: rgba(0, 0, 0, .4);
  251. -webkit-box-shadow: inset 1px 1px 0 rgba(0, 0, 0, .1);
  252. }
  253. /*正常时候的主干部分*/
  254. .tree::-webkit-scrollbar-track {
  255. border-radius: 10px;
  256. -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0);
  257. background-color: white;
  258. }
  259. /*鼠标悬浮在滚动条上的主干部分*/
  260. .tree::-webkit-scrollbar-track:hover {
  261. -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, .4);
  262. background-color: rgba(0, 0, 0, .01);
  263. }
  264. </style>