﻿<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="name">
							<el-input v-model="dataForm.name" placeholder="请输入" clearable required :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="身份证号码" prop="idCard">
							<el-input v-model="dataForm.idCard" placeholder="请输入" clearable required :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="电话号码" prop="phone">
							<el-input v-model="dataForm.phone" placeholder="请输入" clearable required :style='{"width":"100%"}' >
							</el-input>
						</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="totalPrice">
							<el-input v-model="dataForm.totalPrice" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col> -->
					<el-col :span="24">
						<el-form-item label="订单" prop="orderId">
							<el-select v-model="dataForm.orderId" placeholder="请选择" clearable :style='{"width":"100%"}' >
								<el-option v-for="(item, index) in orderIdOptions" :key="index" :label="item.F_OrderNumber" :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,
					orderNumber:undefined,
					name:undefined,
					idCard:undefined,
					phone:undefined,
					status:undefined,
					totalPrice:undefined,
					orderId:undefined,
					creatorTime:undefined,
					lastModifyTime:undefined,
				},
				rules: {
					userId:[
						{
							required:true,
							message:'请输入用户',
							trigger:'change'
						},
					],
					name:[
						{
							required:true,
							message:'请输入真实姓名',
							trigger:'blur'
						},
					],
					idCard:[
						{
							required:true,
							message:'请输入身份证号码',
							trigger:'blur'
						},
						{
							pattern:/^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
							message:'请输入正确的身份证号码',
							trigger:'blur'
						},
					],
					phone:[
						{
							required:true,
							message:'请输入电话号码',
							trigger:'blur'
						},
						{
							pattern:/^1[3456789]\d{9}$|^0\d{2,3}-?\d{7,8}$/,
							message:'请输入正确的联系方式',
							trigger:'blur'
						},
					],
					// status:[
					// 	{
					// 		required:true,
					// 		message:'请输入状态',
					// 		trigger:'change'
					// 	},
					// ],
					// totalPrice:[
					// 	{
					// 		pattern:/^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$/,
					// 		message:'请输入正确的金额',
					// 		trigger:'blur'
					// 	},
					// ],
				},
				statusOptions:[{"fullName":"未付款","id":"1"},{"fullName":"已付款","id":"2"},{"fullName":"已完成","id":"3"}],
				orderIdOptions : [],
			}
		},
		computed: {},
        watch: {},
        created() {
			this.getorderIdOptions();
		},
		mounted() {
        },
		methods: {
			getorderIdOptions(){
				previewDataInterface('394660105041216773').then(res => {
					this.orderIdOptions = 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/TbTicketsOrder/' + 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/TbTicketsOrder`,
                                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/TbTicketsOrder/' + 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>
