fei.wang
7 天以前 ae7b22322555448d95fd56f505bafa325c167a26
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<template>
  <view class="filter">
    <view class="label">{{label}}:</view>
    <view style="flex: 1;">
      <uni-data-select v-model="current" :disabled="disabled" placement="top" :localdata="data" @change="change"></uni-data-select>
    </view>
  </view>
</template>
 
<script>
  export default {
    props: {
      modelValue: {
        type: [String, Number],
        default: ''
      },
      label: {
        type: String,
        default: ''
      },
      data: {
        type: Array,
        default: []
      },
      valueType: {
        type: String,
        default: 'text'
      },
      disabled: {
        type: Boolean,
        default: false
      }
    },
 
    watch: {
      value: {
        handler: function(val) {
          if (this.valueType === 'text') {
            this.current = this.data.findIndex(item => item.text === val);
          } else {
            this.current = this.data.findIndex(item => item.value === val);
          }
        },
        immediate: true
      },
      data: {
        handler: function(val) {
          if (this.valueType === 'text') {
            this.current = this.data.findIndex(item => item.text === this.modelValue);
          } else {
            this.current = this.data.findIndex(item => item.value === this.modelValue);
          }
        },
        immediate: true,
        deep: true
      }
    },
    data() {
      return {
        current: 0
      }
    },
    methods: {
      change(e) {
        if (this.valueType === 'text') {
          this.$emit('update:modelValue', this.data[e]?.text);
        } else {
          this.$emit('update:modelValue', this.data[e]?.value);
        }
      }
    }
  }
</script>
 
<style lang="scss" scoped>
  .filter {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 1px;
  }
 
  .label {
    width: 70px;
    text-align: right;
  }
</style>