ObjLocation.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /**
  2. @author:guoguo
  3. @date:2018.11.30
  4. @info: 对象位置
  5. **/
  6. <template>
  7. <el-cascader
  8. style="width: 249px;"
  9. placeholder="对象位置"
  10. :options="options"
  11. :value="value"
  12. @active-item-change="handleItemChange"
  13. @change="change"
  14. :props="configObj"
  15. ></el-cascader>
  16. </template>
  17. <script>
  18. export default {
  19. name: "obj-location",
  20. data() {
  21. return {
  22. options: [{
  23. value: 'zhinan',
  24. label: '指南',
  25. children:[]
  26. }],
  27. configObj: {
  28. label: "name",
  29. value: "id",
  30. },
  31. value: []
  32. }
  33. },
  34. props:{
  35. projectId: {
  36. type: String,
  37. required: true
  38. }
  39. },
  40. methods: {
  41. //id=[建筑id|楼层Id]
  42. getList(type, id, BdId) {
  43. let params = {
  44. criteria:{
  45. id: id || undefined,
  46. type: [type]
  47. }
  48. }
  49. this.postJson(`/server/dataplatform/object/subquery?projectId=${this.projectId}`, params, resp => {
  50. if (resp.Result === 'success' && resp.Count) {
  51. if(type == "Bd") {
  52. this.handleBd(resp.Content);
  53. } else if ( type == "Fl") {
  54. this.handleFl(resp.Content, id)
  55. } else {
  56. this.handleSp(resp.Content, BdId, id)
  57. }
  58. } else { //如果是室外
  59. if(type == "Sp") {
  60. let arr = [this.allItem()];
  61. this.options.forEach(item => {
  62. item.children?item.children.forEach(ele => {
  63. if(ele.id == id) {
  64. ele.children = arr;
  65. }
  66. }):""
  67. })
  68. }
  69. }
  70. })
  71. },
  72. handleBd(content) {
  73. let arr = [];
  74. content.forEach(item=> {
  75. let obj = {
  76. id: item.id,
  77. name: item.infos.BuildLocalName,
  78. children: []
  79. }
  80. arr.push(obj);
  81. })
  82. this.options = arr;
  83. this.options.unshift(this.allBdItem())
  84. },
  85. handleFl(content, id) {
  86. let arr = [];
  87. content.forEach(item=> {
  88. let obj = {
  89. id: item.id,
  90. name: item.infos.FloorLocalName,
  91. children:[]
  92. }
  93. arr.push(obj);
  94. })
  95. this.options.forEach(item => {
  96. if(item.id == id) {
  97. item.children = arr
  98. }
  99. })
  100. },
  101. handleSp(content, BdId, flId) {
  102. let arr = []
  103. content.forEach(item => {
  104. let obj = {
  105. id: item.id,
  106. name: item.infos.RoomLocalName,
  107. }
  108. arr.push(obj);
  109. });
  110. arr.unshift(this.allItem())
  111. this.options.forEach(item => {
  112. if(item.id == BdId) {
  113. item.children.forEach(ele => {
  114. if(ele.id == flId) {
  115. ele.children = arr;
  116. }
  117. })
  118. }
  119. })
  120. },
  121. allBdItem() {
  122. return {id: "", name: "对象位置:全部"}
  123. },
  124. allItem() {
  125. return {id: "" , name: "全部"}
  126. },
  127. handleItemChange(val) {
  128. if(val.length == 1 && val[0]) {
  129. this.getList( "Fl", val[0]);
  130. } else if(val.length == 2){
  131. this.getList( "Sp", val[1], val[0]);
  132. }
  133. },
  134. change(val) {
  135. let id = val[val.length - 1];
  136. if(val.length > 1 && !val[val.length-1]){
  137. id = val[val.length-2];
  138. }
  139. this.$emit("change", id)
  140. }
  141. },
  142. watch: {
  143. projectId: {
  144. immediate: true,
  145. handler(val){
  146. this.getList("Bd")
  147. }
  148. }
  149. }
  150. }
  151. </script>