1
jhzh
2025-04-20 d157d0892f1ab5517dbe3a08328ccb9c4e446615
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
import Vue from "vue";
import picker from "./picker";
 
let BoxConstructor = Vue.extend(picker)
let $picker = function (columns, config) {
    let defaultConfig = Object.assign({
        title: this.$t('common.select')
    }, config)
    return new Promise((res, err) => {
        let instance = new BoxConstructor({
            el: document.createElement('div'),
            data() {
                return {
                    show: false,
                    columns: [
                        {
                            values: columns.map(item => item.label),
                            defaultIndex: columns.findIndex(item => item.value == defaultConfig.value) || 0
                        }
                    ],
                    title: defaultConfig.title
                }
            },
            methods: {
                close() {
                    this.show = false
                    let $el = instance.$el
                    setTimeout(() => {
                        instance.$destroy()
                        if ($el.parentNode) {
                            $el.parentNode.removeChild($el)
                        }
                    }, 600)
                },
                input(boo) {
                    if (boo) {
                        this.show = boo
                    } else {
                        this.close()
                    }
                },
                onConfirm(value, index) {
                    this.close()
                    res(columns[index].value, value)
                },
                onCancel() {
                    this.close()
                    err()
                },
                onChange() { }
            },
            mounted() {
                this.$nextTick(() => {
                    this.show = true
                })
            },
        })
        document.body.appendChild(instance.$el);
    })
 
 
}
export {
    $picker
}