drawer.vue 9.13 KB
<template>
	<div class="report">
		<el-drawer :title="type == 1 ? '修改名单' : type == 2 ? '未提交详情' : ''" :visible.sync="drawer" :direction="direction"
			:before-close="handleClose">
			<div class="demo-drawer__content">
				<div class="content">
					<div class="title">基本信息</div>
					<template v-if="type == 1">
						<el-transfer :key="key" class="transfer" v-model="value" filterable :titles="['待选列表', '已选列表']"
							:left-default-checked="leftDefaultChecked" :right-default-checked="rightDefaultChecked" :format="{
								noChecked: '${total}项',
								hasChecked: '${checked}/${total}项'
							}" @change="handleChange" @left-check-change="leftChange" @right-check-change="rightChange"
							:data="transferData">
							<span slot-scope="{ option }">{{ option.label }}</span>
							<el-button class="transfer-footer" slot="left-footer" size="mini"
								@click="selectTranfer('left')">反选</el-button>
							<el-button class="transfer-footer" slot="right-footer" size="mini"
								@click="selectTranfer('right')">反选</el-button>
						</el-transfer>
					</template>
					<template v-else-if="type == 2">
						<div class="basic-info"><span>日报模板:</span>{{ templateData.typeName }}</div>
						<div class="basic-info"><span>日报日期:</span>{{ templateData.createdDate }}</div>
						<div class="basic-info"><span>缺失份数:</span>{{ templateData.undoCount }}份</div>
						<div class="title">明细数据 <el-button type="primary" size="mini" @click="exportTable">导出</el-button></div>
						<el-table :key="key" :data="tableData" height="400" border style="width: 100%;text-align: center;">
							<el-table-column v-for="(item, index) in tableParams" :sortable="item.sortable" :key="index"
								:prop="item.prop" :label="item.label">
								<template slot-scope="scope">
									<slot :scope="scope.row">
										{{ scope.row[item.prop] == null ? '-' : scope.row[item.prop] }}
									</slot>
								</template>
							</el-table-column>
							<!-- <el-table-column prop="staffName" label="督导姓名">
								{{ scope.row.staffName || "-" }}
							</el-table-column>
							<el-table-column prop="lastSubmitDate" sortable label="最近提交日报日期">
							</el-table-column>
							<el-table-column prop="weekSubmitCount" sortable label="本周提交总数">
							</el-table-column>
							<el-table-column prop="monthSubmitCount" sortable label="本月提交总数">
							</el-table-column> -->
						</el-table>
					</template>
					<template v-else>
						<span>我来啦!</span>
					</template>
				</div>
				<div class="demo-drawer__footer" v-if="type == 1">
					<el-button @click="cancel">取 消</el-button>
					<el-button type="primary" @click="submit">确 定</el-button>
				</div>
			</div>
		</el-drawer>
	</div>
</template>
<script>
import { getSummaryStaff, exportSummary, getAllStaff, getStaffList } from "@api/resident"
import { mapActions, mapState } from 'vuex'
export default {
	name: 'Drawer',
	props: {
		drawerVisible: {
			type: Boolean,
			default: false
		},
		direction: {
			type: String,
			default: 'rtl'
		},
		type: {
			type: Number,
			default: 0
		},
		templateData: {
			type: Object,
			default: () => { }
		}
	},
	watch: {
		drawerVisible(val) {
			this.drawer = val
			if (val) {
				if (this.type == 2) {
					this.getSummaryStaff()
				} else if (this.type == 1) {
					this.value = []
					this.leftChecked = []
					this.rightChecked = []
					this.leftDefaultChecked = []
					this.rightDefaultChecked = []
					this.getStaff()
				}
				this.key = new Date().getTime()
			}
		}
	},
	data() {
		const generateData = _ => {
			const data = [];
			for (let i = 1; i <= 15; i++) {
				data.push({
					key: i + '',
					label: `备选项 ${i}`,
					// disabled: i % 4 === 0
				});
			}
			return data;
		};
		return {
			drawer: false,
			transferData: generateData(),
			value: [],
			leftChecked: [],
			rightChecked: [],
			leftDefaultChecked: [],
			rightDefaultChecked: [],
			tableData: [],
			tableParams: [
				{
					label: '督导姓名',
					prop: 'staffName'
				},
				{
					label: '最近提交日报日期',
					prop: 'lastSubmitDate',
					sortable: true
				},
				{
					label: '本周提交总数',
					prop: 'weekSubmitCount',
					sortable: true
				},
				{
					label: '本月提交总数',
					prop: 'monthSubmitCount',
					sortable: true
				}
			],
			key: new Date().getTime()
		}
	},

	computed: {
		...mapState({
			dowloadList: (state) => state.d2admin.user.dowloadList
		})
	},
	methods: {
		...mapActions({
			get: 'd2admin/base/get',
			close: 'd2admin/page/close'
		}),
		...mapActions('d2admin/user', ['actionSetDownloadList']),
		handleClose(done) {
			done()
			this.$emit('handleClose')
		},
		handleChange(value, direction, movedKeys) {
			this.$emit('drawerChange', value)
		},
		leftChange(currentValue, selectValue) {
			this.leftChecked = currentValue
		},
		rightChange(currentValue, selectValue) {
			this.rightChecked = currentValue
		},
		selectTranfer(type) {
			switch (type) {
				case 'left':
					// 左边反选的 = 全部 - value - 左边已选的
					const all = new Set(this.transferData.map(item => item.key))
					const leftArr = this.value.concat(this.leftChecked) // value + 左边已选
					leftArr.map(item => all.delete(item))
					this.leftDefaultChecked = Array.from(all)
					this.leftChecked = this.leftDefaultChecked  // 修改左边已选的值
					break
				case 'right':
					// 右边边反选的 = value - 右边已选的
					const value = new Set(this.value)
					this.rightChecked.map(item => value.delete(item))
					this.rightDefaultChecked = Array.from(value)
					this.rightChecked = this.rightDefaultChecked
					break
				default:
					break
			}
		},
		cancel() {
			if (this.type == 1) {
				this.drawer = false
				this.leftChecked = []
				this.rightChecked = []
				this.leftDefaultChecked = []
				this.rightDefaultChecked = []
				this.$emit('handleClose')
			} else {
				this.$emit('handleClose')
			}
		},
		submit() {
			if (this.type == 1) {
				this.drawer = false
				this.leftChecked = []
				this.rightChecked = []
				this.leftDefaultChecked = []
				this.rightDefaultChecked = []
				const _data = []
				const { transferData } = this
				this.value.forEach(i => {
					_data.push(transferData[i].userId)
				})
				this.$emit('handleSubmit', _data)
			} else {
				this.$emit('handleSubmit')
			}
		},
		exportTable() {
			const { typeName, code, createdDate, staffUuidList } = this.templateData
			const params = {
				typeName,
				templateCode: code,
				createdDate
			}
			if (staffUuidList.length) params.staffUuidListStr = staffUuidList.join(',')
			params.method = 'dj.api.smartcarlife.digital.management.record.staff.summary.export'
			const list = [
				...this.dowloadList,
				{
					name: '未提交清单',
					exportParam: JSON.stringify(params),
					status: 'waiting',
					timeid: new Date().getTime()
				}
			]
			this.actionSetDownloadList({ list, type: 'dowloadList' })
		},
		async getStaff() {
			const staff = (await getAllStaff({}))  // 过滤了已绑定的
			const params = {
				typeName: this.templateData.typeName,
				templateCode: this.templateData.code
			}
			const selectStaff = await getStaffList(params)
			const allStaff = staff.concat(selectStaff)
			// console.log(allStaff);
			allStaff.forEach((item, index) => {
				item.key = index
				item.label = item.userName
			})
			this.transferData = allStaff
			console.log(selectStaff);
			selectStaff.forEach(i => {
				const _item = allStaff.find(j => j.userId == i.userId)
				if (_item) {
					i.key = _item.key
					i.label = _item.label
					this.value.push(_item.key)
				}
			})
		},
		getSummaryStaff() {
			const { typeName, code, createdDate, staffUuidList } = this.templateData
			const params = {
				typeName,
				templateCode: code,
				createdDate
			}
			if (staffUuidList.length) params.staffUuidListStr = staffUuidList.join(',')
			getSummaryStaff(params).then(res => {
				// console.log(res, '====');
				// if (res.length) {
				// 	res.forEach(item => {
				// 		if (!item.staffName) item.s
				// 	})
				// }
				this.tableData = res
			})
		}
	}
}
</script>

<style lang="scss">
.report {
	.el-drawer__header {
		padding: 18.5px 20px;
		margin-bottom: 0;
		border-bottom: 1px solid #E5E5E5;
		color: #333 !important;
		font-weight: 600 !important;
	}

	.el-drawer.rtl {
		width: 774px !important;
	}

	.el-transfer-panel {
		width: 270px;
	}

	.el-transfer-panel .el-transfer-panel__footer {
		padding-left: 16px;
	}

	.el-table .cell {
		text-align: center;
	}
}
</style>
<style lang="scss" scoped>
.report {
	.basic-info {
		font-size: 14px;
		color: #333;
		padding-left: 100px;
		margin: 16px 20px 0 0;

		span {
			color: #666;
		}
	}

	.content {
		padding: 0 20px;

		.title {
			display: flex;
			color: #333333;
			font-size: 16px;
			justify-content: space-between;
			padding: 13.5px 0;
			border-bottom: 1px solid #E5E5E5;
		}

		.transfer {
			text-align: left;
			display: inline-block;
			margin-top: 16px;
		}
	}

	.demo-drawer__content {
		display: flex;
		flex-direction: column;
		height: 100%;
	}

	.demo-drawer__footer {
		background-color: #fff;
		display: flex;
		position: absolute;
		bottom: 20px;
		right: 20px;
	}
}
</style>