﻿<template>
	<transition name="el-zoom-in-center">
		<div class="NCC-preview-main">
			<div class="NCC-common-page-header">
				<el-page-header @back="goBack" :content="!dataForm.id ? '新建' : isDetail ? '详情' : '编辑'"/>
				<div class="options">
					<el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail">确 定</el-button>
					<el-button @click="goBack">取 消</el-button>
				</div>
			</div>
			<el-row :gutter="15"  class="main" :style="{margin: '0 auto',width:'100%'}">
				<el-form ref="elForm" :model="dataForm" size="medium" label-width="111px" label-position="right" :disabled="!!isDetail" :rules="rules">
					<el-col :span="12" >
						<el-form-item label="线索编码" prop="customerId">
							<el-input v-model="dataForm.customerId" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<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="12" >
						<el-form-item label="行业" prop="industry">
							<el-select v-model="dataForm.industry" placeholder="请选择" clearable required :style='{"width":"100%"}' >
								<el-option v-for="(item, index) in industryOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="类型" prop="customerTypeId">
							<el-select v-model="dataForm.customerTypeId" placeholder="请选择" clearable required :style='{"width":"100%"}' >
								<el-option v-for="(item, index) in customerTypeIdOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="联系人" prop="userName">
							<el-input v-model="dataForm.userName" placeholder="请输入" clearable required :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="联系电话" prop="mobile">
							<el-input v-model="dataForm.mobile" placeholder="请输入" clearable required :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="所属区域" prop="area">
							<NCC-Address v-model="dataForm.area" placeholder="请选择" required :level="2" >
							</NCC-Address>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="地址" prop="address">
							<el-input v-model="dataForm.address" placeholder="请输入" clearable required :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="跟进人员" prop="desPerson">
							<user-select v-model="dataForm.desPerson" placeholder="请选择" required >
							</user-select>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="线索来源" prop="source">
							<el-select v-model="dataForm.source" placeholder="请选择" clearable required :style='{"width":"100%"}' >
								<el-option v-for="(item, index) in sourceOptions" :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="profile">
							<el-input v-model="dataForm.profile" placeholder="请输入" required show-word-limit :style='{"width":"100%"}' type='textarea' :autosize='{"minRows":4,"maxRows":4}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24" >
						<el-form-item label="线索图片" prop="photos">
							<NCC-UploadImg v-model="dataForm.photos" :fileSize="2" sizeUnit="MB" :limit="9" >
							</NCC-UploadImg>
						</el-form-item>
					</el-col>
					<el-col :span="6" v-if="false" >
						<el-form-item label="创建人" prop="creater">
							<el-input v-model="dataForm.creater" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6" v-if="false" >
						<el-form-item label="创建时间" prop="createTime">
							<el-input v-model="dataForm.createTime" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6" v-if="false" >
						<el-form-item label="最后修改人" prop="modifyer">
							<el-input v-model="dataForm.modifyer" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6" v-if="false" >
						<el-form-item label="修改时间" prop="modifyTime">
							<el-input v-model="dataForm.modifyTime" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
				</el-form>
			</el-row>
		</div>
	</transition>
</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: {
					customerId:undefined,
					name:undefined,
					industry:undefined,
					customerTypeId:undefined,
					userName:undefined,
					mobile:undefined,
					area:[],
					address:undefined,
					desPerson:undefined,
					source:undefined,
					profile:undefined,
					photos:[],
					creater:undefined,
					createTime:undefined,
					modifyer:undefined,
					modifyTime:undefined,
				},
				rules: {
					name:[
						{
							required:true,
							message:'请输入名称',
							trigger:'blur'
						},
					],
					industry:[
						{
							required:true,
							message:'请输入行业',
							trigger:'change'
						},
					],
					customerTypeId:[
						{
							required:true,
							message:'请输入类型',
							trigger:'change'
						},
					],
					userName:[
						{
							required:true,
							message:'请输入联系人',
							trigger:'blur'
						},
					],
					mobile:[
						{
							required:true,
							message:'请输入联系电话',
							trigger:'blur'
						},
						{
							pattern:/^1[3456789]\d{9}$|^0\d{2,3}-?\d{7,8}$/,
							message:'请输入正确的联系方式',
							trigger:'blur'
						},
					],
					area:[
						{
							required:true,
							message:'请输入所属区域',
							trigger:'change'
						},
					],
					address:[
						{
							required:true,
							message:'请输入地址',
							trigger:'blur'
						},
					],
					desPerson:[
						{
							required:true,
							message:'请输入跟进人员',
							trigger:'change'
						},
					],
					source:[
						{
							required:true,
							message:'请输入线索来源',
							trigger:'change'
						},
					],
					profile:[
						{
							required:true,
							message:'请输入线索描述',
							trigger:'blur'
						},
					],
				},
				industryOptions : [],
				customerTypeIdOptions : [],
				sourceOptions : [],
			}
		},
		computed: {},
        watch: {},
        created() {
			this.getindustryOptions();
			this.getcustomerTypeIdOptions();
			this.getsourceOptions();
		},
		mounted() {
        },
		methods: {
			getindustryOptions(){
				getDictionaryDataSelector('7070527a3aac44ec8dc6fcbe87bb6878').then(res => {
					this.industryOptions = res.data.list
				});
			},
			getcustomerTypeIdOptions(){
				getDictionaryDataSelector('038d293fca544c86afa3f2bc65421fd7').then(res => {
					this.customerTypeIdOptions = res.data.list
				});
			},
			getsourceOptions(){
				getDictionaryDataSelector('4ce486ec911e46cb914ea53f685ead75').then(res => {
					this.sourceOptions = res.data.list
				});
			},
			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/SubDev/ZyOaClue/' + 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/SubDev/ZyOaClue`,
                                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/SubDev/ZyOaClue/' + 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>
