﻿<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="mdbh">
							<el-input v-model="dataForm.mdbh" 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="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="hymc">
							<el-input v-model="dataForm.hymc" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="顾客类型" prop="gklx">
							<el-select v-model="dataForm.gklx" placeholder="请选择" clearable :style='{"width":"100%"}' >
								<el-option v-for="(item, index) in gklxOptions" :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="xfje">
							<el-input v-model="dataForm.xfje" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="手工费用" prop="sgfy">
							<el-input v-model="dataForm.sgfy" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="是否有科技部" prop="sfykjb">
							<el-radio-group v-model="dataForm.sfykjb" :style='{}' >
								<el-radio v-for="(item, index) in sfykjbOptions" :key="index" :label="item.id"  >{{item.fullName}}</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label-width="0">
							<el-table :data="dataForm.lqXhJksyjList" 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="glkdbh" label="关联开单编号" v-if="false">
									<template slot-scope="scope">
										<el-input v-model="scope.row.glkdbh" placeholder="请输入" clearable ></el-input>
									</template>
								</el-table-column>
								<el-table-column prop="jks" label="健康师">
									<template slot-scope="scope">
										<user-select v-model="scope.row.jks" placeholder="请选择" clearable ></user-select>
									</template>
								</el-table-column>
								<el-table-column prop="jksxm" label="健康师姓名">
									<template slot-scope="scope">
										<el-input v-model="scope.row.jksxm" placeholder="请输入" clearable ></el-input>
									</template>
								</el-table-column>
								<el-table-column prop="jkszh" label="健康师账号">
									<template slot-scope="scope">
										<el-input v-model="scope.row.jkszh" placeholder="请输入" clearable ></el-input>
									</template>
								</el-table-column>
								<el-table-column prop="jksyj" label="健康师业绩">
									<template slot-scope="scope">
										<el-input v-model="scope.row.jksyj" placeholder="请输入" clearable ></el-input>
									</template>
								</el-table-column>
								<el-table-column prop="yjsj" label="业绩时间" v-if="false">
									<template slot-scope="scope">
										<el-input v-model="scope.row.yjsj" 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="handleDelLqXhJksyjEntityList(scope.$index)">删除</el-button>
									</template>
								</el-table-column>
							</el-table>
							<div class="table-actions" @click="addHandleLqXhJksyjEntityList()">
								<el-button type="text" icon="el-icon-plus">新增</el-button>
							</div>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label-width="0">
							<el-table :data="dataForm.lqXhKjbsyjList" 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="glkdbh" label="关联开单编号" v-if="false">
									<template slot-scope="scope">
										<el-input v-model="scope.row.glkdbh" placeholder="请输入" clearable ></el-input>
									</template>
								</el-table-column>
								<el-table-column prop="kjbls" label="科技部老师">
									<template slot-scope="scope">
										<user-select v-model="scope.row.kjbls" placeholder="请选择" clearable ></user-select>
									</template>
								</el-table-column>
								<el-table-column prop="kjblsxm" label="科技部老师姓名">
									<template slot-scope="scope">
										<el-input v-model="scope.row.kjblsxm" placeholder="请输入" clearable ></el-input>
									</template>
								</el-table-column>
								<el-table-column prop="kjblszh" label="科技部老师账号">
									<template slot-scope="scope">
										<el-input v-model="scope.row.kjblszh" placeholder="请输入" clearable ></el-input>
									</template>
								</el-table-column>
								<el-table-column prop="kjblsyj" label="科技部老师业绩">
									<template slot-scope="scope">
										<el-input v-model="scope.row.kjblsyj" placeholder="请输入" clearable ></el-input>
									</template>
								</el-table-column>
								<el-table-column prop="yjsj" label="业绩时间" v-if="false">
									<template slot-scope="scope">
										<el-input v-model="scope.row.yjsj" 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="handleDelLqXhKjbsyjEntityList(scope.$index)">删除</el-button>
									</template>
								</el-table-column>
							</el-table>
							<div class="table-actions" @click="addHandleLqXhKjbsyjEntityList()">
								<el-button type="text" icon="el-icon-plus">新增</el-button>
							</div>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label-width="0">
							<el-table :data="dataForm.lqXhPxmxList" 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="glkdbh" label="关联开单编号" v-if="false">
									<template slot-scope="scope">
										<el-input v-model="scope.row.glkdbh" 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="pxmc" label="品项名称">
									<template slot-scope="scope">
										<el-input v-model="scope.row.pxmc" placeholder="请输入" clearable ></el-input>
									</template>
								</el-table-column>
								<el-table-column prop="pxjg" label="品项价格">
									<template slot-scope="scope">
										<el-input v-model="scope.row.pxjg" placeholder="请输入" clearable ></el-input>
									</template>
								</el-table-column>
								<el-table-column prop="xfzs" label="是否赠送">
									<template slot-scope="scope">
										<el-select v-model="scope.row.xfzs" placeholder="请选择" clearable >
											<el-option v-for="(item, index) in xfzsOptions" :key="index" :label="item.fullName" :value="item.id" :disabled="item.disabled"></el-option>
										</el-select>
									</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="handleDelLqXhPxmxEntityList(scope.$index)">删除</el-button>
									</template>
								</el-table-column>
							</el-table>
							<div class="table-actions" @click="addHandleLqXhPxmxEntityList()">
								<el-button type="text" icon="el-icon-plus">新增</el-button>
							</div>
						</el-form-item>
					</el-col>
					<el-col :span="24" v-if="false" >
						<el-form-item label="耗卡时间" prop="hksj">
							<el-input v-model="dataForm.hksj" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24" v-if="false" >
						<el-form-item label="操作人员" prop="czry">
							<el-input v-model="dataForm.czry" 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:'',
					id:undefined,
					md:undefined,
					mdbh:undefined,
					mdmc:undefined,
					hy:undefined,
					hyzh:undefined,
					hymc:undefined,
					gklx:undefined,
					xfje:undefined,
					sgfy:undefined,
					sfykjb:undefined,
					lqXhJksyjList:[],
					lqXhKjbsyjList:[],
					lqXhPxmxList:[],
					hksj:undefined,
					czry:undefined,
				},
				rules: {
				},
				mdOptions : [],
				hyOptions : [],
				gklxOptions:[{"fullName":"会员","id":"会员"},{"fullName":"非会员","id":"非会员"},{"fullName":"19.9","id":"19.9"}],
				sfykjbOptions:[{"fullName":"是","id":"是"},{"fullName":"否","id":"否"}],
				pxOptions : [],
				xfzsOptions:[{"fullName":"是","id":"否"},{"fullName":"否","id":"否"}],
			}
		},
		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/LqXhHyhk/' + 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/LqXhHyhk`,
                                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/LqXhHyhk/' + 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)
                                    }
                                })
                            })
                        }
                    }
                })
			},
			addHandleLqXhJksyjEntityList() {
				let item = {
					id:undefined,
					glkdbh:undefined,
					jks:undefined,
					jksxm:undefined,
					jkszh:undefined,
					jksyj:undefined,
					yjsj:undefined,
				}
				this.dataForm.lqXhJksyjList.push(item)
			},
			handleDelLqXhJksyjEntityList(index) {
				this.dataForm.lqXhJksyjList.splice(index, 1);
			},
			addHandleLqXhKjbsyjEntityList() {
				let item = {
					id:undefined,
					glkdbh:undefined,
					kjbls:undefined,
					kjblsxm:undefined,
					kjblszh:undefined,
					kjblsyj:undefined,
					yjsj:undefined,
				}
				this.dataForm.lqXhKjbsyjList.push(item)
			},
			handleDelLqXhKjbsyjEntityList(index) {
				this.dataForm.lqXhKjbsyjList.splice(index, 1);
			},
			addHandleLqXhPxmxEntityList() {
				let item = {
					id:undefined,
					glkdbh:undefined,
					px:undefined,
					pxmc:undefined,
					pxjg:undefined,
					xfzs:undefined,
				}
				this.dataForm.lqXhPxmxList.push(item)
			},
			handleDelLqXhPxmxEntityList(index) {
				this.dataForm.lqXhPxmxList.splice(index, 1);
			},
		}
	}
</script>
