﻿<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" v-if="false" >
						<el-form-item label="主键" prop="id">
							<el-input v-model="dataForm.id" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="门店编码" prop="mdbm">
							<el-input v-model="dataForm.mdbm" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="单据门店编号" prop="djmdbh">
							<el-input v-model="dataForm.djmdbh" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="单据门店" prop="djmd">
							<el-input v-model="dataForm.djmd" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="店名" prop="dm">
							<el-input v-model="dataForm.dm" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="城市" prop="cs">
							<el-input v-model="dataForm.cs" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="地址" prop="dz">
							<el-input v-model="dataForm.dz" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="姓名" prop="xm">
							<el-input v-model="dataForm.xm" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="电话号码" prop="dhhm">
							<el-input v-model="dataForm.dhhm" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="座机" prop="zj">
							<el-input v-model="dataForm.zj" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="开业时间" prop="kysj">
							<el-date-picker v-model="dataForm.kysj" placeholder="请选择" clearable :style='{"width":"100%"}' type='date' format="yyyy-MM-dd" value-format="timestamp" >
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="最新状态" prop="zxzt">
							<el-select v-model="dataForm.zxzt" placeholder="请选择" clearable :style='{"width":"100%"}' >
								<el-option v-for="(item, index) in zxztOptions" :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="gsmc">
							<el-input v-model="dataForm.gsmc" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="法人" prop="fr">
							<el-input v-model="dataForm.fr" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="有无社保" prop="ywsb">
							<el-select v-model="dataForm.ywsb" placeholder="请选择" clearable :style='{"width":"100%"}' >
								<el-option v-for="(item, index) in ywsbOptions" :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="zzrs">
							<el-input-number v-model="dataForm.zzrs" :min="0" :step="1" :precision="0" placeholder="请输入" :style='{"width":"100%"}' />
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="门店类别" prop="storeCategory">
							<el-select v-model="dataForm.storeCategory" placeholder="请选择" clearable :style='{"width":"100%"}' >
								<el-option v-for="(item, index) in storeCategoryOptions" :key="index" :label="item.Name" :value="item.Value" ></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="门店类型" prop="storeType">
							<el-select v-model="dataForm.storeType" placeholder="请选择" clearable :style='{"width":"100%"}' >
								<el-option v-for="(item, index) in storeTypeOptions" :key="index" :label="item.Name" :value="item.Value" ></el-option>
							</el-select>
						</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:'',
					id:undefined,
					mdbm:undefined,
					djmdbh:undefined,
					djmd:undefined,
					dm:undefined,
					cs:undefined,
					dz:undefined,
					xm:undefined,
					dhhm:undefined,
					zj:undefined,
					kysj:undefined,
					zxzt:undefined,
					gsmc:undefined,
					fr:undefined,
					ywsb:undefined,
					zzrs:0,
					storeCategory:undefined,
					storeType:undefined,
				},
				rules: {
				},
				zxztOptions:[{"fullName":"开店","id":"开店"},{"fullName":"闭店","id":"闭店"}],
				ywsbOptions:[{"fullName":"有","id":"有"},{"fullName":"无","id":"无"}],
				storeCategoryOptions:[],
				storeTypeOptions:[],
			}
		},
		computed: {},
        watch: {},
        created() {
			this.loadStoreCategoryOptions();
			this.loadStoreTypeOptions();
		},
		mounted() {
        },
		methods: {
			goBack() {
                this.$emit('refresh')
            },
			// 加载门店类别选项
			loadStoreCategoryOptions() {
				request({
					url: '/api/Extend/lqmdxx/Selector/StoreCategory',
					method: 'get'
				}).then(res => {
					this.storeCategoryOptions = res.data || [];
				}).catch(err => {
					console.error('加载门店类别选项失败:', err);
					this.storeCategoryOptions = [];
				});
			},
			// 加载门店类型选项
			loadStoreTypeOptions() {
				request({
					url: '/api/Extend/lqmdxx/Selector/StoreType',
					method: 'get'
				}).then(res => {
					this.storeTypeOptions = res.data || [];
				}).catch(err => {
					console.error('加载门店类型选项失败:', err);
					this.storeTypeOptions = [];
				});
			},
			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/LqMdxx/' + 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/LqMdxx`,
                                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/LqMdxx/' + 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>
