<template>
	<div>
		<div class="box">
			<el-tabs v-model="formData.status">
				<el-tab-pane v-for="(item, index) in tabsOption" :key="index" :label="item.label" :name="item.name"></el-tab-pane>
			</el-tabs>

			<el-form ref="formData" :inline="true" :model="formData" label-width="80px">
				<el-form-item label="积分类型">
					<el-select v-model="formData.pt_id" clearable placeholder="请选择积分类型">
						<el-option v-for="item in point_type" :key="item.id" :label="item.name" :value="item.id"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="执行人" label-width="60px">
					<el-select  v-model="formData.employee_id" filterable clearable placeholder="请输入执行人">
					  <el-option v-for="item in employee_map" :key="item.id" :label="item.name" :value="item.id"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="排序" label-width="60px">
					<el-select v-model="formData.sort" placeholder="请选择排序">
						<el-option v-for="item in sort" :key="item.id" :label="item.name" :value="item.code"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item>
					<el-input v-model="formData.content" placeholder="请输入任务内容" max="200" @keyup.enter.native="getContent()" class="persons_name">
						<el-button slot="append" icon="el-icon-search" @click="getContent()"></el-button>
					</el-input>
				</el-form-item>
			</el-form>

			<div>
				<el-table :data="list" style="width: 100%" v-loading="loading">
					<el-table-column label="执行人" prop="employee_id">
					  <template slot-scope="scope">
					   <div class="flex-box-ce">
					      <userImage  width="50px" :id="scope.row.employee_id" height="50px"  :user_name="scope.row.employee_name" ></userImage>
					      <span style="line-height: 50px; padding-left: 10px;">{{scope.row.employee_name}}</span>
					    </div>
					  </template>
					</el-table-column>
					<el-table-column label="任务内容" prop="task_name">
						<template slot-scope="scope">
							<span class="font-flex-word" style="max-width: 200px;">{{ scope.row.task_name }}</span>
						</template>
					</el-table-column>
					<el-table-column label="积分">
						<template slot-scope="scope">
							<span class="red" v-if="scope.row.point_config.base_point > 0">
								+{{ scope.row.point_config.base_point }} {{ scope.row.pt_name }}
							</span>
							<span class="green" v-else>
								{{ scope.row.point_config.base_point }} {{ scope.row.pt_name }}
							</span>
<!-- 							<span class="red" v-if="scope.row.point_config.review_point!=0">
								+{{ scope.row.point_config.review_point }} {{ scope.row.pt_name }}
							</span>
							<span class="red" v-else>
								+{{ scope.row.point_config.base_point }} {{ scope.row.pt_name }}
							</span> -->
						</template>
					</el-table-column>
					<el-table-column label="截止时间" prop="expire_time"></el-table-column>
<!-- 					<el-table-column label="状态" prop="review_status" v-if="formData.status=='complete'">
						<template slot-scope="scope">
							  <div class="yellow" v-if="scope.row.review_status == 0">待处理</div>
							  <div class="green" v-if="scope.row.review_status ==1">已通过</div>
							  <div class="red" v-if="scope.row.review_status == 2">已驳回</div>
						</template>
					</el-table-column> -->
					<el-table-column label="操作" prop="owner_id">
						<template slot-scope="scope">
							<el-link type="primary" :underline="false" @click.stop="openDetail(scope.row)" class="blue">查看任务</el-link>
							<el-link style="margin-left: 10px;" v-if="formData.status=='complete'" type="primary" :underline="false" @click.stop="openDetailXq(scope.row)">去审批</el-link>
							<el-link style="margin-left: 10px;" v-if="formData.status=='reviewed'" type="primary" :underline="false" @click.stop="openDetailXq(scope.row)">查看审批</el-link>
						</template>
					</el-table-column>
					<template slot="empty">
						<noData></noData>
					</template>
				</el-table>
			</div>

			<center style="padding: 20px 0;">
				<el-pagination
					background
					@size-change="handleSizeChange"
					@current-change="handleCurrentChange"
					:page-sizes="[10, 20, 50, 100]"
					layout="total, sizes, prev, pager, next"
					:current-page="formData.page"
					:page-size="formData.page_size"
					:total="total"
				></el-pagination>
			</center>
		</div>

		<!-- 详情弹窗 -->
		<taskDetailsPopup :visible.sync="showDetailPopup" v-if="showDetailPopup" :id="detailId" :title="'任务详情'"></taskDetailsPopup>
		
		<!-- 审批详情 -->
		<examinePopup :title="'审核详情'" :id="detail_id" :show.sync="detailShow"></examinePopup>
	</div>
</template>

<script>

import examinePopup from '@/components/examinePopup.vue';
import taskDetailsPopup from '@/views/common/taskDetailsPopup'

export default {
	name: 'my_task',
	data() {
		return {
			active: 'running',
			tabsOption: [{ label: '待完成', name: 'running' }, { label: '待审批', name: 'complete' }, { label: '已审批', name: 'reviewed' }],
			list: [],
			loading: false,
			total: null,
			sort: [ { id: 2, code: 'publish', name: '按发布时间' },{ id: 1, code: 'expire', name: '按截止时间' }],
			point_type: null,
			detail_form: {
				id: '',
				remark: ''
			},
			formData: {
				employee_id:'',
				status: 'running',
				pt_id: 0,
				sort: 'publish',
				source_type: '0',
				page: 1,
				page_size: 10,
				content: ''
			},
			completeShow: false,
			showDetailPopup: false,
			detailId: null,
			showRepetitiveTasksPopup: false,
			showRewardTaskDetailsPopup: false,
			employee_map:[],
			
			// 审批相关
			detail_id:0,
			detailShow:false,
		};
	},
	components: { taskDetailsPopup,examinePopup },
	watch: {
		'formData.pt_id'(val) {
			this.formData.page = 1;
			this.list = []
			this.getSpList();
		},
		'formData.sort'(val) {
			this.formData.page = 1;
			this.list = []
			this.getSpList();
		},
		'formData.employee_id'(val) {
			this.formData.page = 1;
			this.list = []
			this.getSpList();
		},
		'formData.status'(val) {
			this.formData.content = '';
			this.formData.page = 1;
			this.formData.pt_id = 0;
			this.formData.employee_id=''
			this.formData.sort = 'publish';
			this.list = [];
			this.getSpList();
		}
	},
	created() {
		this.getEmployee()
	},
	mounted() {
		this.getSpList();
		this.point_type = this.getPointType();
	},
	methods: {
		getContent(){
			this.formData.page = 1
			this.list = []
			this.getSpList();
		},
		//获取员工列表
		getEmployee() {
			this.$axios('get', '/api/employee/index', { dept_id: 0, page: 1, page_size: 3000 }).then(res => {
				this.employee_map = res.data.data.list;
			})
		},
		openDetailXq(item) {
			this.detail_id = item.review_id;
			this.detailShow = true;
		},
		getPointType() {
			let point = window.plus ? JSON.parse(puls.storage.getItem('types')) : JSON.parse(localStorage.getItem('types'));
			// point.splice(0,1)
			point.unshift({ code: 'AF', id: 0, name: '全部' });
			return point;
		},
		// 页码变更
		handleCurrentChange(val) {
			this.formData.page = val;
			this.getSpList();
		},
		handleSizeChange(val) {
			this.formData.page_size = val;
			this.getSpList();
		},
		openDetail(row) {
			this.detailId = parseInt(row.id);
			this.showDetailPopup = true;
		},
		getSpList() {
			let self = this;
			self.loading = true;
			let params = JSON.parse(JSON.stringify(this.formData));
			if (params.pt_id == 0) {
				delete params.pt_id;
			}
			if (params.employee_id == '') {
				delete params.employee_id;
			}
			self.$axios('get', '/api/integral/work/list/reviewer', params)
				.then(res => {
					if (res.data.code == 1) {
						self.list = res.data.data.list;
						self.total = res.data.data.total;
					} else {
						self.$message.error(res.data.data.msg);
					}
				})
				.finally(() => {
					self.loading = false;
				});
		}
	}
};
</script>

<style scoped lang="scss">
.box {
	min-height: calc(100vh - 184px);
	min-width: 800px;
	background-color: #fff;
	padding: 20px;
}
::v-deep .el-table tr:hover {
	cursor: pointer;
}
.details_content {
	padding: 20px;
	height: calc(100vh - 60px);
	overflow: auto;
	.row_title {
		position: relative;
		margin: 0 0 20px 0;
		padding-top: 12px;
		font-size: 16px;
		color: #303133;
		line-height: 22px;
	}
	.row_title:before {
		position: absolute;
		top: 0;
		content: ' ';
		width: 100%;
		border-top: 1px #f8f8f8 solid;
	}
	.el-row {
		margin-bottom: 10px;
		font-size: 14px;
		.el-col-4 {
			color: #606266;
		}
	}
}
.details_title {
	font-size: 18px;
	padding: 20px;
	border-bottom: 1px #efefef solid;
}
</style>
