Просмотр исходного кода

【质检工单】取样,单位支持搜索

hezhanp 8 месяцев назад
Родитель
Сommit
d22cd9236b

+ 64 - 55
src/components/Dict/DictSelection.vue

@@ -1,9 +1,12 @@
 <template>
+  <!-- 1. 添加filterable开启输入过滤,filter-placeholder设置输入提示 -->
   <el-select
     v-model="selectVal"
     style="width: 100%"
     v-bind="$attrs"
     v-on="$listeners"
+    filterable
+    :filter-placeholder="filterPlaceholder"
   >
     <el-option
       v-for="item in dictList"
@@ -15,64 +18,70 @@
 </template>
 
 <script>
-  import dictEnum from '@/enum/dict';
-  import { mapActions, mapGetters } from 'vuex';
-  export default {
-    model: {
-      prop: 'value',
-      event: 'updateVal'
+import dictEnum from '@/enum/dict';
+import { mapActions, mapGetters } from 'vuex';
+
+export default {
+  model: {
+    prop: 'value',
+    event: 'updateVal'
+  },
+  props: {
+    // 原有props保留
+    value: {
+      type: [String, Number],
+      default: ''
     },
-    props: {
-      value: {
-        type: [String, Number],
-        default: ''
-      },
-      dictName: {
-        type: String,
-        required: true
-      },
-      labelName: {
-        type: String,
-        default: 'dictValue'
-      },
-      valueName: {
-        type: String,
-        default: 'dictCode'
-      },
-      listFormatte: Function
+    dictName: {
+      type: String,
+      required: true
     },
-    data () {
-      return {};
+    labelName: {
+      type: String,
+      default: 'dictValue'
     },
-    computed: {
-      ...mapGetters(['dict', 'getDict']),
-      dictList () {
-        return (
-          (this.listFormatte &&
-            this.listFormatte(this.dict[dictEnum[this.dictName]] || [])) ||
-          this.dict[dictEnum[this.dictName]] ||
-          []
-        );
-      },
-      selectVal: {
-        set (val) {
-          this.$emit('updateVal', val);
-          // change获取选中项所有数据
-
-          this.$emit('itemChange', this.getDict(this.dictName, val));
-        },
-        get () {
-          return this.value;
-        }
-      }
+    valueName: {
+      type: String,
+      default: 'dictCode'
     },
-    created () {
-      if (this.dictName) {
-        this.requestDict(this.dictName);
-      }
+    listFormatte: Function,
+    // 2. 新增props:输入框提示文字(可选,默认给默认值)
+    filterPlaceholder: {
+      type: String,
+      default: '请输入关键词搜索'
+    }
+  },
+  data() {
+    return {};
+  },
+  computed: {
+    ...mapGetters(['dict', 'getDict']),
+    dictList() {
+      // 原有字典数据逻辑不变,过滤由el-select自动处理
+      return (
+        (this.listFormatte &&
+          this.listFormatte(this.dict[dictEnum[this.dictName]] || [])) ||
+        this.dict[dictEnum[this.dictName]] ||
+        []
+      );
     },
-    methods: {
-      ...mapActions('dict', ['requestDict'])
+    selectVal: {
+      set(val) {
+        this.$emit('updateVal', val);
+        this.$emit('itemChange', this.getDict(this.dictName, val));
+      },
+      get() {
+        return this.value;
+      }
+    }
+  },
+  created() {
+    if (this.dictName) {
+      this.requestDict(this.dictName);
     }
-  };
-</script>
+  },
+  methods: {
+    ...mapActions('dict', ['requestDict'])
+  }
+};
+</script>

+ 7 - 7
src/views/inspectionWork/components/newQualityContentTabs.vue

@@ -79,13 +79,13 @@
                     style="margin: 0"
                   >
                     <DictSelection
-                      dictName="计量单位"
-                      clearable
-                      v-model="formData.sampleUnit"
-                      size="mini"
-                      @change="changeSamUnit"
-                    >
-                    </DictSelection>
+  dictName="计量单位"
+  clearable
+  v-model="formData.sampleUnit"
+  size="mini"
+  filter-placeholder="请输入计量单位搜索"  
+  @change="changeSamUnit"
+></DictSelection>
                   </el-form-item>
                 </el-col>
                 <el-col :span="8" v-if="conditionType == 2">