-
Notifications
You must be signed in to change notification settings - Fork 38
/
DocumentOperatorEdit.vue
89 lines (84 loc) · 2.42 KB
/
DocumentOperatorEdit.vue
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
<template>
<el-button
v-bind="triggerConfig"
@click="getEditFields"
>
{{ triggerConfig.text }}
</el-button>
</template>
<script>
import _id_mixin from '@/mixins/document/_id_mixin';
import {
logError,
hasOwnProperty,
} from '@/widget/utility';
import SingletonDialogEditors from '@/components/common/Editors/SingletonDialogEditors';
import _edit_mixin from './_edit_mixin';
export default {
name: 'DocumentOperatorEdit',
mixins: [
_id_mixin,
_edit_mixin,
],
props: {
data: {
type: Object,
required: true,
},
triggerConfig: {
type: Object,
default () {
return {};
},
},
},
singleton: {
singletonDialogEditors: null,
},
methods: {
showDialog () {
this.singletonDialogEditors = this.$singleton(
SingletonDialogEditors,
{
...this.$attrs,
fields: this.fields,
editableFields: this.editableFields,
record: this.record,
handleConfirm: this.handleConfirm,
mode: 'edit',
},
this.$root
);
this.singletonDialogEditors.show();
},
getEditFields () {
this.getEditInfo(this.data).then(({
editableFields,
record,
}) => {
editableFields.forEach((field) => {
if (!hasOwnProperty(record, field)) {
const configDefault = this.fields[field].editor.default;
record[field] = typeof configDefault === 'function' ? configDefault.call(this, field) : configDefault;
}
});
this.editableFields = editableFields;
this.record = record;
this.showDialog();
}).catch(logError);
},
handleConfirm (data) {
if (this.isUpdating) {
return;
}
this.isUpdating = true;
this.doEditRequest(this.transformData(data)).then(() => {
this.singletonDialogEditors.hide();
this.$emit('update');
}).catch(logError).finally(() => {
this.isUpdating = false;
});
},
},
};
</script>