partsDieList.vue 3.0 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 { getEqCode, getEquipBelongs, queryPartsDie } from "@/api/scan/request";
  11. export default {
  12. name: "getCode",
  13. props: {
  14. isWidth: {
  15. type: Boolean,
  16. default: true
  17. },
  18. Family: {
  19. type: String,
  20. default: '',
  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. mounted() {
  39. if(this.Family != "") {
  40. this.getAllData()
  41. }
  42. },
  43. watch: {
  44. projectId() {
  45. this.value = [''];
  46. this.getAllData()
  47. }
  48. // Family: {
  49. // handler: function (val) {
  50. // if(val != "") {
  51. // this.getAllData()
  52. // }
  53. // },
  54. // immediate: true
  55. // }
  56. },
  57. methods: {
  58. setValue(val) {
  59. if (val && val.length) {
  60. this.value = val
  61. }
  62. },
  63. //修改val
  64. changeVal(val) {
  65. let value = {}
  66. this.options.map(item => {
  67. if (item.code == val) {
  68. value = item
  69. }
  70. })
  71. this.value = val
  72. this.$emit("change", value)
  73. },
  74. //获取当前项目下的设备类型(只拿到编码-需要过滤)
  75. getData() {
  76. let param = {
  77. Distinct: true,
  78. PageNumber: 1,
  79. PageSize: 500,
  80. Projection: [
  81. "Category"
  82. ]
  83. }
  84. queryPartsDie(param, res => {
  85. this.content = res.Content
  86. this.filterForOptions()
  87. let val = this.options.length?[this.options[0].code]:[""]
  88. this.changeVal(val)
  89. })
  90. },
  91. //获取物理世界所有设备类型
  92. getAllData() {
  93. let param = {
  94. data: {
  95. Filters: `Family='${this.Family}'`,
  96. Distinct: true,
  97. Orders: "EquipName asc",
  98. PageNumber: 1,
  99. PageSize: 500,
  100. Projection: [
  101. "EquipCode", "EquipName"
  102. ]
  103. }
  104. }
  105. getEquipBelongs(param, res => {
  106. this.options = this.formatOptions(res.Content)
  107. this.getData()
  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.find(value => value.Category == item.code)) {
  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>