Form.vue
5.91 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<template>
<el-dialog :title="!dataForm.id ? '新建委托' : '编辑委托'" :close-on-click-modal="false"
:visible.sync="visible" class="NCC-dialog NCC-dialog_center" lock-scroll width="600px">
<el-form ref="dataForm" :model="dataForm" :rules="dataRule" label-width="100px"
v-loading="loading">
<el-form-item label="被委托人" prop="toUserId">
<user-select v-model="dataForm.toUserId" placeholder="选择被委托人" @change="onChange" />
</el-form-item>
<el-form-item label="委托流程" prop="flowId">
<el-select v-model="dataForm.flowId" placeholder="请选择流程" @change="handleChange" filterable>
<el-option-group v-for="group in flowEngineList" :key="group.id"
:label="group.fullName+'【'+group.num+'】'">
<el-option v-for="item in group.children" :key="item.id"
:label="item.fullName+'/'+item.enCode" :value="item.id">
</el-option>
</el-option-group>
</el-select>
</el-form-item>
<el-form-item label="开始时间" prop="startTime">
<el-date-picker v-model="dataForm.startTime" type="date" placeholder="选择日期"
value-format="timestamp" :editable='false' :picker-options="pickerOptions">
</el-date-picker>
</el-form-item>
<el-form-item label="结束时间" prop="endTime">
<el-date-picker v-model="dataForm.endTime" type="date" placeholder="选择日期"
value-format="timestamp" :editable='false' :picker-options="pickerOptions">
</el-date-picker>
</el-form-item>
<el-form-item label="委托说明" prop="description">
<el-input v-model="dataForm.description" placeholder="委托说明" type="textarea" :rows="3" />
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="visible = false">{{$t('common.cancelButton')}}</el-button>
<el-button type="primary" @click="dataFormSubmit()" :loading="btnLoading">
{{$t('common.confirmButton')}}</el-button>
</span>
</el-dialog>
</template>
<script>
import { FlowDelegateInfo, Create, Update } from '@/api/workFlow/FlowDelegate'
import { FlowEngineListAll } from '@/api/workFlow/FlowEngine'
export default {
data() {
var checkStartTime = (rule, value, callback) => {
if (!this.dataForm.endTime) {
callback()
} else {
if (this.dataForm.endTime < value) {
callback(new Error('开始日期应该小于结束日期'));
} else {
this.$refs.dataForm.validateField('endTime');
callback()
}
}
}
var checkEndTime = (rule, value, callback) => {
if (!this.dataForm.startTime) {
callback()
} else {
if (this.dataForm.startTime > value) {
callback(new Error('结束日期应该大于开始日期'));
} else {
callback()
}
}
}
return {
visible: false,
pickerOptions: {
disabledDate: time => {
return new Date(time).getTime() < new Date().getTime() - 86400000;
}
},
dataForm: {
id: '',
toUserId: '',
flowId: '',
description: '',
startTime: '',
endTime: '',
flowName: '',
flowCategory: '',
toUserName: ''
},
dataRule: {
toUserId: [
{ required: true, message: '被委托人不能为空', trigger: 'change' }
],
flowId: [
{ required: true, message: '委托流程不能为空', trigger: 'change' }
],
startTime: [
{ required: true, message: '开始时间不能为空', trigger: 'change' },
{ validator: checkStartTime, trigger: 'change' }
],
endTime: [
{ required: true, message: '结束时间不能为空', trigger: 'change' },
{ validator: checkEndTime, trigger: 'change' }
],
},
loading: false,
btnLoading: false,
flowEngineList: []
}
},
methods: {
getFlowEngineList() {
FlowEngineListAll().then((res) => {
this.flowEngineList = res.data.list
this.$nextTick(() => {
this.$refs['dataForm'].resetFields()
if (this.dataForm.id) {
FlowDelegateInfo(this.dataForm.id).then(res => {
this.dataForm = res.data
})
}
this.loading = false
})
})
},
init(id) {
this.dataForm.id = id || ''
this.visible = true
this.loading = true
this.getFlowEngineList()
},
dataFormSubmit() {
this.$refs['dataForm'].validate((valid) => {
if (valid) {
this.btnLoading = true
const formMethod = this.dataForm.id ? Update : Create
formMethod(this.dataForm).then(res => {
this.$message({
message: res.msg,
type: 'success',
duration: 1000,
onClose: () => {
this.visible = false
this.btnLoading = false
this.$emit('refreshDataList')
}
})
}).catch(() => { this.btnLoading = false })
}
})
},
handleChange(val) {
if (!val) {
this.dataForm.flowName = ''
this.dataForm.flowCategory = ''
return
}
let active = {}
for (let i = 0; i < this.flowEngineList.length; i++) {
const item = this.flowEngineList[i];
if (item.children && item.children.length) {
for (let j = 0; j < item.children.length; j++) {
if (item.children[j].id === val) {
active = item.children[j]
break
}
}
}
}
this.dataForm.flowName = active.fullName + '/' + active.enCode
this.dataForm.flowCategory = active.category
},
onChange(ids, selectedData) {
if (!selectedData.length) return
this.dataForm.toUserName = selectedData[0].fullName
}
}
}
</script>