index_1.vue
1.77 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<template>
<view class="ncc-wrap ncc-wrap-form">
<ncc-parser :formConf="formData" ref="dynamicForm" v-if="!loading" @submit="sumbitForm" :key="key" />
<view class="buttom-actions">
<u-button class="buttom-btn" @click="resetForm">重置</u-button>
<u-button class="buttom-btn" type="primary" @click="submit" :loading="btnLoading">
{{formData.confirmButtonText||'确定'}}
</u-button>
</view>
</view>
</template>
<script>
import {
createModel
} from '@/api/apply/visualDev'
export default {
props: ['config', 'modelId', 'isPreview'],
data() {
return {
dataForm: {
data: ''
},
formData: {},
key: +new Date(),
btnLoading: false,
loading: true,
}
},
created() {
this.init()
},
methods: {
init() {
this.formData = JSON.parse(this.config.formData)
this.loading = true
this.$nextTick(() => {
this.loading = false
this.key = +new Date()
})
},
sumbitForm(data) {
if (!data) return
this.btnLoading = true
this.dataForm.data = JSON.stringify(data)
createModel(this.modelId, this.dataForm).then(res => {
uni.showToast({
title: res.msg,
complete: () => {
setTimeout(() => {
this.btnLoading = false
uni.navigateBack()
}, 1500)
}
})
}).catch(() => {
this.btnLoading = false
})
},
submit() {
if (this.isPreview == '1') {
uni.showToast({
title: '功能预览不支持数据保存',
icon: 'none'
})
return
}
this.$refs.dynamicForm && this.$refs.dynamicForm.submitForm()
},
resetForm() {
this.loading = true
this.key = +new Date()
this.$nextTick(() => {
this.loading = false
this.$refs.dynamicForm && this.$refs.dynamicForm.resetForm()
})
}
}
}
</script>