﻿<template>
	<div class="mesWorkGroup-container">
		<el-table :data="dataList" style="width: 100%">
			<el-table-column type="index" label="序号" width="55" align="center" />
			<el-table-column prop="workSiteCode" label="工位编码" show-overflow-tooltip="" />
			<el-table-column prop="workSiteName" label="工位名称" show-overflow-tooltip="" />
			<el-table-column prop="person" label="人员" show-overflow-tooltip="">
				<template #default="{ row }">
				<el-select v-model="row.choosePerson" @change="onPersonChange(row)">
					<el-option v-for="item in row.person" :key="item.account" :label="item.realName" :value="item.account" />
				</el-select>	
				</template>
			</el-table-column>
		</el-table>
	</div>
</template>
<style lang="scss" scoped>
:deep(.el-select),
:deep(.el-input-number) {
	width: 100%;
}
</style>
<script lang="ts" setup>
import { ref, onMounted, reactive } from 'vue';
import { ElMessage } from 'element-plus';
import type { FormRules } from 'element-plus';
import { getProductionLineWorkSiteList,saveProductionLineWorkSitePerson } from '/@/api/mes/mesWorkGroup';

//父级传递来的参数
var props = defineProps({
	workGroupCode: {
		type: String,
		default: '',
	},
});
//父级传递来的函数，用于回调
const emit = defineEmits(['reloadTable']);

const userList = ref([]);
const dataList = ref([]);
onMounted(async () => {
	var res = await getProductionLineWorkSiteList({ workGroupCode: props.workGroupCode });

	res.data.result.forEach((el: any) => {
		var spsCode = el.personCodes.split(',');
		var spsName = el.personNames.split(',');
		el.person=[];
		spsCode.forEach((item: any, index: number) => {
			if (item) {
				el.person.push({
					account: item,
					realName: spsName[index],
				});
			}
		});
	});

	dataList.value = res.data.result;
});

const onPersonChange = async (item:any)=>{
 await saveProductionLineWorkSitePerson({WorkGroupCode:props.workGroupCode,WorkSiteCode:item.workSiteCode,PersonCode:item.choosePerson})
 ElMessage.success('保存成功');
}

//将属性或者函数暴露给父组件
defineExpose({});
</script>
