<template>
    <view class="padding box-border">
        <view class="flex padding-tb-20 border-list" v-for="(item, index) in rows">
            <view class="grow-1 flex items-center">{{item.teamName}}</view>
            <view class="flex items-center">
                <button size="mini" type="primary" @tap="select(item.workingTeamId, item.teamName)"> 选择</button>
            </view>
        </view>
    </view>
</template>

<script>
    import extend from '../../utils/extend';
    import request from '../../utils/request';
    import message from '../../utils/message';

    export default {
        data() {
            return {
                rows: []
            };
        },
        async onLoad() {
            await this.load();
        },
        methods: {
            async load() {
                uni.showLoading();
                let res = await request.sendToken({
                    url: 'working-team/search',
                    data: {
                        opened: true
                    }
                });
                uni.hideLoading();
                if (res.success) {
                    if (extend.isObject(res.data) && extend.isArray(res.data.rows)) {
                        this.rows = res.data.rows;
                        console.log(res.data.rows);
                    }
                } else {
                    uni.showModal({
                        title: '错误',
                        content: res.message
                    });
                }
            },

            getRow(workingTeamId) {
                let res = null;
                for (let i = 0; i < this.rows.length; i++) {
                    if (this.rows[i].workingTeamId === workingTeamId) {
                        res = this.rows[i];
                        break;
                    }
                }
                return res;
            },

            select(workingTeamId, teamName) {
                let row = this.getRow(workingTeamId);
                if (extend.isObject(row)) {
                    extend.addStorage('select_workingTeam', row);
                    uni.navigateBack();
                }
            }
        }
    }
</script>

<style lang="scss">

</style>