5dbcc27064bc2a0185dcc3e746d66dab3ef68203.svn-base 10.0 KB

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