{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 label="简历ID"value="resume_id"></el-option>
		    <el-option label="UID"value="uid"></el-option>
		    <el-option label="姓名"value="name"></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
			ref="tableList"
	      	:data="tableData"
    		v-loading="search.ajax"
    		style="width: 100%;"
    		header-cell-class-name="table-header-DDE6FB"
    		@selection-change="handleSelectionChange">
		  <el-table-column
			  type="selection"
			  width="55">
		  </el-table-column>
	      <el-table-column
	        prop="id"
	        label="ID"
	        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>
						{{scope.row.nickname}}
		      		</div>
		      	</div>
		      </template>
	      </el-table-column>
	      <el-table-column
	      	prop="name"
	        label="姓名"
	        width="120">
	      </el-table-column>
	      <el-table-column
	        label="基本信息"
	        min-width="240">
		      <template slot-scope="scope">
	      		<div class="flex text-nowrap flex-center">
		        	<div>{{XYBase.Date.getMStoYear(scope.row.age*1000)}}</div>
	      			<div class="mx-1">·</div>
					<div v-if="scope.row.sex==1">男</div>
					<div v-else-if="scope.row.sex==2">女</div>
					<div v-else="scope.row.sex">未设置</div>
	      			<div class="mx-1">·</div>
		        	<div>{{scope.row.educational_background}}</div>
	      			<div class="mx-1">·</div>
		        	<div>{{XYBase.Date.getMStoYear(scope.row.work_experience_time*1000)}}年经验</div>
	      		</div>
		      </template>
	      </el-table-column>
	      <el-table-column
	      	prop="sum"
	        label="投递次数"
	        width="120">
	      </el-table-column>
	      <el-table-column
	        label="状态"
	        width="120">
		      <template slot-scope="scope">
		      	<transition>
		      		<el-button type="success" size="minism"
		      		v-if="scope.row.status==1">委托中</el-button>
		      		<el-button type="info" size="minism" 
		      		v-else="scope.row.status==0">已取消</el-button>
				</transition>
		      </template>
	      </el-table-column>
	      <el-table-column
	        prop="start_time"
	        label="开始~结束时间"
	        width="240">
		      <template slot-scope="scope">
		      	<div class="flex small">
		          <div>{{ scope.row.start_time }}</div>
		          <div class="px-1" v-if="scope.row.end_time">~</div>
		          <div>{{ scope.row.end_time }}</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>{{ scope.row.cancel_time }}</div>
		      	</div>
		      </template>
	      </el-table-column>
	      <el-table-column
	        label="/"
	        width="160">
		      <template slot-scope="scope" v-if="scope.row.status===1">
		        <el-button
		            type="primary"
		            plain
		            round
		            size="minism"
		            @click="window.open('/resume/matching/'+scope.row.resume_id)">
		            匹配
		        </el-button>
		        <el-button
		            type="info"
		            plain
		            round
		            size="minism"
		            @click="cancelConsignment(scope.row)">
		            取消委托
		        </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">
</script>
<script type="text/javascript">
	var vm=new Vue({
		el:'#app',
		data:{
			view:XYBase.view,
			labelPosition:'right',
			multipleSelection:[],
			search:{
				search_type:'resume_id',
				key:'',
				attestation:'all',
				ajax:false,
				page:1,
				total:0,
				pageSize:10
			},
			tableData:[],
		},
		watch:{
		    view:XYBase.viewWatch,
		},
		created(){
			XYBase.created(this);
		},
	    methods: {
		    toggleSelection(rows) {
		        if (rows) {
		          rows.forEach(row => {
		            this.$refs.tableList.toggleRowSelection(row);
		          });
		        } else {
		          this.$refs.tableList.clearSelection();
		        }
		    },
		    handleSelectionChange(val) {
		        this.multipleSelection = val;
		    },
	    	getSearchType(){
	    		var text='简历ID';
	    		switch(this.search.search_type){
	    			case 'resume_id':
	    				text='简历ID';
	    				break;
	    			case 'uid':
	    				text='UID';
	    				break;
	    			case 'name':
	    				text='姓名';
	    				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();
			},
			cancelConsignment(row){
	      		var _this=this;
		        this.$confirm('是否确定取下【'+row.name+'】的委托吗?', '提示', {
		          confirmButtonText: '确定',
		          cancelButtonText: '取消',
		          type: 'warning'
		        }).then(() => {
		    		const loading=XYBase.openloading();
		    		$.getJSON('/resume/cancelConsignment/'+row.id,function(ret){
		    			loading.close();
		    			if (ret) {
		    				if (ret.code === 0) {
		    					row.status=0;
		    					row.cancel_time=ret.time;
		    				}else XYBase.msg(ret.msg);
		    			}else XYBase.error(XYBase.config.system_network_error);
		    		});
		        }).catch(() => {
					XYBase.msg('已取消');
		        });
			},
	      	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}