<template>
    <view class="flex direction-column height-100pre">
        <easy-tab type="line" @change="onTabChange">
            <easy-tab-item v-for="(item, index) in process">{{item.processName}}</easy-tab-item>
        </easy-tab>
        <view class="flex grow-1 height-0 width-100per">
            <page-dispatch ref="child" :url="url" :method="method" buttonText="派工" :buttonUrl="reportUrl"></page-dispatch>
        </view>
    </view>
</template>

<script>
    import url from '../../utils/url';
    import request from '../../utils/request';
    import user from '../../utils/user';

    let userinfo = user.get();

    export default {
        data() {
            return {
                url: 'dispatching-order/search',
                reportUrl: 'produce/dispatch',
                method: 'get',
                process: []
            };
        },
        async onLoad() {
            await this.getProcess();
            await this.getOrders();
        },
        async onShow() {
            console.log('userinfo:', userinfo);
        },
        methods: {
            onTabChange(e) {
                console.log(e);
            },

            async getProcess() {
                let res = await request.sendToken({
                    url: `${url.apiUrl}process/search`,
                    data: {
                        name: '',
                        groupNumber: '',
                        // workshopSectionId: 0,
                        opened: true
                    }
                });
                if (res.success) {
                    this.process = res.data.rows;
                    console.log('process:', res.data.rows);
                } else {
                    uni.showModal({
                        title: '错误',
                        content: res.message
                    });
                }
            },
            
            async getOrders(){
                let res = await request.sendToken({
                    url: `${url.apiUrl}dispatching-order/search`,
                    data: {
                        name: '',
                        groupNumber: '',
                        // workshopSectionId: 0,
                        opened: true
                    }
                });
                if (res.success) {
                    this.process = res.data.rows;
                    console.log('process:', res.data.rows);
                } else {
                    uni.showModal({
                        title: '错误',
                        content: res.message
                    });
                }
            }
        }
    }
</script>

<style lang="scss">

</style>