<template>
    <a-modal title="跟进信息新增" ok-text="确认" cancel-text="取消" :visible="childShow" :confirm-loading="followloading"
        @ok="followOk" @cancel="followCancel" :width=600>
        <a-row style="display: flex; align-items: center; margin-bottom: 20px;">
            <a-col span="4" style="text-align: right;"><span style="color: tomato; ">*</span>跟进日期:</a-col>
            <a-col span="1"></a-col>
            <a-col span="18">
                <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" :disabledDate="disabledFollowDate"
                    v-model="followDate" ></j-date>
            </a-col>
        </a-row> 
        <a-row style="display: flex; align-items: center; margin-bottom: 20px;">
            <a-col span="4" style="text-align: right;">跟进方式:</a-col>
            <a-col span="1"></a-col>
            <a-col span="18">
                <a-radio-group v-model="followType" style="width: 395px">
                 <a-radio v-for="(item, key) in followTypeList" :key="key" :value="item.value">{{ item.text }}</a-radio>
                </a-radio-group>
            </a-col>
        </a-row> 
        <a-row style="display: flex; align-items: center; margin-bottom: 20px;">
            <a-col span="4" style="text-align: right;"><span style="color: tomato; ">*</span>跟进状态:</a-col>
            <a-col span="1"></a-col>
            <a-col span="18">
                <j-dict-select-tag type="list"   style="width: 195px" v-model="followStatus" dictCode="customer_follow_status" />
            </a-col>
        </a-row> 

        <a-row style="display: flex; align-items: center; margin-bottom: 20px;">
            <a-col span="4" style="text-align: right;">意向度:</a-col>
            <a-col span="1"></a-col>
            <a-col span="18">
                <a-radio-group v-model="intendedDegress" style="width: 395px">
                 <a-radio v-for="(item, key) in intentionOptions" :key="key" :value="item.value">{{ item.text }}</a-radio>
                </a-radio-group>
            </a-col>
        </a-row> 
        
        <a-row style="display: flex; align-items: center; margin-bottom: 20px;">
            <a-col span="4" style="text-align: right;"><span style="color: tomato; ">*</span>跟进内容:</a-col>
            <a-col span="1"></a-col>
            <a-col span="18">
                <a-textarea v-model="followContent" rows="4" placeholder="请输入跟进内容" />
            </a-col>
        </a-row> 

        <a-row style="display: flex; align-items: center; margin-bottom: 10px;">
            <a-col span="4" style="text-align: right;">图片:</a-col>
            <a-col span="1"></a-col>
            <a-col span="18">
                <j-image-upload text="上传" v-model="fileList" :isMultiple="true"></j-image-upload>
            </a-col>
        </a-row> 
        <a-row style="display: flex; align-items: center; margin-bottom: 10px;">
            <a-col span="4" style="text-align: right;"><span style="color: tomato; ">*</span>下次跟进:</a-col>
            <a-col span="1"></a-col>
            <a-col span="18">
                <j-date :show-time="false" style="width: 195px" date-format="YYYY-MM-DD" :disabledDate="disabledDate" v-model="nextFollowTime"></j-date>
            </a-col>
        </a-row>
    </a-modal>
</template>
<script>
import { postAction } from '@/api/manage'
import { initDictOptions } from '@/components/dict/JDictSelectUtil'
import JImageUpload from '@/components/jeecg/JImageUpload'
import moment from 'moment'
import store from '@/store'
export default {
    name: 'CustomerFollowAdd',
    components: {
        JImageUpload
    },
    data() {
        return {
            childShow: false,
            followloading: false,
            followDate: undefined,
            followStatus: 0,
            followType: "",
            followContent: "",
            followDetailVisible: false,
            intendedDegress: undefined,
            nextFollowTime: "",
            followTypeList: "",
            followStatusList:"",
            fileList: [],
            intentionOptions:[]
        }
    },
    props: ['followShow', 'dataPara'],
    watch: {
        followShow: {
            handler() {
                this.childShow = this.followShow
                initDictOptions('customer_follow_type').then((res) => {
                    if (res.success) {
                        this.followTypeList = res.result;
                    }
                });
                initDictOptions('customer_follow_status').then((res) => {
                    if (res.success) {
                        this.followStatusList = res.result;
                    }
                });
                initDictOptions('customer_intention_status').then((res) => {
                    if (res.success) {
                        this.intentionOptions = res.result;
                    }
                });
                this.followDate = moment(new Date()).format("YYYY-MM-DD HH:mm:ss");
                this.followStatus = this.dataPara.followStatus;
                this.intendedDegress = String(this.dataPara.intendedDegress);
                this.followType = '1';
            },
        }
    },
    methods: {
        disabledDate(current) {
            return current < moment().endOf("day"); // 当前时间之前的所有日期都禁用
        },
        disabledFollowDate(current) {
            return current > moment().endOf("day"); // 当前时间之后的所有日期都禁用
        },
        followOk() {
            if (this.followDate == "") {
                this.$message.warn('请输入跟进内容');
                return;
            }
            if (this.followType == "") {
                this.$message.warn('请输入跟进类型');
                return;
            }
            if (this.followContent == "") {
                this.$message.warn('请输入跟进内容');
                return;
            }
            if (this.nextFollowTime == "") {
                this.$message.warn('请输入跟进日期');
                return;
            }
            let params = {
                schoolDistrictId: Number(this.dataPara.schoolDistrictId),
                cpId: this.dataPara.id,
                followType: this.followType,
                followContent: this.followContent,
                followPic: String(this.fileList),
                salesCode: this.dataPara.saleCode,
                createBy: store.getters.userInfo.username,
                nextFollowTime: this.nextFollowTime,
                followDate: this.followDate,
                followStatus: this.followStatus,
                intendedDegress: this.intendedDegress,
                follower:store.getters.userInfo.username,
            }
            this.followloading = true;
            postAction("/customer/customerFollow/addFollow", params).then((res) => {
                if (res.success) {
                    this.$emit('ok');
                    this.$message.success('添加成功');
                } else {
                    this.$message.warn('添加失败:' + res.message);
                }
            }).finally(() => {
                this.followloading = false;
                this.followVisible = false;
                this.followType = "";
                this.followContent = "";
                this.fileList = [];
                this.dataFollow = "";
                this.nextFollowTime = "";
                this.$emit('follow-event', 'follow');
            });
        },
        followCancel() {
            this.$emit('follow-event', 'follow');
            if(JSON.stringify(this.fileList) !== '[]' || Object.keys(this.fileList).length !== 0) {
            let bizPath =[];
            if(this.fileList.indexOf(",")!= -1) {
                bizPath = this.fileList.split(',');
            }else {
                bizPath.push(this.fileList)
            }
            postAction("/sys/common/delUploadTemp", bizPath).then((res) => {
            });
            }
            this.fileList = [];
            this.dataFollow = "";
            this.childShow = false;
            this.followType = "";
            this.followContent = "";
            this.nextFollowTime = "";
        },
    }
}
</script>
