<template>
    <view class="body">
        <mescroll-uni ref="mescrollRef" @down="downCallback" @up="getData" :up="upOption" :down="downOption">
            <view class="body_content">
                <view class="swiper_con">
                    <swiper :current="swiperIndex" @change="swiperChange" class="swiper" :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval" :duration="duration">
                        <swiper-item v-for="(item,index) in detail.imgurl2" :key="index">
                            <image class="swiper_img" :src="item" mode="widthFix"></image>
                        </swiper-item>
                    </swiper>
                    <view class="swiper_page d_flex j_center a_center">
                        <view class="swiper_page_txt" v-text="swiperIndex + 1"></view>
                        <view class="swiper_page_line">/</view>
                        <view class="swiper_page_txt" v-text="detail.imgurl2.length"></view>
                    </view>
                </view>
                <view class="detail_con">
                    <view class="detail_box">
                        <view class="detail_box_1 d_flex j_between">
                            <view class="left">
                                <view class="detail_title font_bold" v-text="detail.Title"></view>
                                <view class="detail_subtitle">活动时间:<text v-text="detail.stime + ' - ' + detail.etime"></text></view>
                            </view>
                            <view class="right d_flex j_center">
                                <view class="detail_box_nav" @click="collectClick">
                                    <image v-if="isCollect==0" class="detail_box_icon icon1" src="/static/collect1.png" mode="heightFix"></image>
                                    <image v-else class="detail_box_icon icon1" src="/static/collect2.png" mode="heightFix"></image>
                                    <view class="txt">收藏</view>
                                </view>
                                <button hover-class="none" open-type="share" class="detail_box_nav">
                                    <image class="detail_box_icon icon2" src="/static/share_icon.png" mode="heightFix"></image>
                                    <view class="txt">分享</view>
                                </button>
                            </view>
                        </view>
                        <view class="detail_box_2 d_flex a_center">
                            <image class="phone_icon" src="/static/people_icon1.png" mode="widthFix"></image>
                            <view class="phone_txt">负责人</view>
                            <view class="phone_num" v-text="detail.zqbx">陈立将</view>
                        </view>
                        <view class="detail_box_2 d_flex a_center">
                            <image class="phone_icon" src="/static/people_icon2.png" mode="widthFix"></image>
                            <view class="phone_txt">主办方</view>
                            <view class="phone_num" v-text="detail.TrueName">盛世嘉园</view>
                        </view>
                        <view class="detail_box_2 d_flex a_center">
                            <view class="address_txt text_hidden">活动地址：<block v-text="detail.person1"></block></view>
                            <!-- <image class="address_icon" src="/static/map_icon.png"></image> -->
                        </view>
                        <view @click="goUrl" :data-url="'/pages/activity/course/index?id=' + id" class="content_btn_con btn_con1">
                            <view class="main_content_btn btn1">查看活动历程</view>
                        </view>
                    </view>
                    <view class="cgd2_box">
                        <view class="i2_head d_flex j_between a_center">
                            <view class="i2_head_left"><text class="color_red">入选</text>名单</view>
                            <view class="i2_head_right"><text v-text="havenum"></text>/<text v-text="maxnum"></text>人</view>
                        </view>
                        <scroll-view scroll-x="true" class="cgd2_content">
                            <view class="cgd2_content_nav" v-for="(item,index) in heads" :key="index">
                                <view class="cgd2_content_img">
                                    <image class="img" :src="item.userimg"></image>
                                </view>
                                <view class="cgd2_content_title" v-text="item.TrueName"></view>
                            </view>
                        </scroll-view>
                    </view>
                    <view class="cgd_box cgd1_box">
                        <view class="i1_head">
                            <view class="i1_head_left">活动介绍</view>
                            <view class="i1_head_right"></view>
                        </view>
                        <view class="cgd1_content">
                            <view class="cgd1_txt1" v-text="detail.content1">为贯彻落实《公共文化服务保障法》、省委省政府《全面实施乡村振兴战略高水平推进农业农村现代化行动计划（2018-2022年）》以及省委办公厅、省政府办公厅《关于推进农村文化礼堂建设的意见》，发挥公共图书馆的服务职能，推动全省农村文化礼堂建设与发展，助力美丽乡村建设，将举办“全民饮茶日活动”</view>
                        </view>
                    </view>
                    
                </view>
            </view>
        </mescroll-uni>
        <view v-if="isActivity==1 && isyy==0" class="content_btn_con bottom_btn" @click="applyClick">
            <view class="main_content_btn" :class="isApplyClick?'gray_content_btn':''">报名</view>
        </view>
        <view v-else-if="isActivity==1 && isyy==1" class="content_btn_con bottom_btn">
            <view class="main_content_btn gray_content_btn">已报名</view>
        </view>
        <view v-else class="content_btn_con bottom_btn">
            <view class="main_content_btn gray_content_btn">报名结束</view>
        </view>
        <view class="time_alert" :class="isAlert?'on':''">
            <view class="time_alert_con">
                <view class="time_alert_title">当前用户进行报名</view>
                <view class="time_alert_content">
                    <view class="input_box d_flex a_center">
                        <view class="left">姓名</view>
                        <view class="right">
                            <input class="input" type="text" v-model="name" placeholder="请输入姓名" />
                        </view>
                    </view>
                    <view class="input_box d_flex a_center" v-if="neddPhone">
                        <view class="left">手机号</view>
                        <view class="right">
                            <input class="input" type="number" v-model="phone" placeholder="请输入手机号" />
                        </view>
                    </view>
                    <view class="input_box d_flex a_center" v-if="neddCard">
                        <view class="left">身份证</view>
                        <view class="right">
                            <input class="input" type="idcard" v-model="yycard" placeholder="请输入身份证" />
                        </view>
                    </view>
                </view>
                <view class="time_alert_btn">
                    <view class="btn" @click="cancelClick">取消</view>
                    <view class="btn" @click="trueClick">确定</view>
                </view>
            </view>
        </view>
    </view>
</template>


<script>
import MescrollMixin from '@/components/mescroll-uni/mescroll-mixins.js';
export default {
    mixins: [MescrollMixin],
    components: {
        
    },
    data() {
        return {
            indicatorDots:false,
            autoplay:true,
            interval:5000,
            duration:1000,
            mescroll: null,
            downOption: {
                use: false, //是否启用下拉刷新
                auto: false //是否自动加载
            },
            upOption: {
                use: false, //是否启用上拉加载更多
                auto: false //是否自动加载
            },
            swiperIndex:0,
            banners:[],
            id:"",
            detail:{
                stime:"",
                etime:""
            },
            heads:[],
            isCollect: 0 ,// 判断收藏
            isActivity:0,
            havenum:0,
            maxnum:0,
            isLogin:false,
            isyy:0,
            isApplyClick:false,
            isAlert:false,
            name:"",
            phone:"",
            neddCard:0,
            neddPhone:0
        };
    },
    onLoad(options) {
        let that = this;
        that.id = options.id;
        that.getData();
    },
    onReady() {
        
    },
    onShow() {
        if(this.$util.isLogin()){
            this.isLogin = true;
            this.getCollect();
        }else{
            this.isLogin = false;
        }
    },
    methods: {
        goUrl(e){
            let toUrls = e.currentTarget.dataset.url;
            if(!this.isLogin){
                this.goLogin();
                return;
            }
            uni.navigateTo({
                url: toUrls
            });
        },
        goLogin(){
            let url = '/pages/activity/detail/index?id=' + this.id;
            url = encodeURIComponent(url);
            uni.navigateTo({
                url: '/pages/login/index?url=' + url
            });
        },
        cancelClick(){
            this.isAlert = false;
        },
        trueClick(){
            let that = this;
            if(!that.name){
                that.$util.showToast("请输入姓名");
                return;
            }
            if(that.neddPhone){
                if(!that.phone){
                    that.$util.showToast("请输入手机号码");
                    return;
                }
                if(!that.$util.isPhone(that.phone)){
                    that.$util.showToast("手机号码格式错误");
                    return;
                }
            }
            if(that.neddCard){
                if(!that.yycard){
                    that.$util.showToast("请输入身份证");
                    return;
                }
                if(that.yycard.length<15){
                    that.$util.showToast("请输入正确的身份证");
                    return;
                }
            }
            let data = {
                mod: 'AddHD',
                cgid: that.id,
                yyname:that.name
            }
            if(that.neddPhone){
                data.yyphone = that.phone;
            }
            if(that.neddCard){
                data.yycard = that.yycard;
            }
            that.$doPost('Server.aspx', data)
            .then(res => {
                if (res.data.resultcode != 0) {
                    that.$util.showToast(res.data.msg);
                    return;
                }
                that.$util.showToast(res.data.msg);
                that.isAlert = false;
                that.isApplyClick = true;
            })
            .catch(err => {
                console.log('request fail', err);
            });
            
        },
        applyClick(){
            let that = this;
            if(that.isApplyClick){
                return;
            }
            if(!that.isLogin){
                that.goLogin();
                return;
            }
            that.isAlert = true;
        },
        collectClick(e) {
            let that = this;
            if(!this.isLogin){
                this.goLogin();
                return;
            }
            that.$doPost('Server.aspx', {
                mod: 'addSC',
                scid: that.id,
                type: 0
            })
            .then(res => {
                if (res.data.resultcode != 0) {
                    that.$util.showToast(res.data.msg);
                    return;
                }
                if (that.isCollect == 0) {
                    that.isCollect = 1;
                } else {
                    that.isCollect = 0;
                }
                that.$util.showToast('操作成功');
            })
            .catch(err => {
                console.log('request fail', err);
            });
        },
        getCollect() {
            let that = this;
            that.$doPost('Server.aspx', {
                mod: 'isSC',
                scid: that.id,
                type: 0
            })
            .then(res => {
                if (res.data.resultcode != 0) {
                    that.$util.showToast(res.data.msg);
                    return;
                }
                let body = res.data.data;
                that.isCollect = body.id && body.id!=0 ? 1 : 0;
            })
            .catch(err => {
                console.log('request fail', err);
            });
        },
        swiperChange(e){
            this.swiperIndex = e.detail.current;
        },
        getData(){
            let that = this;
            that.$doPost('Server.aspx', {
                mod:"getHDinfo",
                hdid:that.id
            })
            .then(res => {
                if (res.data.resultcode!=0) {
                    that.$util.showToast(res.data.msg);
                    return;
                }
                let body = res.data.data;
                if(new Date() > that.$util.strDateFormat(body.theinfo.etime)){
                    that.isActivity = 0;
                }else{
                    that.isActivity = 1;
                }
                that.neddCard = body.theinfo.neddCard || 0;
                that.neddPhone = body.theinfo.neddPhone || 0;
                body.theinfo.stime = that.$util.strDateFormat(body.theinfo.stime,"yyyy年MM月dd");
                body.theinfo.etime = that.$util.strDateFormat(body.theinfo.etime,"yyyy年MM月dd");
                body.theinfo.imgurl2 = body.theinfo.imgurl2.split("|");
                body.theinfo.imgurl = that.baseImgUrl + body.theinfo.imgurl;
                for (let i = 0; i < body.theinfo.imgurl2.length; i++) {
                    body.theinfo.imgurl2[i] = that.baseImgUrl + body.theinfo.imgurl2[i];
                }
                that.detail = body.theinfo;
                that.havenum = body.havenum;
                that.maxnum = body.maxnum;
                that.heads = body.havelist;
                that.isyy = body.isyy;
            })
            .catch(err => {
                console.log('request fail', err);
            });
        },
        downCallback(mescroll) {
            setTimeout(function(){
                mescroll.endSuccess(0);
            },600)
        }
    },
    onShareTimeline(res) {
        let that = this;
        let detail = this.detail;
        return {
            title: detail.Title,
            imageUrl: detail.imgurl,
            query: '/pages/activity/detail/index?id=' + that.id
        };
    },
    onShareAppMessage(res) {
        let that = this;
        let detail = this.detail;
        return {
            title: detail.Title,
            imageUrl: detail.imgurl,
            path: '/pages/activity/detail/index?id=' + that.id
        };
    }
};
</script>

<style lang="scss">
    page,.body{
        background: #fff;
    }
    .body_content{
        padding-bottom: 148upx;
    }
    /*标题*/
    .i1_head{
        padding: 30upx 0 0 0;
        overflow: hidden;
        background: #fff;
    }
    .i1_head .i1_head_left{
        color:#000000;
        font-size: 36upx;
        padding-left: 14upx;
        position: relative;
    }
    .i1_head .i1_head_left::after{
        width: 8upx;
        height: 26upx;
        background: #ffb155;
        border-radius: 10upx;
        content: "";
        left: 0;
        top:50%;
        transform: translateY(-50%);
        position: absolute;
    }
    .i1_head .i1_head_right{
        font-size: 24upx;
        color:#888a87;
    }
    .i1_head .more_arrow{
        width: 12upx;
        height: 19upx;
        margin-left: 8upx;
    }
    /*广告*/
    .swiper,.swiper_img,.swiper_con{
        width: 100%;
        height: 430upx;
        position: relative;
    }
    .swiper_page{
        width: 76upx;
        height: 30upx;
        border-radius: 20upx;
        background: rgba(0,0,0,0.6);
        text-align: center;
        color:#fff;
        font-size: 20upx;
        position: absolute;
        right: 30upx;
        bottom: 50upx;
        z-index: 1000;
    }
    .swiper_page .swiper_page_line{
        margin: 0 5upx;
    }
    /*详情*/
    .detail_con{
        background: #fff;
    }
    .detail_con .detail_box{
        border-radius: 20upx;
        box-shadow: 0px 0px 15upx 0px rgba(0, 0, 0, 0.15);
        position: relative;
        z-index: 1010;
        top:-20upx;
        background: #fff;
        padding:0 30upx;
    }
    .detail_box_1{
        width: 100%;
        border-bottom: 1upx solid #edeaea;
        padding:46upx 0;
    }
    .detail_box_1 .detail_box_nav{
        background: transparent;
        line-height: 24upx;
    }
    .detail_box_1 .detail_box_nav:first-child{
        margin-right: 26upx;
    }
    .detail_box_1 .left{
        width: 72%;
    }
    .detail_box_1 .right{
        width: 28%;
        position: relative;
    }
    .detail_box_1 .right::after{
        content: "";
        left: 0;
        width: 1upx;
        background: #edeaea;
        height: 80upx;
        top:0;
        position: absolute;
    }
    .detail_box_1 .detail_box_icon{
        height: 39upx;
    }
    .detail_box_1 .detail_box_icon.icon1{
        width: 40upx;
    }
    .detail_box_1 .detail_box_icon.icon2{
        width: 42upx;
    }
    .detail_box_1 .txt{
        font-size: 20upx;
        text-align: center;
        margin-top: 10upx;
        color:#767676;
    }
    .detail_box_1 .detail_title{
        font-size: 36upx;
        line-height: 40upx;
        color: #000000;
        padding-bottom: 20upx;
        padding-right: 26upx;
    }
    .detail_box_1 .detail_subtitle{
        font-size: 24upx;
        line-height: 30upx;
        color:#767676;
    }
    .detail_box_2{
        width: 100%;
        border-bottom: 1upx solid #edeaea;
        padding:30upx 0;
        color:#6a6a6a;
        font-size: 28upx;
    }
    .detail_box_2 .address_txt{
        max-width: calc(100% - 50upx);
        margin-right: 14upx;
    }
    .detail_box_2 .address_icon{
        width: 36upx;
        height: 34upx;
    }
    .detail_box_2:last-child{
        border-bottom: none;
    }
    .detail_box_2 .phone_icon{
        width: 36upx;
        margin-right: 10upx;
    }
    .detail_box_2 .phone_txt{
        font-size: 30upx;
        color:#000000;
    }
    .detail_box_2 .phone_num{
        margin-left: 16upx;
        padding-left: 16upx;
        border-left: 1upx solid #edeaea;
    }
    .cgd_box{
        margin: 0 30upx;
    }
    .cgd1_box .i1_head{
        padding-top: 20upx !important;
    }
    .cgd1_box .cgd1_content{
        font-size: 28upx;
        line-height: 38upx;
        color:#000;
        padding-top: 26upx;
        padding-bottom: 20upx;
    }
    .cgd1_box .img{
        width: 100%;
        margin: 20upx 0 10upx 0;
    }
    .cgd1_box .cgd1_txt1{
        font-size: 30upx;
        color:#777777;
        line-height: 48upx;
    }
    .cgd1_box .cgd1_txt2{
        font-size: 30upx;
        color:#000;
        line-height: 48upx;
        margin: 0 0 10upx 0;
    }
    .cgd1_box .cgd1_txt3{
        font-size: 24upx;
        color:#777777;
        line-height: 38upx;
    }
    .cgd1_box image{
        display: block;
        margin: auto;
        max-width: 100%;
    }
    .cgd2_box{
        border-radius: 17upx;
        box-shadow: 0px 0px 15px 0px rgba(0, 0, 0, 0.15);
        margin-bottom: 30upx;
        margin-top: 10upx;
    }
    .i2_head{
        margin: 0 30upx;
        padding-top: 24upx;
    }
    .i2_head .i2_head_left{
        font-size: 36upx;
    }
    .i2_head .i2_head_right{
        font-size: 30upx;
    }
    .cgd2_box .cgd2_content{
        margin: 0 30upx;
        width: calc(100% - 60upx);
        white-space: nowrap;
        padding-top: 20upx;
        padding-bottom: 40upx;
    }
    .cgd2_box .cgd2_content_nav{
        display: inline-block;
        margin-right: 30upx;
        text-align: center;
    }
    .cgd2_box .cgd2_content_nav .cgd2_content_img{
        width: 100upx;
        height: 100upx;
        border:6upx solid #f5f5f5;
        border-radius: 50%;
        overflow: hidden;
        box-sizing: border-box;
        margin: auto;
    }
    .cgd2_box .cgd2_content_nav .cgd2_content_img .img{
        width: 100%;
        height: 100%;
    }
    .cgd2_box .cgd2_content_nav .cgd2_content_title{
        font-size: 28upx;
        color:#000000;
        padding-top: 10upx;
    }
    .gray_content_btn{
        background: #bbb8b8;
    }
    .bottom_btn{
       padding: 30upx;
       position: fixed;
       left: 0;
       bottom: 0;
       z-index: 1002;
       width: calc(100% - 60upx);
       background: #fff;
    }
    .btn_con1{
        padding-top: 30upx;
        padding-bottom: 30upx;
    }
    .btn1{
        margin: auto;
        width: 330upx;
        border-radius: 60upx;
        line-height: 68upx;
        height: 68upx;
        font-weight: initial;
        font-size: 30upx;
    }
    
    .time_alert{
        position: fixed;
        left: 0;
        top: 0;
        height: 100%;
        width: 100%;
        z-index: 1002;
        background: rgba(0,0,0,0.6);
        display: none;
    }
    .time_alert.on{
        display: block;
    }
    .time_alert .time_alert_con{
        width: 90%;
        position: absolute;
        left: 50%;
        top: 50%;
        -webkit-transform: translate(-50%,-50%);
        transform: translate(-50%,-50%);
        background: #fff;
        border:1px solid #e5e5e5;
        border-radius: 20upx;
    }
    .time_alert_con .time_alert_title{
        line-height:88upx;
        text-align: center;
        position: relative;
        border-bottom:1px solid #e5e5e5;
        font-size: 32upx;
    }
    .time_alert_con .time_alert_close{
        position: absolute;
        right: 0;
        top:0;
        color: red;
        padding:0 10upx 0 20upx;
        cursor: pointer;
    }
    .time_alert_con .time_alert_content{
        padding:60upx 0;
        font-size: 30upx;
    }
    
    .time_alert_btn{
        height: 88upx;
        border-top: 1px solid #e5e5e5;
        line-height: 88upx;
        font-size: 32upx;
        overflow: hidden;
    }
    .time_alert_btn .btn{
        height: 100%;
        width: 50%;
        float: left;
        text-align: center;
        box-sizing: border-box;
        cursor: pointer;
    }
    .time_alert_btn .btn:first-child{
        border-right: 1px solid #e5e5e5;
        color:#666;
    }
    .time_alert_btn .btn:last-child{
        color:#288efd;
    }
    .input_box{
        height: 88upx;
        margin: 0 30upx;
        border-bottom: 1upx solid #e5e5e5;
        font-size: 28upx;
    }
    .input_box:last-child{
        border-bottom: none;
    }
    .input_box .left{
        width: 120upx;
    }
    .input_box .right{
        width: calc(100% - 120upx);
    }
    .input_box .right .input{
        font-size: 28upx;
    }
</style>
