dengjunjie
5 天以前 4f39dcc195f28fa275fc2d065fbf1bf6a46c21b7
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<template>
  <view
    class="tn-list-view-class tn-list-view"
    :class="[
      backgroundColorClass,
      viewClass
    ]"
    :style="[viewStyle]"
  >
    <view
      v-if="showTitle"
      class="tn-list-view__title"
      :class="[
        fontColorClass
      ]"
      :style="[titleStyle]"
      @tap="handleClickTitle"
    >{{ title }}</view>
    
    <view
      v-else
      :class="[{'tn-list-view__title--card': card}]"
      @tap="handleClickTitle"
    >
      <slot name="title"></slot>
    </view>
    
    <view
      class="tn-list-view__content tn-border-solid-top tn-border-solid-bottom"
      :class="[contentClass]"
    >
      <slot></slot>
    </view>
  </view>
</template>
 
<script>
  import componentsColorMixin from '../../libs/mixin/components_color.js'
  export default {
    mixins: [ componentsColorMixin ],
    name: 'tn-list-view',
    props: {
      // 标题
      title: {
        type: String,
        default: ''
      },
      // 去掉边框 上边框 top, 下边框 bottom, 所有边框 all
      unlined: {
        type: String,
        default: 'all'
      },
      // 上外边距
      marginTop: {
        type: String,
        default: ''
      },
      // 内容是否显示为卡片模式
      card: {
        type: Boolean,
        default: false
      },
      // 是否自定义标题
      customTitle: {
        type: Boolean,
        default: false
      }
    },
    computed: {
      showTitle() {
        return !this.customTitle && this.title
      },
      viewClass() {
        let clazz = ''
        
        if (this.card) {
          clazz += ' tn-list-view--card'
        }
        
        return clazz
      },
      viewStyle() {
        let style = {}
        
        if (this.backgroundColorStyle) {
          style.backgroundColor = this.backgroundColorStyle
        }
        
        if (this.marginTop) {
          style.marginTop = this.marginTop
        }
        
        return style
      },
      titleStyle() {
        let style = {}
        
        if (this.fontColorStyle) {
          style.color = this.fontColorStyle
        }
        if (this.fontSize) {
          style.fontSize = this.fontSize + this.fontUnit
        }
        
        return style
      },
      contentClass() {
        let clazz = ''
        
        if (this.card) {
          clazz += ' tn-list-view__content--card'
        }
        
        switch(this.unlined) {
          case 'top':
            clazz += ' tn-none-border-top'
            break
          case 'bottom':
            clazz += ' tn-none-border-bottom'
            break
          case 'all':
            clazz += ' tn-none-border'
            break
        }
        
        return clazz
      }
    },
    data () {
      return {
        kindShowFlag: this.showKind
      }
    },
    methods: {
      // 处理标题点击事件
      handleClickTitle() {
        if (!this.kindList) return
        this.kindShowFlag = !this.kindShowFlag
        this.$emit("clickTitle", {})
      }
    }
  }
</script>
 
<style lang="scss" scoped>
  
  .tn-list-view {
    background-color: #FFFFFF;
    
    &__title {
      width: 100%;
      padding: 30rpx;
      font-size: 30rpx;
      line-height: 30rpx;
      box-sizing: border-box;
      
      &--card {
        // margin: 0rpx 30rpx;
      }
    }
    
    &__content {
      width: 100%;
      position: relative;
      border-radius: 0;
      
      &--card {
        // width: auto;
        // overflow: hidden;
        // margin-right: 30rpx;
        // margin-left: 30rpx;
        // border-radius: 20rpx
      }
    }
    
    &--card {
      // padding-bottom: 30rpx;
      border-radius: 20rpx;
      overflow: hidden;
    }
    
  }
  
</style>