treeHouse.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <template>
  2. <div class="organ-trees-view">
  3. <div v-if="showHouseTree">
  4. <div>
  5. <el-input v-model="filterText" v-if="!showCheckboxTree" placeholder="请输入关键字" suffix-icon="el-icon-search"></el-input>
  6. <el-input
  7. v-model="selectHouse"
  8. placeholder="选择的房间"
  9. @focus="inputFocue('house')"
  10. maxlength="10"
  11. suffix-icon="el-icon-search"
  12. v-else
  13. ></el-input>
  14. </div>
  15. <div class="tree-house-style-box" v-show="inputFocueHouse" :style="{ 'z-index': inputFocueHouse ? index : 0 }">
  16. <GeminiScrollbar class="my-scroll-bar" :autoshow="true">
  17. <el-tree
  18. :data="organList"
  19. ref="tree"
  20. node-key="id"
  21. :highlight-current="true"
  22. :props="defaultProps"
  23. :expand-on-click-node="false"
  24. @check="clickCheckTree"
  25. :default-expand-all="defaultExpandAllTree"
  26. :filter-node-method="filterNode"
  27. :show-checkbox="showCheckboxTree"
  28. :accordion="accordion"
  29. :prevDetailData="prevDetailData"
  30. :default-expanded-keys="defaultSelectAll"
  31. :check-on-click-node="true"
  32. >
  33. </el-tree>
  34. </GeminiScrollbar>
  35. <div class="end-btn">
  36. <el-button type="plain" @click="endBtn" size="mini">取消</el-button>
  37. <el-button type="primary" @click="endBtn" size="mini">确定</el-button>
  38. </div>
  39. </div>
  40. </div>
  41. <div>
  42. <el-input
  43. v-show="!showHouseTree"
  44. v-model="selectPeople"
  45. placeholder="选择的人员"
  46. maxlength="10"
  47. @focus="inputFocues()"
  48. suffix-icon="el-icon-search"
  49. ></el-input>
  50. <div class="transfer-style-box" v-show="inputFocuePeople" :style="{ 'z-index': inputFocuePeople ? index : 0 }">
  51. <GeminiScrollbar class="my-scroll-bar" :autoshow="true">
  52. <el-tree
  53. :data="dataPeopleList"
  54. ref="treePeople"
  55. node-key="id"
  56. :highlight-current="true"
  57. :props="defaultPropsPeople"
  58. :expand-on-click-node="false"
  59. @check="clickCheckTreePeople"
  60. :default-expand-all="defaultExpandAllTree"
  61. :filter-node-method="filterNodePeople"
  62. :show-checkbox="showCheckboxTree"
  63. :accordion="accordionPeople"
  64. :selectAll="selectAll"
  65. :prevDetailData="prevDetailData"
  66. :check-on-click-node="true"
  67. >
  68. </el-tree>
  69. </GeminiScrollbar>
  70. <div class="end-btn">
  71. <el-button type="plain" @click="endBtn" size="mini">取消</el-button>
  72. <el-button type="primary" @click="endBtn" size="mini">确定</el-button>
  73. </div>
  74. </div>
  75. </div>
  76. </div>
  77. </template>
  78. <script>
  79. export default {
  80. name: 'treeHouse',
  81. props: {
  82. buildingType: { type: String, default: 'buildingType' },
  83. showCheckboxTree: {
  84. //显示多选框
  85. type: Boolean,
  86. default: false
  87. },
  88. disabledHouse: {
  89. type: Boolean,
  90. default: true
  91. },
  92. disabledPeople: {
  93. type: Boolean,
  94. default: true
  95. },
  96. defaultExpandAllTree: {
  97. //是否默认展开所有节点
  98. type: Boolean,
  99. default: true
  100. },
  101. showHouseTree: {
  102. //显示房间树
  103. type: Boolean,
  104. default: true
  105. },
  106. accordion: {
  107. //房间展开手风琴
  108. type: Boolean,
  109. default: false
  110. },
  111. accordionPeople: {
  112. //人员展开手风琴
  113. type: Boolean,
  114. default: false
  115. },
  116. prevDetailData: {
  117. type: Array,
  118. default() {
  119. return [];
  120. }
  121. }
  122. },
  123. data() {
  124. return {
  125. //输入框获得焦点
  126. inputFocueHouse: false,
  127. inputFocuePeople: false,
  128. index: 99,
  129. filterText: '',
  130. selectHouse: '',
  131. selectPeople: '',
  132. organList: [],
  133. dataPeopleList: [],
  134. defaultSelectAll: [],
  135. defaultProps: {
  136. children: 'children',
  137. label: 'name'
  138. },
  139. defaultPropsPeople: {
  140. children: 'children',
  141. label: 'label'
  142. }
  143. };
  144. },
  145. watch: {
  146. selectHouse(val) {
  147. // this.$refs.tree.filter(val);
  148. }
  149. // dataPeopleList(val) {
  150. // console.log('====================================');
  151. // console.log('dataPeopleList', val);
  152. // console.log('====================================');
  153. // this.$refs.tree.filter(val);
  154. // }
  155. },
  156. computed: {},
  157. methods: {
  158. // 输入框获得焦点
  159. inputFocue(val) {
  160. this.index++;
  161. console.log('输入框获得焦点', val);
  162. this.inputFocueHouse = true;
  163. this.inputFocuePeople = false;
  164. },
  165. inputFocues() {
  166. this.index++;
  167. console.log('输入框获得焦点inputFocues');
  168. this.inputFocueHouse = false;
  169. this.inputFocuePeople = true;
  170. },
  171. endBtn() {
  172. this.inputFocueHouse = false;
  173. this.inputFocuePeople = false;
  174. },
  175. // 过滤选中的社区下的房间
  176. filterhouse(val, datas) {
  177. let array = datas;
  178. let data;
  179. for (let index = 0; index < array.length; index++) {
  180. const element = array[index];
  181. if (element.id == val && element.children) {
  182. data = element.children;
  183. }
  184. }
  185. this.organList = data;
  186. this.defaultSelectAll = data;
  187. this.selectAllHouse();
  188. this.clickCheckTree();
  189. // this.$refs.tree.setCheckedNodes('C1栋');
  190. console.log('this.$refs.tree.setCheckedNodes(this.organList);', this.organList);
  191. },
  192. // 选中所有房间
  193. selectAllHouse() {
  194. this.$nextTick(() => {
  195. this.$refs.tree.setCheckedNodes(this.organList);
  196. this.clickCheckTree();
  197. });
  198. },
  199. // 选中指定房间
  200. selectHouseOr() {
  201. this.$nextTick(() => {
  202. this.$refs.tree.setCheckedKeys([]);
  203. this.clickCheckTree();
  204. });
  205. },
  206. // 选中所有人员
  207. selectAllPeople() {
  208. this.$nextTick(() => {
  209. this.$refs.treePeople.setCheckedNodes(this.dataPeopleList);
  210. this.clickCheckTreePeople();
  211. });
  212. },
  213. // 选中指定人员
  214. selectPeopleOr() {
  215. this.$nextTick(() => {
  216. this.$refs.treePeople.setCheckedKeys([]);
  217. this.clickCheckTreePeople();
  218. });
  219. },
  220. // 获取房间
  221. getOrgTreeList() {
  222. this.houseNames = [];
  223. this.$http
  224. .get('/sc-community/assets/tree/community/find', { buildingType: this.buildingType })
  225. .then(({ status, data, msg }) => {
  226. if (status === 0 && data) {
  227. this.organList = data;
  228. }
  229. });
  230. },
  231. // 获取人员
  232. getPeopleList() {
  233. this.$http.get('/sc-user-center/user/findUserList').then(({ status, data, msg }) => {
  234. if (status === 0) {
  235. this.dataPeopleList = data;
  236. this.$emit('dataPeople', data);
  237. } else {
  238. this.$message(warning, '获取人员失败,请稍后重试');
  239. }
  240. console.log('获取人员', data);
  241. });
  242. },
  243. getSelect(data) {
  244. var str = [];
  245. const getStr = function (list) {
  246. list.forEach(function (row) {
  247. if (row.children) {
  248. getStr(row.children);
  249. } else {
  250. str.push(row.value);
  251. }
  252. });
  253. };
  254. getStr(data);
  255. return str;
  256. console.log('getStr', str);
  257. },
  258. // 多选框返回选中房间的数据
  259. clickCheckTree(val) {
  260. let tree = this.$refs.tree;
  261. let nameArr = [];
  262. let array = tree.getCheckedNodes();
  263. for (let index = 0; index < array.length; index++) {
  264. const element = array[index];
  265. nameArr.push(element.name);
  266. if (Array.isArray(element) && element.length > 0) {
  267. nameArr.push(element.name);
  268. }
  269. }
  270. // 输入框显示的房间
  271. this.selectHouse = nameArr;
  272. var arr = [];
  273. array.forEach(function (item) {
  274. if (item.type === 'room' && Number(item.value) !== String) {
  275. arr.push(Number(item.value));
  276. }
  277. });
  278. let obj = {};
  279. obj.userList = arr;
  280. obj.checkData = array;
  281. console.log('多选框返回选中房间的数据', array);
  282. // 选中的房间id
  283. this.$emit('selectData', obj);
  284. },
  285. // 多选框返回选中人员的数据
  286. clickCheckTreePeople(val) {
  287. let nameArr = [];
  288. let tree = this.$refs.treePeople;
  289. let array = tree.getCheckedNodes();
  290. for (let index = 0; index < array.length; index++) {
  291. const element = array[index];
  292. nameArr.push(element.label);
  293. if (Array.isArray(element) && element.length > 0) {
  294. nameArr.push(element.label);
  295. }
  296. }
  297. let checkDatas = tree.getCheckedNodes();
  298. var a = [];
  299. for (let i in checkDatas) {
  300. if (checkDatas[i].children == null) {
  301. a.push(checkDatas[i].id);
  302. }
  303. }
  304. let obj = {};
  305. obj.userList = a;
  306. obj.checkData = array;
  307. console.log('多选框返回选中人员的数据', JSON.stringify(checkDatas));
  308. // 输入框显示的人员
  309. this.selectPeople = nameArr.toString();
  310. // 选中的人员id
  311. this.$emit('selectPeople', obj);
  312. },
  313. filterNode(value, data) {
  314. if (!value) return true;
  315. return data.name.indexOf(value) !== -1;
  316. },
  317. filterNodePeople(value, data) {
  318. if (!value) return true;
  319. return data.label.indexOf(value) !== -1;
  320. }
  321. },
  322. created() {
  323. this.getOrgTreeList();
  324. this.getPeopleList();
  325. }
  326. };
  327. </script>
  328. <style lang="scss" scoped>
  329. /deep/ .gm-scroll-view {
  330. width: 568px !important;
  331. height: 510px !important;
  332. // /deep/ .gm-scrollbar.-horizontal .thumb {
  333. // height: 0;
  334. // }
  335. }
  336. .organ-trees-view {
  337. box-sizing: border-box;
  338. float: left;
  339. &::before {
  340. clear: both;
  341. }
  342. .tree-house-style-box {
  343. position: absolute;
  344. top: 38px;
  345. left: 0%;
  346. background: #fff;
  347. width: 568px;
  348. height: 510px;
  349. z-index: 999;
  350. padding: 10px 10px 50px 10px;
  351. z-index: 99;
  352. box-shadow: 0px 2px 10px 0px #e6ebf4;
  353. }
  354. .transfer-style-box {
  355. position: absolute;
  356. top: 68px;
  357. left: 0%;
  358. background: #fff;
  359. width: 568px;
  360. height: 480px;
  361. z-index: 999;
  362. padding: 10px 10px 50px 10px;
  363. z-index: 99;
  364. box-shadow: 0px 2px 10px 0px #e6ebf4;
  365. }
  366. .end-btn {
  367. position: absolute;
  368. right: 30px;
  369. bottom: 10px;
  370. }
  371. }
  372. </style>