(function () {
    let baseUrl = '' //打包
    // let baseUrl = 'http://hnbwg.4dage.com' //本地测试

    let arr = []

    const getList = function (searchKey) {
        fetch(`${baseUrl}/api/show/goods/list`, {
            method: 'post',
            body: JSON.stringify({
                type: 'model',
                searchKey,
                pageSize:99999
            }),
            headers: {
                'Content-Type': 'application/json'
            }
        }).then(res => res.text()) //请求得到的数据转换为text
            .then(res => {
                let ul = document.querySelector('.con');
                ul.innerHTML = ''

                let res2 = JSON.parse(res)
                arr = res2.data.records

                // 如果没有数据
                if (arr.length === 0) {
                    $('.none').css({ opacity: 1, pointerEvents: 'auto' })
                } else {
                    $('.none').css({ opacity: 0, pointerEvents: 'none' })
                    let fragment = document.createDocumentFragment();
                    arr.forEach(v => {
                        let li = document.createElement('li');
                        let divWrap = document.createElement('div');
                        let a = document.createElement('a');
                        let div = document.createElement('div');
                        let p = document.createElement("p");
                        divWrap.classList.add('case');
                        a.classList.add('link-a');
                        a.href = `Model.html?m=${v.fileName}`;
                        div.classList.add('card-img');
                        div.style = `background-image: url(${v.thumb})`;
                        p.innerHTML = v.name;
                        a.appendChild(div);
                        divWrap.appendChild(a);
                        li.appendChild(divWrap);
                        li.appendChild(p);
                        fragment.appendChild(li);
                    })

                    ul.appendChild(fragment);

                }
            })
    }

    getList('')

    $('.search').keyup(function (e) {
        if (e.key === 'Enter') {
            let txt = $('.myInp').val().trim()
            getList(txt)
        }
    })

    $('.searImg').click(function () {
        let txt = $('.myInp').val().trim()
        getList(txt)
    })


})()