﻿<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="xmbh">
							<el-input v-model="dataForm.xmbh" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="项目名称" prop="xmmc">
							<el-input v-model="dataForm.xmmc" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="标准价格" prop="bzjg">
							<el-input type="number" v-model="dataForm.bzjg" placeholder="请输入标准价格" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="手工费" prop="sgf">
							<el-input type="number" v-model="dataForm.sgf" placeholder="请输入手工费" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="时长（分）" prop="xmsc">
							<el-input type="number" v-model="dataForm.xmsc" placeholder="请输入时长" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<!-- <el-col :span="24">
						<el-form-item label="基础服务提成" prop="jcfwtc">
							<el-input v-model="dataForm.jcfwtc" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col> -->
					<el-col :span="24">
						<el-form-item label="归类" prop="beautyType">
							<!-- <el-input v-model="dataForm.beautyType" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input> -->
							<el-select allow-create filterable v-model="dataForm.beautyType" placeholder="请选择">
								<el-option
								v-for="item in options8"
								:key="item.value"
								:label="item.label"
								:value="item.value">
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="分类1汇总表" prop="fl1">
							<!-- <el-input v-model="dataForm.fl1" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input> -->
							<el-select allow-create filterable v-model="dataForm.fl1" placeholder="请选择">
								<el-option
								v-for="item in options1"
								:key="item.value"
								:label="item.label"
								:value="item.value">
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="分类2汇总表" prop="fl2">
							<!-- <el-input v-model="dataForm.fl2" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input> -->
							<el-select allow-create filterable v-model="dataForm.fl2" placeholder="请选择">
								<el-option
								v-for="item in options2"
								:key="item.value"
								:label="item.label"
								:value="item.value">
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="分类3工资用" prop="fl3">
							<!-- <el-input v-model="dataForm.fl3" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input> -->
							<el-select allow-create filterable v-model="dataForm.fl3" placeholder="请选择">
								<el-option
								v-for="item in options3"
								:key="item.value"
								:label="item.label"
								:value="item.value">
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="分类4品项用" prop="fl4">
							<!-- <el-input v-model="dataForm.fl4" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input> -->
							<el-select allow-create filterable v-model="dataForm.fl4" placeholder="请选择">
								<el-option
								v-for="item in options4"
								:key="item.value"
								:label="item.label"
								:value="item.value">
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="统计类别" prop="tjlb">
							<el-input v-model="dataForm.tjlb" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="折扣类别" prop="zklb">
							<el-input v-model="dataForm.zklb" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="分类" prop="fl">
							<!-- <el-input v-model="dataForm.fl" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input> -->
							<el-select allow-create filterable v-model="dataForm.fl" placeholder="请选择">
								<el-option
								v-for="item in options5"
								:key="item.value"
								:label="item.label"
								:value="item.value">
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="其它1" prop="qt1">
							<!-- <el-input v-model="dataForm.qt1" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input> -->
							<el-select allow-create filterable v-model="dataForm.qt1" placeholder="请选择">
								<el-option
								v-for="item in options6"
								:key="item.value"
								:label="item.label"
								:value="item.value">
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="其它2" prop="qt2">
							<!-- <el-input v-model="dataForm.qt2" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input> -->
							<el-select allow-create filterable v-model="dataForm.qt2" placeholder="请选择">
								<el-option
								v-for="item in options7"
								:key="item.value"
								:label="item.label"
								:value="item.value">
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="是否有效" prop="isEffective">
							<el-select v-model="dataForm.isEffective" placeholder="请选择">
								<el-option
								v-for="item in effectiveOptions"
								:key="item.value"
								:label="item.label"
								: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'
import { init } from 'echarts/lib/echarts';
	export default {
		components: {},
		props: [],
		data() {
			return {
				loading: false,
				visible: false,
				isDetail: false,
				dataForm: {
					id:'',
					sgf:undefined,
					id:undefined,
					xmbh:undefined,
					xmmc:undefined,
					bzjg:undefined,
					xmsc:undefined,
					jcfwtc:undefined,
					fl1:undefined,
					fl2:undefined,
					fl3:undefined,
					fl4:undefined,
					tjlb:undefined,
					zklb:undefined,
					fl:undefined,
					qt1:undefined,
					qt2:undefined,
					beautyType:undefined,
					isEffective: 1, // 默认有效
				},
				rules: {
				},
				options1:[],
				options2:[],
				options3:[],
				options4:[],
				options5:[],
				options6:[],
				options7:[],
				options8:[],
				effectiveOptions: [],
			}
		},
		computed: {},
        watch: {},
        created() {
		
		},
		mounted() {
			
        },
		methods: {
			getoptions(){
				request({
					url: '/api/Extend/lqxmzl/GetDistinctFieldData?fieldName=fl1',
					method: 'get',
				}).then(res => {
					if (res.code == 200 && res.data && res.data.values) {
						this.options1 = res.data.values.map(item => ({
							label: item,
							value: item
						}));
					}else {
						this.options1 = []
					}
				})
				request({
					url: '/api/Extend/lqxmzl/GetDistinctFieldData?fieldName=fl2',
					method: 'get',
				}).then(res => {
					if (res.code == 200 && res.data && res.data.values) {
						this.options2 = res.data.values.map(item => ({
							label: item,
							value: item
						}));
					}else {
						this.options2 = []
					}
				})
				request({
					url: '/api/Extend/lqxmzl/GetDistinctFieldData?fieldName=fl3',
					method: 'get',
				}).then(res => {
					if (res.code == 200 && res.data && res.data.values) {
						this.options3 = res.data.values.map(item => ({
							label: item,
							value: item
						}));
					}else {
						this.options3 = []
					}
				})
				request({
					url: '/api/Extend/lqxmzl/GetDistinctFieldData?fieldName=fl4',
					method: 'get',
				}).then(res => {
					if (res.code == 200 && res.data && res.data.values) {
						this.options4 = res.data.values.map(item => ({
							label: item,
							value: item
						}));
					}else {
						this.options4 = []
					}
				})
				request({
					url: '/api/Extend/lqxmzl/GetDistinctFieldData?fieldName=fl',
					method: 'get',
				}).then(res => {
					if (res.code == 200 && res.data && res.data.values) {
						this.options5 = res.data.values.map(item => ({
							label: item,
							value: item
						}));
					}else {
						this.options5 = []
					}
				})
				request({
					url: '/api/Extend/lqxmzl/GetDistinctFieldData?fieldName=qt1',
					method: 'get',
				}).then(res => {
					if (res.code == 200 && res.data && res.data.values) {
						this.options6 = res.data.values.map(item => ({
							label: item,
							value: item
						}));
					}else {
						this.options6 = []
					}
				})
				request({
					url: '/api/Extend/lqxmzl/GetDistinctFieldData?fieldName=qt2',
					method: 'get',
				}).then(res => {
					if (res.code == 200 && res.data && res.data.values) {
						this.options7 = res.data.values.map(item => ({
							label: item,
							value: item
						}));
					}else {
						this.options7 = []
					}
				})
				request({
					url: '/api/Extend/lqxmzl/GetDistinctFieldData?fieldName=beautyType',
					method: 'get',
				}).then(res => {
					if (res.code == 200 && res.data && res.data.values) {
						this.options8 = res.data.values.map(item => ({
							label: item,
							value: item
						}));
					}else {
						this.options8 = []
					}
				})
				// 获取状态枚举数据
				request({
					url: '/api/Extend/lqkdkdjlb/status-enum',
					method: 'get',
				}).then(res => {
					if (res.code == 200 && res.data) {
						this.effectiveOptions = res.data.map(item => ({
							label: item.Name,
							value: item.Value
						}));
					} else {
						this.effectiveOptions = []
					}
				})
			},
			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/LqXmzl/' + this.dataForm.id,
							method: 'get'
						}).then(res =>{
							this.dataForm = res.data;
							this.dataForm.isEffective = res.data.isEffective?res.data.isEffective:1;
						})
					}
				})
				this.getoptions()
			},
			dataFormSubmit() {
				this.$refs['elForm'].validate((valid) => {
                    if (valid) {
                        if (!this.dataForm.id) {
                            request({
                                url: `/api/Extend/LqXmzl`,
                                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/LqXmzl/' + 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>
