<template>
    <!-- myPages/pages/deviceBatchList/deviceBatchList.wxml -->
    <view class="container">
        <view class="list">
            <view class="item" v-for="(item, index) in devicelist" :key="index">
                <view class="battery">{{ item.battery_sn }}</view>

                <view class="del-op" @tap="bindDel" :data-index="index">{{ $t('删除') }}</view>
            </view>
        </view>
    </view>
</template>

<script>
// myPages/pages/deviceBatchList/deviceBatchList.js
var storage = require('../../../common/storage.js');
export default {
    data() {
        return {
            devicelist: []
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad: function (options) {
		uni.setNavigationBarTitle({
			title: this.$t('设备列表')
		});
        const devicelist = storage.getBatchSelectedDeviceList();
        if (!devicelist || devicelist.length === 0) {
            uni.navigateBack({
                delta: 1
            });
        }
        this.setData({
            devicelist: devicelist
        });
    },
    methods: {
        bindDel: function (e) {
            const index = e.currentTarget.dataset.index;
            console.log(index);
            let devicelist = [];
            this.devicelist.forEach((item, idx) => {
                console.log(item, idx);
                if (index != idx) {
                    devicelist.push(item);
                }
            });
            storage.setBatchSelectedDeviceList(devicelist);
            this.setData({
                devicelist: devicelist
            });
        }
    }
};
</script>
<style>
@import './deviceBatchList.css';
</style>
