<template>
    <a-modal title="跟进信息新增" ok-text="确认" cancel-text="取消" :visible="childShow" :confirm-loading="followloading"
        @ok="followOk" @cancel="followCancel">

        <a-row >
          <a-col :md="24" :xs="24">
            <a-form-item label="跟进日期" :labelCol="{md: 3,xs:22}" :wrapperCol="{md: 1,xs:22}" style="width: 110%;">
                <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" :disabledDate="disabledFollowDate"
                    v-model="followDate" ></j-date>
            </a-form-item>
          </a-col>
        </a-row> 

        <a-row >
          <a-col :md="24" :xs="24">
            <a-form-item label="跟进状态" :labelCol="{md: 3,xs:22}" :wrapperCol="{md: 1,xs:22}" style="width: 110%;">
                <j-dict-select-tag type="list"   style="width: 195px" v-model="followStatus" dictCode="customer_follow_status" />
            </a-form-item>
          </a-col>
        </a-row> 

        <a-row >
          <a-col :md="24" :xs="24">
            <a-form-item label="跟进类别" :labelCol="{md: 3,xs:22}" :wrapperCol="{md: 1,xs:22}" style="width: 110%;">
                <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-form-item>
          </a-col>
        </a-row> 

        <a-row >
          <a-col :md="24" :xs="24">
            <a-form-item label="下次跟进" :labelCol="{md: 3,xs:22}" :wrapperCol="{md: 1,xs:22}" style="width: 110%;">
                 <j-date :show-time="false" style="width: 195px" date-format="YYYY-MM-DD" :disabledDate="disabledDate" v-model="nextFollowTime">
            </j-date>
            </a-form-item>
          </a-col>
        </a-row> 

        <a-form-item label="跟进内容">
            <a-textarea v-model="followContent" rows="4" placeholder="请输入跟进内容" />
        </a-form-item>
        <a-form-item label="图片" style="width: 400px">
            <j-image-upload text="上传" v-model="fileList" :isMultiple="true"></j-image-upload>
        </a-form-item>
    </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,
            nextFollowTime: "",
            followTypeList: "",
            followStatusList:"",
            fileList: [],
        }
    },
    props: ['followAddVisible', 'addRow'],
    watch: {
        followAddVisible: {
            handler() {
                this.childShow = this.followAddVisible
                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;
                    }
                });
                this.followDate = moment(new Date()).format("YYYY-MM-DD HH:mm:ss");
                this.followStatus = this.addRow.followStatus;
            },
        }
    },
    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.addRow.schoolDistrictId),
                cpId: this.addRow.id,
                followType: this.followType,
                followContent: this.followContent,
                followPic: String(this.fileList),
                salesCode: this.addRow.saleCode,
                createBy: store.getters.userInfo.username,
                nextFollowTime: this.nextFollowTime,
                followDate: this.followDate,
                followStatus: this.followStatus
            }
            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('update:followAddVisible', false);
            });
        },
        followCancel() {
            this.$emit('update:followAddVisible', false);
            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>
