<template>
    <a-modal title="转为潜客" :visible="childShow" @ok="editOk" @cancel="editCancel" :width=800
        :body-style="{width:200}">
        <a-row style="display: flex; align-items: center; margin-bottom: 10px;">
            <a-col span="3" style="text-align: right;"><span style="color: tomato; ">*</span>姓名:</a-col>
            <a-col span="1"></a-col>
            <a-col span="7">
                <a-input placeholder="请输入姓名" :key="666" v-model="cb_name"></a-input>
            </a-col>
            <a-col span="3" style="text-align: right;"><span style="color: tomato; ">*</span>主要联系人:</a-col>
            <a-col span="1"></a-col>
            <a-col span="3">      
                <a-select style="width: 100%;" v-model="contactName" >
                <a-select-option v-for="(item, key)  in linkmanOptinos" :key="key" :value="item.value">
                    {{item.text}}
                </a-select-option>
                </a-select>
            </a-col>
            <a-col span="5">
                <a-input style="margin-left: 5px;" v-model="contactPhone">
                </a-input>
            </a-col>
        </a-row>
        <a-row style="display: flex; align-items: center; margin-bottom: 10px;">
            <a-col span="3" style="text-align: right;"><span style="color: tomato; ">*</span>性别:</a-col>
            <a-col span="1"></a-col>
            <a-col span="7">
                <a-radio-group v-model="sex" placeholder="请选择机构类型">
                    <a-radio value="1">
                      男
                    </a-radio>
                    <a-radio value="2">
                      女
                    </a-radio>
                    <a-radio value="0">
                      未知
                    </a-radio>
                  </a-radio-group>
            </a-col>
            <a-col span="3" style="text-align: right;">备用联系人:</a-col>
            <a-col span="1"></a-col>
            <a-col span="3">      
                <a-select style="width: 100%;" v-model="contact1Name" >
                <a-select-option v-for="(item, key)  in linkmanOptinos" :key="key" :value="item.value">
                    {{item.text}}
                </a-select-option>
                </a-select>
            </a-col>
            <a-col span="5">
                <a-input style="margin-left: 5px;"  v-model="contact1Phone">
                </a-input>
            </a-col>
        </a-row>
        <a-row style="display: flex; align-items: center; margin-bottom: -10px;">
            <a-col span="3" style="text-align: right;">生日:</a-col>
            <a-col span="1"></a-col>
            <a-col span="4">
                <a-date-picker placeholder="生日" valueFormat="YYYY-MM-DD" v-model="birthday" @change="handleDateChange" />
            </a-col>
            <a-col span="2" style="text-align: right;">年龄:</a-col>
            <a-col span="1" style="text-align: center;">
               {{age}}
            </a-col>
            <a-col span="3" style="text-align: right;"></a-col>
            <a-col span="1"></a-col>
            <a-col span="3">      
                <a-select style="width: 100%;" v-model="contact2Name" >
                <a-select-option v-for="(item, key)  in linkmanOptinos" :key="key" :value="item.value">
                    {{item.text}}
                </a-select-option>
                </a-select>
            </a-col>
            <a-col span="5">
                <a-input style="margin-left: 5px;"  v-model="contact2Phone">
                </a-input>
            </a-col>
        </a-row>
        <a-divider  dashed />

        <a-row style="display: flex; align-items: center; margin-bottom: 10px; margin-top: -10px;">
            <a-col span="3" style="text-align: right;">昵称:</a-col>
            <a-col span="1"></a-col>
            <a-col span="7">
                <a-input placeholder="请输入昵称" v-model="nickname"></a-input>
            </a-col>
        </a-row>

        <a-row style="display: flex; align-items: center; margin-bottom: 10px;">
            <a-col span="3" style="text-align: right;"><span style="color: tomato; ">*</span>选择校区:</a-col>
            <a-col span="1"></a-col>
            <a-col span="7">
                <a-select style="width: 100%;" v-model="schoolDistrictId" placeholder="请选择校区" >
                <a-select-option v-for="(item, key)  in schoolOptions" :key="key" :value="item.value">
                    {{item.text}}
                </a-select-option>
                </a-select>
            </a-col>
            <a-col span="3" style="text-align: right;"><span style="color: tomato; ">*</span>意向度:</a-col>
            <a-col span="1"></a-col>
            <a-col span="8">
                <span>
                    <a-rate v-model="intendedDegress" :tooltips="desc" :count="3"/>
                    <span class="ant-rate-text" style="color:tomato">{{ desc[intendedDegress - 1] }}</span>
                </span>
            </a-col>
        </a-row>
        <a-row style="display: flex; align-items: center; margin-bottom: 10px;">
            <a-col span="3" style="text-align: right;">顾问:</a-col>
            <a-col span="1"></a-col>
            <a-col span="7">
                <a-select style="width: 100%;" placeholder="请选择顾问" v-model="salesCode">
                <a-select-option v-for="(item, key)  in lecturerOptions" :key="item.value" :value="item.value">
                    {{item.text}}
                </a-select-option>
                </a-select>
            </a-col>
        </a-row>
        <a-row style="display: flex; align-items: center; margin-bottom: 10px;">
            <a-col span="3" style="text-align: right;">备注:</a-col>
            <a-col span="1"></a-col>
            <a-col span="19">
                <a-textarea type="textarea" v-model="remarks" :rows="5" />
            </a-col>
        </a-row>
    </a-modal>
</template>
<script>

import { postAction } from '@/api/manage'
import { getAge } from '../../../../utils/util';
import {initDictOptions} from '@/components/dict/JDictSelectUtil'
import {ajaxGetDictItems} from '@/api/api'
import store from '@/store'
export default {
    name: 'CustomerBusinessPotential',
    data() {
        return {
            age: 0,
            desc: ['意向一般', '意向中等', '意向强烈'],
            linkmanOptinos:[],
            schoolOptions:[],
            lecturerOptions: [],
            channelType: undefined,
            collectinoCode: undefined,
            cb_name: undefined,
            contactPhone: undefined,
            contactName: undefined,
            mark: undefined,
            salesCode: undefined,
            sex: undefined,
            birthday: undefined,
            saleCode_text: undefined,
            contact1Name: undefined,
            contact1Phone: undefined,
            contact2Name: undefined,
            contact2Phone: undefined,
            nickname: undefined,
            schoolDistrictId: undefined,
            intendedDegress: 3,
            remarks: undefined
        }
    },
    props: ['childShow', 'para'],
    watch: {
        immediate: true,
        childShow: {
            handler() {
                if(this.childShow) {
                    let tempPara = JSON.parse(JSON.stringify(this.para));
                    this.channelType = tempPara.channel;
                    this.collectinoCode = tempPara.collectinoCode;
                    this.cb_name = tempPara.name;
                    this.contactPhone = tempPara.phone;
                    this.contactName = tempPara.parents;
                    this.mark = tempPara.remarks;
                    this.salesCode = tempPara.salesCode;
                    this.sex = tempPara.sex;
                    this.birthday = tempPara.birthday;
                    this.saleCode_text = tempPara.salesCode_dictText;
                    if(this.birthday !== null && this.birthday !== "" && this.birthday !== undefined) {
                        this.age = getAge(this.birthday);
                    }
                    ajaxGetDictItems('school_organization,name,id', null).then((res) => {
                    if (res.success) {
                            this.schoolOptions = res.result;
                        }
                    });
                    ajaxGetDictItems('sys_user,realname,id', null).then((res) => {
                    if (res.success) {
                        this.lecturerOptions = res.result;
                    }
                    });
                    initDictOptions('customer_linkman').then((res) => {
                        if (res.success) {
                            this.linkmanOptinos = res.result;
                        }
                    });
                }
            },
        }
    },
    methods: {
        editOk() {
            if(this.cb_name === null || this.cb_name === undefined || this.cb_name ==="") {
                this.$message.warning('请输入姓名');
                return;
            }
            if(this.sex === null || this.sex === undefined || this.sex ==="") {
                this.$message.warning('请输入性别');
                return;
            }
            if(this.contactName === null || this.contactName === undefined || this.contactName ==="") {
                this.$message.warning('请输入联系人');
                return;
            }
            if(this.contactPhone === null || this.contactPhone === undefined || this.contactPhone ==="") {
                this.$message.warning('请输入手机号');
                return;
            }
            if(this.schoolDistrictId === null || this.schoolDistrictId === undefined || this.schoolDistrictId ==="") {
                this.$message.warning('请选择校区');
                return;
            }
            if(this.intendedDegress === null || this.intendedDegress === undefined || this.intendedDegress ==="") {
                this.$message.warning('请输入意向度');
                return;
            }
            let infoPara = {
                cbId: this.para.id,
                channelType: this.channelType,
                collectinoCode: this.collectinoCode,
                name: this.cb_name,
                contactName: this.contactName,
                contactPhone: this.contactPhone,
                contact1Name: this.contact1Name,
                contact1Phone: this.contact1Phone,
                contact2Name: this.contact2Name,
                contact2Phone: this.contact2Phone,
                mark: this.remarks,
                nickname: this.nickname,
                salesCode: this.salesCode,
                sex: this.sex,
                birthday: this.birthday,
                schoolDistrictId: this.schoolDistrictId,
                intendedDegress: this.intendedDegress,
                createBy: store.getters.userInfo.id,
                saleCode_text: this.para.salesCode_dictText,
                school_text: this.schoolOptions.find(item => {return item.value == this.schoolDistrictId }).text,
            }
            postAction("/customer/customerInfo/changePotential", infoPara).then((res) => {
                if(res.success) {
                    this.$message.success('编辑成功');
                    this.$emit('childReturn',false);
                    this.schoolDistrictId = undefined;
                }
            });
        },
        editCancel() {
            this.$emit('childReturn',false);
            this.schoolDistrictId = undefined;
        },
        handleDateChange() {
            this.age = getAge(this.infoParams.birthday);
        },
    }
}
</script>
  