Blame view

ceres-uniapp-master/components/lb-picker/pickers/unlinked-selector-picker.vue 3.29 KB
3f535f30   杨鑫   '初始'
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
  <template>
    <view class="lb-selector-picker lb-picker-item"
      :style="{ height: height }">
      <picker-view :value="pickerValue"
        :indicator-style="indicatorStyle"
        :style="{ height: height }"
        @change="handleChange">
        <picker-view-column v-for="(column, index) in pickerColumns"
          :key="index">
          <!-- #ifdef H5 -->
          <view v-for="(item, i) in column || []"
            :class="[
  				    'lb-picker-column',
  				    (item[props.value] || item) === selectValue[index]
  				      ? 'lb-picker-column-active'
  				      : ''
  				  ]"
            :key="i"
            :data-item="pressEnable ? JSON.stringify(item) : ''"
            @touchstart="touchstart"
            @touchmove="touchmove"
            @touchend="touchend">
            <!-- #endif -->
            <!-- #ifndef H5 -->
            <view v-for="(item, i) in column || []"
              :class="[
              'lb-picker-column',
              (item[props.value] || item) === selectValue[index]
                ? 'lb-picker-column-active'
                : ''
            ]"
              :key="i"
              :data-item="item"
              @touchstart="touchstart"
              @touchmove="touchmove"
              @touchend="touchend">
              <!-- #endif -->
              <!-- #ifdef APP-PLUS || H5 -->
              <text :class="[
                'lb-picker-column-label',
                `lb-picker-column-label-${align}`
              ]"
                :style="[
                (item[props.value] || item) === selectValue[index]
                ? activeColumnStyle
                : columnStyle
              ]">{{ getLabel(item, i, index) }}</text>
              <!-- #endif -->
  
              <!-- #ifndef APP-PLUS || H5 -->
              <text :class="[
                'lb-picker-column-label',
                `lb-picker-column-label-${align}`
              ]">{{ item[props.label] || item }}</text>
              <!-- #endif -->
            </view>
        </picker-view-column>
      </picker-view>
    </view>
  </template>
  
  <script>
  import { isObject } from '../utils'
  import { commonMixin } from '../mixins'
  export default {
    props: {
      value: Array,
      list: Array,
      mode: String,
      props: Object,
      visible: Boolean,
      height: String,
      columnStyle: Object,
      activeColumnStyle: Object,
      align: String,
      pressEnable: Boolean,
      pressTime: Number,
      formatter: Function
    },
    mixins: [commonMixin],
    data () {
      return {
        pickerValue: [],
        pickerColumns: [],
        selectValue: [],
        selectItem: []
      }
    },
    methods: {
      handleChange (item) {
        const pickerValue = item.detail.value
        const columnIndex = pickerValue.findIndex((item, i) => item !== this.pickerValue[i])
        if (columnIndex > -1) {
          const valueIndex = pickerValue[columnIndex]
          const columnItem = this.list[columnIndex][valueIndex]
          const valueItem = isObject(columnItem)
            ? columnItem[this.props.value]
            : columnItem
          this.pickerValue = pickerValue
          this.$set(this.selectValue, columnIndex, valueItem)
          this.$set(this.selectItem, columnIndex, columnItem)
          this.$emit('change', {
            value: this.selectValue,
            item: this.selectItem,
            index: this.pickerValue,
            change: 'scroll'
          })
        }
      }
    }
  }
  </script>
  
  <style lang="scss" scoped>
  @import "../style/picker-item.scss";
  </style>