{extend name="main"}
{block name="style"}
<style type="text/css">
	.flex-lable{width: 100px;color: #6c757d;text-align: right;padding-right: 10px;}
</style>
{/block}
{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="search_type" class="flex mb-0 pl-3">
	  	<el-select v-model="search.search_type" placeholder="请选择" class="w-100px">
		    <el-option key="uid"label="UID"value="uid"></el-option>
		    <el-option key="app_openid"label="APPOpenId"value="app_openid"></el-option>
		    <el-option key="pc_openid"label="PCOpenId"value="pc_openid"></el-option>
		    <el-option key="unionid"label="UnionId"value="unionid"></el-option>
		</el-select>
	  </el-form-item>

	  <el-form-item :label="getSearchType()" prop="key" class="flex mb-0 pl-3">
	    <el-input v-model="search.key" 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
	      	:data="tableData"
    		v-loading="search.ajax"
    		style="width: 100%;"
    		header-cell-class-name="table-header-DDE6FB"
    		@expand-change="getUserInfo">
    		<el-table-column type="expand" width="20">
		      <template slot-scope="scope">
		      	<div class="flex" v-if="scope.row.user_info==1">
		      		<div class="flex-1">
		      			<div class="flex flex-center pb-3">
		      				<div class="flex-lable">UID</div>
		      				<div class="flex-1">{{scope.row.data.id}}</div>
		      			</div>
		      			<div class="flex flex-center pb-3">
		      				<div class="flex-lable">用户</div>
		      				<div>
								<el-image
								  	v-if="scope.row.data.headimg" 
								    style="width: 30px; height: 30px"
								    lazy
								    class="rounded-circle mr-2"
								    :src="scope.row.data.headimg" 
								    :preview-src-list="[scope.row.data.headimg]">
								</el-image>
							</div>
		      				<div class="flex-1">
								{{scope.row.data.nickname}}
		      				</div>
		      			</div>
		      			<div class="flex flex-center pb-3">
		      				<div class="flex-lable">账号</div>
		      				<div class="flex-1">{{scope.row.data.user}}</div>
		      			</div>
		      			<div class="flex flex-center pb-3">
		      				<div class="flex-lable">手机号</div>
		      				<div class="flex-1">{{scope.row.data.mobile}}</div>
		      			</div>
		      			<div class="flex flex-center pb-3">
		      				<div class="flex-lable">邮箱</div>
		      				<div class="flex-1">{{scope.row.data.email}}</div>
		      			</div>
		      			<div class="flex flex-center pb-3">
		      				<div class="flex-lable">实名</div>
		      				<div class="flex-1" v-if="scope.row.data.name">{{scope.row.data.name}} {{scope.row.data.idcard}}</div>
		      				<div class="flex-1 text-secondary" v-else="scope.row.data.name">未实名</div>
		      			</div>
		      			<div class="flex flex-center pb-3">
		      				<div class="flex-lable">当前身份</div>
		      				<div class="flex-1 text-primary" 
		      				v-if="scope.row.data.role_type">企业</div>
		      				<div class="flex-1 text-success" 
		      				v-else="scope.row.data.role_type">个人</div>
		      			</div>
		      			<div class="flex flex-center pb-3" v-if="scope.row.data.pid">
		      				<div class="flex-lable">上级</div>
		      				<div>
								<el-image
								  	v-if="scope.row.data.pheadimg" 
								    style="width: 30px; height: 30px"
								    lazy
								    class="rounded-circle mr-2"
								    :src="scope.row.data.pheadimg" 
								    :preview-src-list="[scope.row.data.pheadimg]">
								</el-image>
							</div>
		      				<div class="flex-1">
								{{scope.row.data.pid}}{{scope.row.data.pnickname}}
		      				</div>
		      			</div>
		      			<div class="flex flex-center pb-3">
		      				<div class="flex-lable">禁用消息</div>
		      				<div class="flex-1">{{scope.row.data.disable_msg}}</div>
		      			</div>
		      		</div>
		      		<div class="flex-1">
		      			<el-timeline>
						    <el-timeline-item 
						    :timestamp="scope.row.data.register_time" >
						        <h6>注册</h6>
						        <p class="mb-0 text-secondary small">{{scope.row.data.register_ip}}</p>
						        <p class="mb-0 text-secondary small">{{scope.row.data.register_devices}}</p>
						    </el-timeline-item>
						    <el-timeline-item 
						    :timestamp="scope.row.data.update_time">
						        <h6>账户</h6>
						    </el-timeline-item>
						    <el-timeline-item 
						    :timestamp="scope.row.data.info_update_time">
						        <h6>资料</h6>
						    </el-timeline-item>
						    <el-timeline-item 
						    :timestamp="scope.row.data.login_time">
						        <h6>最后登录</h6>
						        <p class="mb-0 text-secondary small">{{scope.row.data.login_ip}}</p>
						        <p class="mb-0 text-secondary small">{{scope.row.data.login_devices}}</p>
						    </el-timeline-item>
						    <el-timeline-item 
						    :timestamp="scope.row.data.online_time">
						        <h6>最后在线</h6>
						        <p class="mb-0 text-secondary small">{{scope.row.data.online_ip}}</p>
						        <p class="mb-0 text-secondary small">{{scope.row.data.online_devices}}</p>
						    </el-timeline-item>
						</el-timeline>
		      		</div>
		      	</div>
		      	<div class="text-center py-5 text-secondary small" v-else-if="scope.row.user_info==0">
		      		<i class="el-icon-loading mr-2"></i>加载中...
		      	</div>
		      	<div class="text-center py-5 text-secondary small" v-else="scope.row.user_info">
		      		未获取到用户信息
		      	</div>
		      </template>
		    </el-table-column>
	      <el-table-column
	        prop="id"
	        label="UID"
	        width="100">
	      </el-table-column>
	      <el-table-column
	        label="用户"
	        min-width="180">
		      <template slot-scope="scope">
		      	<div class="flex flex-center">
					<el-image
					  	v-if="scope.row.headimgurl" 
					    style="width: 30px; height: 30px"
					    lazy
					    class="rounded-circle mr-2"
					    :src="scope.row.headimgurl" 
					    :preview-src-list="[scope.row.headimgurl]">
					</el-image>
		      		<div>{{scope.row.nickname}}</div>
		      	</div>
		      </template>
	      </el-table-column>
	      <el-table-column
	        label="性别"
	        width="120">
		      <template slot-scope="scope">
		      	<div>
		      		<span class="text-primary" 
		      		v-if="scope.row.gender=='男'">男</span>
		      		<span class="text-danger"
		      		v-else-if="scope.row.gender=='女'">女</span>
		      		<span class="text-secondary"
		      		v-else>保密</span>
				</div>
		      </template>
	      </el-table-column>
	      <el-table-column
	        prop="city"
	        label="城市"
	        width="120">
	      </el-table-column>
	      <el-table-column
	        prop="province"
	        label="省份"
	        width="120">
	      </el-table-column>
	      <el-table-column
	        label="OpenId"
	        width="400">
		      <template slot-scope="scope">
		      	<div>
			      	<div class="flex small">
			      		<div class="w-100px text-primary">APP：</div>
			      		<div class="flex-1">{{scope.row.app_openid}}</div>
			      	</div>
			      	<div class="flex small">
			      		<div class="w-100px text-primary">PC：</div>
			      		<div class="flex-1">{{scope.row.pc_openid}}</div>
			      	</div>
			      	<div class="flex small">
			      		<div class="w-100px text-primary">UnionId：</div>
			      		<div class="flex-1">{{scope.row.unionid}}</div>
			      	</div>
		      	</div>
		      </template>
	      </el-table-column>
	      <el-table-column
	        label="创建/更新时间"
	        width="180">
		      <template slot-scope="scope">
		      	<div class="small">
		          <div>{{ scope.row.create_time }}</div>
		          <div>{{ scope.row.update_time }}</div>
		      	</div>
		      </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:{
				search_type:'uid',
				key:'{notempty name=":request()->get('uid')"}{:request()->get('uid')}{/notempty}',
				subscribe:'all',
				ajax:false,
				page:1,
				total:0,
				pageSize:10
			},
			tableData:[],
		},
		watch:{
		    view:XYBase.viewWatch,
		},
		created(){
			XYBase.created(this);
		},
	    methods: {
	    	getSearchType(){
	    		var text='UID';
	    		switch(this.search.search_type){
	    			case 'uid':
	    				text='UID';
	    				break;
	    			case 'wx_openid':
	    				text='公众号OpenId';
	    				break;
	    			case 'app_openid':
	    				text='APPOpenId';
	    				break;
	    			case 'pc_openid':
	    				text='PCOpenId';
	    				break;
	    			case 'unionid':
	    				text='UnionId';
	    				break;
	    		}
	    		return text;
	    	},
			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();
			},
			getUserInfo(row,expandedRows) {
				if (row.user_info)return;
				if (!row.uid)return row.user_info=2;
	    		$.getJSON('/getUserInfo/'+row.uid,function(ret){
	    			if (ret) {
	    				if (ret.code === 0) {
	    					row.user_info=1;
	    					row.data=ret.data;
	    				}else{
	    					row.user_info=2;
	    					XYBase.msg(ret.msg);
	    				}
	    			}else{
						XYBase.error(XYBase.config.system_network_error);
	    			}
	    		});
			},
	      	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}