syncBeiSenDialog.vue 3.73 KB
<!-- 北森同步弹窗 -->
<template>
	<baseDialog :dialog-config="dialogConfig" :is-show.sync="visible" @handleClick="submitSyncBeiSen"
		:config="baseDialogConfig">
		<div class="sync-beisen-dialog">
			<div class="search-container">
				<el-input v-model="syncSearchForm.staffName" placeholder="请输入姓名" class="search-input" clearable></el-input>
				<el-input v-model="syncSearchForm.mobilePhone" placeholder="请输入手机号" class="search-input"
					clearable></el-input>
				<el-button type="primary" @click="handleSyncSearch">查询</el-button>
			</div>

			<div v-loading="syncLoading" class="result-container">
				<div v-if="!syncResultList.length" class="empty-state">
					<img src="@/assets/empty.png" alt="" class="empty-img">
					<span class="empty-text">未查询到匹配的北森员工数据</span>
				</div>
				<el-radio-group v-else v-model="selectedBeiSenUserId" class="radio-group-list">
					<el-radio v-for="item in syncResultList" :key="item.userID" :label="item.userID">
						{{ item.name }} | {{ item.mobilePhone }}
					</el-radio>
				</el-radio-group>
			</div>
		</div>
	</baseDialog>
</template>

<script>
import { beiSenEmployeePageApi, beiSenEmployeeSingleSyncApi } from "@/api/resident";

export default {
	name: "SyncBeiSenDialog",
	props: {
		syncBeiSenVisible: {
			type: Boolean,
			default: false,
		},
		satffId: {
			type: Number,
			default: 0,
		}
	},
	data() {
		return {
			dialogConfig: {
				title: "北森同步",
				width: "600px",
			},
			syncSearchForm: {
				staffName: "",
				mobilePhone: "",
			},
			syncLoading: false,
			syncResultList: [],
			selectedBeiSenUserId: "",
		};
	},
	computed: {
		visible: {
			get() {
				return this.syncBeiSenVisible;
			},
			set(newVal) {
				this.$emit("dialogClose", { flag: newVal, attrName: "syncBeiSenVisible" });
			},
		},
		baseDialogConfig() {
			return {
				showClose: true,
				appendToBody: false, // 是否将自身插入至 body 元素,有嵌套的弹窗时一定要设置
				isShowFooter: true,
				confirm_name: "提交同步",
				cancel_name: "取 消"
			}
		}
	},
	mounted() {
		// 默认查询
		// this.handleSyncSearch();
	},
	methods: {
		handleSyncSearch() {
			if (!this.syncSearchForm.staffName && !this.syncSearchForm.mobilePhone) {
				this.syncResultList = [];
				return;
			}
			this.syncLoading = true;
			const params = {
				staffName: this.syncSearchForm.staffName,
				mobilePhone: this.syncSearchForm.mobilePhone,
				pageNum: 1,
				pageSize: 9999
			};
			beiSenEmployeePageApi(params).then(res => {
				this.syncLoading = false;
				this.syncResultList = res.list || [];
				this.selectedBeiSenUserId = "";
			}).catch(() => {
				this.syncLoading = false;
			});
		},
		submitSyncBeiSen() {
			if (!this.selectedBeiSenUserId) {
				this.$message.warning("请选择北森员工");
				return;
			}
			const params = {
				staffId: this.satffId,
				beiSenUserID: this.selectedBeiSenUserId
			};
			beiSenEmployeeSingleSyncApi(params).then(() => {
				this.$message.success("同步成功");
				this.visible = false;
				this.$emit("refreshDetail");
			});
		},
	},
};
</script>

<style scoped lang="scss">
.sync-beisen-dialog {
	padding: 0 20px;
}

.search-container {
	display: flex;
	gap: 10px;
	margin-bottom: 20px;
}

.search-input {
	width: 200px;
}

.result-container {
	background-color: #F5F7FA;
	min-height: 100px;
	max-height: 400px;
	overflow-y: auto;
	padding: 16px;
	border: 1px solid #ECEEF5;
	border-radius: 4px;
}

.empty-state {
	margin-top: 16px;
	display: flex;
	flex-direction: column;
	align-items: center;
}

.empty-img {
	width: 64px;
	margin-bottom: 10px;
	display: block;
}

.empty-text {
	color: #999999;
}

.radio-group-list {
	display: flex;
	flex-direction: column;
	gap: 15px;


	::v-deep .el-radio {
		color: #333333;
	}
}
</style>