<template>
    <div class='app-todo-list'>
        <el-table :data="myTasks" :border="true" style="width: 100%">
            <el-table-column prop="" sortable label="标题">
                <template slot-scope="scope">
                    <span class="title" @click="handleClick(scope.row)">{{ scope.row.description }}</span>
                </template>
            </el-table-column>
            <el-table-column prop="processDefinitionName" sortable label="流程" width="200">
            </el-table-column>
            <el-table-column prop="name" sortable label="状态" width="200">
            </el-table-column>
            <el-table-column prop="createTime" sortable label="创建时间" width="200">
            </el-table-column>
        </el-table>
    </div>
</template>

<script lang = 'ts'>
import { Environment } from '@/environments/environment';
import { Component, Vue } from 'vue-property-decorator';

@Component({
})
export default class AppTodoList extends Vue {

    /**
     * 待办数据
     */
    public myTasks: any[] = [];

    /**
     * vue创建
     */
    created(): void {
        this.getMyTasks();
    }

    /**
     * 获取待办列表
     */
    public getMyTasks() {
        let url: any = '/wfcore/mytasks';
        this.$http.get(url).then((response: any) => {
            if (response && response.status == 200) {
                const data: any = response.data;
                if (data && data.length > 0) {
                    this.myTasks = data;
                } else {
                    this.myTasks = [];
                }
            }
        }).catch((error: any) => {
            const message = error.message ? error.message : '加载数据错误';
            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: message });
        })
    }


    /**
     * 处理点击
     */
    public handleClick(data: any) {
        if (!data) return;
        const baseUrl: any = Environment.BaseUrl;
        this.$http.get(baseUrl + `/wfcore/mytasks/${data.processDefinitionKey}/web/${data.processInstanceBusinessKey}/usertasks/${data.taskDefinitionKey}`).then((response: any) => {
            const { status, data } = response;
            if (status && status == 200) {
                const url = data.substr(data.indexOf("#") + 1);
                const indexPath = this.$viewTool.getIndexRoutePath(this.$route);
                this.$router.push({ path: `${indexPath}${url}` });
            } else {
                const message = data.message ? data.message : '跳转失败';
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: message });
            }
        }).catch((error: any) => {
            const message = error.message ? error.message : '跳转失败';
            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: message });
        })
    }

}
</script>

<style lang="less">
@import './app-todo-list.less';
</style>