$(function () {
    var info =[];
UrlSearch();
    function UrlSearch() {
        var name,value;
        // var str=location.href;
        var str = "http://apptest.jieweizhineng.com/assets/html/QRcoddetails/index.html?name=孙宇"+"&uuid=15017866"+"&pageId=447ecc7ad6664e8ab95fa3fbc7c12d52"+"&organizationIds=8136abdd0ffd4728b5bbf27106849394";
        var num=str.indexOf("?")
        str=str.substr(num+1);
        var arr=str.split("&");
        for(var i=0;i < arr.length;i++){
            num=arr[i].indexOf("=");
            if(num>0){
                name=arr[i].substring(0,num);
                value=arr[i].substr(num+1);
                this[name]=value;
                info.push(value)
            }
        }
    }
        var objs = {
            pageId:info[2],
            sourceType:'',
            organizationIds:info[3],
            userId:info[1],
            userName:info[0],
        };
    // setItem('organizationIds',info[3]);
    setItem('UserQrcode',JSON.stringify(objs));
    var base64 = new Base64(),num = 0;
    $.ajax({
        url: Url+'/page/v1/detailPage',
        type: 'get',
        dataType: 'json',
        data:objs,
        success: function (res) {
            console.log(res.data);
            for (var i = 0; i < res.data.pageItemList.length; i++) {
                var mnum = num++ +1;
                if (res.data.pageItemList[i].pageRelation.businessType === "TEXT" && res.data.pageItemList[i].pageRelation.zIndex == mnum) {
                    var str =`
                     <div class="m-card">
                         <div class="card">
                            <span>${res.data.pageItemList[i].textVo.title}</span>
                         </div>
                        <p>${base64.decode(res.data.pageItemList[i].textVo.dataContent)}</p>
                    </div>`;
                    $('.content').append(str)
                }else if (res.data.pageItemList[i].pageRelation.businessType === "IMAGE_TEXT" && res.data.pageItemList[i].pageRelation.zIndex == mnum) {
                    console.log(mnum,'mnum001')

                    var str = ` <div class="m-card imgText">
                    <div class="card">
                    <span>${res.data.pageItemList[i].imageText.title}</span>
                    </div>
                    <img src="${res.data.pageItemList[i].imageText.imageUrl}" alt="">
                    <p>${base64.decode(res.data.pageItemList[i].imageText.dataContent)}</p>
                    </div>`;
                    $('.content').append(str)
                }else if (res.data.pageItemList[i].pageRelation.businessType === "PICTURE" && res.data.pageItemList[i].pageRelation.zIndex == mnum) {
                    var str = `<div class="mui-content-padded">
                            <div class="swiper-container">
                                <div class="swiper-wrapper">
                                    
                                </div>
                                <div class="swiper-pagination"></div>
                            </div>
                        </div>`;
                    $('.content').append(str);
                    for (var j = 0; j < res.data.pageItemList[i].pictureList.length; j++) {
                        var html = `<div class="swiper-slide">
                            <a href="${res.data.pageItemList[i].pictureList[j].imageLinking}">
                                <img src="${res.data.pageItemList[i].pictureList[j].imageUrl}">
                                <div class="banner-tit">
                                     <p>${res.data.pageItemList[i].pictureList[j].imageTitle}</p>
                                </div>
                            </a>
                        </div>`;
                        $('.swiper-wrapper').append(html);
                        var swiper = new Swiper('.swiper-container', {
                            // autoplay: true,
                            loop:true,
                            pagination: {
                                el: '.swiper-pagination',
                                type: 'fraction',
                            },
                            autoplay: {
                                disableOnInteraction: false
                            }
                        });
                    }
                } else if (res.data.pageItemList[i].pageRelation.businessType === "FILE" && res.data.pageItemList[i].pageRelation.zIndex == mnum) {

                    var str = `<div class="m-card imgText">
                             <div class="card detMar">
                                 <span>${res.data.pageItemList[i].fileList[0].title}</span>
                            </div>
                        <div class="weui-panel weui-panel_access detMar">
                             <div class="weui-panel__bd file_list">
                             
                             </div>
                        </div>
                    </div>`;
                    $('.content').append(str);
                    var html ="";
                    for (var j = 0; j < res.data.pageItemList[i].fileList.length; j++) {
                        var fileTyle = res.data.pageItemList[i].fileList[j].fileName.substring(res.data.pageItemList[i].fileList[j].fileName.length-3);
                        // console.log(fileTyle,'fileTyle')；
                        if(fileTyle == 'zip' || fileTyle == 'rar' ){
                            html += `<div class="item">
                                    <a href="javascript:void(0);" class="weui-media-box weui-media-box_appmsg item_cell">
                                        <div class="weui-media-box__hd">
                                             <img class="weui-media-box__thumb" src="image/${fileTyle}.png">
                                        </div>
                                        <div class="weui-media-box__bd">
                                             <h4 class="weui-media-box__title">${res.data.pageItemList[i].fileList[j].fileName}</h4>
                                             <p class="weui-media-box__desc">${res.data.pageItemList[i].fileList[j].fileSize}</p>
                                        </div>
                                        <div class="weui-cell__ft"></div>
                                    </a>
                                    <div class="See_download">
                                        <button class="download"><a href="${res.data.pageItemList[i].fileList[j].filePath}">下载</a></button>
                                    </div>
                            </div>`
                        }else if (fileTyle == 'pdf') {
                            html += `<div class="item">
                                <a href="javascript:void(0);" class="weui-media-box weui-media-box_appmsg item_cell">
                                    <div class="weui-media-box__hd">
                                         <img class="weui-media-box__thumb" src="image/${fileTyle}.png">
                                    </div>
                                    <div class="weui-media-box__bd">
                                         <h4 class="weui-media-box__title">${res.data.pageItemList[i].fileList[j].fileName}</h4>
                                         <p class="weui-media-box__desc">${res.data.pageItemList[i].fileList[j].fileSize}</p>
                                    </div>
                                    <div class="weui-cell__ft"></div>
                                </a>
                                <div class="See_download">
                                    <button class="download downloadPDF" file-Url="${res.data.pageItemList[i].fileList[j].filePath}">
                                    下载
                                    </button>
                                    <button class="See seePdf" file-Url="${res.data.pageItemList[i].fileList[j].filePath}">预览</button>
                            </div>
                        </div>`
                        }else if (fileTyle == 'lsx') {
                            html += `<div class="item">
                                <a href="javascript:void(0);" class="weui-media-box weui-media-box_appmsg item_cell">
                                    <div class="weui-media-box__hd">
                                         <img class="weui-media-box__thumb" src="image/${fileTyle}.png">
                                    </div>
                                    <div class="weui-media-box__bd">
                                         <h4 class="weui-media-box__title">${res.data.pageItemList[i].fileList[j].fileName}</h4>
                                         <p class="weui-media-box__desc">${res.data.pageItemList[i].fileList[j].fileSize}</p>
                                    </div>
                                    <div class="weui-cell__ft"></div>
                                </a>
                                <div class="See_download">
                                  <button class="download"><a href="${res.data.pageItemList[i].fileList[j].filePath}">下载</a></button>
                                  <button class="See seeXlsx" file-Url="${res.data.pageItemList[i].fileList[j].filePath}">预览</button>
                            </div>
                        </div>`;
                        }else if (fileTyle == 'doc') {
                            html += `<div class="item">
                                <a href="javascript:void(0);" class="weui-media-box weui-media-box_appmsg item_cell">
                                    <div class="weui-media-box__hd">
                                         <img class="weui-media-box__thumb" src="image/${fileTyle}.png">
                                    </div>
                                    <div class="weui-media-box__bd">
                                         <h4 class="weui-media-box__title">${res.data.pageItemList[i].fileList[j].fileName}</h4>
                                         <p class="weui-media-box__desc">${res.data.pageItemList[i].fileList[j].fileSize}</p>
                                    </div>
                                    <div class="weui-cell__ft"></div>
                                </a>
                               <div class="See_download">
                                    <button class="download"><a href="${res.data.pageItemList[i].fileList[j].filePath}">下载</a></button>
                                    <button class="See seeDoc" file-Url="${res.data.pageItemList[i].fileList[j].filePath}">预览</button>
                            </div>
                        </div>`;

                        }else if (fileTyle == 'ptx' || fileTyle == 'ppt') {
                            html += `<div class="item">
                                <a href="javascript:void(0);" class="weui-media-box weui-media-box_appmsg item_cell">
                                    <div class="weui-media-box__hd">
                                         <img class="weui-media-box__thumb" src="image/${fileTyle}.png">
                                    </div>
                                    <div class="weui-media-box__bd">
                                         <h4 class="weui-media-box__title">${res.data.pageItemList[i].fileList[j].fileName}</h4>
                                         <p class="weui-media-box__desc">${res.data.pageItemList[i].fileList[j].fileSize}</p>
                                    </div>
                                    <div class="weui-cell__ft"></div>
                                </a>
                               <div class="See_download">
                                <button class="download"><a href="${res.data.pageItemList[i].fileList[j].filePath}">下载</a></button>
                                <button class="See seePpt" file-Url="${res.data.pageItemList[i].fileList[j].filePath}">预览</button>
                            </div>
                        </div>`;

                        }
                        $('.file_list').html(html);
                    }
                }else if (res.data.pageItemList[i].pageRelation.businessType === "LINKS" && res.data.pageItemList[i].pageRelation.zIndex == mnum) {
                    var str = `<div class="m-card">
                         <div class="card">
                        <span>${res.data.pageItemList[i].linksList[0].title}</span>
                        </div>
                        <div class="weui-cells link_items">
                        
                         </div>
                     </div>`;
                    $('.content').append(str);
                    for (var j = 0; j < res.data.pageItemList[i].linksList.length; j++) {
                        var html=` <a class="weui-cell" hrefs="${res.data.pageItemList[i].linksList[j].linkUrl}" href="${res.data.pageItemList[i].linksList[j].linkUrl}">
                                <div class="weui-cell__hd">
                                <img src="image/link.png">
                                </div>
                                <div class="weui-cell__bd">
                                <p>${res.data.pageItemList[i].linksList[j].linkName}</p>
                                </div>
                            <div class="weui-cell__ft"></div>
                            </a>`;
                        $('.link_items').append(html);
                    }
                }else if (res.data.pageItemList[i].pageRelation.businessType === "EQUIPMENT" && res.data.pageItemList[i].pageRelation.zIndex == mnum) {
                    var str = `
                    <div class="m-card imgText">
                        <div class="card detMar">
                             <span>${res.data.pageItemList[i].equipmentList[0].title}</span>
                        </div>
                        <div class="weui-form-preview__bd itemsa">
                             <div class="weui-form-preview__item fistItem">
                                <label class="weui-form-preview__label">名称</label>
                                <span class="weui-form-preview__value">内容</span>
                             </div>
                        </div>
                    </div>`;
                    $('.content').append(str);
                    for (var j = 0; j < res.data.pageItemList[i].equipmentList.length; j++) {
                        var html = ` <div class="weui-form-preview__item">
                            <label class="weui-form-preview__label">${res.data.pageItemList[i].equipmentList[j].paramName}</label>
                            <span class="weui-form-preview__value">${res.data.pageItemList[i].equipmentList[j].paramContent}</span>
                        </div>`;
                        $('.fistItem').after(html);

                    }
                }else if (res.data.pageItemList[i].pageRelation.businessType === "RECORD" && res.data.pageItemList[i].pageRecordList !=null) {
                    $('.addRecord').show();
                    $('.content').css("margin-bottom", "66px");
                    var str = `<li>
                        <p>
                            ${res.data.pageItemList[i].pageRecordList[0].recordName}
                            <i class="icoRight"></i>
                        </p>
                        <ul class="ul_son">
                            <li recordId="${res.data.pageItemList[i].pageRecordList[0].id}" templateId="${res.data.pageItemList[i].pageRecordList[0].templateId}" templateName="${res.data.pageItemList[i].pageRecordList[0].templateName}">
                                ${res.data.pageItemList[i].pageRecordList[0].templateName}
                                <i class="icoRight"></i>
                            </li>
                        </ul>
                    </li>`;
                    $('.record_items').append(str);
                    var recordItems = `<li class="nav-item" recordTerm-id="${res.data.pageItemList[i].pageRecordList[0].parentId}" QRcode-id="${res.data.page.id}">
                                        <a href="javascript:void(0);">
                                            <i class="icon nav-icon icon-49"></i>
                                            <span>${res.data.pageItemList[i].pageRecordList[0].templateName}</span>
                                            <i class="icon icon-108 Posa"></i>
                                        </a>
                                    </li>`;
                    $('.recordItems').append(recordItems);
                }
            }
        },
        error:function () {

        }
    });
    $('body').on('click','.item .cell-item',function () {
        $(this).find('.cell-arrow').toggleClass('cell-arrowIco');
        $(this).parent().find('.See_download').toggleClass('show');
    });
    $('body').on('click','.seeXlsx',function () {
        var url = $(this).attr('file-Url');
        window.open('https://view.officeapps.live.com/op/view.aspx?src='+url)
    });
    $('body').on('click','.seeDoc',function () {
        var url = $(this).attr('file-Url');
        window.open('https://view.officeapps.live.com/op/view.aspx?src='+url)
    });
    $('body').on('click','.downloadPDF',function () {
        var url = $(this).attr('file-Url');
        window.location.href = url;

    });
    $('body').on('click','.seePdf',function () {
        var url = $(this).attr('file-Url');
        setItem('pdfUrl',url);
        window.open('http://apptest.jieweizhineng.com/assets/html/QRcoddetails/pdf.html');
    });
    $('body').on('click','.seePpt',function () {
        var url = $(this).attr('file-Url');
        window.open('https://view.officeapps.live.com/op/view.aspx?src='+url)
    });
    $('body').on('click','.ul_son li',function () {
        var recordId = $(this).attr('recordId'),templateId = $(this).attr('templateId'),templateName= $(this).attr('templateName');
        setItem('templateName',templateName);
        location.href = "addRecord.html?recordId="+recordId+"&parentId="+JSON.parse(getItem('UserQrcode')).pageId+"&templateId="+templateId;
    });
    $('body').on('click','.nav-item',function () {
        location.href = 'static/note-list.html?pageId='+JSON.parse(getItem('UserQrcode')).pageId+'&pageRecordParentId='+$(this).attr('recordTerm-id')
    })
});