assets.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <div id="cascaderMap">
  3. <span class="buildFloor" style="padding-right: 12px;">设备族</span>
  4. <el-select v-model="value" placeholder="请选择" clearable :props="props" filterable
  5. :style="isWidth ? '' : 'width:160px;'" size="small" @change="changeVal">
  6. <el-option v-for="item in options" :key="item.code" :label="item.facility" :value="item.code"></el-option>
  7. </el-select>
  8. <!-- <el-cascader
  9. placeholder="请选择"
  10. :options="options"
  11. v-model="value"
  12. :props="props"
  13. filterable
  14. :style="isWidth ? '' : 'width:160px;'"
  15. size="small"
  16. @change="changeVal"
  17. change-on-select
  18. ></el-cascader> -->
  19. </div>
  20. </template>
  21. <script>
  22. import { mapGetters } from 'vuex';
  23. import { getEquipBelongs, queryProperty } from "@/api/scan/request";
  24. export default {
  25. name: "getCode",
  26. props: {
  27. isWidth: {
  28. type: Boolean,
  29. default: true
  30. },
  31. all: {
  32. type: Boolean,
  33. default: false,
  34. }
  35. },
  36. computed: {
  37. ...mapGetters("layout", [
  38. "projectId",
  39. ])
  40. },
  41. data() {
  42. return {
  43. value: [],
  44. options: [],
  45. props: {
  46. value: "code",
  47. label: "facility"
  48. },
  49. falg: true,
  50. content: []
  51. };
  52. },
  53. created() {
  54. this.getData();
  55. },
  56. watch: {
  57. projectId() {
  58. this.value = ['']
  59. }
  60. },
  61. methods: {
  62. setValue(val) {
  63. this.value = val
  64. },
  65. //修改val
  66. changeVal(val) {
  67. let value = {}
  68. this.options.map(item => {
  69. if (item.code == val) {
  70. value = item
  71. }
  72. })
  73. this.value = val
  74. this.$emit("change", value)
  75. },
  76. getData() {
  77. let _this = this
  78. let param1 = {
  79. data: {
  80. distinct: true,
  81. pageNumber: 1,
  82. pageSize: 500,
  83. projection: ["family", "familyName"]
  84. }
  85. }, param2 = {
  86. distinct: true,
  87. pageNumber: 1,
  88. pageSize: 500,
  89. projection: [
  90. "family"
  91. ]
  92. }
  93. let promise1 = new Promise((resolve, reject) => {
  94. getEquipBelongs(param1, res => {
  95. resolve(res)
  96. })
  97. })
  98. let promise2 = new Promise((resolve, reject) => {
  99. queryProperty(param2, res => {
  100. resolve(res)
  101. })
  102. })
  103. Promise.all([promise1, promise2]).then((res) => {
  104. let allData = res[0], data = res[1]
  105. _this.options = _this.changeArr(allData.content)
  106. if (_this.value) {
  107. _this.changeVal(this.value)
  108. }
  109. if (!_this.all) {
  110. _this.content = data.content.map(item => {
  111. return item.family
  112. });
  113. _this.changeList();
  114. if (_this.value) {
  115. _this.changeVal(this.value)
  116. }
  117. }
  118. })
  119. // getEquipBelongs(params, res => {
  120. // this.options = this.changeArr(res.Content)
  121. // if (!!this.value && this.value.length) {
  122. // let value = {}
  123. // this.options.map(item => {
  124. // if (item.code == this.value[0]) {
  125. // value = item
  126. // }
  127. // })
  128. // this.$emit("change", value)
  129. // }
  130. // if (!this.falg) {
  131. // this.changeList()
  132. // }
  133. // })
  134. console.log(this.options,'=========================')
  135. },
  136. changeArr(arr) {
  137. let data = [];
  138. arr.map(item => {
  139. data.push({ code: item.family, facility: item.familyName, disabled: false })
  140. });
  141. return data;
  142. },
  143. pushData(content) {
  144. this.content = content
  145. if (this.options.length) {
  146. this.falg = true
  147. this.changeList()
  148. } else {
  149. this.falg = false
  150. }
  151. },
  152. changeList() {
  153. this.options = this.options.filter(item => {
  154. if (this.content.indexOf(item.code) > -1) {
  155. return item
  156. }
  157. })
  158. }
  159. }
  160. };
  161. </script>
  162. <style lang="less" scoped>
  163. #cascaderMap {
  164. float: left;
  165. margin-left: 10px;
  166. .buildFloor {
  167. color: #999999;
  168. font-size: 14px;
  169. }
  170. }
  171. </style>