TreeData.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. <template>
  2. <table v-if="treeData && treeData.orgName">
  3. <tr>
  4. <td
  5. :colspan="treeData.children ? treeData.children.length * 2 : 1"
  6. :class="{
  7. parentLevel: treeData.children,
  8. extend: treeData.children && treeData.children.length && treeData.isExtend,
  9. }"
  10. >
  11. <div :class="{ node: true, hasMate: treeData.mate }">
  12. <div class="person" @click="$emit('click-node', treeData)">
  13. <!-- <el-popover v-if="false" placement="top" width="180" trigger="hover" > -->
  14. <el-popover
  15. v-if="
  16. !isDetail &&
  17. !(
  18. userInfo.roleType == '3' ||
  19. (userInfo.roleType == '4' && Number(treeData.level) === 2) ||
  20. (userInfo.roleType == '5' && Number(treeData.level) === 3)
  21. )
  22. "
  23. placement="top"
  24. width="180"
  25. trigger="hover"
  26. >
  27. <!-- v-if="treeData.isAdd && userInfo.roleType != '3'" -->
  28. <div style="margin: 0">
  29. <el-button
  30. size="mini"
  31. type="primary"
  32. @click="addStock(0)"
  33. v-if="
  34. !(
  35. userInfo.roleType == '3' ||
  36. (userInfo.roleType == '4' && Number(treeData.level) === 2) ||
  37. (userInfo.roleType == '4' && Number(treeData.level) === 3) ||
  38. (userInfo.roleType == '5' && Number(treeData.level) === 4)
  39. )
  40. "
  41. >添加</el-button
  42. >
  43. <el-button
  44. type="primary"
  45. size="mini"
  46. @click="addStock(1)"
  47. v-if="
  48. !(
  49. userInfo.roleType == '3' ||
  50. (userInfo.roleType == '4' && Number(treeData.level) === 2) ||
  51. (userInfo.roleType == '4' && Number(treeData.level) === 3) ||
  52. (userInfo.roleType == '5' && Number(treeData.level) === 4)
  53. )
  54. "
  55. >编辑</el-button
  56. >
  57. <el-button
  58. type="primary"
  59. size="mini"
  60. @click="deleteStock"
  61. v-if="
  62. !(
  63. userInfo.roleType == '3' ||
  64. (userInfo.roleType == '4' && Number(treeData.level) === 2)
  65. )
  66. "
  67. >删除</el-button
  68. >
  69. <span
  70. v-if="
  71. userInfo.roleType == '3' ||
  72. (userInfo.roleType == '4' && Number(treeData.level) === 2)
  73. "
  74. >
  75. 暂无权限
  76. </span>
  77. </div>
  78. <div
  79. class="avat"
  80. :class="{
  81. parent: !treeData.level,
  82. company: Number(treeData.level) === 1,
  83. }"
  84. slot="reference"
  85. >
  86. <img
  87. v-show="Number(treeData.level) === 1"
  88. style="margin-bottom: 10px"
  89. src="../assets/img/group/gen.png"
  90. />
  91. <img
  92. v-show="Number(treeData.level) === 2"
  93. style="margin-bottom: 10px"
  94. src="../assets/img/group/er.png"
  95. />
  96. <span
  97. style="
  98. background-color: #edf7f2;
  99. padding: 10px;
  100. border-radius: 10px;
  101. display: flex;
  102. line-height: 30px;
  103. justify-content: center;
  104. "
  105. >
  106. {{ treeData.orgName }}
  107. </span>
  108. </div>
  109. </el-popover>
  110. <div
  111. v-if="
  112. !isDetail &&
  113. (userInfo.roleType == '3' ||
  114. (userInfo.roleType == '4' && Number(treeData.level) === 2) ||
  115. (userInfo.roleType == '5' && Number(treeData.level) === 3))
  116. "
  117. class="avat"
  118. :class="{
  119. parent: !treeData.level,
  120. company: Number(treeData.level) === 1,
  121. }"
  122. slot="reference"
  123. >
  124. <img
  125. v-show="Number(treeData.level) === 1"
  126. style="margin-bottom: 10px"
  127. src="../assets/img/group/gen.png"
  128. />
  129. <img
  130. v-show="Number(treeData.level) === 2"
  131. style="margin-bottom: 10px"
  132. src="../assets/img/group/er.png"
  133. />
  134. <span
  135. style="
  136. background-color: #edf7f2;
  137. padding: 10px;
  138. border-radius: 10px;
  139. display: flex;
  140. line-height: 30px;
  141. justify-content: center;
  142. "
  143. >
  144. {{ treeData.orgName }}
  145. </span>
  146. </div>
  147. </div>
  148. </div>
  149. <div
  150. class="extend_handle"
  151. v-if="treeData.children && treeData.children.length"
  152. @click="toggleExtend(treeData)"
  153. ></div>
  154. </td>
  155. </tr>
  156. <!-- 这是一个递归组件,注意,这里还要调用,需要传递的数据这里也要传递,否则操作时拿不到子级的数据 -->
  157. <tr v-if="treeData.children && treeData.children.length && treeData.isExtend">
  158. <td
  159. v-for="(children, index) in treeData.children"
  160. :key="index"
  161. colspan="2"
  162. class="childLevel"
  163. >
  164. <TreeChart
  165. :json="children"
  166. :isDetail="isDetail"
  167. @add="$emit('add', $event)"
  168. @delete="$emit('delete', $event)"
  169. @click-node="$emit('click-node', $event)"
  170. />
  171. </td>
  172. </tr>
  173. </table>
  174. </template>
  175. <script>
  176. import { oSessionStorage } from "../utils/utils";
  177. export default {
  178. name: "TreeChart",
  179. props: {
  180. json: {}, // 渲染数据
  181. isDetail: {
  182. default: false, // 是否是详情
  183. },
  184. },
  185. data() {
  186. return {
  187. treeData: {},
  188. userInfo: {},
  189. };
  190. },
  191. created() {
  192. // console.log(this.json)
  193. },
  194. watch: {
  195. isDetail: function (val) {
  196. // 是否是详情,详情不能添加编辑
  197. this.isDetail = val;
  198. },
  199. json: {
  200. // 遍历当前的数据
  201. handler: function (Props) {
  202. let extendKey = function (jsonData) {
  203. jsonData.isExtend = jsonData.isExtend === void 0 ? true : !!jsonData.isExtend;
  204. // if (Array.isArray(jsonData.children) && jsonData.children.length) {
  205. // jsonData.children.forEach(c => {
  206. // extendKey(c);
  207. // });
  208. // }
  209. return jsonData;
  210. };
  211. if (Props) {
  212. this.treeData = extendKey(Props);
  213. }
  214. },
  215. immediate: true,
  216. deep: true,
  217. },
  218. },
  219. mounted() {
  220. this.userInfo = JSON.parse(oSessionStorage.getItem("userInfo"));
  221. },
  222. methods: {
  223. toggleExtend(treeData) {
  224. treeData.isExtend = !treeData.isExtend;
  225. this.$forceUpdate();
  226. },
  227. // 新增编辑股东,val: 0 新增, 1 编辑
  228. addStock(val) {
  229. // console.log(this.treeData)
  230. this.$emit("add", { val: val, data: this.treeData });
  231. },
  232. // 删除股东
  233. deleteStock() {
  234. this.$emit("delete", this.treeData);
  235. },
  236. },
  237. };
  238. </script>
  239. <style lang="less">
  240. table {
  241. border-collapse: separate !important;
  242. border-spacing: 0 !important;
  243. }
  244. td {
  245. position: relative;
  246. vertical-align: top;
  247. padding: 0 0 50px 0;
  248. text-align: center;
  249. }
  250. .parent {
  251. background: #199ed8 !important;
  252. font-weight: bold;
  253. }
  254. .extend_handle {
  255. position: absolute;
  256. left: 50%;
  257. bottom: 27px;
  258. width: 10px;
  259. height: 10px;
  260. padding: 10px;
  261. transform: translate3d(-15px, 0, 0);
  262. cursor: pointer;
  263. }
  264. .extend_handle:before {
  265. content: "";
  266. display: block;
  267. width: 100%;
  268. height: 100%;
  269. box-sizing: border-box;
  270. border: 2px solid;
  271. border-color: #ccc #ccc transparent transparent;
  272. transform: rotateZ(135deg);
  273. transform-origin: 50% 50% 0;
  274. transition: transform ease 300ms;
  275. }
  276. .extend_handle:hover:before {
  277. border-color: #333 #333 transparent transparent;
  278. }
  279. .extend .extend_handle:before {
  280. transform: rotateZ(-45deg);
  281. }
  282. .extend::after {
  283. content: "";
  284. position: absolute;
  285. left: 50%;
  286. bottom: 15px;
  287. height: 15px;
  288. border-left: 2px solid #ccc;
  289. transform: translate3d(-1px, 0, 0);
  290. }
  291. .childLevel::before {
  292. content: "";
  293. position: absolute;
  294. left: 50%;
  295. bottom: 100%;
  296. height: 15px;
  297. border-left: 2px solid #ccc;
  298. transform: translate3d(-1px, 0, 0);
  299. }
  300. .childLevel::after {
  301. content: "";
  302. position: absolute;
  303. left: 0;
  304. right: 0;
  305. top: -15px;
  306. border-top: 2px solid #ccc;
  307. }
  308. .childLevel:first-child:before,
  309. .childLevel:last-child:before {
  310. display: none;
  311. }
  312. .childLevel:first-child:after {
  313. left: 50%;
  314. height: 15px;
  315. border: 2px solid;
  316. border-color: #ccc transparent transparent #ccc;
  317. border-radius: 6px 0 0 0;
  318. transform: translate3d(1px, 0, 0);
  319. }
  320. .childLevel:last-child:after {
  321. right: 50%;
  322. height: 15px;
  323. border: 2px solid;
  324. border-color: #ccc #ccc transparent transparent;
  325. border-radius: 0 6px 0 0;
  326. transform: translate3d(-1px, 0, 0);
  327. }
  328. .childLevel:first-child.childLevel:last-child::after {
  329. left: auto;
  330. border-radius: 0;
  331. border-color: transparent #ccc transparent transparent;
  332. transform: translate3d(1px, 0, 0);
  333. }
  334. .node {
  335. position: relative;
  336. display: inline-block;
  337. box-sizing: border-box;
  338. text-align: center;
  339. padding: 0 5px;
  340. }
  341. .node .person {
  342. padding-top: 15px;
  343. position: relative;
  344. display: inline-block;
  345. z-index: 2;
  346. width: 120px;
  347. overflow: hidden;
  348. }
  349. .node .person .avat {
  350. padding: 5px;
  351. padding-top: 10px;
  352. display: block;
  353. width: 100%;
  354. height: 100%;
  355. margin: auto;
  356. word-break: break-all;
  357. background: transparent;
  358. box-sizing: border-box;
  359. border-radius: 4px;
  360. .opreate_icon {
  361. display: none;
  362. }
  363. &:hover {
  364. .opreate_icon {
  365. display: block;
  366. position: absolute;
  367. top: -3px;
  368. right: -3px;
  369. padding: 5px;
  370. }
  371. }
  372. &.company {
  373. // background: #199ed8;
  374. background: transparent;
  375. font-weight: 700;
  376. }
  377. &.other {
  378. background: #ccc;
  379. }
  380. }
  381. .node .person .avat img {
  382. cursor: pointer;
  383. }
  384. .node .person .name {
  385. height: 2em;
  386. line-height: 2em;
  387. overflow: hidden;
  388. width: 100%;
  389. }
  390. .node.hasMate::after {
  391. content: "";
  392. position: absolute;
  393. left: 2em;
  394. right: 2em;
  395. top: 15px;
  396. border-top: 2px solid #ccc;
  397. z-index: 1;
  398. }
  399. .node.hasMate .person:last-child {
  400. margin-left: 1em;
  401. }
  402. .el-dialog__header {
  403. padding: 0;
  404. padding-top: 30px;
  405. margin: 0 30px;
  406. // border-bottom: 1px solid #f1f1f1;
  407. text-align: left;
  408. .el-dialog__title {
  409. font-size: 14px;
  410. font-weight: bold;
  411. color: #464c5b;
  412. line-height: 20px;
  413. }
  414. }
  415. .tips {
  416. padding: 0 20px;
  417. .el-select {
  418. width: 100%;
  419. }
  420. .blue {
  421. color: #00b5ef;
  422. }
  423. .check {
  424. margin-left: 100px;
  425. }
  426. .inquiry {
  427. font-weight: bold;
  428. }
  429. .el-form-item__label {
  430. display: block;
  431. float: none;
  432. text-align: left;
  433. }
  434. .el-form-item__content {
  435. margin-left: 0;
  436. }
  437. }
  438. .el-dialog__body {
  439. padding: 30px 25px;
  440. p {
  441. margin-bottom: 15px;
  442. }
  443. }
  444. .el-dialog__headerbtn {
  445. top: 30px;
  446. right: 30px;
  447. }
  448. // 竖向
  449. .landscape {
  450. transform: translate(-100%, 0) rotate(-90deg);
  451. transform-origin: 100% 0;
  452. .node {
  453. text-align: left;
  454. height: 8em;
  455. width: 8em;
  456. }
  457. .person {
  458. position: relative;
  459. transform: rotate(90deg);
  460. // padding-left: 4.5em;
  461. // height: 4em;
  462. top: 35px;
  463. left: 12px;
  464. width: 110px;
  465. }
  466. }
  467. .el-popover {
  468. .el-button {
  469. padding: 8px !important;
  470. margin-left: 5px !important;
  471. float: left;
  472. }
  473. }
  474. </style>