<!-- 应急事件 -->
<template>
    <view class="main">
        <view class="emergencyList pad15">
            <view class="emergencyItem" v-for="(item, index) in showList" :key="index" @click="handleShowDetail(item)"
                :style="{
                    marginBottom: index + 1 === showList.length ? '0' : '',
                    border: item.status === 1 ? '2rpx solid #f4db9c' : item.status === 2 ? '2rpx solid #d3d3d3' : ''
                }">
                <view class="emergencyItemTitle">
                    <view class="emergencyItemTitleLeft">
                        {{ type === 1 ? item.title || "" : type === 2 ? item.service || "" : "" }}
                    </view>
                    <view class="emergencyItemTitleRight">
                        <view class="emergencyItemStatus" :style="{
                            background: item.status === 1 ? '#ecbd44' : item.status === 2 ? '#d3d3d3' : '',
                            color: item.status === 1 ? '#fff' : item.status === 2 ? '#fff' : ''
                        }">
                            {{ item.status === 1 ? '已完成' : item.status ===
                                2 ? '处理中' : '' }}</view>
                    </view>
                </view>
                <view class="emergencyDesc">{{ item.desc || "" }}</view>

                <view class="line"></view>

                <view class="otherMessageRow">
                    <image class="otherMessageIcon" src="https://eshangtech.com/cyy_DIB/personIcon.png" />
                    <view class="otherMessageValue">{{ item.person }}</view>
                </view>

                <view class="otherMessageRow">
                    <image class="otherMessageIcon" src="https://eshangtech.com/cyy_DIB/phoneLabelIcon.png" />
                    <view class="otherMessageValue">{{ item.phone }}</view>
                </view>

                <view class="otherMessageRow" style="margin-bottom: 0;">
                    <image class="otherMessageIcon" src="https://eshangtech.com/cyy_DIB/timeIcon.png" />
                    <view class="otherMessageValue">{{ item.time }}</view>
                </view>

            </view>



            <!-- <view :class="item.status === 1 ? 'event-item left-ok' : item.status === 2 ? 'event-item' : ''"
                v-for="(item, index) in showList" :key="index" @click="handleShowDetail(item)">
                <view class="event-header">
                    <view class="event-title">{{ type === 1 ? item.title || "" : type === 2 ? item.service || "" : "" }}
                    </view>
                    <view class="event-meta">
                        <view class="event-time">
                            <text>🕐</text><text>{{ item.time || "" }}</text>
                        </view>
                        <view class="event-priority priority-high" :style="{
                            background: item.status === 1 ? '#E7F8EE' : item.status === 2 ? '#f9dfe2' : '',
                            color: item.status === 1 ? '#3DC272' : item.status === 2 ? '#ff4757' : ''
                        }">
                            {{ item.status === 1 ? '已完成' : item.status ===
                                2 ? '处理中' : '' }}</view>
                    </view>
                </view>
                <view class="event-content">
                    <view class="event-description">
                        <text class="line">{{ item.desc || "" }}</text>
                    </view>
                </view>
            </view> -->
        </view>

        <!-- 应急事件详情 -->
        <uni-popup ref="popup" border-radius="10px 10px 0 0" @change="handlePopupChange">
            <!-- 应急事件的 -->
            <view class="eventsPopupBox" v-if="eventsDetail && type === 1">
                <view class="eventsItem">
                    <view class="eventsHaveImgLabel">
                        <image class="eventsHaveImg" src="https://eshangtech.com/cyy_DIB/personIcon.png" />
                        <view class="eventsHaveLabel">联系人：</view>
                    </view>
                    <view class="eventsValue">{{ eventsDetail.person || "" }}</view>
                </view>
                <view class="eventsItem">
                    <view class="eventsHaveImgLabel">
                        <image class="eventsHaveImg" src="https://eshangtech.com/cyy_DIB/phoneLabelIcon.png" />
                        <view class="eventsHaveLabel">联系电话：</view>
                    </view>
                    <view class="eventsValue">{{ eventsDetail.phone || "" }}</view>
                </view>
                <view class="eventsItem">
                    <view class="eventsHaveImgLabel">
                        <image class="eventsHaveImg" src="https://eshangtech.com/cyy_DIB/timeIcon.png" />
                        <view class="eventsHaveLabel">处理用时：</view>
                    </view>
                    <view class="eventsValue">{{ eventsDetail.haveTime || "" }}</view>
                </view>

                <view class="line"></view>


                <view class="eventsItem">
                    <view class="eventsLabel">标题：</view>
                    <view class="eventsValue">{{ eventsDetail.title || "" }}</view>
                </view>
                <view class="eventsItem">
                    <view class="eventsLabel">事件片区：</view>
                    <view class="eventsValue">{{ eventsDetail.area || "" }}</view>
                </view>
                <view class="eventsItem">
                    <view class="eventsLabel">事件服务区：</view>
                    <view class="eventsValue">{{ eventsDetail.service || "" }}</view>
                </view>

                <view class="eventsItem">
                    <view class="eventsLabel">死亡人数：</view>
                    <view class="eventsValue">{{ eventsDetail.diePerson || "" }}</view>
                </view>
                <view class="eventsItem">
                    <view class="eventsLabel">事件概况：</view>
                    <view class="eventsValue">{{ eventsDetail.desc || "" }}</view>
                </view>
                <view class="eventsItem">
                    <view class="eventsLabel">事件损失情况：</view>
                    <view class="eventsValue">{{ eventsDetail.lossDesc || "" }}</view>
                </view>
                <view class="eventsItem">
                    <view class="eventsLabel">处理结果：</view>
                    <view class="eventsValue">{{ eventsDetail.res || "" }}</view>
                </view>
                <view class="eventsItemPic">
                    <view class="eventsLabel">事件现场照片：</view>
                    <view class="eventsPic" v-if="eventsDetail.imgList && eventsDetail.imgList.length > 0">
                        <view class="eventsPicItem" v-for="(item, index) in eventsDetail.imgList" :key="index"
                            @click="showImg(eventsDetail.imgList, index)">
                            <image class="eventsPicImg" :src="item.url" />

                        </view>
                    </view>
                </view>
            </view>

            <!-- 日常问题 -->
            <view class="eventsPopupBox" v-if="eventsDetail && type === 2">
                <!-- <view class="eventsItem">
                    <view class="eventsLabel">处理状态：</view>
                    <view class="eventsValue"></view>
                </view> -->

                <view class="eventsItem">
                    <view class="eventsHaveImgLabel">
                        <image class="eventsHaveImg" src="https://eshangtech.com/cyy_DIB/personIcon.png" />
                        <view class="eventsHaveLabel">联系人：</view>
                    </view>
                    <view class="eventsValue">{{ eventsDetail.person || "" }}</view>
                </view>
                <view class="eventsItem">
                    <view class="eventsHaveImgLabel">
                        <image class="eventsHaveImg" src="https://eshangtech.com/cyy_DIB/phoneLabelIcon.png" />
                        <view class="eventsHaveLabel">联系电话：</view>
                    </view>
                    <view class="eventsValue">{{ eventsDetail.phone || "" }}</view>
                </view>

                <view class="line"></view>

                <view class="eventsItem">
                    <view class="eventsLabel">事件片区：</view>
                    <view class="eventsValue">{{ eventsDetail.area || "" }}</view>
                </view>
                <view class="eventsItem">
                    <view class="eventsLabel">事件服务区：</view>
                    <view class="eventsValue">{{ eventsDetail.service || "" }}</view>
                </view>
                <view class="eventsItem">
                    <view class="eventsLabel">类型：</view>
                    <view class="eventsValue">{{ eventsDetail.type || "" }}</view>
                </view>
                <view class="eventsItem">
                    <view class="eventsLabel">问题描述：</view>
                    <view class="eventsValue">{{ eventsDetail.desc || "" }}</view>
                </view>


                <view class="eventsSmallTitle">协调处理情况</view>

                <view class="eventsItem">
                    <view class="eventsLabel">协调处理结果：</view>
                    <view class="eventsValue">{{ eventsDetail.startRes || "" }}</view>
                </view>
                <view class="eventsItem">
                    <view class="eventsLabel">办理人：</view>
                    <view class="eventsValue">{{ eventsDetail.startPerson || "" }}</view>
                </view>
                <view class="eventsItem">
                    <view class="eventsLabel">办理完成时间：</view>
                    <view class="eventsValue">{{ eventsDetail.startTime || "" }}</view>
                </view>

                <view class="eventsSmallTitle">经营公司协调处理情况</view>

                <view class="eventsItem">
                    <view class="eventsLabel">协调处理结果：</view>
                    <view class="eventsPic">{{ eventsDetail.endRes || "" }}</view>
                </view>
                <view class="eventsItem">
                    <view class="eventsLabel">办理人：</view>
                    <view class="eventsValue">{{ eventsDetail.endPerson || "" }}</view>
                </view>
                <view class="eventsItem">
                    <view class="eventsLabel">办理完成时间：</view>
                    <view class="eventsValue">{{ eventsDetail.endTime || "" }}</view>
                </view>
                <view class="eventsItemPic">
                    <view class="eventsLabel">事件现场照片：</view>
                    <view class="eventsPic" v-if="eventsDetail.imgList && eventsDetail.imgList.length > 0">
                        <view class="eventsPicItem" v-for="(item, index) in eventsDetail.imgList" :key="index"
                            @click="showImg(eventsDetail.imgList, index)">
                            <image class="eventsPicImg" :src="item.url" />

                        </view>
                    </view>
                </view>
            </view>
        </uni-popup>
    </view>
</template>

<script>
export default {
    data() {
        return {
            dataList: [
                {
                    title: "中和停车区下行停水",
                    time: "2023-09-26 13:30:38",
                    area: "昭通片区管理补",// 片区
                    service: "中和加油站-上行",// 事件服务区
                    eventType: "事件类型1",// 事件类型
                    person: "徐琴",// 联系人
                    phone: "13408871099",//联系电话
                    theInjured: "",// 受伤人数
                    haveTime: "待定",// 处理用时
                    diePerson: "0",//死亡人数
                    desc: "水泵房故障，导致停水，急需处理",//事件现场概况
                    lossDesc: "因突发情况 卫生间卫生无法保障",// 事件损失情况
                    res: "已联系施工方，未处理",//处理结果
                    imgList: [{ url: "https://eshangtech.com/cyy_DIB/1695785143848.jpg" }],// 事件现场照片
                    status: 1,
                },
                {
                    title: "楼坝服务区停水",
                    time: "2023-08-02 13:57:27",
                    area: "昭通片区管理补",// 片区
                    service: "楼坝服务区-下行",// 事件服务区
                    eventType: "事件类型1",// 事件类型
                    person: "孔令婷",// 联系人
                    phone: "19987196597",//联系电话
                    theInjured: "",// 受伤人数
                    haveTime: "7小时",// 处理用时
                    diePerson: "0",//死亡人数
                    desc: "楼坝街道主水管道被路面改造施工的挖机挖断，目前正在抢修中，预计7小时后可正常供水，服务区现用水箱里的储水进行供水。",//事件现场概况
                    lossDesc: "无",// 事件损失情况
                    res: "正在进行抢修，预计7小时后可正常供水，服务区现用水箱里的储水进行供水。",//处理结果
                    imgList: null,// 事件现场照片
                    status: 2,
                } // status  1 已完成  2 处理中
            ],
            everyDayList: [
                {
                    area: "版纳片区管理部", // 事件片区：
                    service: "小勐养服务区-上行", // 事件服务区：
                    time: "2024-09-12 09:14:47",
                    type: "其他", // 类型：
                    desc: "小勐养服务区上行卫生间5号蹲坑隔板底座损坏，已修复。",// 问题描述：
                    person: "杨杰",// 联系人：
                    phone: "13628710377",// 联系电话：
                    startRes: "修复完毕，建议结束流程",// 协调处理结果：
                    startPerson: "刀天华",// 办理人：
                    startTime: "2024-09-12 09:43:53",// 办理完成时间：
                    endRes: "",// 协调处理结果：
                    endPerson: "",// 办理人：
                    endTime: "流转后自动显示",// 办理完成时间：
                    imgList: [
                        { url: "https://eshangtech.com/cyy_DIB/1726104387683_mmexport1726104287279.jpg" },
                        { url: "https://eshangtech.com/cyy_DIB/1726104504808_IMG_20240912_091809.jpg" }
                    ],// 事件现场照片
                    status: 1,
                },
                {
                    area: "昆东片区管理部", // 事件片区：
                    service: "阳宗服务区-上行", // 事件服务区：
                    time: "2024-08-08 13:45:25",
                    type: "维修上报", // 类型：
                    desc: "关于昆东片区管理部阳宗服务区上行更换入口车辆引导标识牌的请示",// 问题描述：
                    person: "唐林波",// 联系人：
                    phone: "15287959258",// 联系电话：
                    startRes: "按照公司相关流程进行更换标识牌审批事宜",// 协调处理结果：
                    startPerson: "申锐娟",// 办理人：
                    startTime: "流转后自动显示",// 办理完成时间：
                    endRes: "",// 协调处理结果：
                    endPerson: "",// 办理人：
                    endTime: "流转后自动显示",// 办理完成时间：
                    imgList: null,// 事件现场照片
                    status: 2,
                }
            ],
            showList: [],
            eventsDetail: null,
            type: 0
        }
    },
    onLoad(query) {
        if (query.type) {
            this.type = Number(query.type)
            if (this.type === 1) {
                this.showList = this.dataList
            } else {
                this.showList = this.everyDayList
                uni.setNavigationBarTitle({
                    title: '日常问题'
                })
            }
        }
    },
    methods: {
        handleShowDetail(obj) {
            // this.$refs.popup.open('center')
            // this.eventsDetail = obj
            this.$util.toNextRoute("navigateTo", `/pages/attendanceStatus/emergencyEventsDetail?detail=${JSON.stringify(obj)}&type=${this.type}`);

        },
        handlePopupChange(e) {
            this.showPopup = e.show
            console.log('e', e);
            if (!e.show) {
                this.userDetail = null
            }
        },
        // 图片预览
        showImg(list, index) {
            console.log('list', list);
            console.log('indexindex', index);
            let urls = []
            list.forEach((item) => {
                urls.push(item.url)
            })

            uni.previewImage({
                urls: urls,
                current: list[index].url,
            });
        },
    }
}
</script>
<style lang="less" scoped>
@bg: #f8f9fa;
@muted: #666;
@card: #fff;
@shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
@primary: #27B25F;
@primary2: #4CCC7F;
@ok: #2ed573;
@warn: #ff9f43;
@danger: #ff4757;

/* 抽屉页（特情/设施） */
.main {
    width: 100vw;
    height: 100vh;

    .emergency-details-header {
        background: linear-gradient(135deg, @danger, #ff3838);
        color: #fff;
        padding: 40rpx;
        position: relative;
        box-shadow: @shadow;

        &.facilities-theme {
            background: linear-gradient(135deg, #20bf6b, #0fb9b1);
        }

        .emergency-back-btn {
            position: absolute;
            left: 30rpx;
            top: 30rpx;
            background: rgba(255, 255, 255, .2);
            border: none;
            color: #fff;
            font-size: 36rpx;
            width: 80rpx;
            height: 80rpx;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .h1 {
            text-align: center;
            display: block;
            margin-bottom: 6rpx;
        }

        .current-area {
            text-align: center;
            display: block;
            opacity: .9;
        }
    }

    .emergencyList {
        padding: 30rpx;

        .emergencyItem {
            width: 100%;
            border-radius: 8rpx;
            background-color: #fff;
            box-shadow: @shadow;
            box-sizing: border-box;
            padding: 24rpx;
            margin-bottom: 24rpx;

            .emergencyItemTitle {
                display: flex;
                align-items: center;
                justify-content: space-between;
                margin-bottom: 24rpx;

                .emergencyItemTitleLeft {
                    font-size: 28rpx;
                    font-weight: 600;
                    display: inline-block;
                    width: 80%;
                }

                .emergencyItemStatus {
                    font-size: 24rpx;
                    padding: 4rpx 16rpx;
                    border-radius: 32rpx;
                }

            }

            .emergencyDesc {
                font-size: 24rpx;
            }

            .line {
                width: 100%;
                height: 2rpx;
                background-color: #dad9d3;
                margin: 24rpx 0;

            }

            .otherMessageRow {
                width: 100%;
                margin-bottom: 8rpx;
                display: flex;
                align-items: flex-start;

                .otherMessageIcon {
                    width: 30rpx;
                    height: 30rpx;
                    margin-right: 16rpx;
                    margin-top: 6rpx;
                }

                .otherMessageValue {
                    font-size: 24rpx;

                }
            }
        }

    }

    .add-event-btn {
        position: fixed;
        bottom: 160rpx;
        right: 40rpx;
        width: 96rpx;
        height: 96rpx;
        background: linear-gradient(135deg, @primary, @primary2);
        border-radius: 50%;
        border: none;
        color: #fff;
        font-size: 40rpx;
        box-shadow: 0 8rpx 24rpx rgba(74, 144, 226, .4);
    }

    .promo-banner {
        margin: 30rpx;
        border-radius: 24rpx;
        overflow: hidden;
        box-shadow: @shadow;

        .promo-image {
            width: 100%;
            height: 240rpx;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            display: flex;
            align-items: center;
            justify-content: center;
            color: #fff;
            font-size: 48rpx;
            position: relative;
            overflow: hidden;

            .promo-content {
                position: absolute;
                bottom: 0;
                left: 0;
                right: 0;
                background: linear-gradient(transparent, rgba(0, 0, 0, .7));
                padding: 40rpx 30rpx 30rpx;
                color: #fff;

                .promo-title {
                    font-size: 32rpx;
                    font-weight: 700;
                    margin-bottom: 8rpx;
                }

                .promo-subtitle {
                    font-size: 24rpx;
                    opacity: .9;
                }
            }
        }
    }

    .facilities-section {
        margin: 30rpx;
        background: #fff;
        border-radius: 24rpx;
        overflow: hidden;
        box-shadow: @shadow;

        .facilities-header {
            background: linear-gradient(135deg, #20bf6b, #0fb9b1);
            color: #fff;
            padding: 30rpx;
            font-weight: 700;
            font-size: 32rpx;
            display: flex;
            align-items: center;
            gap: 16rpx;
        }
    }

    .eventsPopupBox {
        width: 90vw;
        height: 80vh;
        background-color: #fff;
        border-radius: 16rpx;
        box-sizing: border-box;
        padding: 24rpx;
        overflow-y: auto;

        .eventsItemTitle {
            width: 100%;
            font-size: 28rpx;
            font-weight: 600;
        }

        .eventsItem {
            width: 100%;
            margin-bottom: 16rpx;
            display: flex;
            align-items: flex-start;

            .eventsHaveImgLabel {
                display: flex;
                width: 200rpx;
                align-items: center;

                .eventsHaveImg {
                    width: 30rpx;
                    height: 30rpx;
                    margin-right: 16rpx;
                    margin-top: 6rpx;
                }

                .eventsHaveLabel {
                    width: 154rpx;
                    font-size: 26rpx;
                }
            }

            .eventsLabel {
                width: 200rpx;
                text-align: left;
                font-size: 26rpx;
            }

            .eventsValue {
                flex: 1;
                font-size: 24rpx;
            }
        }

        .line {
            width: 100%;
            height: 2rpx;
            background-color: #dad9d3;
            margin: 24rpx 0;

        }

        .eventsSmallTitle {
            margin: 16rpx 0;
            width: 100%;
            font-size: 28rpx;
            font-weight: 600;
        }

        .eventsItemPic {
            width: 100%;

            .eventsLabel {
                width: 200rpx;
                text-align: left;
                font-size: 26rpx;
            }

            .eventsPic {
                flex: 1;
                display: flex;
                align-items: center;
                font-size: 24rpx;

                .eventsPicItem {
                    width: 100rpx;
                    height: 100rpx;
                    margin-right: 8rpx;
                    margin-bottom: 8rpx;

                    .eventsPicImg {
                        width: 100%;
                        height: 100%;
                    }
                }
            }
        }

    }


}
</style>