$(function() {
    var siteId = PAGE_CONFIG.site
    var yearId = ''
    var urlType = PAGE_CONFIG.envir;
    var urlObj = {
        'dev': 'http://hw-scms-api.pcuion.com',
        'pre': 'http://pre-scms-api.pcuion.com',
        'online': 'https://cmsmanage-siteapi.gwm.com.cn',
    }
    var baseUrl = urlObj[urlType];
    var annData = $('.ann_data').data('param')
    $('.announce_year_box').off().on('click', 'li', function() {
        $(this).siblings().removeClass('active');
        $(this).addClass('active');
        yearId = $(this).data('id');
        getList();
        var yearTd = $(this).find('a').text()
        Global.trackEvent('投资者关系_公告通函_Tab_'+ yearTd +'')
    })
    var yearQuery = {
        "limit": annData.limit,
        "render": annData.render,
        "classify_id": annData.classify_id,
        "modular_type": annData.modular_type,
        "site_id": siteId
    };
    var vm = new Vue({
        el: '#contentApp',
        template: `<div class="nav-box-con">
            <div class="announce_year_box">
                <ul>
                    <li v-for="(item, idx) in years" v-show="idx <= currentIndex" :class="{active: listQuery.classify_id == item.id}" :data-id="item.id" @click="handleYear(item.id, item.name)" :key="'year'+idx"><a>{{item.name}}</a></li>
                </ul>
                <div class="moreBox" @click="moreBox" v-show="currentIndex!=100">
                    展开更多
                </div>
            </div>
            <div class="announce_tab_box ann_list_cont">
                <ul>
                <li v-for="(item, idx) in dataList" class="list_min into">
                    <div class="lm_left">
                        <img src="https://www.gwm.com.cn/dist/images/other-page/society/v2/pdf.png" />
                        <a v-if="item.url.indexOf('.txt')" :href="item.url" target="_blank" @click="openToCn(item, $event)"><p>{{item.title}}</p></a>
                    </div>
                    <div class="lm_right">
                        <a class="ann_download" target="_blank" :data-url="item.url" :href="apiBaseUrl + item.url" @click="openToCn(item, $event)">
                        <img src="https://www.gwm.com.cn/dist/images/other-page/society/v2/download.png" />
                        </a>
                    </div>
                </li>
                </ul>
                <div class="announce_more" v-show="showMore" @click="Global.trackEvent('InvestorRelations_Announcement&Circular_More', {Tab: 'Announcement & Circular'})">
                    <p @click="handleMore">查看更多</p>
                </div>
            </div>

            </div>
            <div class="tocn-pop" v-show="txtVisible">
                <div class="tocn-cont">
                    <span class="to-close" @click="closeOpenToCn"></span>
                    <dl class="tocn-cont-dl">
                        <dt>Listed Company Information </dt>
                        <dd>An announcement has just been published by the issuer in the Chinese section of this website, a corresponding version of which may or may not be published in this section.</dd>
                        <dd>
                            <p><a @click='tdCodeadd' href="https://www.gwm.com.cn" target="_blank" class="a-to">Go to Chinese website</a></p>
                            <p><a class="a-close" @click="closeOpenToCn">Back</a></p>
                        </dd>
                    </dl>
                </div>
        </div>`,
        data: {
            apiBaseUrl: baseUrl + '/content/download?url=',
            h: '',
            currentIndex:10,
            years: [],
            txtVisible: false,
            tdCode: {
                ContentName: '',
                LocationIndex: 'L4',
                PublishDate: '',
                Tab: ''
            },
            dataList: [
                // {
                //     url: 'https://official-website-pro.obs.cn-north-4.myhuaweicloud.com/UploadEn/Announcement/20130816055037_32_9.txt',
                //     title: 'title',
                //     name: '123123123',
                //     release_time: '2019-202',
                //     id: 100
                // },
                // {
                //     url: 'https://official-website-pro.obs.cn-north-4.myhuaweicloud.com/UploadEn/Announcement/20130816055037_32_9.pdf',
                //     title: 'pdfpdfpdfpdfpdf',
                //     name: '123123123',
                //     release_time: '2019-202',
                //     id: 100
                // }
            ],
            yearId: '',
            listTotalPage: 0,
            listQuery: {
                limit: 20,
                page: 1,
                render: annData.render,
                classify_id: '',
                modular_type: annData.modular_type,
                site_id: siteId,
                isRelease: 0
            }
        },
        computed: {
            showMore: function() {
                return this.listQuery.page < this.listTotalPage;
            }
        },
        mounted: function() {
            // 获取年
            var _that = this
            Tool.ajaxHttp("post","/content/date", yearQuery, function(res) {
                console.log(res)
                if (res.code === 0) {
                    _that.years = res.data;
                    _that.listQuery.classify_id = _that.years[0].id;
                    _that.getFileList();
                }
            }, function(err) {
                console.log(err)
            })
            this.h = $(".announce_year_box ul").height();
        },
        methods: {
            // 是否是txt
            isTxt: function(url) {
                if (/\.txt/ig.test(url)) {
                    return false;
                }
                return url;
            },
            openToCn: function(row, evt) {
                Global.trackEvent('投资者关系_公告通函_点击下载')
                if (/\.txt/ig.test(row.url) || !row.url) {
                    this.txtVisible = true;
                    this.tdCode.ContentName = row.title
                    this.tdCode.PublishDate = row.release_time
                    this.tdCode.Tab = row.classify_name
                    evt.preventDefault();
                    evt.returnValue = false;
                    Global.trackEvent('InvestorRelations_Announcement&Circular_NotePopUp', 
                    {ContentName: row.title,LocationIndex: 'L3',PublishDate: row.release_time,Tab:row.classify_name})
                }
                
            },
            tdCodeadd: function() {
                Global.trackEvent('InvestorRelations_Announcement&Circular_ToChineseVersion', 
                    {ContentName: this.tdCode.ContentName,LocationIndex: 'L4',PublishDate: this.tdCode.PublishDate,Tab:this.tdCode.Tab})
            },
            closeOpenToCn: function() {
                this.txtVisible = false;
                Global.trackEvent('InvestorRelations_Announcement&Circular_BrowseOther')
            },
            moreBox: function() {
                this.currentIndex = 100
            },
            handleYear: function(id,name) {
                this.listQuery.classify_id = id;
                this.listQuery.page = 1;
                this.dataList = [];
                this.getFileList();
                 Global.trackEvent('InvestorRelations_Announcement&Circular_Tab_'+name);
            },
            // 获取列表
            getFileList: function() {
                var _thats = this
                console.dir(this.listQuery);
                Tool.ajaxHttp("post","/content/investor", this.listQuery, function(res) {
                    if (res.code === 0) {
                        res.data && res.data.list && res.data.list.forEach(function(item) {
                            _thats.dataList.push(item);
                        });
                        _thats.listTotalPage = res.data.total_page;
                        _thats.$nextTick(function(){
                             console.log($(".ann_download").length);
                             var ua = navigator.userAgent.toLowerCase();
                                if(ua.match(/MicroMessenger/i)=="micromessenger") {
                                    $(".ann_download").hide()
                                }
                        })

                    }
                }, function(err) {
                });
            },
            handleMore: function() {
                this.listQuery.page++;
                this.getFileList();
            }
        },
    });
})