<template>
    <view v-show="show">
        <view v-if="isfeedback && total" class="clear" @click="clearList">
            <view class="total">共 {{ total }} 条</view>
            <view class="clear-but" hover-class="navigator-hover">
                清空队列
            </view>
        </view>
        <operate-list :list="list" />
    </view>
</template>

<script>
let paging = {}
import operateList from "./operateList";
export default {
    components: { operateList },
    name: "queue",
    props: {
        w_deviceid: String,
        isfeedback: {
            type: [String, Number]
        }
    },
    data() {
        return {
            total: 0,
            show: false,
            uninitialized: true,
            list: [],
            "where": {
                "begindate": "",
                "enddate": ""
            }
        }
    },
    methods: {
        getList(init = false) {
            if (init) paging = {
                pageNumber: 1,
                pageTotal: 1,
            };
            return new Promise((resolve) => {
                if (paging.pageNumber > paging.pageTotal) return resolve()
                this.$Http.basic({
                    "id": 20230701132202,
                    "content": {
                        "type": 2,
                        "w_deviceid": this.w_deviceid,
                        ...paging,
                        "where": this.where
                    }
                }).then(res => {
                    console.log('操作队列', res)
                    resolve(!this.cutoff(res.msg));
                    if (this.cutoff(res.msg)) return;
                    paging.pageNumber = res.pageNumber + 1;
                    paging.pageTotal = res.pageTotal;
                    this.list = res.pageNumber == 1 ? res.data : this.list.concat(res.data)
                    this.total = res.total;
                })
            })
        },
        clearList() {
            let that = this;
            uni.showModal({
                title: '提示',
                content: '是否确定清空操作队列',
                success: function (res) {
                    if (res.confirm) that.$Http.basic({
                        "id": 20231128145402,
                        "content": {
                            w_deviceid: that.w_deviceid
                        }
                    }).then(res => {
                        if (that.cutoff(res.msg, '已清空队列')) return;
                        that.getList(true)
                    })
                }
            });
        }
    },
}
</script>

<style lang="scss" scoped>
.clear {
    display: flex;
    justify-content: space-between;
    color: #fff;
    width: 100vw;
    padding: 0 18px 10px;
    box-sizing: border-box;
    font-size: 12px;
}
</style>