allocationDialog.vue 2.91 KB
<template>
    <d2-dialog title="新增课程"
               :is-visible.sync="isVisible"
               width="1120px"
               btn-ok-label="确定"
               @confirmDialog="handleConfirm"
               @closeDialog="handleClose">
        <CurriculaVariable ref="curriculaVariable"
                           :course-list="courseList"
                           :course-total="courseTotal"
                           :selected-rows="selectedDialogRows"
                           @handleCourse="handleCourse"
                           @fromAllocation="fromAllocation">
        </CurriculaVariable>
    </d2-dialog>
</template>

<script>
import { getStaffTagCourseList } from "@/api/serviceCentre";
import curriculaVariable from "./allocation";

export default {
	components: {
		CurriculaVariable: curriculaVariable,
	},
	props: {
		isVisible: {
			type: Boolean,
			default: false,
		},
		selectedRows: {
			type: Array,
			default: () => [],
		},
		staffItem: {
			type: Object,
			default: () => {},
		},
	},
	data() {
		return {
			selectData: [],
			courseList: [],
			courseTotal: 0,
		};
	},
	computed: {
		selectedDialogRows() {
			return this.selectedRows.map((item) => {
				return item;
			});
		},
	},
	watch: {
		isVisible: {
			handler(val) {
				if (val) {
					// 弹框每次 v-if 重建后 selectData 为空,需从 props 同步已选数据
					this.selectData = Array.isArray(this.selectedRows)
						? [...this.selectedRows]
						: [];
					this.getStaffTagCourseList();
				}
			},
			immediate: true,
		},
	},
	methods: {
		getStaffTagCourseList(courseForm = {}) {
			let params = {
				staffPhone: this.staffItem.phone,
				currentPage: 1,
				pageSize: 5,
				queryAll: false,
				...courseForm,
			};
			getStaffTagCourseList(params).then((res) => {
				this.courseList = res ? res.list : [];
				this.courseTotal = res ? res.total : 0;
			});
		},
		handleCourse(data) {
			this.selectData = data;
		},
		fromAllocation(val) {
			this.getStaffTagCourseList(val);
		},
		// 确认仅返回整条数据数组
		handleConfirm() {
			const curriculaRef = this.$refs.curriculaVariable;
			const data
				= curriculaRef && Array.isArray(curriculaRef.selectCourseList)
					? [...curriculaRef.selectCourseList]
					: [...this.selectData];
			this.$emit("handleConfirm", data);
		},
		handleClose() {
			this.$emit("handleClose");
		},
	},
};
</script>

<style lang="scss" scoped>
.relateEmp {
	::v-deep .el-dialog__header {
		border-bottom: 1px solid #e5e5e5;
	}
	::v-deep .d2-search .d2-search-block {
		padding: 0px !important;
	}
	::v-deep .el-dialog__header {
		font-size: 20px;
		line-height: 24px;
	}
	.select-text {
		color: #333333;
		font-size: 14px;
		position: relative;
		right: 65%;
		margin-bottom: 8px;
	}
	.online-status {
		display: flex;
		justify-content: center;
		align-items: center;

		.dot {
			display: inline-block;
			width: 8px;
			height: 8px;
			border-radius: 50%;
			margin-right: 8px;
		}
	}
}
</style>