<template>
    <!-- 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">删除</view>
            </view>
        </view>
    </view>
</template>

<script>
// pages/deviceBatchList/deviceBatchList.js
var storage = require('../../common/storage.js');
export default {
    data() {
        return {
            devicelist: []
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad: function (options) {
        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>
