<template>
    <!-- pages/tabBar/personalcenter/help/help.wxml -->
    <view class="help-wrapper">
        <view class="top">
            <image :src="imgDomain + '/images/icon/doctor/help.png'" style="height: 110px; width: 100%"></image>
            <view class="header-title">常见问题</view>
        </view>
        <view class="help-content">
            <view :data-url="item.url" @tap="help" class="issue-border" v-for="(item, index) in issueList" :key="index">
                <mp-cell class="issueItem" :value="item.seqNo + '.' + item.descripts" link></mp-cell>
            </view>
        </view>
        <view class="help-btn">
            <button class="multiBtn-left" @tap="onFeedback">我要反馈</button>
            <button class="multiBtn-right" @tap="onHelp">联系客服</button>
        </view>
        <van-popup class="nav-wrap-modal" :show="loading" @close="handleClose" close-icon-position="top-right" custom-style="width: 80%; background: transparent;">
            <view>
                <mp-loading extClass="loading" type="circle" tips="正在加载" v-if="loading"></mp-loading>
            </view>
        </van-popup>
    </view>
</template>

<script>
// pages/tabBar/personalcenter/help/help.js
import { httpconfig } from '../../../../config/httpConfig.js';
import { $http } from '../../../../config/https.js';
export default {
    components: {},
    data() {
        return {
            issueList: [],
            platform: '',
            visible: false,
            loading: false,
            imgDomain: httpconfig.imgDomain
        };
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {},
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        this.getHelpList();
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {},
    methods: {
        getHelpList: function () {
            let data = {
                params: [
                    {
                        type: 'D'
                    }
                ]
            };
            $http.post('urlDeault', this, {
                code: '03100102',
                data: data,
                success: function (res) {
                    if (res.errorCode == '0') {
                        this.setData({
                            issueList: res.result
                        });
                    }
                }
            });
        },

        onHelp: function () {
            uni.navigateTo({
                url: '/pages/myConsultRoom/page/treatment/treatment?help=true',
                success: function (res) {}
            });
        },

        onFeedback: function () {
            uni.navigateTo({
                url: '../feedback/feedback',
                success: function (res) {}
            });
        },

        help: function (event) {
            let url = event.currentTarget.dataset.url;
            let that = this;
            if (url != '') {
                if (this.platform != '' && this.platform != 'ios') {
                    //非IOS设备打开文档
                    this.setData(
                        {
                            loading: true
                        },
                        () => {
                            this.openDocument(url);
                        }
                    );
                } else {
                    if (this.platform == '') {
                        //未获取到设备信息
                        uni.getSystemInfo({
                            success: function (res) {
                                that.setData({
                                    platform: res.platform
                                });
                                if (res.platform != 'ios') {
                                    that.setData(
                                        {
                                            loading: true
                                        },
                                        () => {
                                            that.openDocument(url);
                                        }
                                    );
                                }
                            }
                        });
                    } else {
                        //IOS 设备
                        uni.navigateTo({
                            url: '/pages/oneselfCenter/page/helppdf/helppdf?url=' + url,
                            success: function (res) {}
                        });
                    }
                }
            } else {
                uni.showToast({
                    title: '无帮助文档',
                    icon: false
                });
            }
        },

        /**
         * 打开文档
         */
        openDocument: function (url) {
            let that = this;
            uni.downloadFile({
                url: url,
                success: function (res) {
                    console.log(res);
                    var Path = res.tempFilePath; //返回的文件临时地址，用于后面打开本地预览所用
                    uni.openDocument({
                        filePath: Path,
                        success: function (res) {
                            that.setData({
                                loading: false
                            });
                        }
                    });
                },
                fail: function (res) {
                    uni.showToast({
                        title: '文档加载失败',
                        icon: 'none'
                    });
                    that.setData({
                        loading: false
                    });
                }
            });
        },

        handleClose() {
            console.log('占位：函数 handleClose 未声明');
        }
    }
};
</script>
<style>
/* pages/tabBar/personalcenter/help/help.wxss */

.issue-border {
    border-bottom: 1px solid var(--weui-FG-3);
    font-size: 32rpx;
    font-family: PingFang SC;
    font-weight: bold;
    color: rgba(51, 51, 51, 1);
}

.top {
    width: 100%;
}

.header-title {
    padding: 20rpx;
    padding-top: 10rpx;
    background: #f5f4f4;
    height: 80rpx;
    font-size: 32rpx;
    font-family: PingFang SC;
    font-weight: bold;
    color: rgba(51, 51, 51, 1);
    line-height: 80rpx;
}

.multiBtn-left {
    flex: 1;
    align-items: center;
    justify-content: center;
    display: flex;
    border-radius: 0 !important;
}

.multiBtn-left::after {
    border-radius: 0 !important;
}

.multiBtn-content {
    padding: 0 40rpx;
}

.multiBtn-right {
    flex: 1;
    align-items: center;
    justify-content: center;
    display: flex;
    background-color: #1890ff;
    color: #fff;
    border-radius: 0 !important;
}

.issueItem {
    text-overflow: ellipsis;
    overflow: hidden;
}

/*  */

.help-wrapper {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.help-content {
    flex: 1;
    overflow: auto;
    background-color: #fff;
}

.help-btn {
    display: flex;
    padding-bottom: env(safe-area-inset-bottom);
    background-color: #fff;
}

.loading .weui-loadmore__tips {
    color: #fff;
}
</style>
