Form.vue 7.36 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="100px" label-position="right"
				:disabled="!!isDetail" :rules="rules">
				<el-col :span="24">
					<el-form-item label="用户" prop="userId">
						<user-select v-model="dataForm.userId" placeholder="请选择" clearable required>
						</user-select>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="盲盒订单" prop="boxOrderId">
						<el-select v-model="dataForm.boxOrderId" placeholder="请选择" clearable required
							:style='{"width":"100%"}'>
							<el-option v-for="(item, index) in boxOrderIdOptions" :key="index"
								:label="item.F_OrderNumber" :value="item.F_Id"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="路线" prop="type">
						<el-select v-model="dataForm.type" placeholder="请选择" clearable required
							:style='{"width":"100%"}' @change="TypeChange">
							<el-option v-for="(item, index) in typeOptions" :key="index" :label="item.fullName"
								:value="item.id"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="status=='1'">
					
					<el-form-item label="地域线路" prop="areaLineId">
						<el-select v-model="dataForm.areaLineId" placeholder="请选择" clearable required
							:style='{"width":"100%"}'>
							<el-option v-for="(item, index) in areaLineIdOptions" :key="index" :label="item.F_Title"
								:value="item.F_Id"></el-option>
						</el-select>
					</el-form-item>

				</el-col>
				<el-col :span="24" v-if="status=='1'">
					<el-form-item label="地域" prop="areaId">
						<el-select v-model="dataForm.areaId" placeholder="请选择" clearable :style='{"width":"100%"}'>
							<el-option v-for="(item, index) in areaIdOptions" :key="index" :label="item.F_Name"
								:value="item.F_Id"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="status=='2'">
					
					<el-form-item label="人格线路" prop="mbtLineId">
						<el-select v-model="dataForm.mbtLineId" placeholder="请选择" clearable required
							:style='{"width":"100%"}'>
							<el-option v-for="(item, index) in mbtLineIdOptions" :key="index" :label="item.F_Name"
								:value="item.F_Id"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="status=='2'">
					<el-form-item label="人格" prop="mbtId">
						<el-select v-model="dataForm.mbtId" placeholder="请选择" clearable :style='{"width":"100%"}'>
							<el-option v-for="(item, index) in mbtIdOptions" :key="index" :label="item.F_Name"
								:value="item.F_Id"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="false">
					<el-form-item label="创建时间" prop="creatorTime">
						<el-input v-model="dataForm.creatorTime" placeholder="系统自动生成" readonly>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="false">
					<el-form-item label="修改时间" prop="lastModifyTime">
						<el-input v-model="dataForm.lastModifyTime" placeholder="系统自动生成" readonly>
						</el-input>
					</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: '',
					userId: undefined,
					boxOrderId: undefined,
					areaId: undefined,

					type: '1',
					areaLineId: undefined,
					mbtId: undefined,

					mbtLineId: undefined,
					creatorTime: undefined,
					lastModifyTime: undefined,
				},
				rules: {
					userId: [{
						required: true,
						message: '请输入用户',
						trigger: 'change'
					}, ],
					boxOrderId: [{
						required: true,
						message: '请输入盲盒订单',
						trigger: 'change'
					}, ],
					type: [{
						required: true,
						message: '请输入路线',
						trigger: 'change'
					}, ],
					areaLineId: [{
						required: true,
						message: '请输入地域线路',
						trigger: 'change'
					}, ],
					mbtLineId: [{
						required: true,
						message: '请输入人格线路',
						trigger: 'change'
					}, ],
				},
				boxOrderIdOptions: [],
				status: '1',
				typeOptions: [{
					"fullName": "地域路线",
					"id": "1"
				}, {
					"fullName": "人格路线",
					"id": "2"
				}],
				areaIdOptions: [],
				mbtIdOptions: [],

				areaLineIdOptions: [],
				mbtLineIdOptions: [],
			}
		},
		computed: {},
		watch: {},
		created() {
			this.getboxOrderIdOptions();
			this.getareaLineIdOptions();
			this.getareaIdOptions();
			this.getmbtIdOptions();
			this.getmbtLineIdOptions();
		},
		mounted() {},
		methods: {
			getareaIdOptions() {
				previewDataInterface('393301869759300869').then(res => {
					this.areaIdOptions = res.data
				});
			},
			getmbtIdOptions() {
				previewDataInterface('393301869759300869').then(res => {
					this.mbtIdOptions = res.data
				});
			},
			TypeChange(e) {
				this.status = e
			},
			getboxOrderIdOptions() {
				previewDataInterface('394660105041216773').then(res => {
					this.boxOrderIdOptions = res.data
				});
			},
			getareaLineIdOptions() {
				previewDataInterface('393304215318955269').then(res => {
					this.areaLineIdOptions = res.data
				});
			},
			getmbtLineIdOptions() {
				previewDataInterface('393728611745531141').then(res => {
					this.mbtLineIdOptions = 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/Blind/TbBoxLog/' + 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/Blind/TbBoxLog`,
								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/Blind/TbBoxLog/' + 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>