Blame view

pages/apply/dynamicModel/components/form/index.vue 3.89 KB
290144e9   易尊强   第一次
1
  <template>
9b1c150c   “wangming”   1
2
3
4
5
6
7
8
9
  	<view class="ncc-wrap ncc-wrap-form"  style="width: 96%;margin: 0 auto;margin-top: 20rpx; background-color: white;border-radius: 20rpx;padding-bottom: 15rpx;">
  		<view class="titleall-box">
  			<view class="titleall-left">
  				<view class="titleall-left-line"></view>填写信息
  			</view>
  		</view>
  		<ncc-parser :formConf="formData" ref="dynamicForm" v-if="!loading" @submit="sumbitForm" :key="key" style="padding-bottom: 70rpx;"/>
  		<view class="buttom-actions" style="margin: 0 auto;width: 96%;">
290144e9   易尊强   第一次
10
  			<u-button class="buttom-btn" @click="resetForm">重置</u-button>
9b1c150c   “wangming”   1
11
  			<u-button class="buttom-btn" type="primary" style="background-color: #e60012;" @click="submit" :loading="btnLoading">
290144e9   易尊强   第一次
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
  				{{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() {
9b1c150c   “wangming”   1
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  				var  dformData = {}
  				// console.log('本地数据',localData)
  				let localData = uni.getStorageSync(this.modelId)
  				if(localData){
  					// this.formData = JSON.parse(localData)
  					dformData = JSON.parse(localData)
  					console.log('本地数据2',dformData)
  					this.formData = JSON.parse(this.config.formData)
  				}else{
  					this.formData = JSON.parse(this.config.formData)
  				}
  				// this.formData = JSON.parse(this.config.formData)
  				
  				// var  dformData = {ZhiWu:'111111'}
  				
  				this.fillFormData(this.formData, dformData)
  				
  				
  				console.log('formdata',this.formData)
290144e9   易尊强   第一次
59
60
61
62
63
64
  				this.loading = true
  				this.$nextTick(() => {
  					this.loading = false
  					this.key = +new Date()
  				})
  			},
9b1c150c   “wangming”   1
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
  			fillFormData(form, data) {
  				const loop = list => {
  					for (let i = 0; i < list.length; i++) {
  						let item = list[i]
  						if (item.__vModel__) {
  							const val = data[item.__vModel__]
  							if (val) item.__config__.defaultValue = val
  						}
  						if (item.__config__ && item.__config__.nccKey !== 'table' && item.__config__.children && Array
  							.isArray(item.__config__.children)) {
  							loop(item.__config__.children)
  						}
  					}
  				}
  				loop(form.fields)
  			},
  			
290144e9   易尊强   第一次
82
83
  			sumbitForm(data) {
  				if (!data) return
9b1c150c   “wangming”   1
84
  				// this.btnLoading = true
290144e9   易尊强   第一次
85
  				this.dataForm.data = JSON.stringify(data)
9b1c150c   “wangming”   1
86
87
88
89
  				console.log('数据格式',this.dataForm)
  				console.log('数据格式2',data)
  				// localStorage.setItem(this.modelId,this.dataForm.data)
  				uni.setStorageSync(this.modelId,this.dataForm.data)
290144e9   易尊强   第一次
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
  				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()
9b1c150c   “wangming”   1
113
114
  				console.log('表单json',this.$refs.dynamicForm)
  				
290144e9   易尊强   第一次
115
116
117
118
119
120
121
122
123
124
125
126
  			},
  			resetForm() {
  				this.loading = true
  				this.key = +new Date()
  				this.$nextTick(() => {
  					this.loading = false
  					this.$refs.dynamicForm && this.$refs.dynamicForm.resetForm()
  				})
  			}
  		}
  	}
  </script>
9b1c150c   “wangming”   1
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
  <style lang="scss" scoped>
  	.titleall-box {
  		display: flex;
  		justify-content: space-between;
  		padding: 40rpx 20rpx 20rpx 0;
  		.titleall-left {
  			font-size: 32rpx;
  			font-weight: bold;
  			display: flex;
  			align-items: center;
  			.titleall-left-line {
  				width: 14rpx;
  				height: 36rpx;
  				border-radius: 0 10rpx 10rpx 0;
  				background-color: #E60012;
  				box-shadow: 0 0 10rpx 5rpx #fbdadc;
  				margin-right: 20rpx;
  			}
  			text {
  				font-size: 28rpx;
  				color: #999999;
  			}
  		}
  	}
  </style>