cascader.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <div id="cascaderMap">
  3. <span class="buildFloor" style="margin-right: 12px;">设备类别</span>
  4. <el-cascader placeholder="请选择" :options="options" v-model="value" :props="props" filterable :style="isWidth ? '' : 'width:160px;'" size="small"
  5. @change="changeVal" change-on-select></el-cascader>
  6. </div>
  7. </template>
  8. <script>
  9. import { mapGetters } from 'vuex';
  10. import { getEquipBelongs, queryEquip } from "@/api/scan/request";
  11. export default {
  12. name: "getCode",
  13. props: {
  14. isWidth: {
  15. type: Boolean,
  16. default: true
  17. },
  18. all: {
  19. type: Boolean,
  20. default: false,
  21. }
  22. },
  23. computed: {
  24. ...mapGetters("layout", ["projectId"])
  25. },
  26. data() {
  27. return {
  28. value: [""],
  29. options: [],
  30. props: {
  31. value: "code",
  32. label: "facility"
  33. },
  34. falg: true,
  35. content: []
  36. };
  37. },
  38. created() {
  39. this.getData();
  40. },
  41. watch: {
  42. projectId() {
  43. this.value = [''];
  44. this.getData();
  45. }
  46. },
  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. //获取当前项目下的设备类型(只拿到编码-需要过滤)
  63. getData() {
  64. let param2 = {
  65. Distinct: true,
  66. PageNumber: 1,
  67. PageSize: 500,
  68. Projection: [
  69. "Category"
  70. ]
  71. }
  72. let param1 = {
  73. data: {
  74. Distinct: true,
  75. Orders: "EquipName asc",
  76. PageNumber: 1,
  77. PageSize: 500,
  78. Projection: [
  79. "EquipCode", "EquipName"
  80. ]
  81. }
  82. }
  83. let promise2 = new Promise((resolve, reject) => {
  84. queryEquip(param2, res => {
  85. resolve(res)
  86. })
  87. })
  88. let promise1 = new Promise((resolve, reject) => {
  89. getEquipBelongs(param1, res => {
  90. resolve(res)
  91. })
  92. })
  93. Promise.all([promise1,promise2]).then((res) => {
  94. let allData = res[0], data = res[1]
  95. this.options = this.formatOptions(allData.Content)
  96. if (this.value) {
  97. this.changeVal(this.value)
  98. }
  99. if(!this.all) {
  100. this.content = data.Content.map(t => {
  101. return t.Category
  102. });
  103. this.filterForOptions();
  104. if (this.value) {
  105. this.changeVal(this.value)
  106. }
  107. }
  108. })
  109. },
  110. //格式化options数据
  111. formatOptions(arr) {
  112. let data = [];
  113. arr.map(t => {
  114. let temp = {};
  115. temp.code = t.EquipCode;
  116. temp.facility = t.EquipName;
  117. data.push(temp)
  118. })
  119. return data;
  120. },
  121. //过滤
  122. filterForOptions() {
  123. this.options = this.options.filter(item => {
  124. if (this.content.indexOf(item.code) > -1) {
  125. return item
  126. }
  127. })
  128. }
  129. }
  130. };
  131. </script>
  132. <style lang="less" scoped>
  133. #cascaderMap {
  134. float: left;
  135. margin-left: 10px;
  136. .buildFloor {
  137. color: #999999;
  138. font-size: 14px;
  139. }
  140. }
  141. </style>