<template>
    <view class="container">
        <cu-custom id="custom"
            bgImage="https://yostest175549.obs.cn-east-2.myhuaweicloud.com:443/202306151686796745663B52544232.png"
            :isBack="true">
            <block slot="backText">返回</block>
            <block slot="content">
                工单
            </block>
        </cu-custom>
        <My_search ref="My_search" @onFilter="onFilter" @startSearch="startSearch" dateRange />
        <My_listbox ref="List" @getlist="getlist" :empty='empty'>
            <list :list1="list" />
        </My_listbox>
    </view>
</template>

<script>
import { list } from "../../pages/index/modules/workorderList.vue"
export default {
    components: { list },
    name: "workOrder",
    data() {
        return {
            empty: true,
            "content": {
                "pageNumber": 1,
                "pageSize": 20,
                "pageTotal": 1,
                "where": {
                    "condition": "",
                    "begindate": "",
                    "enddate": ""
                }
            },
            list: []
        }
    },
    mounted() {
        this.getlist();
    },
    methods: {
        getlist(init = false) {
            let content = this.content;
            if (init) content.pageNumber = 1;
            if (content.pageNumber > content.pageTotal) return;
            this.$Http.basic({
                "id": "20231007095502",
                content
            }).then(res => {
                console.log("获取工单列表", res)
                if (this.cutoff(res.msg)) return;
                this.$refs.List.RefreshToComplete();
                this.$refs.List.setHeight();
                this.$refs.My_search.onFinish()
                this.empty = !res.data.length;
                content.pageNumber = res.pageNumber + 1;
                content.pageTotal = res.pageTotal;
                let list = res.data.map(v => {
                    switch (v.sourcetable) {
                        case "w_eventid":
                            v.source = "巡检：" + (v.planno || ' --')
                            break;
                        case "w_event_log":
                            v.source = "告警：" + (v.eventname || ' --')
                            break;
                        default:
                            v.source = "现场"
                            break;
                    }
                    v.users = v.teamRows.map(u => u.name)
                    return v
                })
                this.list = res.pageNumber == 1 ? list : this.list.concat(list)
                this.content = content;
            })
        },
        startSearch(e) {
            this.content.where.condition = e;
            this.getlist(true)
        },
        onFilter(e) {
            let where = this.content.where,
                condition = where.condition;
            where = e;
            where.condition = condition;
            this.content.where = where;
            this.getlist(true)
        }
    }
}
</script>

<style lang="scss" scoped>
</style>
