<?php
/**
 * 管理员管理
 * $Id: account_list.inc,v 1.1 2015/10/08 11:18:50 wanggb Exp $
 * @author netvillage
 * @access public
 * @package manager.templates
 */

global $account_list;
global $account_count;

?>
<div id="classSetting">
	<div class="list_title">
		账号管理-账号分配
		 <div style="float: right;">
			<el-button type="primary" style="margin-right: 10px;" @click="addAccount()">新建账号</el-button>
		</div>
	</div>

  <br />
  <div class="result_list">
  	<el-table :data="tableData" border>
  		<el-table-column  prop="id" label="编号" ></el-table-column>
  		<el-table-column  prop="role" label="角色名称" width=""></el-table-column>
  		<el-table-column  prop="login" label="账号" width=""></el-table-column>
  		<el-table-column  prop="password" label="原始密码" width=""></el-table-column>
  		<el-table-column  prop="comment" label="账号备注" width=""></el-table-column>
  		<el-table-column  prop="registration_date" label="创建日期" width=""></el-table-column>
  		<el-table-column  label="操作"  width="100">
  			<template slot-scope="scope">
  				<el-button @click="handleChange(scope.row)" type="text" size="small">编辑</el-button>
  				<el-button type="text" size="small" @click.native.prevent="deleteRow(scope.row)">删除</el-button>
  			</template>
  			</el-table-column>
  	</el-table>
  </div>
</div>
<?
	if ($account_count > 0) {
?>
<!--page begin-->
<?
require_once("page_common.inc");
?>
<!--page end-->
<?
}
?>
<script type="text/javascript">
	var list=[];
	<?
	foreach ($account_list as $account_mst) {
	?>
		var data={
			id:<?=$account_mst->id ?>,
			role:'<?=AccountRole::getTitleById($account_mst->role) ?>',
			login:'<?=htmlspecialchars($account_mst->login)?>',
			password:'<?=htmlspecialchars($account_mst->password)?>',
			comment:'<?=htmlspecialchars($account_mst->comment) ?>',
			registration_date:'<?=htmlspecialchars($account_mst->registration_date) ?>'
		};
		list.push(data);
	<?
	}
	?>

	new Vue({
		el:'#classSetting',
		data:{
			tableData: list
		},
		methods:{
			handleChange(row) {
		  	console.log(row);
		  	window.location.href='account_edit_input.php?id='+row.id;
		  },
		  deleteRow(rows) {
	    	this.$confirm('是否删除?', '提示', {
		    	confirmButtonText: '确定',
		    	cancelButtonText: '取消',
		    	type: 'warning'
		 		}).then(() => {
		    	this.$message({
		      	type: 'success',
		      	message: '删除成功!'
		     	});
//	        		rows.splice(index, 1);
					window.location.href='account_delete_result.php?id='+rows.id;
		   	}).catch(() => {
		    	this.$message({
		      	type: 'info',
		      	message: '已取消删除'
		    	});          
		    });
	    },
	    addAccount(){
	    	window.open('account_new_input.php','_self')
	    }
		}
	})
</script>

