LicensePlate.js
1.35 KB
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
// components/LicensePlate/LicensePlate.js
const list = '京津晋冀蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼渝川贵云藏陕甘青宁新'
import {componentsMixin } from '../../mixins/index'
Component({
behaviors:[componentsMixin],
/**
* 组件的属性列表
*/
properties: {
show: Boolean,
activeItem: String
},
observers: {
'activeItem': function (newVal) {
this.init()
}
},
/**
* 组件的初始数据
*/
data: {
licensePlateList: []
},
lifetimes: {
attached() {
this.init()
}
},
/**
* 组件的方法列表
*/
methods: {
choose(e) {
let { index } = e.currentTarget.dataset
let { licensePlateList } = this.data
licensePlateList.map(e => e.active = false)
licensePlateList[index].active = true
let platPrefix = licensePlateList[index].text
this.setData({ licensePlateList, platPrefix })
},
confirm() {
let { platPrefix } = this.data
this.triggerEvent('confirm', platPrefix || '')
this.setData({
show: false
})
},
init() {
let { activeItem } = this.data
let licensePlateList = []
list.split('').map(e => {
licensePlateList.push({
text: e,
active: activeItem == e
})
})
this.setData({
licensePlateList
})
}
}
})