{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="'user'">用户名</el-radio>
	      <el-radio :label="'mobile'">手机号</el-radio>
	      <el-radio :label="'email'">邮箱</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="status">
	    <el-radio-group v-model="search.status">
	      <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 label="身份" prop="role_type">
	    <el-radio-group v-model="search.role_type">
	      <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-button type="primary" size="mini" @click="window.open('/user/addUser')" plain>手动添加用户</el-button>
	</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 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>
							<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 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">绑定QQ</div>
		      				<el-link
		      				v-if="scope.row.data.bind_qq"
		      				type="primary"
		      				:underline="false">{{scope.row.data.bind_qq.nickname}}</el-link>
		      				<el-link
		      				v-else
		      				type="info"
		      				:underline="false">未绑定</el-link>
		      			</div>
		      			<div class="flex flex-center pb-3">
		      				<div class="flex-lable">绑定微信</div>
		      				<el-link
		      				v-if="scope.row.data.bind_wx"
		      				type="primary"
		      				:href="'/wxUser?uid='+scope.row.id"
		      				target="_blank"
		      				:underline="false">{{scope.row.data.bind_wx.nickname}}</el-link>
		      				<el-link
		      				v-else
		      				type="info"
		      				:underline="false">未绑定</el-link>
		      			</div>
		      			<div class="flex flex-center pb-3">
		      				<div class="flex-lable">绑定AppleID</div>
		      				<el-link
		      				v-if="scope.row.data.bind_apple"
		      				type="primary"
		      				:underline="false">已绑定</el-link>
		      				<el-link
		      				v-else
		      				type="info"
		      				:underline="false">未绑定</el-link>
		      			</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 class="flex flex-center pb-3">
		      				<div class="flex-lable"></div>
		      				<div class="flex-1">
					        <el-button
					            type="info"
					            size="minism"
					            @click="window.open('/user/loginLog?uid='+scope.row.id)">
					            登录日志
					        </el-button>
					        <el-button
					            type="info"
					            size="minism"
					            @click="window.open('/user/apiLog?uid='+scope.row.id)">
					            操作日志
					        </el-button>
		      				</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.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>
				      	<el-link @click="openWinTo(scope.row)" target="_blank"
				      	:underline="false"
				      	title="免登录跳转至用户中心">{{scope.row.nickname}}</el-link>
		      		</div>
		      	</div>
		      </template>
	      </el-table-column>
	      <el-table-column
	        prop="user"
	        label="账号"
	        width="120">
	      </el-table-column>
	      <el-table-column
	        prop="mobile"
	        label="手机号"
	        width="120">
	      </el-table-column>
	      <el-table-column
	        prop="email"
	        label="邮箱"
	        width="160">
	      </el-table-column>
	      <el-table-column
	        prop="app_name"
	        label="来源"
	        width="160">
	      </el-table-column>
	      <el-table-column
	        label="身份"
	        width="80">
		      <template slot-scope="scope">
		      	<transition>
		      		<el-button type="primary" size="minism"
		      		v-if="scope.row.role_type==1">企业</el-button>
		      		<el-button type="success" size="minism" 
		      		v-else="scope.row.role_type==0">个人</el-button>
				</transition>
		      </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.is_real_name==1">已实名</el-button>
		      		<el-button type="info" size="minism" 
		      		v-else="scope.row.is_real_name==0">未实名</el-button>
				</transition>
		      </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="setStatus(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="setStatus(scope.row);" 
		      		:loading="scope.row.status==2">禁用</el-button>
				</transition>
		      </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-column
	        label="/"
	        width="120">
		      <template slot-scope="scope">
		        <el-button
		            type="success"
		            size="minism"
		            v-if="scope.row.role_type"
		            :disabled="!scope.row.company_id"
		            @click="Business.openBusiness(scope.row.company_id,true)">
		            业务
		        </el-button>
		        <el-button
		            type="success"
		            size="minism"
		            :disabled="!scope.row.resume_id"
		            v-else
		            @click="Business.openBusiness(scope.row.resume_id)">
		            业务
		        </el-button>
		        <el-button
		            type="primary"
		            size="minism"
		            @click="window.open('/user/editUser/'+scope.row.id)">
		            编辑
		        </el-button>
		      </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>
<el-dialog
  title="禁止登录"
  :visible.sync="dialogVisible"
  width="600px"
  :before-close="cancelRefuseWinSubmit">
	<el-form :model="disable_form" label-width="80px" :rules="rules" ref="disable_form" size="small">
		  <el-form-item label="禁用原因" prop="msg">
		    <el-input type="textarea" v-model="disable_form.msg" class="col-12 pl-0 pr-0" :autosize="{ minRows: 4, maxRows: 20}" maxlength="200" show-word-limit></el-input>
		  </el-form-item>
		  <el-form-item label="封禁期限" prop="auto_disable">
		    <el-date-picker
		      v-model="disable_form.auto_disable"
		      align="right"
		      type="date"
		      format="yyyy-M-d"
		      value-format="yyyy-M-d"
			    :picker-options="endPickerOptions"
		      placeholder="End Time">
		    </el-date-picker>
		  	<p class="small text-danger">自动解封期限</p>
		  </el-form-item>
	</el-form>
	<div class="pointer text-primary small py-1" @click="showLog= !showLog;">{{showLog?'收起日志':'查看日志'}}</div>
  	<div v-show="showLog" style="max-height:500px;overflow-y: auto;">
		<div class="py-2 border-bottom mb-2" v-for="(v,index) in UserFind.log">
			<div class="flex">
				<div class="text-success" v-if="v.status===1">解除封禁</div>
				<div class="text-danger" v-if="v.status===0">封号</div>
				<div class="flex-1 pl-2">{{v.nickname}}</div>
				<div class="small text-secondary">{{v.create_time}}</div>
			</div>
			<div class="pt-2">{{v.disable_msg}}</div>
			<div class="pt-2 small" v-if="v.auto_time">自动解封日期：{{v.auto_time}}<span v-if="v.auto_status" class="ml-1 text-success">已执行</span></div>
		</div>
  	</div>
	<div slot="footer">
	    <el-button @click="cancelRefuseWinSubmit">取 消</el-button>
	    <el-button type="primary" @click="submitDisable('disable_form');" :loading="disable_form.ajax">{{disable_form.ajax?'提交中...':'提交'}}</el-button>
	</div>
</el-dialog>
{/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',
			showLog:false,
			dialogVisible:false,
			UserFind:{},
		    endPickerOptions: {
		        disabledDate(time) {
		          return time.getTime() < Date.now();
		        },
		        shortcuts: [{
		            text: '1天',
		            onClick(picker) {
		              const date = new Date();
		              date.setTime(date.getTime() + 3600 * 1000 * 24);
		              picker.$emit('pick', date);
		            }
		        }, {
		            text: '3天',
		            onClick(picker) {
		              const date = new Date();
		              date.setTime(date.getTime() + 3600 * 1000 * 24 * 3);
		              picker.$emit('pick', date);
		            }
		        }, {
		            text: '7天',
		            onClick(picker) {
		              const date = new Date();
		              date.setTime(date.getTime() + 3600 * 1000 * 24 * 7);
		              picker.$emit('pick', date);
		            }
		        }, {
		            text: '15天',
		            onClick(picker) {
		              const date = new Date();
		              date.setTime(date.getTime() + 3600 * 1000 * 24 * 15);
		              picker.$emit('pick', date);
		            }
		        }, {
		            text: '30天',
		            onClick(picker) {
		              const date = new Date();
		              date.setTime(date.getTime() + 3600 * 1000 * 24 * 30);
		              picker.$emit('pick', date);
		            }
		        }]
		   	},
			disable_form:{
				ajax:false,
				msg:'',
				auto_disable:''
			},
	        rules: {
	          msg: [
	            { required: true, message: '请输入禁用原因', trigger: 'blur' },
	          ],
	        },
			search:{
				{notempty name=":request()->get('uid')"}
				search_type:'uid',
				key:'{:request()->get('uid')}',
				{elseif request()->get('user')/}
				search_type:'user',
				key:'{:request()->get('user')}',
				{elseif request()->get('mobile')/}
				search_type:'mobile',
				key:'{:request()->get('mobile')}',
				{elseif request()->get('email')/}
				search_type:'email',
				key:'{:request()->get('email')}',
				{else/}
				search_type:'uid',
				key:'',
				{/notempty}
				status:'all',
				role_type:'all',
				ajax:false,
				page:1,
				total:0,
				pageSize:10
			},
			tableData:[],
		},
		watch:{
		    view:XYBase.viewWatch,
		},
		created(){
			XYBase.created(this);
		},
	    methods: {
	    	openWinTo(row){
		        this.$confirm('即将免登录打开【'+row.nickname+'】,是否继续？', '提示', {
		        	dangerouslyUseHTMLString:true,
		          confirmButtonText: '继续',
		          cancelButtonText: '取消',
		          type: 'warning'
		        }).then(() => {
	    			window.open('user/exemptLoginRedirect/'+row.id+'?path=/user');
		        }).catch(() => {
					XYBase.msg('已取消');
		        });
	    	},
	    	getSearchType(){
	    		var text='UID';
	    		switch(this.search.search_type){
	    			case 'uid':
	    				text='UID';
	    				break;
	    			case 'user':
	    				text='用户名';
	    				break;
	    			case 'mobile':
	    				text='手机号';
	    				break;
	    			case 'email':
	    				text='邮箱';
	    				break;
	    		}
	    		return text;
	    	},
	      	cancelRefuseWinSubmit(done){
	      		this.UserFind={};
	      		this.$refs.disable_form&&this.$refs.disable_form.resetFields();
	      		typeof done==='function'&&done();
				this.dialogVisible=false;
	      	},
	    	setStatus(data){
	    		if (data.status==2) return;
	    		if (data.status==1) {
	    			this.UserFind=data;
	    			this.dialogVisible=true;
	    		}else{
		    		var status=1,oldStatus=data.status;
		    		if (data.status) status=0;
		    		data.status=2;
		    		$.getJSON('/user/setStatus/'+data.id,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);
		    			}
		    		});
	    		}
	    	},
	    	submitDisable(){
	    		var _this=this;
	    		if (this.UserFind.status==2) return;
	    		var status=1,oldStatus=this.UserFind.status;
	    		if (this.UserFind.status) status=0;
	    		this.UserFind.status=2;
	    		this.disable_form.ajax=true;
	    		$.ajax({
	    			url:'/user/setStatus/'+this.UserFind.id,
	    			data:this.disable_form,
	    			type:'post',
	    			dataType:'json',
	    			error:function(err) {
	    				_this.disable_form.ajax=false;
	    				_this.UserFind.status=oldStatus;
						XYBase.error(XYBase.config.system_network_error);
	    			},
	    			success:function(ret) {
	    				_this.disable_form.ajax=false;
		    			_this.UserFind.status=oldStatus;
		    			if (ret) {
		    				if (ret.code === 0) {
		    					_this.UserFind.status=status;
		    					_this.UserFind.disable_msg=_this.disable_form.msg;
		    					_this.cancelRefuseWinSubmit();
		    				}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();
			},
			getUserInfo(row,expandedRows) {
				if (row.user_info)return;
	    		$.getJSON('/getUserInfo/'+row.id,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>
{include file="business"/}
{/block}