{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 p-3">
	<el-form :model="search" @submit.native.prevent="submitForm" ref="search" label-width="120px" :label-position="labelPosition" size="mini">

	  <el-form-item label="搜索类型" prop="search_type">
	    <el-radio-group v-model="search.search_type">
	      <el-radio :label="'uid'">UID</el-radio>
	      <el-radio :label="'app_openid'">APPOpenId</el-radio>
	      <el-radio :label="'pc_openid'">PCOpenId</el-radio>
	      <el-radio :label="'unionid'">UnionId</el-radio>
	    </el-radio-group>
	  </el-form-item>

	  <el-form-item :label="getSearchType()" prop="key">
	    <el-input v-model="search.key" class="col-12 col-sm-2 pl-0 pr-0"></el-input>
	  </el-form-item>

	  <el-form-item label="订阅" prop="subscribe">
	    <el-radio-group v-model="search.subscribe">
	      <el-radio :label="'all'">全部</el-radio>
	      <el-radio :label="1">已订阅</el-radio>
	      <el-radio :label="0">未订阅</el-radio>
	    </el-radio-group>
	  </el-form-item>

	  <el-form-item>
	    <el-button type="primary" @click="initHtml">查询</el-button>
	    <el-button @click="resetForm('search')">重置</el-button>
	  </el-form-item>
	</el-form>
	<div class="table-responsive py-3">
		<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 class="table-responsive">
		<el-table
	      	:data="tableData"
    		stripe
    		v-loading="search.ajax"
    		style="width: 100%;"
    		row-class-name="row-flex"
    		@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">
				<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>
				{{scope.row.nickname}}
		      </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="性别"
	        width="80">
		      <template slot-scope="scope">
		      	<transition>
		      		<el-button type="primary" size="minism" 
		      		v-if="scope.row.gender=='男'">男</el-button>
		      		<el-button type="success" size="minism"
		      		v-else-if="scope.row.gender=='女'">女</el-button>
		      		<el-button type="info" size="minism" 
		      		v-else>保密</el-button>
				</transition>
		      </template>
	      </el-table-column>
	      <el-table-column
	        label="OpenId"
	        width="400">
		      <template slot-scope="scope">
		      	<div>
			      	<div class="flex small">
			      		<div class="w-100px">APP：</div>
			      		<div class="flex-1">{{scope.row.app_openid}}</div>
			      	</div>
			      	<div class="flex small">
			      		<div class="w-100px">PC：</div>
			      		<div class="flex-1">{{scope.row.pc_openid}}</div>
			      	</div>
			      	<div class="flex small">
			      		<div class="w-100px">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">
		        <el-popover trigger="hover" placement="top">
		          <p>创建时间: {{ scope.row.create_time }}</p>
		          <p>更新时间: {{ scope.row.update_time }}</p>
		          <div slot="reference" class="name-wrapper">
		            <el-tag size="small" type="info">{{ scope.row.create_time }}</el-tag>
		          </div>
		        </el-popover>
		      </template>
	      </el-table-column>
	    </el-table>
	</div>
	<div class="table-responsive py-3">
		<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}