<template>
    <view class="page">
        <gallery :hideOnClick="false" @tab="tabClick" :showDelete="false" :show="show" @change="change" @hide="hide" :img-urls="imgUrls" :current="currentIndex - 1"></gallery>
    </view>
</template>

<script>
import Cache from '../../../../utils/cache';
import gallery from '@/pages/components/gallery/gallery';
// pages/showPicture/showPicture.js
export default {
    components: {
        gallery
    },
    data() {
        return {
            imgUrls: [],
            show: true,
            currentIndex: 0
        };
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var currentIndex = +options.currentIndex + 1;
        var arr = [];
        var tempPicture = Cache.get('tempPicture');
        for (var i = 0; i < tempPicture.length; i++) {
            arr.push(tempPicture[i].src ? tempPicture[i].src : tempPicture[i]);
        }
        this.setData({
            imgUrls: arr,
            currentIndex: currentIndex
        });
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {
        Cache.remove('tempPicture');
    },
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {
        Cache.remove('tempPicture');
    },
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {},
    methods: {
        tabClick: function (e) {
            console.log(e);
        },

        change(e) {},
        deleteFun(e) {},

        hide() {
            setTimeout(() => {
                uni.navigateBack({});
            }, 100);
        },

        showGallery(options) {
            var currentIndex = +options.currentIndex + 1;
            var arr = [];
            var tempPicture = Cache.get('tempPicture');
            for (var i = 0; i < tempPicture.length; i++) {
                arr.push(tempPicture[i].src ? tempPicture[i].src : tempPicture[i]);
            }
            this.setData({
                imgUrls: arr,
                currentIndex: currentIndex
            });
            currentIndex = 0;
            $wuxGallery().show({
                currentIndex,
                arr
            });
        }
    }
};
</script>
<style>
/* pages/showPicture/showPicture.wxss */
</style>
