﻿<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="100px" label-position="right" :disabled="!!isDetail" :rules="rules">
					<el-col :span="24" >
						<el-form-item label="线索/客户" prop="typeId">
							<el-select v-model="dataForm.typeId" placeholder="请选择" clearable required :style='{"width":"100%"}' >
								<el-option v-for="(item, index) in typeIdOptions" :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="customerId" v-if="dataForm.typeId==1">
							<el-select v-model="dataForm.customerId" placeholder="请选择" clearable required :style='{"width":"100%"}' >
								<el-option v-for="(item, index) in customerIdOptions" :key="index" :label="item.Name" :value="item.Id" ></el-option>
							</el-select>
						</el-form-item>
						<el-form-item label="线索名称" prop="customerId" v-if="dataForm.typeId==0">
							<el-select v-model="dataForm.customerId" placeholder="请选择" clearable required :style='{"width":"100%"}' >
								<el-option v-for="(item, index) in clueIdOptions" :key="index" :label="item.Name" :value="item.Id" ></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="跟进时间" prop="trackTime">
							<el-date-picker v-model="dataForm.trackTime" placeholder="请选择" clearable required :style='{"width":"100%"}' type='datetime' format="yyyy-MM-dd HH:mm:ss" value-format="timestamp" >
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="跟进阶段" prop="trackStage">
							<el-select v-model="dataForm.trackStage" placeholder="请选择" clearable required :style='{"width":"100%"}' >
								<el-option v-for="(item, index) in trackStageOptions" :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="result">
							<el-input v-model="dataForm.result" 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="measure">
							<el-input v-model="dataForm.measure" 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" >
						<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="24" >
						<el-form-item label="附件" prop="appendix">
							<NCC-UploadFz v-model="dataForm.appendix" :fileSize="2" sizeUnit="MB" :limit="9" buttonText="点击上传" >
							</NCC-UploadFz>
						</el-form-item>
					</el-col>
					<el-col :span="12" 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="12" 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-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: {
					id:'',
					typeId:undefined,
					customerId:undefined,
					trackTime:undefined,
					trackStage:undefined,
					result:undefined,
					measure:undefined,
					photos:[],
					appendix:[],
					creater:undefined,
					createTime:undefined,
				},
				rules: {
					typeId:[
						{
							required:true,
							message:'请输入线索/客户',
							trigger:'change'
						},
					],
					customerId:[
						{
							required:true,
							message:'请输入名称',
							trigger:'change'
						},
					],
					trackTime:[
						{
							required:true,
							message:'请输入跟进时间',
							trigger:'change'
						},
					],
					trackStage:[
						{
							required:true,
							message:'请输入跟进阶段',
							trigger:'change'
						},
					],
					result:[
						{
							required:true,
							message:'请输入跟进结果',
							trigger:'blur'
						},
					],
				},
				typeIdOptions:[{"fullName":"客户","id":"1"},{"fullName":"线索","id":"0"}],
				customerIdOptions : [],
				clueIdOptions : [],
				trackStageOptions : [],
			}
		},
		computed: {},
        watch: {},
        created() {
			this.getcustomerIdOptions();
			this.getclueIdOptions();
			this.gettrackStageOptions();
		},
		mounted() {
        },
		methods: {
			getcustomerIdOptions(){
				previewDataInterface('195029830188664069').then(res => {
					this.customerIdOptions = res.data
				});
			},
			getclueIdOptions(){
				previewDataInterface('208082463908431109').then(res => {
					this.clueIdOptions = res.data
				});
			},
			gettrackStageOptions(){
				getDictionaryDataSelector('208067702508487941').then(res => {
					this.trackStageOptions = 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/ZyOaCustomerTrack/' + 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/ZyOaCustomerTrack`,
                                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/ZyOaCustomerTrack/' + 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>
