<template>
    <view>
        <view class="content" v-if="pageType == 1">
            <view class="title f18 fw500">伯才稻田欢迎您</view>
            <view class="info f14">
                <view>伯才稻田（以下简称“稻田”），是一个专门服务代理的平台。</view>
                <view>
                    稻田秉承“资源共享、伙伴共赢”的理念，为合作伙伴提供海量项目内容分发及流量分佣。在稻田，您可以享受项目查看、老乡报名、面试跟踪、财务结算等一站式服务，省时、省心、省力。
                </view>
                <view>
                    如果您还现在不是稻田的合作代理，您可以在此
                    <view @tap="showTobe" class="tobeText" hover-class="textHov">申请成为代理</view>
                    ，共享平台项目及流量资源。
                </view>
                <view>稻田期待与您一道，细细耕耘，共同助力人力资源行业新发展，为劳动者创造价值。</view>
                <view>感谢您的支持与合作！</view>
            </view>
            <view class="bottom f14">
                <view>伯才稻田运营中心</view>
                <view>2023年6月16日</view>
            </view>
            <view aria-role="dialog" :aria-modal="true" class="fadeIn" v-if="iosDialogTobe">
                <view class="weui-mask"></view>
                <view class="weui-dialog contact tobe" style="box-sizing: border-box">
                    <i class="iconfont icon-guanbi guanbi c6 biggerSize" @click="closeDialog"></i>
                    <view class="weui-dialog__hd">
                        <view class="f20 bbd1 top" hover-class="none" :hover-stop-propagation="false">
                            <view class="fw500" hover-class="none" :hover-stop-propagation="false">成为伯才代理</view>
                            <view class="f16 c6" hover-class="none" :hover-stop-propagation="false">请联系客户经理</view>
                        </view>
                        <view class="bottom" hover-class="none" :hover-stop-propagation="false">
                            <view class hover-class="none" :hover-stop-propagation="false">
                                <view class="fw500 f18" hover-class="none" :hover-stop-propagation="false">客户经理</view>
                                <view class="c3 f14">
                                    {{ serviceInfo.userName }}
                                    <i class="mr4"></i>
                                    <p>{{ serviceInfo.tel || '0371-6611 3723' }}</p>
                                </view>
                                <image :src="serviceInfo.qrCode" :show-menu-by-longpress="true" style="width: 161px; height: 161px"></image>
                                <view class="f14 c9 mt6">长按识别二维码</view>
                            </view>
                        </view>
                    </view>
                </view>
            </view>
        </view>
        <view v-else-if="pageType == 2" class hover-class="none" :hover-stop-propagation="false">
            <view class="messageContent">
                <view class="mb4 f20 fw500" :selectable="false" :space="false" :decode="false">通许聚创人力</view>
                <view class="f14 c9" :selectable="false" :space="false" :decode="false">请求添加你为团队成员</view>
            </view>
            <view class="btnBox">
                <button class="cancel">拒绝</button>
                <button class="agree">同意</button>
            </view>
        </view>
        <view v-else-if="pageType == 3" class hover-class="none" :hover-stop-propagation="false">
            <view class="messageContent">
                <view class="mb4 f20 fw500" :selectable="false" :space="false" :decode="false">张三</view>
                <view class="f14 c9" :selectable="false" :space="false" :decode="false">已同意成为你的成员</view>
            </view>
            <!-- <view class="btnBox">
    <button class="cancel">拒绝</button>
    <button class="agree">同意</button>
  </view>-->
        </view>
        <view class="content" v-else hover-class="none" :hover-stop-propagation="false">
            <view class="title f18 fw500">{{ currentInfo.title }}</view>
            <rich-text class="info f14" space="nbsp" :nodes="showText"></rich-text>
        </view>
    </view>
</template>

<script>
const app = getApp();
// pages/messageDetail/index.js
export default {
    data() {
        return {
            iosDialogTobe: false,

            serviceInfo: {
                tel: '',
                qrCode: ''
            },

            pageType: null,
            currentId: null,

            currentInfo: {
                title: ''
            },

            showText: '',

            tagStyle: {
                p: 'margin-top: 0; margin-bottom: 0;line-height: 1.8; white-space:pre-wrap;',
                body: " margin: 0; color: #333; font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-variant: tabular-nums; line-height: 1.8; -webkit-font-feature-settings: 'tnum'; font-feature-settings: 'tnum';",
                h1: ' margin-top: 0; margin-bottom: 0.5em;margin-top:0.3em; color: rgba(0, 0, 0, 0.85); font-weight: 500;line-height: 1.1;font-size:24px; ',
                h2: ' margin-top: 0; margin-bottom: 0.5em;margin-top:0.3em; color: rgba(0, 0, 0, 0.85); font-weight: 500;line-height: 1.1;font-size:21px; ',
                h3: ' margin-top: 0; margin-bottom: 0.5em;margin-top:0.3em; color: rgba(0, 0, 0, 0.85); font-weight: 500;line-height: 1.1;font-size:16px; ',
                h4: ' margin-top: 0; margin-bottom: 0.5em;margin-top:0.3em; color: rgba(0, 0, 0, 0.85); font-weight: 500;line-height: 1.1 ',
                h5: ' margin-top: 0; margin-bottom: 0.5em;margin-top:0.3em; color: rgba(0, 0, 0, 0.85); font-weight: 500;line-height: 1.1 ',
                h6: ' margin-top: 0; margin-bottom: 0.5em;margin-top:0.3em; color: rgba(0, 0, 0, 0.85); font-weight: 500;line-height: 1.1 ',
                strong: 'font-weight: bolder;',
                b: 'font-weight: bolder;',
                dl: 'margin-top: 0; margin-bottom: 1em;',
                ol: 'margin-top: 0; margin-bottom: 1em;',
                ul: 'margin-top: 0; margin-bottom: 1em;',
                li: 'line-height: 1.8',
                hr: 'box-sizing: content-box;height:1rpx;overflow: visible;background-color: #ddd;border:0;',
                table: 'border-collapse: collapse;border: 1px solid #d9d9d9;margin: 18px 0 16px 0;line-height: 1.8',
                td: 'border: 1px solid #d9d9d9;vertical-align: top;padding: 4px 8px;line-height: 1.8'
            },

            html: ''
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad(options) {
        console.log(options);
        if (options.type) {
            this.setData({
                pageType: options.type
            });
        }
        if (options.id) {
            this.setData({
                currentId: options.id
            });
            this.requestInfo();
        }
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        setTimeout(() => {
            this.setData({
                serviceInfo: app.globalData.serviceInfo
            });
        }, 10);
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {},
    methods: {
        /**
         * 用户点击右上角分享
         */
        onShareAppMessage1() {},

        requestInfo() {
            let that = this;
            uni.showLoading({
                title: '正在获取内容'
            });
            uni.request({
                url: app.globalData.ip + '/bocai/cms/details/' + this.currentId,
                header: app.globalData.headers,
                success: function (res) {
                    console.log(res);
                    if (res.data.status == 200) {
                        setTimeout(() => {
                            // let reg = /<a[^>]*href=['"]([^"]*)['"][^>]*>(.*?)<\/a>/g.exec(res.data.data.content);
                            // console.log(reg);

                            var s = res.data.data.content.replace(/<img/g, '<img style="max-width:100% !important;height:auto !important;margin-top:10px;"');
                            console.log(s);
                            that.setData({
                                currentInfo: res.data.data,
                                showText: s,
                                html: res.data.data.content.replace(/<!doctype html>/g, '')
                            });
                            uni.hideLoading();
                        }, 1000);
                        uni.request({
                            url: app.globalData.ip + '/bocai/cms/read/' + that.currentId,
                            header: app.globalData.headers,
                            success: function (res) {
                                console.log(res);
                                if (res.data.status == 200) {
                                }
                            }
                        });
                    } else {
                        uni.showToast({
                            title: res.data.msg,
                            icon: 'none',
                            duration: 2000
                        });
                        uni.hideLoading();
                    }
                }
            });
        },

        showTobe() {
            this.setData({
                iosDialogTobe: true
            });
        },

        closeDialog() {
            this.setData({
                iosDialogTobe: false
            });
        }
    }
};
</script>
<style>
@import './index.css';
</style>
