11
jhzh
2024-08-01 69518ee75abbbd000c913e4b8bc045dd5c7dd3ed
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<template>
  <div class="px-32">
    <div class="flex justify-between box-border items-center">
      <div class="text-grey font-26">{{ $t(title) }}</div>
      <div class="font-26" @click="show = !show">
        <span class="mr-17 text-color">{{ $t("全部") }}</span>
        <van-icon name="arrow-down" class="text-color" />
      </div>
    </div>
    <div class="select-wrapper mt-35" :class="{ show: show }">
      <div
        v-if="dataType() === '[object Object]'"
        class="relative h-82 lh-82 text-center rounded-xl font-28 c2cColor box-border tabBackground"
        @click="handlerClick({ code: 99 })"
        :class="{ active: value === 99 }"
      >
        <img
          v-show="value === 99"
          class="absolute top-0 left-0 w-full h-full"
          :src="require('@/assets/image/c2c/Group317.png')"
          alt=""
        />
        {{ $t("全部") }}
      </div>
      <div
        class="relative text-center rounded-xl font-28 c2cColor box-border tabBackground px-6 py-10"
        v-for="(item, index) in options"
        :key="index"
        @click="handlerClick(item)"
        :class="{ active: a(value, item) }"
      >
        <img
          v-show="a(value, item)"
          class="absolute top-0 left-0 w-full h-full"
          :src="require('@/assets/image/c2c/Group317.png')"
          alt=""
        />
        {{ item.title || item.name }}
      </div>
    </div>
  </div>
</template>
 
<script>
import { Icon } from "vant";
 
export default {
  name: "SelectItem",
  props: ["title", "options", "value"],
  data() {
    return {
      activeIndex: 0,
      show: false,
    };
  },
  created() {
    console.log(this.options);
    // const type = Object.prototype.toString.call(this.options)
    // if (type === '[object Array]') {
    //   this.activeIndex = 0;
    // } else {
    //   const keys = Object.keys(this.options)
    //   console.log(keys[0]);
    //   this.activeIndex = this.options[keys[0]].code;
    // }
  },
  methods: {
    handlerClick(item) {
      let val;
      if (item.method_type || item.method_type === 0) {
        console.log(item.method_type);
        val = item.method_type;
      } else {
        val = item.code;
      }
      console.log(val);
      // this.activeIndex = index;
      this.$emit("input", val);
    },
    dataType() {
      return Object.prototype.toString.call(this.options);
    },
    a(a, item) {
      let val;
      if (item.method_type || item.method_type === 0) {
        val = item.method_type;
      } else {
        val = item.code;
      }
      return a === val;
    },
  },
  components: {
    [Icon.name]: Icon,
  },
};
</script>
 
<style lang="scss" scoped>
.text-color {
  color: #868d9a;
}
 
.show {
  height: 310px !important;
}
 
.active {
  border-color: #1d91ff !important;
}
 
.select-wrapper {
  overflow-y: scroll;
  height: 82px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 32px;
  transition: all ease 0.4s;
  //background: #00ff33;
 
  & > div {
    border-width: 1px;
    border-style: solid;
 
    @include themify() {
      border-color: themed("tab_background");
    }
  }
}
</style>