<template>
    <div>
        <div class="content">
            <dataBreadcrumb :breads="breads"></dataBreadcrumb>
            <el-button type="primary" @click="add">创建新的角色</el-button>
            <dataTable :table-data="tableData" :columns="columns" :is-pageobj="false" :tableTop="30">
                <el-table-column slot="operate" label="操作" align="center" fixed="right">
                    <template slot-scope="scope">
                        <el-button type="text" size="small" @click="see(scope.row)">查看</el-button>
                        <el-button type="text" size="small" @click="handdelete(scope.row)" v-if="scope.row.roleId !== 1">删除</el-button>
                    </template>
                </el-table-column>
            </dataTable>
        </div>
    </div>
</template>

<script>
import { roleList, roledelete } from '@api/purchaser/organization';
import dataTable from '@components/nopageTable.vue';
import dataBreadcrumb from '@components/dataBreadcrumb.vue';
export default {
    components: {
        dataTable,
        dataBreadcrumb
    },
    data() {
        return {
            breads: ['系统管理', '角色管理'],
            tableData: [],
            columns: [
                {
                    label: '角色名称',
                    prop: 'roleName',
                    width: 400
                },
                {
                    label: '备注',
                    prop: 'remark',
                    width: 400
                },
                {
                    slot: 'operate'
                }
            ], // 操作列

            pageObj: {
                size: 10,
                total: 1,
                currentPage: 1,
                sizes: [100, 200, 300],
                func: (currentPage) => {
                    this.pageTurning(currentPage);
                }
            }
        };
    },
    methods: {
        // 删除
        async handdelete(row) {
            try {
                await this.$confirm('确定要删除么？', '提示', {
                    type: 'warning'
                });
                const { msg, code } = await roledelete(row.roleId);
                if (code == 200) {
                    this.$message.success(msg);
                    this.getroleList();
                } else {
                    this.$message.error(msg);
                }
            } catch (e) {
                console.log(e);
            }
        },
        see(row) {
            this.$router.push(`/supply/organization/jurisdictionSee?id=${row.roleId}`);
        },
        add() {
            this.$router.push('/supply/organization/jurisdictionSee');
        },
        async getroleList() {
            let type = JSON.parse(localStorage.getItem('userInfo')).type;
            const { data, code } = await roleList(type);
            for (let item of data) {
                if (!item.remark) {
                    item.remark = '空';
                }
            }
            this.tableData = data;
        }
    },
    created() {
        this.getroleList();
    }
};
</script>

<style scoped>
</style>
