You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

244 lines
10 KiB

<template>
<a-modal
title="新增@(@Model.BusName)"
:width="900"
:visible="visible"
:confirmLoading="confirmLoading"
@@ok="handleSubmit"
@@cancel="handleCancel">
<a-spin :spinning="confirmLoading">
<a-form :form="form">
@foreach (var column in Model.TableField){
if (@column.ColumnKey != "True"){
if (@column.WhetherAddUpdate == "Y"){
if (@column.EffectType == "select" || @column.EffectType == "radio" || @column.EffectType == "checkbox"){
@:<a-form-item label="@column.ColumnComment" :labelCol="labelCol" :wrapperCol="wrapperCol">
}else{
@:<a-form-item label="@column.ColumnComment" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
}
if (@column.EffectType == "user"){
if (@column.WhetherRequired == "Y"){
@:<user-select placeholder="请输入@(@column.ColumnComment)" v-decorator="['@column.ColumnName', {rules: [{required: true, message: '请输入@(@column.ColumnComment)'}]}]" />
}else{
@:<user-select placeholder="请输入@(@column.ColumnComment)" v-decorator="['@column.ColumnName']" />
}
}
if (@column.EffectType == "depart"){
if (@column.WhetherRequired == "Y"){
@:<depart-select placeholder="请输入@(@column.ColumnComment)" v-decorator="['@column.ColumnName', {rules: [{required: true, message: '请输入@(@column.ColumnComment)'}]}]" />
}else{
@:<depart-select placeholder="请输入@(@column.ColumnComment)" v-decorator="['@column.ColumnName']" />
}
}
if (@column.EffectType == "input"){
if (@column.WhetherRequired == "Y"){
@:<a-input placeholder="请输入@(@column.ColumnComment)" v-decorator="['@column.ColumnName', {rules: [{required: true, message: '请输入@(@column.ColumnComment)'}]}]" />
}else{
@:<a-input placeholder="请输入@(@column.ColumnComment)" v-decorator="['@column.ColumnName']" />
}
}
if (@column.EffectType == "textarea"){
if (@column.WhetherRequired == "Y"){
@:<a-textarea placeholder="请输入@(@column.ColumnComment)" v-decorator="['@column.ColumnName', {rules: [{required: true, message: '请输入@(@column.ColumnComment)'}]}]" :auto-size="{ minRows: 3, maxRows: 6 }"/>
}else{
@:<a-textarea placeholder="请输入@(@column.ColumnComment)" v-decorator="['@column.ColumnName']" :auto-size="{ minRows: 3, maxRows: 6 }"/>
}
}
if (@column.EffectType == "inputnumber"){
if (@column.WhetherRequired == "Y"){
@:<a-input-number placeholder="请输入@(@column.ColumnComment)" style="width: 100%" v-decorator="['@column.ColumnName', {rules: [{required: true, message: '请输入@(@column.ColumnComment)'}]}]" />
}else{
@:<a-input-number placeholder="请输入@(@column.ColumnComment)" style="width: 100%" v-decorator="['@column.ColumnName']" />
}
}
if (@column.EffectType == "select"){
if (@column.WhetherRequired == "Y"){
@:<a-select style="width: 100%" placeholder="请选择@(@column.ColumnComment)" v-decorator="['@column.ColumnName', {rules: [{ required: true, message: '请选择@(@column.ColumnComment)' }]}]">
@:<a-select-option v-for="(item,index) in @(@column.ColumnName)Data" :key="index" :value="item.code">{{ item.name }}</a-select-option>
@:</a-select>
}else{
@:<a-select style="width: 100%" placeholder="请选择@(@column.ColumnComment)" v-decorator="['@column.ColumnName']" >
@:<a-select-option v-for="(item,index) in @(@column.ColumnName)Data" :key="index" :value="item.code">{{ item.name }}</a-select-option>
@:</a-select>
}
}
if (@column.EffectType == "radio"){
if (@column.WhetherRequired == "Y"){
@:<a-radio-group placeholder="请选择@(@column.ColumnComment)" v-decorator="['@column.ColumnName',{rules: [{ required: true, message: '请选择@(@column.ColumnComment)' }]}]" >
@:<a-radio v-for="(item,index) in @(@column.ColumnName)Data" :key="index" :value="item.code">{{ item.name }}</a-radio>
@:</a-radio-group>
}else{
@:<a-radio-group placeholder="请选择@(@column.ColumnComment)" v-decorator="['@column.ColumnName']" >
@:<a-radio v-for="(item,index) in @(@column.ColumnName)Data" :key="index" :value="item.code">{{ item.name }}</a-radio>
@:</a-radio-group>
}
}
if (@column.EffectType == "checkbox"){
if (@column.WhetherRequired == "Y"){
@:<a-checkbox-group placeholder="请选择@(@column.ColumnComment)" v-decorator="['@column.ColumnName',{rules: [{ required: true, message: '请选择@(@column.ColumnComment)' }]}]" >
@:<a-checkbox v-for="(item,index) in @(@column.ColumnName)Data" :key="index" :value="item.code">{{ item.name }}</a-checkbox>
@:</a-checkbox-group>
}else{
@:<a-checkbox-group placeholder="请选择@(@column.ColumnComment)" v-decorator="['@column.ColumnName']" >
@:<a-checkbox v-for="(item,index) in @(@column.ColumnName)Data" :key="index" :value="item.code">{{ item.name }}</a-checkbox>
@:</a-checkbox-group>
}
}
if (@column.EffectType == "switch"){
if (@column.WhetherRequired == "Y"){
@:<a-switch v-decorator="['@column.ColumnName',{rules: [{ required: true, message: '请选择@(@column.ColumnComment)' }], valuePropName: 'checked'}]" />
}else{
@:<a-switch v-decorator="['@column.ColumnName', { valuePropName: 'checked' }]" />
}
}
if (@column.EffectType == "datepicker"){
if (@column.WhetherRequired == "Y"){
@:<a-date-picker style="width: 100%" placeholder="请选择@(@column.ColumnComment)" v-decorator="['@column.ColumnName',{rules: [{ required: true, message: '请选择@(@column.ColumnComment)' }]}]" @@change="onChange@(@column.ColumnName)"/>
}else{
@:<a-date-picker style="width: 100%" placeholder="请选择@(@column.ColumnComment)" v-decorator="['@column.ColumnName']" @@change="onChange@(@column.ColumnName)"/>
}
}
if (@column.EffectType == "fk"){
if (@column.WhetherRequired == "Y"){
@:<a-select style="width: 100%" placeholder="请选择@(@column.ColumnComment)" v-decorator="['@column.ColumnName', {rules: [{ required: true, message: '请选择@(@column.ColumnComment)' }]}]">
@:<a-select-option v-for="(item,index) in @(@column.FkEntityName)Data" :key="index" :value="item.code">{{ item.name }}</a-select-option>
@:</a-select>
}else{
@:<a-select style="width: 100%" placeholder="请选择@(@column.ColumnComment)" v-decorator="['@column.ColumnName']">
@:<a-select-option v-for="(item,index) in @(@column.FkEntityName)Data" :key="index" :value="item.code">{{ item.name }}</a-select-option>
@:</a-select>
}
}
@:</a-form-item>
}
}
}
</a-form>
</a-spin>
</a-modal>
</template>
<script>
import {
@foreach (var column in Model.TableField){
if(@column.EffectType == "fk" && @column.FkEntityName != "" && @column.FkColumnName != ""){
@:@(@Model.ClassName)Fk@(@column.FkEntityName)List,
}
}
@(@Model.ClassName)Add
} from '@@/api/modular/main/@(@Model.ClassName)Manage'
export default {
data () {
return {
labelCol: {
xs: { span: 24 },
sm: { span: 5 }
},
wrapperCol: {
xs: { span: 24 },
sm: { span: 15 }
},
@foreach (var column in Model.TableField){
if (@column.WhetherAddUpdate == "Y"){
if (@column.DictTypeCode != ""){
if (@column.EffectType == "select" || @column.EffectType == "radio" || @column.EffectType == "checkbox"){
@:@(@column.ColumnName)Data: [],
}
}
if (@column.EffectType == "datepicker"){
@:@(@column.ColumnName)DateString: '',
}
}
}
@foreach (var column in Model.TableField){
if(@column.EffectType == "fk" && @column.FkEntityName != "" && @column.FkColumnName != ""){
@:@(@column.FkEntityName)Data: [],
}
}
visible: false,
confirmLoading: false,
form: this.$form.createForm(this)
}
},
methods: {
@foreach (var column in Model.TableField){
if(@column.EffectType == "fk" && @column.FkEntityName != "" && @column.FkColumnName != ""){
@:@(@Model.ClassName)Fk@(@column.FkEntityName)List() {
@:@(@Model.ClassName)Fk@(@column.FkEntityName)List().then(res => {
@:this.@(@column.FkEntityName)Data = res.data
@:})
@:},
}
}
// 初始化方法
add (record) {
this.visible = true
@foreach (var column in Model.TableField){
if (@column.DictTypeCode != ""){
if (@column.EffectType == "select" || @column.EffectType == "radio" || @column.EffectType == "checkbox"){
@:const @(@column.ColumnName)Option = this.$options
@:this.@(@column.ColumnName)Data = @(@column.ColumnName)Option.filters['dictData']('@column.DictTypeCode')
}
}
}
@foreach (var column in Model.TableField){
if(@column.EffectType == "fk" && @column.FkEntityName != "" && @column.FkColumnName != ""){
@:this.@(@Model.ClassName)Fk@(@column.FkEntityName)List()
}
}
},
/**
* 提交表单
*/
handleSubmit () {
const { form: { validateFields } } = this
this.confirmLoading = true
validateFields((errors, values) => {
if (!errors) {
for (const key in values) {
if (typeof (values[key]) === 'object' && !(values[key]===null)) {
values[key] = JSON.stringify(values[key])
}
}
@foreach (var column in Model.TableField){
if (@column.WhetherAddUpdate == "Y"){
if (@column.EffectType == "datepicker"){
@:values.@column.ColumnName = this.@(@column.ColumnName)DateString
}
}
}
@(@Model.ClassName)Add(values).then((res) => {
if (res.success) {
this.$message.success('新增成功')
this.confirmLoading = false
this.$emit('ok', values)
this.handleCancel()
} else {
this.$message.error('新增失败')// + res.message
}
}).finally((res) => {
this.confirmLoading = false
})
} else {
this.confirmLoading = false
}
})
},
@foreach (var column in Model.TableField){
if (@column.WhetherAddUpdate == "Y"){
if (@column.EffectType == "datepicker"){
@:onChange@(@column.ColumnName)(date, dateString) {
@:this.@(@column.ColumnName)DateString = dateString
@:},
}
}
}
handleCancel () {
this.form.resetFields()
this.visible = false
}
}
}
</script>