Blame view

ceres-uniapp-master/components/lb-picker/mixins/index.js 2.23 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
  import { getColumns, isObject, isFunction } from '../utils'
  export const commonMixin = {
    data () {
      return {
        isConfirmChange: false,
        indicatorStyle: `height: 34px`,
        pressTimeout: null
      }
    },
    created () {
      this.init('init')
    },
    methods: {
      init (changeType) {
        if (this.list && this.list.length) {
          const column = getColumns({
            value: this.value,
            list: this.list,
            mode: this.mode,
            props: this.props,
            level: this.level
          })
          const { columns, value, item, index } = column
          this.selectValue = value
          this.selectItem = item
          this.pickerColumns = columns
          this.pickerValue = index
          this.$emit('change', {
            value: this.selectValue,
            item: this.selectItem,
            index: this.pickerValue,
            change: changeType
          })
        }
      },
      touchstart (e) {
        if (!this.pressEnable) return
        clearTimeout(this.pressTimeout)
        this.pressTimeout = setTimeout(() => {
          let item = {}
          let toastTitle = ''
          // #ifdef APP-NVUE
          item = e.target.dataset.item
          // #endif
  
          // #ifdef H5
          item = JSON.parse(e.currentTarget.dataset.item)
          // #endif
  
          // #ifndef APP-NVUE || H5
          item = e.currentTarget.dataset.item
          // #endif
  
          // #ifdef APP-PLUS || H5
          toastTitle = this.getLabel(item)
          // #endif
  
          // #ifndef APP-PLUS || H5
          toastTitle = item[this.props.label] || item
          // #endif
          uni.showToast({
            title: toastTitle,
            icon: 'none'
          })
        }, this.pressTime)
      },
      touchmove () {
        if (!this.pressEnable) return
        clearTimeout(this.pressTimeout)
      },
      touchend () {
        if (!this.pressEnable) return
        clearTimeout(this.pressTimeout)
      },
      getLabel (item, rowIndex, columnIndex) {
        if (this.formatter && isFunction(this.formatter)) {
          return this.formatter({ item, rowIndex, columnIndex })
        } else {
          return item[this.props.label] || item
        }
      }
    },
    watch: {
      value () {
        if (!this.isConfirmChange) {
          this.init('value')
        }
      },
      list () {
        this.init('list')
      }
    }
  }