<template>
	<div >
		<right-dialog ref="rightDialog" @handleDialogClose="tableResult"></right-dialog>
		<base-layout title="人员信息" ref="layout" @pageChange="pageChange" :isPage="true" :showTitle="false"
			@onFuncBtn="getFuncBtn">
			<div slot="main" style="height: 100%;" slot-scope="{ tableHeight }">
				<base-table ref="customtable" :border="true" :showIndex="false" :slotrow="true"
					:tabLoading.sync="tabLoading" :tableHeight="tableHeight" :tableData="tableData"
					:tableColumn="tableColumn"  @radioChange="radioChange">
					<!-- 所属分类 -->
					<template v-slot:category="{row}">
						<p>{{row.row.category == '1'?'超级管理员':row.row.category == '2'?'管理员':'业务员'}}</p>
					</template>
					<!-- 角色分类 -->
					<template v-slot:roleType="{row}">
						<p>{{row.row.roleType | roleType}}</p>
					</template>
					<!-- 所属分类 -->
					<template v-slot:roleBond="{row}">
						<p>{{row.row.roleBond | roleBond}}</p>
					</template>
					<template v-slot:isBenchmark="{row}">
						<p>{{row.row.isBenchmark =='1'?'是':'否'}}</p>
					</template>
					<template v-slot:externalType="{row}">
						<p>{{row.row.externalType =='1'?'外部':'内部'}}</p>
					</template>
					<template v-slot:isEnable="{row}">
						<p>{{row.row.isEnable =='1'?'显示':'隐藏'}}</p>
					</template>
				</base-table>
			</div>
		</base-layout>
	</div>
</template>

<script>
import baseLayout from "@/components/base/baseLayout";
import BaseTable from '@/components/base/baseTable/index.vue'
import baseDialog from "@/components/base/BaseNewDialog/index.vue";
import BaseSelect from '@/components/base/BaseSelect'
import baseTree from "@/components/base/BaseMenuTree/index.vue";
import rightDialog from "./rightDialog";
import configData from "./configData";
	import {
		authApi
	} from '@/api/apis/auth'
export default {
	name: 'RoleSettings',
	components: {
		baseLayout,
		BaseTable,
		BaseSelect,
		baseDialog,
		baseTree,
		rightDialog
	},
	data() {
		return {
			radioIndex: false,
			radioId: false,
			radioForm: {},
			tabLoading: false,
			tableData: [],
			pageModel: {
				pageNum: 1,
				pageSize: 20,
			},
			tableColumn: configData.tableColumn,
		}
	},

	filters:{
		roleType(val){
			let roleTypeName = ''
			switch (val) {
				case '1':
					roleTypeName = '固定角色'
					break;
				case '2':
					roleTypeName = '相对角色'
					break;
				case '3':
					roleTypeName = '自建角色'
					break;
			}
			return roleTypeName
		},
		roleBond(val){
			let roleBondName = ''
			switch (val) {
				case '0':
					roleBondName = '集团角色'
					break;
				case '1':
					roleBondName = '单位角色'
					break;
				case '2':
					roleBondName = '部门角色'
					break;
				case '3':
					roleBondName = '不使用'
					break;
				case '4':
					roleBondName = '不使用'
					break;
				case '5':
					roleBondName = '业务生成器'
					break;
				case '6':
					roleBondName = 'sso'
					break;
			}
			return roleBondName
		}
	},
	mounted() {
		// this.$refs.baseTree.getMenuList()
		this.getTableList()
	},
	methods: {
		// 点击单元格进行多选操作
		radioChange(val) {
			this.radioIndex = val.index
			this.radioId = val.id
			this.radioForm = val
		},
		// 获取表格内容
		async getTableList() {
			this.radioIndex = false
			this.tabLoading = true
			setTimeout(()=>{
				this.tabLoading = false
			},100000)
			let params = {
				...this.pageModel
			}
			let res = await authApi('roleService','role','queryList','',params)
			if (res.status == '200') {
				this.$refs.layout.setPageTotal(res.attribute.total)
				this.$refs.customtable.clearRadioIndex()
				this.tableData = res.attribute.list
			}
			this.tabLoading = false
		},
		async delData(id) {
			let params = {
				id: id
			}
			let res = await authApi('roleService','role','delectEntity','',params)
			if(res.status == '200'){
				this.$vmNews("删除成功",'success')
				this.tableResult()
			}
		},
		getFuncBtn(btnEven) {
			if (btnEven.menuName == '新增') {
				this.frameTitle = '添加'
				this.$refs.rightDialog.openDialog('新增')
			}
			if (btnEven.menuName == '编辑') {
				if (this.radioIndex === false) {
					this.$vmNews('请选择一条记录')
				} else {
					this.$refs.rightDialog.openDialog('编辑',this.radioForm.id)
				}

			}
			if (btnEven.menuName == '删除') {
				if (this.radioIndex === false) {
					this.$vmNews('请选择一条记录')
				} else {
					this.$delConfirm().then(()=>{
						this.delData(this.radioId)
					})
				}
			}

		},
		tableResult() {
			this.radioForm = {}
			this.radioId = false
			this.radioIndex = false
			this.$refs.customtable.clearRadioIndex()
			this.pageModel.pageNum = 1
			this.$nextTick(() => {
				this.$refs.layout.pageClear(1)
				this.$refs.customtable.clearSelect();
			})
			this.getTableList()
		},
		// 页面改变时
		pageChange(model) {
			this.pageModel = model
			this.getTableList()
		},
	},
}
</script>

<style>
textarea {

	resize: none;

}
</style>
