cascader.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <div id="cascaderMap">
  3. <span class="buildFloor" style="margin-right: 12px;">设备类别</span>
  4. <el-cascader
  5. placeholder="请选择"
  6. :options="options"
  7. v-model="value"
  8. :props="props"
  9. filterable
  10. :style="isWidth ? '' : 'width:160px;'"
  11. size="small"
  12. @change="changeVal"
  13. change-on-select
  14. ></el-cascader>
  15. </div>
  16. </template>
  17. <script>
  18. import { getEqCode } from "@/api/scan/request";
  19. export default {
  20. name: "getCode",
  21. props: {
  22. isWidth: {
  23. type: Boolean,
  24. default: true
  25. },
  26. isAll: {
  27. type: Boolean,
  28. default: false,
  29. }
  30. },
  31. data() {
  32. return {
  33. value: [""],
  34. options: [],
  35. props: {
  36. value: "code",
  37. label: "facility"
  38. },
  39. falg: true,
  40. content: []
  41. };
  42. },
  43. created() {
  44. this.getData();
  45. },
  46. mounted() { },
  47. methods: {
  48. setValue(val) {
  49. this.value = val
  50. },
  51. //修改val
  52. changeVal(val) {
  53. let value = {}
  54. this.options.map(item => {
  55. if (item.code == val) {
  56. value = item
  57. }
  58. })
  59. this.value = val
  60. this.$emit("change", value)
  61. },
  62. async getData() {
  63. await getEqCode().then(res => {
  64. if (this.isAll) {
  65. let data = this.changeArr(res.data.Content)
  66. data.unshift({
  67. code: "all",
  68. facility: "全部"
  69. });
  70. this.options = data
  71. console.log(this.options, "options")
  72. this.value = ["all"]
  73. } else {
  74. this.options = this.changeArr(res.data.Content);
  75. }
  76. if (!!this.value && this.value.length) {
  77. let value = {}
  78. this.options.map(item => {
  79. if (item.code == this.value[0]) {
  80. value = item
  81. }
  82. })
  83. this.$emit("change", value)
  84. }
  85. if (!this.falg) {
  86. this.changeList()
  87. }
  88. });
  89. },
  90. changeArr(arr) {
  91. let data = [];
  92. arr.map(item => {
  93. if (item.content && item.content.length) {
  94. return item.content.map(children => {
  95. if (children.content && children.content.length) {
  96. return children.content.map(i => {
  97. data.push(i);
  98. });
  99. }
  100. });
  101. }
  102. });
  103. return data;
  104. },
  105. pushData(content) {
  106. this.content = content
  107. if (this.options.length) {
  108. this.falg = true
  109. this.changeList()
  110. } else {
  111. this.falg = false
  112. }
  113. },
  114. changeList() {
  115. this.options.map(item => {
  116. item.disabled = true
  117. this.content.map(child => {
  118. if (item.code == child) {
  119. item.disabled = false
  120. }
  121. })
  122. })
  123. }
  124. }
  125. };
  126. </script>
  127. <style lang="less" scoped>
  128. #cascaderMap {
  129. float: left;
  130. margin-left: 10px;
  131. .buildFloor {
  132. color: #999999;
  133. font-size: 14px;
  134. }
  135. }
  136. </style>