relation-tree.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <?php
  2. /*
  3. * @Description: 查询节点
  4. * @Author: lun
  5. * @Date: 2022-04-25 16:16:34
  6. * @Copyright: copyright (c) 2021 广东七件事集团
  7. */
  8. ?>
  9. <link rel="stylesheet" href="/resources/unpkg/orgchart/jquery.orgchart.min.css">
  10. <style>
  11. #jOrgChart {
  12. position: relative;
  13. height: 1000px;
  14. margin: 0.5rem;
  15. overflow: auto;
  16. text-align: center;
  17. }
  18. </style>
  19. <div id="app" v-cloak>
  20. <el-card shadow="never" style="border:0;min-width: 1000px;" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
  21. <div slot="header">
  22. <span >关系树状图</span>
  23. </div>
  24. <div class="table-body">
  25. <div class="input-item">
  26. <el-select v-model="search.type" placeholder="请选择" size="small">
  27. <el-option label="用户ID" :value="1">用户ID</el-option>
  28. <el-option label="手机号码" :value="2">手机号码</el-option>
  29. </el-select>
  30. <el-input style="max-width: 200px;" size="small" placeholder="请输入用户ID/手机号码" v-model="search.keyword" clearable ></el-input>
  31. <el-radio-group v-model="search.tree_type" style="margin: 0 20px;">
  32. <el-radio label="under">团队</el-radio>
  33. <el-radio label="top">上级</el-radio>
  34. </el-radio-group>
  35. <el-button type="primary" size="small" :loading="listLoading" @click="toSearch">搜索</el-button>
  36. </div>
  37. <!-- 节点图 -->
  38. <div class="dataBox" id="jOrgChart"></div>
  39. </div>
  40. </el-card>
  41. <!-- -->
  42. <div class="detailcontent">
  43. <el-popover
  44. placement="top"
  45. width="200"
  46. trigger="manual"
  47. v-model="visible">
  48. <div>
  49. <div >{{detailcontent.id}}</div>
  50. <div >{{detailcontent.id}}--</div>
  51. <div >手机号{{detailcontent.mobile}}</div>
  52. </div>
  53. </el-popover>
  54. </div>
  55. <!-- 这个是复制用的容器,已隐藏 -->
  56. <textarea id="inputs" style="opacity: 0;width: 0;height: 0;">这是幕后黑手</textarea>
  57. </div>
  58. <script src="/resources/unpkg/jquery@3.3.1/dist/jquery.min.js"></script>
  59. <script src="/resources/unpkg/orgchart/jquery.orgchart.min.js"></script>
  60. <script type="text/javascript">
  61. const app = new Vue({
  62. el: '#app',
  63. data() {
  64. return {
  65. detailcontent:{},
  66. listLoading:false,
  67. zoomnum:2,
  68. search: {
  69. type: 1,
  70. keyword: null,
  71. tree_type: 'under',
  72. },
  73. datascource:{},
  74. visible:false,
  75. ischildren:false,
  76. elementchart:'', //要渲染的idming
  77. }
  78. },
  79. computed: {
  80. },
  81. created() {
  82. },
  83. mounted () {
  84. vueObj = this
  85. $('#jOrgChart').delegate('.node_list', 'mouseover', function() {
  86. $(this).find(".detailcontent").addClass('detailcontent1')
  87. })
  88. $('#jOrgChart').delegate('.node_list', 'mouseout', function() {
  89. $(this).find(".detailcontent").removeClass('detailcontent1')
  90. })
  91. $('#jOrgChart').delegate('.copy', 'click', function() {
  92. console.log($(this))
  93. let id = $(this)[0].id
  94. let idnum = id.substr(5,id.length)
  95. var url = $('#'+idnum).find('.title').html();
  96. url = url.replace('<i class="oci oci-leader symbol"></i>', '');// 替换掉
  97. // createElement() 方法通过指定名称创建一个元素
  98. var copyInput = document.createElement('input')
  99. copyInput.setAttribute('value', url)
  100. document.body.appendChild(copyInput)
  101. copyInput.select()
  102. try {
  103. var copyed = document.execCommand('copy')
  104. if (copyed) {
  105. document.body.removeChild(copyInput)
  106. vueObj.$message.success('复制成功')
  107. }
  108. } catch {
  109. vueObj.$message.success('复制失败,请检查浏览器兼容')
  110. }
  111. });
  112. },
  113. methods: {
  114. toSearch() {
  115. if(this.search.keyword !== '') {
  116. this.getquerynodeList();
  117. }
  118. },
  119. getquerynodeList(startTime = null, endTime = null) {
  120. let self = this;
  121. // self.listLoading = true;
  122. $('#jOrgChart').remove
  123. $("#jOrgChart").empty()
  124. this.datascource = {}
  125. request({
  126. params: {
  127. r: 'mall/user/relation-tree',
  128. },
  129. data:{type: this.search.type, keyword: this.search.keyword, tree_type: this.search.tree_type},
  130. method: 'post',
  131. }).then(e => {
  132. self.listLoading = false;
  133. if (e.data.code === 0) {
  134. self.datascource = e.data.data[0]
  135. self.chartFun(self.datascource)
  136. } else {
  137. self.$message.error(e.data.msg);
  138. }
  139. }).catch(e => {
  140. console.log(e);
  141. });
  142. },
  143. chartFun(datascource){
  144. vueObject = this
  145. let OrgChart = ''
  146. if(this.ischildren == true){
  147. // let elementchart = this.elementchart
  148. // $('.node_'+OrgChart).append("<ul class='nodes' id='OrgChart-"+elementchart+"'></ul>")
  149. OrgChart = 'OrgChart-'+this.elementchart
  150. }else{
  151. OrgChart = 'jOrgChart'
  152. }
  153. var oc = $('#'+OrgChart).orgchart({
  154. 'data': datascource,
  155. 'depth': 20,
  156. 'nodeContent': 'nickname',
  157. 'nodeID': 'id',
  158. 'pan':true,
  159. 'zoom':true,
  160. 'direction': 't2b',
  161. 'createNode': function($node, data) {
  162. $node.addClass('node_'+data.id);
  163. $node.appendTo("#node_"+data.id);
  164. $node.addClass('node_list');
  165. let secondMenuIcon = $("<i class='copy el-icon-document-copy' id='copy-"+data.id+"'></i>", {
  166. 'class': 'el-icon-info',
  167. onClick: function() {
  168. console.log(55555)
  169. console.log(22,$(this))
  170. }
  171. });
  172. let secondMenu = "<div class='second-menu' >"+data.mobile+"</div>";
  173. let thridMenu = "<div class='detailcontent'>"+
  174. " <div > 会员ID:"+data.name+"</div> "+
  175. " <div > 会员昵称:"+data.nickname+"</div> "+
  176. " <div > 手机号码:"+data.mobile+"</div> "+
  177. " <div > 会员等级:"+data.level_name+"</div> "+
  178. " <div > 注册时间:"+data.created_at+"</div> "+
  179. " </div>" ;
  180. $node.append(secondMenuIcon).append(secondMenu).append(thridMenu)
  181. }
  182. });
  183. },
  184. }
  185. });
  186. </script>
  187. <style>
  188. #app{
  189. }
  190. .table-body{
  191. height: auto;
  192. }
  193. .copy{
  194. position: absolute;
  195. bottom: 106px;
  196. left: 155px;
  197. color: #fff;
  198. width: 43px;
  199. font-weight: 700;
  200. font-size: 14px;
  201. transform: rotate(-90deg) translate(-45px,-45px) rotateY(180deg);
  202. transform-origin: bottom center;
  203. cursor: pointer;
  204. }
  205. .orgchart .hierarchy::before{
  206. border-top: 2px solid #409EFF;
  207. }
  208. .orgchart>ul>li>ul li>.node::before{
  209. background-color:#409EFF;
  210. }
  211. .orgchart .node:not(:only-child)::after{
  212. background-color:#409EFF;
  213. }
  214. .orgchart .node .content{
  215. border:1px solid #409EFF ;
  216. }
  217. .orgchart .node .title{
  218. background-color:#409EFF;
  219. }
  220. .detailcontent1{
  221. display: block !important;
  222. }
  223. page{
  224. background: #fff;
  225. }
  226. .node_list{
  227. position: relative;
  228. }
  229. .detailcontent{
  230. position: absolute;
  231. top: -40px;
  232. left: -235px;
  233. width: 231px;
  234. background: #fff;
  235. color: #000;
  236. padding: 10px;
  237. border-radius: 5px;
  238. display: none;
  239. box-shadow: -1px 6px 10px grey;
  240. z-index: 99;
  241. text-align: left;
  242. }
  243. .detailcontent div{
  244. line-height: 22px;
  245. }
  246. .orgchart .node .content{
  247. border-radius: 0;
  248. }
  249. .orgchart.l2r .node, .orgchart.r2l .node{
  250. width: 70px;
  251. }
  252. .second-menu{
  253. transform-origin: top center;
  254. width: 130px;
  255. height: 26px;
  256. border:1px solid #409EFF ;
  257. border-top: 0;
  258. }
  259. .orgchart .node{
  260. padding: 6px;
  261. }
  262. </style>