<template>
    <view>
        <view class="container">
            <navigator class target url="/pages/mine/userDetail/index" hover-class="none" open-type="navigate" v-if="isLogin">
                <view class="userinfobox" hover-class="thover">
                    <view class="userinfo">
                        <block v-if="userInfo.user.imgSrc">
                            <view class="por mr12" style="height: 56px" hover-class="none" :hover-stop-propagation="false">
                                <image :src="userInfo.user.imgSrc" class="show-image" mode="aspectFill"></image>
                            </view>
                        </block>
                        <block v-else>
                            <view class="mr12" hover-class="none" :hover-stop-propagation="false">
                                <image src="https://matripe-cms.oss-cn-beijing.aliyuncs.com/1shoudan/defaultAva.svg" class="show-image" mode="aspectFill"></image>
                            </view>
                        </block>
                        <view class="usernamebox">
                            <view class="username">
                                <view class="theusername">{{ userInfo.user.userName || '微信用户' }}</view>
                                <i class="iconfont icon-nv3 f12" style="color: #fb8585; line-height: 20px" v-if="userInfo.user.sex == 2"></i>
                                <i class="iconfont icon-nan3 f12" style="color: #10aeff; line-height: 20px" v-if="userInfo.user.sex == 1"></i>
                            </view>
                            <view>{{ userInfo.user.tel || '-' }}</view>
                        </view>
                    </view>
                    <view hover-class="thover">
                        <view>
                            <i v-if="userInfo.user.idauth" class="t-icon t-icon-yirenzheng color-f40 f20"></i>
                            <view v-else class hover-class="none" :hover-stop-propagation="false">去认证</view>
                        </view>
                        <text class="iconfont icon-gengduo11 c9"></text>
                    </view>
                </view>
            </navigator>
            <navigator class target url="/pages/login/index" hover-class="none" open-type="navigate" v-if="!isLogin">
                <view class="userinfobox" hover-class="thover">
                    <view class="userinfo">
                        <view class="mr12" style="height: 56px" hover-class="none" :hover-stop-propagation="false">
                            <image class="show-image" src="https://matripe-cms.oss-cn-beijing.aliyuncs.com/1shoudan/defaultAva.svg" mode="aspectFill"></image>
                        </view>
                        <view class="usernamebox">
                            <view class="username">
                                <view class="theusername">微信用户</view>
                            </view>
                            <view>钱多活少离家近</view>
                        </view>
                    </view>
                    <view hover-class="thover">
                        <text class="iconfont icon-gengduo11 c9"></text>
                    </view>
                </view>
            </navigator>

            <navigator class :url="isLogin ? '/pages/mine/myJob/index' : '/pages/login/index'" hover-class="none" :hover-stop-propagation="false">
                <view class="br_8" hover-class="none" style="background-color: #fff" :hover-stop-propagation="false">
                    <view class="setting mt_10" hover-class="thover">
                        <view>
                            <view class="t-icon t-icon-wodegongzuo2 mr6" style="width: 22px; height: 22px" hover-class="none" :hover-stop-propagation="false"></view>
                            <view class="c3 f16" hover-class="none" :hover-stop-propagation="false">我的报名</view>
                        </view>
                        <view class hover-class="none" style="line-height: 16px" :hover-stop-propagation="false">
                            <view class="iconfont icon-gengduo11 f12 c9 ml4 mt2"></view>
                        </view>
                    </view>
                </view>
            </navigator>
            <!--  wx:if="{{isMyPro}}"
  <navigator class url="{{isLogin? '/pages/mine/listManagement/index': '/pages/login/index'}}" hover-class="none" hover-stop-propagation="false">
    <view class="br_8" hover-class="none" style="background-color:#fff" hover-stop-propagation="false">
      <view class="setting mt_10" hover-class="thover">
        <view>
          <view class="t-icon t-icon-wodeshoucang1 mr6" style="width:22px;height:22px" hover-class="none" hover-stop-propagation="false"></view>
          <view class="c3 f16" hover-class="none" hover-stop-propagation="false">职位管理</view>
        </view>
        <view class hover-class="none" style="line-height:16px" hover-stop-propagation="false">
          <view class="iconfont icon-gengduo11 f12 c9 ml4 mt2"></view>
        </view>
      </view>
    </view>
  </navigator> -->

            <!-- 我的服务 -->
            <view class="myserve mt_10 br_8">
                <view class="title bb1" hover-class="none" :hover-stop-propagation="false">
                    <view class="ml16 f16 c3 fw500">我的服务</view>
                </view>
                <view class="content">
                    <!-- <view>
        <navigator url="{{isLogin? '/pages/mine/myJob/index': '/pages/login/index'}}" hover-class="thover" open-type="navigate">
          <image class src="https://matripe-cms.oss-cn-beijing.aliyuncs.com/1shoudan/gz92.svg" mode="aspectFit|aspectFill|widthFix" lazy-load="false" binderror bindload></image>
          <view>工作</view>
        </navigator>
      </view> -->
                    <!-- <view>
        <navigator class target url="{{isLogin? '/pages/mine/vitaeList/index?type=edit': '/pages/login/index'}}" hover-class="thover" aria-role="navigate" open-type="navigate">
          <image class src="https://matripe-cms.oss-cn-beijing.aliyuncs.com/1shoudan/yhk911.svg" mode="aspectFit|aspectFill|widthFix" lazy-load="false" binderror bindload></image>
          <view>简历</view>
        </navigator>
      </view> -->

                    <view>
                        <!-- url="{{isLogin? '/pages/addUserCard/index': '/pages/login/index'}}" -->
                        <navigator :url="isLogin ? '/pages/mine/addUserCard/index' : '/pages/login/index'" hover-class="thover" open-type="navigate">
                            <image class src="https://matripe-cms.oss-cn-beijing.aliyuncs.com/1shoudan/zj911.svg" mode="aspectFit|aspectFill|widthFix" :lazy-load="false"></image>
                            <view>证件</view>
                        </navigator>
                    </view>

                    <!-- <view>
        <navigator class="" target="" url="/pages/myEnroll/index" hover-class="none" open-type="navigate">
          <image class="" src="/assets/images/wdbm.svg" mode="aspectFit|aspectFill|widthFix" lazy-load="false" binderror="" bindload=""></image>
          <view>我的报名</view>
        </navigator>
      </view>-->
                    <!-- <view>
        <image class="" src="/assets/images/wdlx.svg" mode="aspectFit|aspectFill|widthFix" lazy-load="false" binderror="" bindload=""></image>
        <view>我的老乡</view>
      </view>-->
                    <view>
                        <!-- url="{{isLogin? '/pages/addressBook/index': '/pages/login/index'}}" -->
                        <navigator :url="isLogin ? './addressBook/index' : '/pages/login/index'" hover-class="thover" open-type="navigate">
                            <image class src="https://matripe-cms.oss-cn-beijing.aliyuncs.com/1shoudan/dzb911.svg" mode="aspectFit|aspectFill|widthFix" :lazy-load="false"></image>
                            <view>地址本</view>
                        </navigator>
                    </view>
                    <view>
                        <navigator class="" :url="isLogin ? '/pages/collect/index' : '/pages/login/index'" hover-class="thover" open-type="navigate">
                            <image
                                class=""
                                src="https://matripe-cms.oss-cn-beijing.aliyuncs.com/1shoudan/sc911.svg"
                                mode="aspectFit | aspectFill | widthFix"
                                :lazy-load="false"
                                @error=""
                                @load=""
                            ></image>
                            <view>收藏</view>
                        </navigator>
                    </view>

                    <!-- <view wx:if="{{!isLogin}}">
        <navigator class="" target="" url="" hover-class="thover" open-type="navigate">
          <image class="" src="/assets/images/wdbm.svg" mode="aspectFit|aspectFill|widthFix" lazy-load="false" binderror="" bindload=""></image>
          <view>我的团队</view>
        </navigator>
      </view>-->
                </view>
            </view>
            <!--
  <view class="servicebox mt_10 br8 fsa">
    <view class="serviceinfo display-flex" hover-class="none">
      <view class="mr10">
        <image wx:if="{{serviceInfo.avatar}}" class="br_8" src="{{serviceInfo.avatar}}" mode="aspectFit|aspectFill|widthFix" lazy-load="false" binderror bindload></image>
        <image wx:else class="br_8" src="https://matripe-cms.oss-cn-beijing.aliyuncs.com/1shoudan/service.jpg" mode="aspectFit|aspectFill|widthFix" lazy-load="false" binderror bindload></image>
      </view>
      <view class="servicenamebox">
        <view class="mb2 f18 fw500">客户经理</view>
        <view class="c3 f16">
          {{serviceInfo.userName }}
          <i class="mr4"></i>
          <p class="f14">{{serviceInfo.tel || '0371-6611 3723'}}</p>
        </view>
      </view>
    </view>
    <view class hover-class="none" hover-stop-propagation="false">
      <view class="iconfont icon-qiyeweixin dib" bindtap="showdialog" hover-class="thover06" style="width:40px;height:40px;border-radius: 50%;background-color: var(--color-ysd-bg);color:var(--color-hover);display: flex;align-items: center;justify-content: center;font-size: 20px;float: right;"></view>
      <view class="iconfont icon-dianhua mr10 dib" bindtap="makePhoneCall" hover-class="thover06" style="width:40px;height:40px;border-radius: 50%;background-color: var(--color-ysd-bg);color:var(--color-hover);display: flex;align-items: center;justify-content: center;font-size: 20px;float: right;"></view>
    </view>
  </view>
-->

            <navigator hover-class target :url="isLogin ? './opinion/index' : '/pages/login/index'">
                <view class="br_8" hover-class="none" style="background-color: #fff" :hover-stop-propagation="false">
                    <view class="setting" hover-class="thover" style="margin-top: 10px">
                        <view>
                            <!-- <image class src="/assets/images/sz.svg" mode="aspectFit|aspectFill|widthFix" lazy-load="false" binderror bindload></image> -->
                            <view class="t-icon t-icon-fankuiyujianyi1 mr6" style="width: 22px; height: 22px" hover-class="none" :hover-stop-propagation="false"></view>
                            <view class>反馈与建议</view>
                        </view>
                        <view class="iconfont icon-gengduo11"></view>
                    </view>
                </view>
            </navigator>

            <!-- url="{{isLogin? '/pages/setting/index': '/pages/login/index'}}" -->
            <navigator class="mb32" hover-class target :url="isLogin ? './setting/index' : '/pages/login/index'">
                <view class="br_8" hover-class="none" style="background-color: #fff" :hover-stop-propagation="false">
                    <view class="setting" hover-class="thover" style="margin-top: 10px">
                        <view>
                            <!-- <image class src="/assets/images/sz.svg" mode="aspectFit|aspectFill|widthFix" lazy-load="false" binderror bindload></image> -->
                            <view class="t-icon t-icon-shezhi4 mr6" style="width: 22px; height: 22px" hover-class="none" :hover-stop-propagation="false"></view>
                            <view class>设置</view>
                        </view>
                        <view class="iconfont icon-gengduo11"></view>
                    </view>
                </view>
            </navigator>

            <!-- <navigator class="mb32" hover-class style="margin-bottom:80px;" target url="{{isLogin? './setting/index': '/pages/login/index'}}">
    <view class="br_8 tc" hover-class="none" style="background-color:#fff" hover-stop-propagation="false">
      <view class="setting" hover-class="thover" style="margin-top: 32px;">
        <view style="flex: 1;justify-content: center;font-size: 16px;">
          <view class="iconfont icon-shangjiahoutai mr6" style="width:22px;height:22px" hover-class="none" hover-stop-propagation="false"></view>
          <view class="fwb">商家后台</view>
        </view>
         <view></view>
      </view>
    </view>
  </navigator> -->

            <!-- <view class="login" wx:if="{{!isLogin}}">
    <navigator class="" target="" url="../login/index" hover-class="none" open-type="navigate">
      <button class="loginBtn" style="font-weight:400;margin-top:0px;" type="primary" role="button" bindtap=''>登录</button>
    </navigator>
  </view>-->
        </view>
        <view aria-role="dialog" :aria-modal="true" @touchmove.stop.prevent="modalMove" class="fadeIn" v-if="iosDialog">
            <view class="weui-mask"></view>
            <view class="weui-dialog contact" style="box-sizing: border-box">
                <view class="weui-dialog__hd">
                    <!-- <strong class="weui-dialog__title">17639080029</strong></view> -->
                    <!-- <view class="weui-dialog__bd">
            <view>现在登录吗?</view>
      </view>-->
                    <!-- <image src="https://matripe-cms.oss-cn-beijing.aliyuncs.com/1shoudan/service.jpg" style="width:56px;height:56px;"></image> -->
                    <!-- <image src="../../assets/Snipaste_2023-06-13_09-25-14.png" show-menu-by-longpress='{{true}}' style="width:56px;height:56px;"></image> -->
                    <i class="iconfont icon-guanbi guanbi c6 biggerSize" @click="closeDialog"></i>
                    <view class="f16 c3 fw500 mb32">加客户经理微信</view>
                    <view
                        v-if="isLoading"
                        class
                        style="position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%)"
                        hover-class="none"
                        :hover-stop-propagation="false"
                    >
                        <view aria-role="img" aria-label="加载中" style class="weui-primary-loading">
                            <view class="weui-primary-loading__dot"></view>
                        </view>
                        <view class hover-class="none" :hover-stop-propagation="false">加载中...</view>
                    </view>
                    <image :src="serviceInfo.qrCode" @load="imageLoad" :show-menu-by-longpress="true" style="width: 184px; height: 184px"></image>
                    <!-- <view class="f14 c9">人才经纪人</view> -->
                    <!-- <view class="mt20 f22 c3">{{pmdUserInfo.tel}}</view> -->
                    <view class="f14 c3 mt6">长按识别二维码</view>
                </view>
                <!-- <view class="display-flex contact_bottomBtn pb20" style="padding-top:20px;">
      <view class="flex-1 lflex v-center" bindtap="closeDialog" hover-class="thover">取消</view>
      <view class="rflex">
        <button class="" type="primary" hover-class="thover" bindtap="makePhoneCall">呼叫</button>
      </view>
    </view>-->
            </view>
        </view>
        <view aria-role="dialog" @touchmove.stop.prevent="modalMove" :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 class>{{ serviceInfo.tel || '0371-6611 3723' }}</p>
                            </view>
                            <view
                                v-if="isLoading"
                                class
                                style="position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%)"
                                hover-class="none"
                                :hover-stop-propagation="false"
                            >
                                <view aria-role="img" aria-label="加载中" style class="weui-primary-loading">
                                    <view class="weui-primary-loading__dot"></view>
                                </view>
                                <view class hover-class="none" :hover-stop-propagation="false">加载中...</view>
                            </view>
                            <image :src="serviceInfo.qrCode" @load="imageLoad" :show-menu-by-longpress="true" style="width: 161px; height: 161px"></image>
                            <view class="f14 c9 mt6">长按识别二维码</view>
                        </view>
                    </view>
                </view>
            </view>
        </view>

        <!-- <button bindtap='showTobe'>123123</button> -->
    </view>
</template>

<script>
// pages/mine/mine.js
const app = getApp();
export default {
    data() {
        return {
            isopen: 1,

            // 账户余额是否显示
            isMyPro: false,

            // 是否是小程序拥有者登录判断
            iosDialog: false,

            iosDialogTobe: false,
            isLoading: true,

            // 成为代理loading效果
            isLogin: app.globalData.isLogin,

            // user:app.globalData.user,
            serviceInfo: {
                qrCode: '',
                tel: ''
            },

            map: {
                num10: '0',
                num20: '0',
                num25: '0',
                num30: '0',
                num40: '0',
                num999: '0',
                user999: '0',
                user40: '0',
                user48: '0',
                user50: '0',
                billStatus10Salary: '0',
                billStatus30Salary: '0'
            },

            motto: 'Hello World',

            userInfo: {
                user: {
                    imgSrc: '',
                    userName: '',
                    sex: 0,
                    tel: '',
                    idauth: ''
                }
            },

            hasUserInfo: false,
            canIUse: uni.canIUse('button.open-type.getUserInfo'),
            canIUseGetUserProfile: false,

            // 如需尝试获取用户信息可改为false
            underReviewNum: -1,

            underReviewList: [],
            searchParam: {},
            recordBillType: '',
            configInfo: {},

            // agencyStatus: 0, // 是否是代理判断
            balance: '0.00',

            corpUserFlag: '',
            selected: 0,
            isShow: false,
            showMoney: false
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad: function (options) {
        setTimeout(() => {
            console.log(app.globalData.loginUserInfo);
            this.setData({
                isLogin: app.globalData.isLogin,
                hasUserInfo: app.globalData.hasUserInfo,
                // agencyStatus: app.globalData.loginUserInfo.agencyStatus,
                userInfo: app.globalData.loginUserInfo,
                serviceInfo: app.globalData.serviceInfo,
                corpUserFlag: app.globalData.loginUserInfo.corpUserFlag
            });
        }, 100);
        this.getProInfo();
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */

    onShow: function () {
        console.log('isshow');
        let that = this;
        uni.setStorageSync('comeFromPage', 'me');
        if (typeof this.getTabBar === 'function' && this.getTabBar()) {
            this.getTabBar().setData({
                selected: 2,
                isShow: true
            });
        }
        uni.setStorageSync('BILLFROM', 'mine');

        // wx.showTabBar({
        //   success(e) {},
        // });
        // if (!app.globalData.isLogin) {
        //   wx.setStorageSync('comeFromPage', "me")
        //   wx.redirectTo({
        // 		url: "/pages/login/index",
        // 	});
        // } else {
        // 	wx.switchTab({
        // 		url: "/pages/mine/index",
        // 	});
        // }
        // let serviceInfo =  wx.getStorageSync('ServiceInfo')
        setTimeout(() => {
            if (app.globalData.isLogin) {
                console.log(that.userInfo);
                that.setData({
                    isLogin: app.globalData.isLogin,
                    hasUserInfo: app.globalData.hasUserInfo,
                    // agencyStatus: app.globalData.loginUserInfo.agencyStatus,
                    userInfo: app.globalData.loginUserInfo,
                    serviceInfo: app.globalData.serviceInfo,
                    corpUserFlag: app.globalData.loginUserInfo.corpUserFlag
                });
                that.getDataNum();
            } else {
                // 由于 userLogin 是网络请求，可能会在 Page.onLoad 之后才返回
                // 所以此处加入 callback 以防止这种情况
                // app.userLoginCallback = (res) => {
                setTimeout(() => {
                    console.log(that.userInfo);
                    that.setData({
                        isLogin: app.globalData.isLogin,
                        hasUserInfo: app.globalData.hasUserInfo,
                        userInfo: app.globalData.loginUserInfo,
                        // agencyStatus: app.globalData.agencyStatus,
                        serviceInfo: app.globalData.serviceInfo
                    });
                }, 100);
                // };
                that.getDataNum();
            }
            console.log(that.serviceInfo);
            // this.watch();
        }, 100);
        this.getConfigInfo();
    },
    onTabItemTap(item) {
        console.log(item.index);
        console.log(item.pagePath);
        console.log(item.text);
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {
        console.log(123);
        this.setData({
            iosDialog: false,
            iosDialogTobe: false
        });
        uni.onAppRoute({
            success(item) {
                console.log(item);
            },
            fail: function (item) {
                console.log(item);
            }
        });
    },
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {
        // var that = this;
        // console.log(that.data.isLogin)
        // if(!that.data.isLogin){
        //   wx.setStorageSync('comeFromPage', "me")
        //   wx.redirectTo({
        // 		url: "/pages/login/index",
        // 	});
        // }
    },
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {},
    methods: {
        openEyes: function () {
            this.setData({
                showMoney: false
            });
        },

        closeEyes: function () {
            this.setData({
                showMoney: true
            });
        },

        /**
         * 获取当前小程序信息
         */
        getProInfo() {
            let that = this;
            uni.request({
                url: app.globalData.ip + '/yishoudan/weixin/config/getConfig',
                // 分类列表获取接口
                header: app.globalData.headers,
                method: 'GET',
                success: function (res) {
                    console.log(res);
                    console.log(app.globalData.loginUserInfo);
                    if (res.data.status == 200) {
                        if (res.data.data.config.agencyId == app.globalData.loginUserInfo.agencyId) {
                            that.setData({
                                isMyPro: true
                            });
                        } else {
                            that.setData({
                                isMyPro: false
                            });
                        }
                    }
                }
            });
        },

        watch() {
            // var obj = app.globalData;
            // this.setData({
            // 	isLogin: obj.isLogin,
            // });
        },

        /**
         * 用户点击右上角分享
         */
        onShareAppMessage1: function () {},

        showbalance(e) {
            this.setData({
                isopen: e.mark.open
            });
        },

        showdialog() {
            this.setData({
                iosDialog: true
            });
        },

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

        closeDialog() {
            this.setData({
                iosDialog: false,
                iosDialogTobe: false
            });
        },

        login() {
            // this.setData({
            //   isLogin:true
            // })

            app.globalData.isLogin = true;
            uni.reLaunch({
                url: '/pages/mine/index'
            });
        },

        /**
         * 获取商家配置信息
         *
         *
         */
        getConfigInfo() {
            let that = this;
            uni.request({
                url: app.globalData.ip + '/yishoudan/agency/config/get',
                // 分类列表获取接口
                header: app.globalData.headers,
                method: 'GET',
                success: function (res) {
                    console.log(res);
                    if (res.data.status == 200) {
                        that.setData({
                            configInfo: res.data.data.config
                        });
                        uni.setStorageSync('configInfo', res.data.data.config);
                        console.log(that.configInfo);
                    }
                }
            });
        },

        makePhoneCall() {
            console.log(1);
            var that = this;
            uni.makePhoneCall({
                // number: that.data.jobDetail.assistantUserTel + ""
                phoneNumber: that.serviceInfo.workPhone || '0371-6611 3723'
            });
        },

        /**
         * 前往工单页面
         *
         *
         */
        goList() {
            if (!app.globalData.isLogin) {
                uni.navigateTo({
                    url: '/pages/login/index'
                });
            } else {
                uni.navigateTo({
                    url: '../myBill/index?status=0'
                });
            }
        },

        /**
         * 获取各个数量
         *
         *
         */
        getDataNum() {
            let that = this;
            uni.request({
                url: app.globalData.ip + '/statistics/home',
                header: app.globalData.headers,
                success(res) {
                    console.log(res);
                    if (res.data.status == 200) {
                        that.setData({
                            map: res.data.data
                        });
                    }
                }
            });
        },

        /**
         * 二维码加载laoding隐藏
         *
         *
         */
        imageLoad() {
            this.setData({
                isLoading: false
            });
        },

        toTodayData() {
            if (!app.globalData.isLogin) {
                uni.navigateTo({
                    url: '/pages/login/index'
                });
            } else {
                uni.navigateTo({
                    url: '/pages/todayData/index'
                });
            }
        },

        modalMove() {
            return false;
        }
    }
};
</script>
<style>
@import './index.css';
</style>
