﻿<template>
	<el-dialog :title="!dataForm.id ? '新建' :  isDetail ? '详情':'编辑'" :close-on-click-modal="false" :visible.sync="visible" class="NCC-dialog NCC-dialog_center" lock-scroll width="90%">
		<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="8" 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="8">
						<el-form-item label="门店" prop="md">
							<el-select v-model="dataForm.md" placeholder="请选择" clearable :style='{"width":"100%"}' filterable >
								<el-option v-for="(item, index) in mdOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="门店编号" prop="mcbh">
							<el-input v-model="dataForm.mcbh" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="门店名称" prop="mdmc">
							<el-input v-model="dataForm.mdmc" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="会员" prop="hy">
							<el-select v-model="dataForm.hy" placeholder="请选择" clearable :style='{"width":"100%"}' filterable >
								<el-option v-for="(item, index) in hyOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="会员姓名" prop="hyxm">
							<el-input v-model="dataForm.hyxm" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="会员账号" prop="hyzh">
							<el-input v-model="dataForm.hyzh" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="健康师" prop="jks">
							<user-select v-model="dataForm.jks" placeholder="请选择" clearable >
							</user-select>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="健康师账号" prop="jkszh">
							<el-input v-model="dataForm.jkszh" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="健康师姓名" prop="jksxm">
							<el-input v-model="dataForm.jksxm" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="备注" prop="bz">
							<el-input v-model="dataForm.bz" placeholder="请输入" show-word-limit :style='{"width":"100%"}' type='textarea' :autosize='{"minRows":4,"maxRows":4}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24" v-if="false" >
						<el-form-item label="退卡品项" prop="tkpx">
							<el-input v-model="dataForm.tkpx" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24" v-if="false" >
						<el-form-item label="退卡时间" prop="tksj">
							<el-input v-model="dataForm.tksj" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24" v-if="false" >
						<el-form-item label="退卡人" prop="tkr">
							<el-input v-model="dataForm.tkr" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label-width="0">
							<el-table :data="dataForm.lqHytkMxList" size='mini'>
								<el-table-column type="index" width="50" label="序号" align="center" />
								<el-table-column prop="id" label="明细编号" v-if="false">
									<template slot-scope="scope">
										<el-input v-model="scope.row.id" placeholder="请输入" clearable ></el-input>
									</template>
								</el-table-column>
								<el-table-column prop="gltkbh" label="关联退卡编号" v-if="false">
									<template slot-scope="scope">
										<el-input v-model="scope.row.gltkbh" placeholder="请输入" clearable ></el-input>
									</template>
								</el-table-column>
								<el-table-column prop="px" label="品项">
									<template slot-scope="scope">
										<el-select v-model="scope.row.px" placeholder="请选择" clearable >
											<el-option v-for="(item, index) in pxOptions" :key="index" :label="item.fullName" :value="item.id" :disabled="item.disabled"></el-option>
										</el-select>
									</template>
								</el-table-column>
								<el-table-column prop="mc" label="品项名称">
									<template slot-scope="scope">
										<el-input v-model="scope.row.mc" placeholder="请输入" clearable ></el-input>
									</template>
								</el-table-column>
								<el-table-column prop="tkje" label="退款金额">
									<template slot-scope="scope">
										<el-input v-model="scope.row.tkje" placeholder="请输入" clearable ></el-input>
									</template>
								</el-table-column>
								<el-table-column prop="cs" label="次数">
									<template slot-scope="scope">
										<el-input v-model="scope.row.cs" placeholder="请输入" clearable ></el-input>
									</template>
								</el-table-column>
								<el-table-column prop="dchk" label="单次耗卡">
									<template slot-scope="scope">
										<el-input v-model="scope.row.dchk" placeholder="请输入" clearable ></el-input>
									</template>
								</el-table-column>
								<el-table-column prop="fssj" label="发生时间" v-if="false">
									<template slot-scope="scope">
										<el-input v-model="scope.row.fssj" placeholder="请输入" clearable ></el-input>
									</template>
								</el-table-column>
								<el-table-column label="操作" width="50">
									<template slot-scope="scope">
										<el-button size="mini" type="text" class="NCC-table-delBtn" @click="handleDelLqHytkMxEntityList(scope.$index)">删除</el-button>
									</template>
								</el-table-column>
							</el-table>
							<div class="table-actions" @click="addHandleLqHytkMxEntityList()">
								<el-button type="text" icon="el-icon-plus">新增</el-button>
							</div>
						</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,
					md:undefined,
					mcbh:undefined,
					mdmc:undefined,
					hy:undefined,
					hyxm:undefined,
					hyzh:undefined,
					jks:undefined,
					jkszh:undefined,
					jksxm:undefined,
					bz:undefined,
					tkpx:undefined,
					tksj:undefined,
					tkr:undefined,
					lqHytkMxList:[],
				},
				rules: {
				},
				mdOptions : [],
				hyOptions : [],
				pxOptions : [],
			}
		},
		computed: {},
        watch: {},
        created() {
			this.getmdOptions();
			this.gethyOptions();
			this.getpxOptions();
		},
		mounted() {
        },
		methods: {
			getmdOptions(){
				previewDataInterface('730960205902251269').then(res => {
					this.mdOptions = res.data
				});
			},
			gethyOptions(){
				previewDataInterface('730998109110273285').then(res => {
					this.hyOptions = res.data
				});
			},
			getpxOptions(){
				previewDataInterface('730971133356016901').then(res => {
					this.pxOptions = 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/LqHytkHytk/' + 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/LqHytkHytk`,
                                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/LqHytkHytk/' + 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)
                                    }
                                })
                            })
                        }
                    }
                })
			},
			addHandleLqHytkMxEntityList() {
				let item = {
					id:undefined,
					gltkbh:undefined,
					px:undefined,
					mc:undefined,
					tkje:undefined,
					cs:undefined,
					dchk:undefined,
					fssj:undefined,
				}
				this.dataForm.lqHytkMxList.push(item)
			},
			handleDelLqHytkMxEntityList(index) {
				this.dataForm.lqHytkMxList.splice(index, 1);
			},
		}
	}
</script>
