<template>
    <div class="btn flexcenter" v-if="!show" @click="show = !show">
        <img class="icon" src="@/assets/img/publicImage/report-icon.svg">
        <div class="text">举报</div>
    </div>

    <div class="alert-form" v-else>
        <div class="comments reports">
            <div class="head">
                <span style="display: flex;align-items: center;">
                    <img style="width:25px;margin-right: 7px;" src="@/assets/img/publicImage/report.png">举报投诉</span>
                <div class="close" @click="show = false"></div>
            </div>
            <form @submit.prevent="submit">
                <div class="radio-area">
                    <el-checkbox-group v-model="checkList">
                        <el-checkbox v-for="s in reasonList" :label="s">{{ s }}</el-checkbox>
                    </el-checkbox-group>
                </div>
                <div class="text-box">
                    <textarea placeholder="请输入举报原因" v-model="text" maxlength="200"></textarea>
                    <div class="text-num">{{ 200 - text.length }}</div>
                </div>
                <div class="footer">
                    <button type="button" @click="show = false">取消</button>
                    <button type="submit" :disabled="checkList.length == 0">提交</button>
                </div>
            </form>
        </div>
    </div>
</template>

<script setup>
import { ref, getCurrentInstance, defineProps } from 'vue'
import { ElMessage } from 'element-plus'

let show = ref(false)
let text = ref("")
let reasonList = ref(['广告、恶意灌水', '欺诈、色情、违规内容', '信息过时、不实信息、侵权', '功能异常、产品建议', '其他'])
let checkList = ref([])
const { proxy } = getCurrentInstance()

let props = defineProps({
    id: String,
})

const submit = () => {
    show.value = false;
    var message = [].concat(toConsumableArray(checkList.value));
    if (text.value.trim() != '') message.push(text.value);

    proxy.$post("/tenement/pc/api/report", {
        type: "housing",
        id: props['id'],
        message
    }).then(res => {
        console.log("res", res);
        if (res.code == 200) {
            ElMessage.success(res.message)
            checkList.value = []
            text.value = ""
            show.value = false
        } else ElMessage.error(res.message)
    })
}

const toConsumableArray = (arr) => {
    if (Array.isArray(arr)) {
        for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {
            arr2[i] = arr[i];
        }
        return arr2;
    } else return Array.from(arr);
}

</script>

<style lang="less" scoped>
@media screen and (max-width: 1360px) {
    .btn {
        right: 20px !important;
    }
}

.btn {
    width: 60px;
    height: 60px;
    cursor: pointer;
    font-size: 14px;
    color: #7F7F7F;
    position: fixed;
    bottom: 98px;
    right: calc((100vw - 1200px) / 2 - 75px);
    border: 1px solid #d7d7d7;
    border-radius: 50%;
    background-color: #fff;
    flex-direction: column;

    .icon {
        width: 19px;
        height: 17px;
    }

    .text {
        line-height: 24px;
    }
}

.alert-form {
    display: block;
    position: fixed;
    z-index: 2100;
    left: 0;
    top: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.7);
}

.alert-form * {
    box-sizing: border-box;
}

.alert-form .reports .radio-area {
    margin-bottom: 40px;
}

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

.alert-form .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;
}

.alert-form .comments .text-box {
    position: relative;
}

.alert-form .comments .text-num {
    position: absolute;
    right: 10px;
    bottom: 10px;
    color: #999;
    font-size: 12px;
}

.alert-form .comments form {
    display: block;
    width: 100%;
    padding: 34px 30px 40px;
}

.alert-form .comments form 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;
}

.alert-form .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;
}

.alert-form .head .close {
    color: #b3b3b3;
    font-size: 14px;
    cursor: pointer;
}

.alert-form .footer {
    display: flex;
    justify-content: center;
    align-items: center;
}

.alert-form .footer button[type=button] {
    margin-right: 20px;
}

.alert-form .footer button {
    border: 1px #999999 solid;
    border-radius: 5px;
    background-color: #ffffff;
    width: 128px;
    height: 38px;
    color: #333;
    font-size: 14px;
    outline: none;
    cursor: pointer;
}

.alert-form .footer button[type=submit] {
    background-color: #50E3C2;
    border-color: #50E3C2;
    color: #fff;
}

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

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

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