<template>
    <div class="">
        <div>
            <el-form ref="ref_form1" :inline="false" :rules="dataRule" class="form">
                <el-form-item label="处理方式" label-width="150px" :class="{ 'form-item': source === 'visiual' }"
                    prop="operationType">
                    <el-radio-group :class="{ 'form-item': source === 'visiual' }" v-model="operationType"
                        @change="handleChangeOperationType">
                        <el-radio v-if="!eventId" label="4">待处理</el-radio>
                        <el-radio label="0">回复</el-radio>
                        <el-radio label="5">指派</el-radio>
                        <el-radio label="6">完成并回复</el-radio>
                        <el-radio label="2">转服务</el-radio>
                    </el-radio-group>
                </el-form-item>
            </el-form>
            <div v-if="operationType === '0'">
                <process-form-replay ref="ref_process_form_replay" :source="source" :eventDetailData="eventDetailData"
                    :eventId="eventId"></process-form-replay>
            </div>
            <div v-if="operationType === '6'">
                <process-form-replay-end ref="ref_process_form_replay_end" :source="source"
                    :eventDetailData="eventDetailData" :eventId="eventId"></process-form-replay-end>
            </div>
            <div v-if="operationType === '5'">
                <process-form-designate ref="ref_process_form_designate" :source="source" :eventDetailData="eventDetailData"
                    :eventId="eventId"></process-form-designate>
            </div>
            <div v-if="operationType === '2'">
                <process-form-demand ref="ref_process_form_demond" :source="source" :eventId="eventId"
                    :transferObj="transferObj" :demandUserId="demandUserId" :demandUserName="demandUserName"
                    :demandUserMobile="demandUserMobile" :eventDetailData="eventDetailData"></process-form-demand>
            </div>
        </div>
    </div>
</template>

<script>
import { Loading } from "element-ui"; // 引入Loading服务
import processFormReplay from "./process-form-replay";
import processFormReplayEnd from "./process-form-replay-end";
import processFormProject from "./process-form-project";
import processFormDemand from "./process-form-demand";
import processFormIssue from "./process-form-issue";
import processFormDesignate from "./process-form-designate";


let loading; // 加载动画

export default {
    data() {
        return {
            casOptions: [],
            iscascaderShow: 0,
            selCategoryArray: [],
            selCateObj: {},
            optionProps: {
                multiple: false,
                value: 'id',
                label: 'name',
                children: 'subCategory',
            },
            operationType: '',
            replayInfo: {},
            demand: {},
            project: {},
            issueInfo: {},
            okflag: false,
            eventDetailCopy: {},
            transferObj: {
                latitude: "",
                longitude: ""
            }
        };
    },
    components: {
        processFormReplay,
        processFormProject,
        processFormDemand,
        processFormIssue,
        processFormDesignate,
        processFormReplayEnd
    },
    computed: {
        dataRule() {
            return {
                operationType: [
                    { required: true, message: "处理方式不能为空", trigger: "blur" },
                ],
            };
        },
    },
    props: {
        demandUserId: {
            type: String,
            default: "",
        },
        demandUserName: {
            type: String,
            default: "",
        },
        demandUserMobile: {
            type: String,
            default: "",
        },
        // gridId: {
        //     type: String,
        //     default: "",
        // },
        eventId: {
            type: String,
            default: "",
        },
        eventDetailData: {
            type: Object,
            default() {
                return {}
            }
        },
        source: {//展示来源：manage  管理平台    visiual  可视化平台
            type: String,
            default: 'manage'
        }
    },

    watch: {},

    created() { },

    async mounted() {
        const { user } = this.$store.state
        this.agencyId = user.agencyId
        if (this.eventId) {
            this.eventDetailCopy = JSON.parse(JSON.stringify(this.eventDetailData));
        }
        if (this.eventDetailData.operationType) {
            this.operationType = this.eventDetailCopy.operationType
        }
        this.$EventBus.$on('map', (val) => {
            this.transferObj.latitude = val.lat
            this.transferObj.longitude = val.lng
        })
    },

    methods: {
        handleChangeOperationType(val) {
            this.operationType = val;
        },
        async getProcessInfo() {
            this.okflag = false
            if (this.operationType === '0') {//回复
                this.$refs.ref_process_form_replay.getReplayInfo();
                if (this.$refs.ref_process_form_replay.okflag) {
                    this.replayInfo = this.$refs.ref_process_form_replay.formData;
                    this.okflag = true;
                }
            }else if(this.operationType === '2'){//转服务
                this.$refs.ref_process_form_demond.getDemandInfo()
                this.demand = this.$refs.ref_process_form_demond.formData;
                if (this.$refs.ref_process_form_demond.okflag) {
                    this.replayInfo = this.$refs.ref_process_form_demond.formData;
                    this.okflag = true;
                }
            } else if (this.operationType === '5') {//指派
                this.$refs.ref_process_form_designate.getReplayInfo()
                this.replayInfo = this.$refs.ref_process_form_designate.formData
                if (this.$refs.ref_process_form_designate.okflag) {
                    this.replayInfo = this.$refs.ref_process_form_designate.formData
                    this.okflag = true
                }
            } else if (this.operationType === '6') {//回复并完成
                this.$refs.ref_process_form_replay_end.getReplayInfo()
                this.replayInfo = this.$refs.ref_process_form_replay_end.formData
                if (this.$refs.ref_process_form_replay_end.okflag) {
                    this.replayInfo = this.$refs.ref_process_form_replay_end.formData
                    this.okflag = true
                }
            } else if(this.operationType === '4')  {
                this.okflag = true
            }else {
                return false
            }
        },
        handleCancle() {
            this.resetData();
        },
        // 开启加载动画
        startLoading() {
            loading = Loading.service({
                lock: true, // 是否锁定
                text: "正在加载……", // 加载中需要显示的文字
                background: "rgba(0,0,0,.7)", // 背景颜色
            });
        },
        resetData() {

        },
        // 结束加载动画
        endLoading() {
            if (loading) {
                loading.close();
            }
        },
    },
};
</script>


<style lang="scss" scoped>
@import "@/assets/scss/modules/shequzhili/event-info.scss";

.el-dialog__body {
    padding: 0 10px 20px !important;
}
</style>
