<template>
    <view
        v-if="feedbackIsShow"
        :class="['feedback-btn-box', !isUpfold ? 'upfold' : '']"
        :style="{
            'bottom': visitBottom,
        }"
        @tap.stop="checkTap"
    >
        <view class="feedback-icon"/>
        <view class="feedback-font">
            <view>{{ complaintText }}</view>
            <view>{{ feedbackText }}</view>
        </view>
    </view>
</template>

<script>
/**
 * @file 问题反馈悬浮窗
 * @author mayifan02@baidu.com
 * @categories 问题反馈悬浮窗组件
 * @tags [component]
 */

/* global getApp, getCurrentPages */
import {navigate, navToBdBoxH5} from '../../utils/navigate';
import * as core from '../../utils/core';
import { ubcSend } from '@utils/log';
export default {
    config: {
        component: true
    },
    options: {
        addGlobalClass: true
    },
    props: {
        feedbackIsShow: {
            // 是否显示反馈悬浮窗
            type: Boolean,
            default: true
        },
        isUpfold: {
            // 展开或者收起
            type: Boolean,
            default: true
        },
        toFeedbackUrl: {
            // 点击反馈跳转路径
            type: String,
            /* eslint-disable max-len */
            default: '/pages/brand/feedbackform/index?pd=med&openapi=1&from_sf=1&resource_id=5216&vn=med&atn=feedbackform&title=我要反馈&word=我要反馈&cat=5'
        },
        ufoFeedbackUrl: {
            // 点击反馈跳转路径
            type: String,
            /* eslint-disable max-len */
            default: ''
        },
        complaintText: {
            type: String,
            default: '投诉'
        },
        feedbackText: {
            type: String,
            default: '反馈'
        },
        /**
         * 反馈入口点击时ubc打点参数
         */
        feedbackUbcLog: {
            type: Object,
            default() {
                return {};
            }
        },
        /**
         * 反馈入口点击时是否跳转
         */
        noJump: {
            type: Boolean,
            default: false
        },
        /**
         * 出诊信息页面底部高度修改
         */
        visitBottom: {
            type: String,
            default: '22%'
        }
    },
    data() {
        return {
            disabled: true
        };
    },
    methods: {
        checkTap() {
            if (this.feedbackUbcLog && this.feedbackUbcLog.value) {
                ubcSend(this.feedbackUbcLog);
            }
            if (this.noJump) {
                this.$emit('noJump');
                return false;
            }
            if (this.ufoFeedbackUrl) {
                if (process.env.MARS_ENV === 'swan') {
                    navToBdBoxH5(this.ufoFeedbackUrl);
                }
                else if (process.env.MARS_ENV === 'h5') {
                    window.location.href = this.ufoFeedbackUrl;
                }
            }
            else {
                // 拿到页面URL
                let pages = getCurrentPages();
                let currentPage = pages[pages.length - 1];
                let feedbackurl = currentPage.route;

                // 拿到页面相关参数
                let feedbackQuery = '';
                if (process.env.MARS_ENV === 'h5') {
                    feedbackQuery = core.getQueryObject(window.location.href);
                } else if (getApp().$api.getURLQuery) {
                    feedbackQuery = getApp().$api.getURLQuery();
                }
                feedbackQuery = JSON.stringify(feedbackQuery || {});
                // 跳转
                navigate({
                    url: `${this.toFeedbackUrl}&feedbackUrl=${feedbackurl}&feedbackQuery=${feedbackQuery}`
                });
            }
        }
    }
};
</script>
<style lang="less" scoped>
.feedback-btn-box {
    padding: 0.07rem 0;
    border-radius: 0.5rem 0 0 0.5rem;
    display: flex;
    align-items: center;
    background-color: #fff;
    position: fixed;
    right: 0px;
    bottom: 22%;
    border-right: none;
    box-shadow: 0 0 5px 1.667px rgba(85, 85, 85, 0.08);
    transition: transform 0.5s;
    transform: translateZ(0);
    z-index: 9;
    .feedback-icon {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 0.3rem;
        height: 0.3rem;
        margin: 0 0.1rem 0 0.05rem;
        background: url(https://medactivity.cdn.bcebos.com/icon/feedback_icon.png)
            no-repeat;
        background-size: 100%;
        border-radius: 50%;
        margin: 0 0.07rem;
        .icon {
            color: #fff;
            font-size: 0.23rem;
        }
    }
    .feedback-font {
        font-size: 0.13rem;
        color: #555;
        line-height: 16px;
        margin-right: 17px;
        font-weight: bold;
    }
    &.upfold {
        transform: translateX(0.46rem);
    }
}
</style>
