Form.vue 6.79 KB
<template>
	<el-dialog :title="!dataForm.id ? '新建' :  isDetail ? '详情':'编辑'" :close-on-click-modal="false" :visible.sync="visible" class="NCC-dialog NCC-dialog_center" lock-scroll width="600px">
		<el-row :gutter="15" class="" >
				<el-form ref="elForm" :model="dataForm" size="small" label-width="120px" label-position="right" :disabled="!!isDetail" :rules="rules">
					<el-col :span="24">
						<el-form-item label="规则名称" prop="ruleName">
							<el-input v-model="dataForm.ruleName" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="场地ID" prop="siteId">
							<el-select v-model="dataForm.siteId" placeholder="请选择" clearable :style='{"width":"100%"}' >
								<el-option v-for="(item, index) in siteIdOptions" :key="index" :label="item.fullName" :value="item.F_id" ></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="套餐类型" prop="packageType">
							<el-radio-group v-model="dataForm.packageType" :style='{}' >
								<el-radio v-for="(item, index) in packageTypeOptions" :key="index" :label="item.id"  >{{item.fullName}}</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="是否为基础套餐" prop="isBasic">
							<el-radio-group v-model="dataForm.isBasic" :style='{}' >
								<el-radio v-for="(item, index) in isBasicOptions" :key="index" :label="item.id"  >{{item.fullName}}</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="套餐时长" prop="duration">
							<el-input-number v-model="dataForm.duration" placeholder="数字文本" :step="1" >
							</el-input-number>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="单位价格" prop="unitPrice">
							<el-input-number v-model="dataForm.unitPrice" placeholder="数字文本" :step="1" >
							</el-input-number>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="日封顶金额" prop="dailyCap">
							<el-input-number v-model="dataForm.dailyCap" placeholder="数字文本" :step="1" >
							</el-input-number>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="总封顶金额" prop="totalCap">
							<el-input-number v-model="dataForm.totalCap" placeholder="数字文本" :step="1" >
							</el-input-number>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="超时每单位价格" prop="overtimePrice">
							<el-input-number v-model="dataForm.overtimePrice" placeholder="数字文本" :step="1" >
							</el-input-number>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="免费时长" prop="freeDuration">
							<el-input-number v-model="dataForm.freeDuration" placeholder="数字文本" :step="1" >
							</el-input-number>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="是否启用" prop="isEnabled">
							<el-switch v-model="dataForm.isEnabled" :active-value="1" :inactive-value="0" >
							</el-switch>
						</el-form-item>
					</el-col>
				</el-form>
		</el-row>
		<span slot="footer" class="dialog-footer">
			<el-button @click="visible = false">取 消</el-button>
			<el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail">确 定</el-button>
		</span>
	</el-dialog>
</template>
<script>
	import request from '@/utils/request'
	import { getDictionaryDataSelector } from '@/api/systemData/dictionary'
	import { previewDataInterface } from '@/api/systemData/dataInterface'
	export default {
		components: {},
		props: [],
		data() {
			return {
				loading: false,
				visible: false,
				isDetail: false,
				dataForm: {
					id:'',
					ruleName:undefined,
					siteId:undefined,
					packageType:"hour",
					isBasic:"1",
					duration:0,
					unitPrice:0,
					dailyCap:0,
					totalCap:0,
					overtimePrice:0,
					freeDuration:0,
					isEnabled:"0",
				},
				rules: {
				},
				siteIdOptions : [],
				packageTypeOptions:[{"fullName":"分钟","id":"minute"},{"fullName":"小时","id":"hour"}],
				isBasicOptions:[{"fullName":"是","id":"1"},{"fullName":"否","id":"0"}],
			}
		},
		computed: {},
        watch: {},
        created() {
			this.getsiteIdOptions();
		},
		mounted() {
        },
		methods: {
			getsiteIdOptions(){
				previewDataInterface('702758837928592645').then(res => {
					this.siteIdOptions = res.data
				});
			},
			goBack() {
                this.$emit('refresh')
            },
			init(id, isDetail) {
				this.dataForm.id = id || 0;
                this.visible = true;
                this.isDetail = isDetail || false;
				this.$nextTick(() => {
					this.$refs['elForm'].resetFields();
					if (this.dataForm.id) {
						request({
							url: '/api/Extend/UavFeeRule/' + this.dataForm.id,
							method: 'get'
						}).then(res =>{
							this.dataForm = res.data;
						})
					}
				})
			},
			dataFormSubmit() {
				this.$refs['elForm'].validate((valid) => {
                    if (valid) {
                        if (!this.dataForm.id) {
                            request({
                                url: `/api/Extend/UavFeeRule`,
                                method: 'post',
                                data: this.dataForm,
                            }).then((res) => {
                                this.$message({
                                    message: res.msg,
                                    type: 'success',
                                    duration: 1000,
                                    onClose: () => {
                                        this.visible = false,
                                            this.$emit('refresh', true)
                                    }
                                })
                            })
                        } else {
                            request({
                                url: '/api/Extend/UavFeeRule/' + this.dataForm.id,
                                method: 'PUT',
                                data: this.dataForm
                            }).then((res) => {
                                this.$message({
                                    message: res.msg,
                                    type: 'success',
                                    duration: 1000,
                                    onClose: () => {
                                        this.visible = false
                                        this.$emit('refresh', true)
                                    }
                                })
                            })
                        }
                    }
                })
			},
		}
	}
</script>