﻿<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="orderNumber">
							<el-input v-model="dataForm.orderNumber" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col> -->
				<el-col :span="24">
					<el-form-item label="路线" prop="type">
						<el-select v-model="dataForm.type" placeholder="请选择" clearable :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">
					<el-form-item label="地域" prop="areaId" v-if="type=='1'">
						<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">
					<el-form-item label="地域线路" prop="areaLineId" v-if="type=='1'">
						<el-select v-model="dataForm.areaLineId" placeholder="请选择" clearable :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">
					<el-form-item label="人格" prop="mbtId" v-if="type=='2'">
						<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">
					<el-form-item label="人格线路" prop="mbtLineId" v-if="type=='2'">
						<el-select v-model="dataForm.mbtLineId" placeholder="请选择" clearable :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">
					<el-form-item label="状态" prop="status">
						<el-select v-model="dataForm.status" placeholder="请选择" clearable required
							:style='{"width":"100%"}'>
							<el-option v-for="(item, index) in statusOptions" :key="index" :label="item.fullName"
								:value="item.id"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="购买类型" prop="isMe">
						<el-select v-model="dataForm.isMe" placeholder="请选择" clearable required
							:style='{"width":"100%"}'>
							<el-option v-for="(item, index) in isMeOptions" :key="index" :label="item.fullName"
								:value="item.id"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="赠送人" prop="giveUserId">
						<user-select v-model="dataForm.giveUserId" placeholder="请选择" clearable>
						</user-select>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="盲盒券" prop="myBoxCouponId">
						<el-select v-model="dataForm.myBoxCouponId" placeholder="请选择" clearable
							:style='{"width":"100%"}'>
							<el-option v-for="(item, index) in myBoxCouponIdOptions" :key="index" :label="item.F_Title"
								:value="item.F_Id"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="二维码" prop="qrCode">
						<NCC-UploadImg v-model="dataForm.qrCode" :fileSize="5" sizeUnit="MB" :limit="9">
						</NCC-UploadImg>
					</el-form-item>
				</el-col>
				<!-- <el-col :span="24">
						<el-form-item label="总金额" prop="totalPrice">
							<el-input v-model="dataForm.totalPrice" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</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,
					orderNumber: undefined,
					type: '1',
					areaId: undefined,
					areaLineId: undefined,
					mbtId: undefined,
					mbtLineId: undefined,
					status: undefined,
					isMe: undefined,
					giveUserId: undefined,
					myBoxCouponId: undefined,
					qrCode: [],

					totalPrice: undefined,
					creatorTime: undefined,
					lastModifyTime: undefined,
				},
				rules: {
					userId: [{
						required: true,
						message: '请输入用户',
						trigger: 'change'
					}, ],
					status: [{
						required: true,
						message: '请输入状态',
						trigger: 'change'
					}, ],
					isMe: [{
						required: true,
						message: '请输入购买类型',
						trigger: 'change'
					}, ],
					totalPrice: [{
						pattern: /^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$/,
						message: '请输入正确的金额',
						trigger: 'blur'
					}, ],
				},
				typeOptions: [{
					"fullName": "地域线路",
					"id": "1"
				}, {
					"fullName": "MBT人格线路",
					"id": "2"
				}],
				type: '1',
				areaIdOptions: [],
				areaLineIdOptions: [],
				mbtIdOptions: [],
				mbtLineIdOptions: [],
				statusOptions: [{
					"fullName": "未付款",
					"id": "1"
				}, {
					"fullName": "已付款",
					"id": "2"
				}],
				isMeOptions: [{
					"fullName": "自己购买",
					"id": "1"
				}, {
					"fullName": "赠送他人",
					"id": "2"
				}],
				myBoxCouponIdOptions: [],
			}
		},
		computed: {},
		watch: {},
		created() {
			this.getareaIdOptions();
			this.getareaLineIdOptions();
			this.getmbtIdOptions();
			this.getmbtLineIdOptions();
			this.getmyBoxCouponIdOptions();
		},
		mounted() {},
		methods: {
			TypeChange(e) {
				console.log('eeee', e)
				this.type = e
			},
			getareaIdOptions() {
				previewDataInterface('393301869759300869').then(res => {
					this.areaIdOptions = res.data
				});
			},
			getareaLineIdOptions() {
				previewDataInterface('393304215318955269').then(res => {
					this.areaLineIdOptions = res.data
				});
			},
			getmbtIdOptions() {
				previewDataInterface('393308680755348741').then(res => {
					this.mbtIdOptions = res.data
				});
			},
			getmbtLineIdOptions() {
				previewDataInterface('393728611745531141').then(res => {
					this.mbtLineIdOptions = res.data
				});
			},
			getmyBoxCouponIdOptions() {
				previewDataInterface('394645492476151045').then(res => {
					this.myBoxCouponIdOptions = 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/TbBoxOrder/' + 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/TbBoxOrder`,
								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/TbBoxOrder/' + 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>
