{extend name="main"}
{block name="body"}
<div class="bg-white mb-3">
	<el-form :model="search" @submit.native.prevent="submitForm" ref="search" label-position="right" class="flex py-3">

	  <el-form-item label="角色" prop="rid" class="flex mb-0 pl-3">
	    <el-select v-model="search.rid" placeholder="请选择">
	      <el-option
	        :key="0"
	        :label="'全部'"
	        :value="0">全部
	      </el-option>
	      <el-option
	        v-for="item in role"
	        :key="item.rid"
	        :label="item.title"
	        :value="item.rid">{{item.title}}
	      </el-option>
	    </el-select>
	  </el-form-item>

	  <el-form-item label="状态" prop="status" class="flex mb-0 pl-3">
	  	<el-select v-model="search.status" placeholder="请选择" class="w-100px">
		    <el-option label="全部"value="all"></el-option>
		    <el-option label="启用":value="0"></el-option>
		    <el-option label="禁用":value="1"></el-option>
		</el-select>
	  </el-form-item>

	  <el-form-item label="昵称" prop="nickname" class="flex mb-0 pl-3">
	    <el-input v-model="search.nickname" placeholder="请输入你想搜索的关键词"></el-input>
	  </el-form-item>
	  <el-form-item label="账号" prop="username" class="flex mb-0 pl-3">
	    <el-input v-model="search.username" placeholder="请输入你想搜索的关键词"></el-input>
	  </el-form-item>

	  <el-form-item class="flex mb-0 pl-3">
	    <el-button type="primary" @click="initHtml">查询</el-button>
	    <el-button @click="resetForm('search')">重置</el-button>
	  </el-form-item>
	</el-form>
</div>
<div class="bg-white p-3">
	<div class="table-responsive">
		<el-table
			ref="tableList"
	      	:data="tableData"
    		v-loading="search.ajax"
    		style="width: 100%;"
    		header-cell-class-name="table-header-DDE6FB">
	      <el-table-column
	        prop="id"
	        label="ID"
	        width="60">
	      </el-table-column>
	      <el-table-column
	        prop="title"
	        label="角色"
	        width="100">
	      </el-table-column>
	      <el-table-column
	        label="账户"
	        width="180">
		      <template slot-scope="scope">
		      	<div class="flex flex-center">
					<el-image
					  	v-if="scope.row.headimg" 
					    style="width: 30px; height: 30px"
					    lazy
					    class="rounded-circle mr-2"
					    :src="scope.row.headimg" 
					    :preview-src-list="[scope.row.headimg]">
					</el-image>
		      		<div class="text-primary">
						{{scope.row.nickname}}
		      		</div>
		      	</div>
	      		<div>
					{{scope.row.username}}
	      		</div>
		      </template>
	      </el-table-column>
	      <el-table-column
	        label="工作日"
	        min-width="400">
		      <template slot-scope="scope">
		      	<el-tag type="success" size="mini" class="mr-1" v-for="v in scope.row.allow_week">{{XYBase.config.weekText[v]}}</el-tag>
		      </template>
	      </el-table-column>
	      <el-table-column
	        label="允许登录时间"
	        width="180">
		      <template slot-scope="scope">
		      	{{scope.row.allow_time_start}}:00 ~ {{scope.row.allow_time_end}}:59
		      </template>
	      </el-table-column>
	      <el-table-column
	        label="状态"
	        width="80">
		      <template slot-scope="scope">
		      	<transition>
		      		<el-button type="success" size="minism"
		      		v-if="scope.row.status==1 || scope.row.status==2" 
		      		@click="setAdminStatus(scope.row);" 
		      		:loading="scope.row.status==2">正常</el-button>
		      		<el-button type="info" size="minism" 
		      		v-else="scope.row.status==0 || scope.row.status==2" 
		      		@click="setAdminStatus(scope.row);" 
		      		:loading="scope.row.status==2">禁用</el-button>
				</transition>
		      </template>
	      </el-table-column>
	      <el-table-column
	        label="默认顾问"
	        width="80">
		      <template slot-scope="scope">
		      	<transition>
		      		<span class="text-success" size="minism"
		      		v-if="scope.row.adviser_default==1">是</span>
		      		<span class="text-secondary" size="minism" 
		      		v-else="scope.row.adviser_default==0">否</span>
				</transition>
		      </template>
	      </el-table-column>
	      <el-table-column
	        label="创建/更新/最后登录时间"
	        width="200">
		      <template slot-scope="scope">
		        <div class="small">
		          <div>{{ scope.row.create_time }}</div>
		          <div>{{ scope.row.update_time }}</div>
		          <div>{{ scope.row.login_time }}</div>
		        </div>
		      </template>
	      </el-table-column>
	      <el-table-column
	        label="/"
	        width="230">
		      <template slot-scope="scope">
		        <el-button
		            type="primary"
		            plain
		            round
		            size="minism"
		            @click="window.open('/editAdmin/'+scope.row.id)">
		            编辑
		        </el-button>
		        <el-button
		            type="info"
		            plain
		            round
		            size="minism"
		            @click="window.open('/editAdmin/'+scope.row.id+'#LoginLog')">
		            登录日志
		        </el-button>
		        <el-button
		            type="info"
		            plain
		            round
		            size="minism"
		            @click="window.open('/editAdmin/'+scope.row.id+'#Log')">
		            操作日志
		        </el-button>
		      </template>
	      </el-table-column>
	    </el-table>
	</div>
	<div class="table-responsive py-3 text-center">
		<el-pagination
		  background
	      @size-change="handleSizeChange"
	      @current-change="handleCurrentChange"
	      :current-page="search.page"
	      :page-sizes="[10,50,100,200]"
	      :page-size="search.pageSize"
	      layout="total, sizes, prev, pager, next, jumper"
	      :total="search.total">
	    </el-pagination>
	</div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
	{empty name="role"}
	var role=[];
	{else/}
	var role={:json_encode($role,JSON_UNESCAPED_UNICODE)};
	{/empty}
</script>
<script type="text/javascript">
	var vm=new Vue({
		el:'#app',
		data:{
			view:XYBase.view,
			role:role,
			labelPosition:'right',
			search:{
				rid:0,
				nickname:'',
				username:'',
				status:'all',
				ajax:false,
				page:1,
				total:0,
				pageSize:10
			},
			tableData:[],
		},
		watch:{
		    view:XYBase.viewWatch,
		},
		created(){
			XYBase.created(this);
		},
	    methods: {
	    	setAdminStatus(data){
	    		if (data.status==2) return;
	    		var status=1,oldStatus=data.status;
	    		if (data.status) status=0;
	    		data.status=2;
	    		$.getJSON('/setAdminStatus/'+data.id+'/'+status,function(ret){
	    			data.status=oldStatus;
	    			if (ret) {
	    				if (ret.code === 0) {
	    					data.status=status;
	    				}else{
	    					XYBase.msg(ret.msg);
	    				}
	    			}else{
						XYBase.error(XYBase.config.system_network_error);
	    			}
	    		});
	    	},
			resetForm:function(formName) {
				this.$refs[formName].resetFields();
			},
			handleSizeChange(val) {
				this.search.page=1;
				this.search.pageSize=val;
	          	this.initHtml();
			},
			handleCurrentChange(val) {
				this.search.page=val;
	          	this.initHtml();
			},
	      	initHtml() {
	      		var _this=this;
	      		_this.search.ajax=true;
				$.ajax({
					url:'',
					type:'get',
					data:_this.search,
					dataType:'json',
					error:function(err){
	      				_this.search.ajax=false;
						XYBase.error(XYBase.config.system_network_error);
					},
					success:function(ret){
	      				_this.search.ajax=false;
						if (ret) {
							if (ret.code === 0) {
								_this.search.total=ret.data.total;
								_this.tableData=ret.data.data;
							}else{
								XYBase.msg(ret.msg);
							}
						}else{
							XYBase.error(XYBase.config.system_network_error);
						}
					}
				});
			}
	    }
	});
	$(function(){
		vm.initHtml();
		reloadWindowSize();
		$(window).resize(function(){
			reloadWindowSize();
		});
	});
	function reloadWindowSize (argument) {
		var winW=$(window).width();
		if(winW <= 576){
			vm.labelPosition='top';
		}else{
			vm.labelPosition='right';
		}
	}
</script>
{/block}