<template>
    <!-- 举报 -->
    <div class="alert-form">
        <div class="comments reports">
            <div class="head">
                <span style="display: flex; align-items: center"> <img style="width: 25px; margin-right: 7px" src="//app.gter.net/image/gter/offer/img/exclamationpoint.png" />举报投诉 </span>
                <div class="close icon-close iconfont" @click="alertShow = false"></div>
            </div>
            <div class="form">
                <div class="radio-area flexacenter">
                    <div class="radio-area-item flexacenter" :class="{ pitch: checkList.includes(s) }" v-for="(s, i) in reasonList" :key="i" @click="selectRadio(s)">
                        <div class="radio-area-frame"></div>
                        {{ s }}
                    </div>
                </div>
                <div class="text-box">
                    <textarea placeholder="请输入举报原因" v-model="alertText" maxlength="200"></textarea>
                    <div class="text-num">{{ 200 - alertText.length }}</div>
                </div>
                <div class="footer">
                    <button type="button" @click="cancel()">取消</button>
                    <button type="submit" @click="alertSubmit">提交</button>
                </div>
            </div>
        </div>
    </div>
</template>
<script setup>
import { ElMessage } from "element-plus";

const props = defineProps(["reportToken", "reportType"]);
const reasonList = ["广告", "辱骂", "重复发送", "不良信息", "其他"];
let reportAlertShow = inject("reportAlertShow");

let checkList = ref([]);
let alertShow = ref(false);
let alertText = ref("");

const selectRadio = (value) => {
    const index = checkList.value.indexOf(value);
    if (index === -1) checkList.value.push(value);
    else checkList.value.splice(index, 1);
};

// 举报提交
const alertSubmit = () => {
    if (checkList.value.length == 0) {
        ElMessage.error("请选择举报类型");
        return;
    }
    checkList.value.push(alertText.value);
    reportAlertShow.value = false;
    (props.reportType === "comment" ? commentReportHttp : reportHttp)({
        message: checkList.value,
        token: props.reportToken,
    }).then((res) => {
        checkList.value = [];
        reportAlertShow.value = false;

        ElMessage.success(res.message || "举报成功");
    });
};

// 取消
const cancel = () => (reportAlertShow.value = false);
</script>

<style lang="less" scoped>
.alert-form {
    display: block;
    position: fixed;
    z-index: 999;
    left: 0;
    top: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.7);
    .reports {
        height: 440px;
        .radio-area {
            margin-bottom: 40px;

            .radio-area-item {
                color: #606266;
                font-size: 14px;
                margin-right: 10px;
                cursor: pointer;

                &.pitch {
                    .radio-area-frame {
                        background-color: #50e3c2;
                        border-color: #50e3c2;

                        &::after {
                            -webkit-transform: rotate(45deg) scaleY(1);
                            transform: rotate(45deg) scaleY(1);
                        }
                    }
                }

                .radio-area-frame {
                    border: 1px solid #dcdfe6;
                    border-radius: 2px;
                    width: 14px;
                    height: 14px;
                    -webkit-transition: border-color 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46), background-color 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46);
                    transition: border-color 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46), background-color 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46);

                    position: relative;
                    margin-right: 10px;

                    &::after {
                        -webkit-box-sizing: content-box;
                        box-sizing: content-box;
                        content: "";
                        border: 1px solid #fff;
                        border-left: 0;
                        border-top: 0;
                        height: 7px;
                        left: 4px;
                        position: absolute;
                        top: 1px;
                        -webkit-transform: rotate(45deg) scaleY(0);
                        transform: rotate(45deg) scaleY(0);
                        width: 3px;
                        -webkit-transition: -webkit-transform 0.15s ease-in 0.05s;
                        transition: -webkit-transform 0.15s ease-in 0.05s;
                        transition: transform 0.15s ease-in 0.05s;
                        transition: transform 0.15s ease-in 0.05s, -webkit-transform 0.15s ease-in 0.05s;
                        -webkit-transform-origin: center;
                        transform-origin: center;
                    }

                    // }
                }
            }
        }
    }

    .el-checkbox-group {
        font-size: 0;
    }

    .comments {
        display: block;
        position: fixed;
        z-index: 11;
        left: 50%;
        top: 50%;
        width: 740px;
        height: 440px;
        max-width: 90vw;
        max-height: 90vh;
        transform: translate(-50%, -50%);
        background-color: #ffffff;
        border: none;
        border-radius: 8px 8px 6px 6px;
        .text-box {
            position: relative;
        }
        .text-num {
            position: absolute;
            right: 10px;
            bottom: 10px;
            color: #999;
            font-size: 12px;
        }
        .form {
            display: block;
            width: 100%;
            padding: 34px 30px 40px;
            textarea {
                height: 172px;
                margin-bottom: 30px;
                display: block;
                width: 100%;
                background: #f7f7f7;
                padding: 18px;
                font-size: 14px;
                border: 1px solid #f7f7f7;
                border-radius: 5px;
                outline: none;
                resize: none;
                line-height: 22px;
            }
        }
    }

    .head {
        padding: 0 18px 0 30px;
        display: flex;
        height: 56px;
        align-items: center;
        justify-content: space-between;
        background: #333333;
        color: #fff;
        font-size: 17px;
        border-radius: 6px 6px 0 0;
        .close {
            color: #b3b3b3;
            font-size: 14px;
            cursor: pointer;
        }
    }

    .footer {
        display: flex;
        justify-content: center;
        align-items: center;
        button[type="button"] {
            margin-right: 20px;
        }

        button {
            border: 1px #999999 solid;
            border-radius: 5px;
            background-color: #ffffff;
            width: 128px;
            height: 38px;
            color: #333;
            font-size: 14px;
            outline: none;
            cursor: pointer;
        }
        button[type="submit"] {
            background-color: #50e3c2;
            border-color: #50e3c2;
            color: #fff;
        }
    }
}

.alert-form .el-checkbox__input.is-checked .el-checkbox__inner,
.alert-form .el-checkbox__input.is-indeterminate .el-checkbox__inner {
    background-color: #50e3c2;
    border-color: #50e3c2;
}

.alert-form .el-checkbox__input.is-focus .el-checkbox__inner,
.alert-form .el-checkbox__inner:hover {
    border-color: #50e3c2;
}

.alert-form .el-checkbox__input.is-checked + .el-checkbox__label {
    color: #50e3c2;
}
</style>
