<template>
	<div class="content-main">
		<el-row>
			<el-form :inline="true" :model="formInline" class="search-bm-boder">
				<el-form-item label="姓名:">
					<el-input
						clearable
						v-model="formInline.ryxm"
						placeholder="请输入"
					></el-input>
				</el-form-item>

				<el-form-item>
					<div class="search-button">
						<span class="search-line"></span>
						<el-button
							type="primary"
							size="small"
							class="iconfont iconchaxun"
							@click="doSearch"
							>查询</el-button
						>
						<el-button
							type="primary"
							@click="
								formInline = {}
								doSearch()
							"
							size="small"
							class="iconfont iconzhongzhi"
							>重置</el-button
						>
					</div>
				</el-form-item>
			</el-form>
		</el-row>
		<el-row class="addBtnBg">
			企业名称：{{ this.$route.query.qymc }}
		</el-row>
		<el-row>
			<!-- v-loading="listLoading"  -->
			<el-table
				:data="tableData"
				stripe
				border
				fit
				highlight-current-row
				style="width: 100%"
			>
				<el-table-column align="center" label="序号" width="70">
					<template slot-scope="scope">
						<span>{{ scope.$index + 1 }}</span>
					</template>
				</el-table-column>
				<!-- <el-table-column
					align="center"
					prop="kdmc"
					show-overflow-tooltip
					label="企业名称"
					min-width="200px"
				></el-table-column> -->
				<el-table-column
					align="center"
					prop="ryxm"
					label="姓名"
					show-overflow-tooltip
				></el-table-column>
				<el-table-column
					align="center"
					prop="xb"
					label="性别"
				></el-table-column>
				<el-table-column
					align="center"
					prop="gwdm"
					label="岗位"
				></el-table-column>
				<el-table-column
					align="center"
					prop="zzmm"
					label="政治面貌"
				></el-table-column>
				<el-table-column
					align="center"
					prop="lxdh"
					label="联系方式"
				></el-table-column>
				<el-table-column
					align="center"
					prop="qyzts"
					label="状态"
				></el-table-column>
				<el-table-column align="center" label="操作" width="150">
					<template slot-scope="scope">
						<!-- <el-button  @click="deleteSubmit(scope.row)" v-if="scope.row.qyzt == '0'" type="primary"  size="small"  class="operate_delete_btn iconfont iconshanchu"></el-button> -->
						<el-tooltip
							class="item"
							effect="light"
							content="查看"
							placement="top"
						>
							<el-button
								@click="detailSubmit(scope.row)"
								type="primary"
								size="small"
								class="operate_show_btn iconfont iconchakan2"
							></el-button>
						</el-tooltip>
						<!-- <el-tooltip
							class="item"
							effect="light"
							content="编辑"
							placement="top"
							v-if="scope.row.qyzt == '0'"
						>
							<el-button
								@click="editSubmit(scope.row)"
								type="primary"
								size="small"
								class="operate_edit_btn iconfont iconxiugai"
							></el-button>
						</el-tooltip> -->
						<!-- <el-tooltip class="item" effect="light" content="提交"  placement="top" v-if="scope.row.qyzt == '0'">
               <el-button  @click="smt(scope.row)"   type="primary"  size="small"  class="operate_show_btn iconfont icontijiao"></el-button>
						</el-tooltip>-->
						<!-- <el-tooltip
							class="item"
							effect="light"
							content="启用"
							placement="top"
							v-if="scope.row.qyzt == '0'"
						>
							<el-button
								@click="open(scope.row)"
								type="primary"
								size="small"
								class="operate_show_btn iconfont iconqiyong1"
							></el-button>
						</el-tooltip>
						<el-tooltip
							class="item"
							effect="light"
							content="禁用"
							placement="top"
							v-if="scope.row.qyzt == '1'"
						>
							<el-button
								@click="close(scope.row)"
								type="primary"
								size="small"
								class="operate_show_btn iconfont iconjinyong1"
							></el-button>
						</el-tooltip>
						<el-tooltip
							class="item"
							effect="light"
							content="删除"
							placement="top"
							v-if="
								scope.row.qyzt == '0' || scope.row.qyzt == '3'
							"
						>
							<el-button
								@click="deleteSubmit(scope.row.rybh)"
								type="primary"
								size="small"
								class="operate_delete_btn iconfont iconshanchu"
							></el-button>
						</el-tooltip> -->
					</template>
				</el-table-column>
			</el-table>
		</el-row>
		<el-row>
			<el-pagination
				@size-change="handleSizeChange"
				@current-change="handleCurrentChange"
				:current-page.sync="pageForm.page"
				:page-sizes="[10, 20, 30, 40]"
				:page-size="pageForm.size"
				layout="total, sizes, prev, pager, next, jumper"
				:total="pageForm.total"
			></el-pagination>
		</el-row>
	</div>
</template>

<script>
import {
	getPageList,
	deleteFn,
	detailsFn,
	personnelEnabled,
	zzmm
} from '@/api/jcxxwh/ryxx'
import { kd } from '@/api/jcxxwh/kd'
import { openOrClose } from './zoots4.js'
import { dateFormat } from '@/utils/index'
import { way, pack, statut, classDj, bookName, xl, gw } from './zoots4.js'
export default {
	data() {
		return {
			kd: '',
			formInline: {
				// rybh: window.sessionStorage.getItem('tyshxydm'),
				kddm: '',
				qyzt: null,
				ryxm: null
			},
			// listLoading: false,
			openOrClose: openOrClose,
			tableData: [],
			pageForm: {
				page: 1,
				size: 10,
				total: 1
			},
			zzmms: [], //政治面貌
			zzmm: {}
		}
	},
	created() {
		// this.init()
		this.initOpts()
	},
	methods: {
		init() {
			kd().then((res) => {
				if (!res) return
				if (!res.data[0]) return
				this.kd = res.data[0].kddm
				this.initOpts()
			})
		},
		initOpts() {
			zzmm().then((res) => {
				if (!res) return
				var _arr = []
				this.zzmms = res.data.filter((d) => {
					if (_arr.includes(d.dictCode)) return false
					else {
						_arr.push(d.dictCode)
						this.zzmm[d.dictCode] = d.dictName
						return true
					}
				})
				this.getList()
			})
		},
		dateFormat: dateFormat,
		doSearch() {
			this.pageForm.page = 1
			this.getList()
		},
		//获取列表
		getList() {
			for (var key in this.formInline) {
				if (this.formInline[key] == '') {
					this.formInline[key] = null
				}
			}
			let data = {
				...this.formInline,
				rybh: this.$route.query.tyshxydm,
				kddm: this.kd,
				page: this.pageForm.page,
				size: this.pageForm.size,
				qyzt: '1'
			}
			getPageList(data).then((res) => {
				this.tableData = res.data.list
				for (var i = 0; i < this.tableData.length; i++) {
					if (this.tableData[i].qyzt == 0) {
						this.tableData[i].qyzts = '禁用'
					}
					if (this.tableData[i].qyzt == 1) {
						this.tableData[i].qyzts = '启用'
					}
					var data = this.tableData[i]
					if (data.gwdm) {
						let cur = gw.filter((d) => d.dictCode == data.gwdm)
						data.gwdm = cur[0] ? cur[0].dictName : ''
					}
					if (data.zzmm) {
						data.zzmm = this.zzmm[data.zzmm]
						// let cur = way.filter((d) => d.dictCode == data.zzmm)
						// data.zzmm = cur[0] ? cur[0].dictName : ''
					}
				}
				this.pageForm.total = res.data.total
			})
		},
		//新增
		addSubmit() {
			this.$router.push({ path: '/jcxxwh/ryxxAdd' })
		},
		//详情
		detailSubmit(row) {
			this.$router.push({
				name: 'ryxxAdd',
				query: {
					rybh: row.rybh,
					type: 'detailsss',
					tyshxydm: this.$route.query.tyshxydm
				}
			})
		},
		//启用
		open(row) {
			this.changeStatus(
				{
					rybh: row.rybh,
					qyzt: 1
				},
				'启用'
			)
			// this.$router.push({
			// 	path: '/jcxxwh/ryxxAdd',
			// 	query: {
			// 		rybh: row.rybh,
			// 		type: 'openOpen'
			// 	}
			// })
		},
		//禁用
		close(row) {
			this.changeStatus(
				{
					rybh: row.rybh,
					qyzt: 0
				},
				'禁用'
			)
		},
		changeStatus(d, type) {
			personnelEnabled(d).then((res) => {
				if (res.infoCode == 200) {
					this.$message.success(type + '成功')
					this.getList()
				} else {
					this.$message.error(type + '失败')
				}
			})
		},
		//直接提交
		smt(row) {
			this.$router.push({
				path: '/jcxxwh/ryxxAdd',
				query: {
					rybh: row.rybh,
					type: 'smts'
				}
			})
		},
		editSubmit(row) {
			this.$router.push({
				path: '/jcxxwh/ryxxAdd',
				query: {
					rybh: row.rybh,
					type: 'editsss'
				}
			})
		},
		//删除
		deleteSubmit(rowId) {
			this.$confirm('此操作将永久删除, 是否继续?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			})
				.then(() => {
					deleteFn(rowId).then((res) => {
						if (res.infoCode == 200) {
							this.$message({
								message: '删除成功',
								type: 'success'
							})
							this.getList()
						} else {
							this.$message({
								message: '删除失败',
								type: 'error'
							})
							this.getList()
						}
					})
				})
				.catch(() => {
					this.$message({
						message: '已取消删除',
						type: 'warning'
					})
				})
		},

		handleSizeChange(val) {
			this.pageForm.size = val
			this.getList()
		},
		handleCurrentChange(val) {
			this.pageForm.page = val
			this.getList()
		}
	}
}
</script>
<style></style>
