<template>
    <lay-table style="margin:0 0 30px 0;" height="200px" :columns="dataColumn" :data-source="dataList">
		<template v-slot:toolbar>
			<p style="float:left;">配方视图</p>
		</template>
	</lay-table>
</template>
<script>
    import {
		ref
	} from 'vue';
    import {
		getTeamworkView
	} from "/src/api/api/halfmaterialteamwork";

    export default {
        setup() {
            const viewList = ref([]);
            const dataColumn = ref([
                {type: 'number', title: '序号', width: '56'},
                {key: '工厂', title: '工厂', align: 'center', width: '130px'},
                {key: '开始生效日期', title: '开始生效日期', align: 'center', width: '130px'},
                {key: 'BOM用途', title: 'BOM用途', align: 'center', width: '130px'},
                {key: 'BOM状态', title: 'BOM状态', align: 'center', width: '130px'},
                {key: '可选文本', title: '可选文本', align: 'center', width: '130px'},
                {key: '可选BOM', title: '可选BOM', align: 'center', width: '130px'},
                {key: '父项编码', title: '父项编码', align: 'center', width: '200px'},
                {key: '父项描述', title: '父项描述', align: 'center', width: '300px'},
                {key: '基本数量', title: '基本数量', align: 'center', width: '130px'},
                {key: '基本单位', title: '基本单位', align: 'center', width: '130px'},
                {key: '子项序号', title: '子项序号', align: 'center', width: '130px'},
                {key: '项目类别', title: '项目类别', align: 'center', width: '130px'},
                {key: '子项编码', title: '子项编码', align: 'center', width: '200px'},
                {key: '子件描述', title: '子件描述', align: 'center', width: '300px'},
                {key: '组件数量', title: '组件数量', align: 'center', width: '130px'},
                {key: '计量单位', title: '计量单位', align: 'center', width: '130px'},
                {key: '工程变更号', title: '工程变更号', align: 'center', width: '130px'},
                {key: '项目ID', title: '项目ID', align: 'center', width: '130px'},
                {key: '物料供应标识符', title: '物料供应标识符', align: 'center', width: '130px'},
                {key: '备件标示', title: '备件标示', align: 'center', width: '130px'},
                {key: '生产仓储地点', title: '生产仓储地点', align: 'center', width: '130px'},
                {key: '组件损耗率', title: '组件损耗率', align: 'center', width: '130px'},
                {key: '成本核算标识相关', title: '成本核算标识相关', align: 'center', width: '130px'},
                {key: '生产相关', title: '生产相关', align: 'center', width: '130px'},
                {key: 'BOM项目文本1', title: 'BOM项目文本1', align: 'center', width: '130px'},
                {key: 'BOM项目文本2', title: 'BOM项目文本2', align: 'center', width: '130px'},
                {key: '替代项目组', title: '替代项目组', align: 'center', width: '130px'},
                {key: '优先级', title: '优先级', align: 'center', width: '130px'},
                {key: '策略', title: '策略', align: 'center', width: '130px'},
                {key: '使用可能性', title: '使用可能性', align: 'center', width: '130px'},
                {key: '固定损耗数量', title: '固定损耗数量', align: 'center', width: '130px'}
            ]);
            const dataList = ref([]);

            return {
                viewList,
				dataColumn,
				dataList
			}
        },
        props: {
            dataInfoObj: {
				type: Object,
				default: () => {},
			},
			teamId: {
				type: String,
				default: () => ""
			},
            halfId: {
                type: String,
                default: () => ""
            }
		},
        mounted() {
            this.initPage();
		},
        methods: {
            async initPage() {
                let dataColumn = [{
					type: "number",
					title: "序号",
					width: "56"
				}];
                let dataList = [];
                debugger
				let postData = {
					FTeamID: this.dataInfoObj.FID,
					FViewType: 2,
					FType: 1,
					HalfId : this.dataInfoObj.FMaterialHalfIDs
				};

				let result = await getTeamworkView(postData);

                let formulaList = result["List1"]

                if (formulaList) {
                    for (let key in formulaList[0]) {
                        let width = (key.indexOf("描述") != -1 || key == "文本" || key == "物料") ? "300px" :
                            "130px";
                        width = key.indexOf("编码") != -1 ? "200px" : width;
                        dataColumn.push({
                            key: key,
                            title: key.split('.').pop(),
                            align: "center",
                            width: width
                        });
                    }
                    
                    formulaList.forEach((item) => {
                        dataList.push(item);
                    });
                }
                // this.dataColumn = dataColumn;
				this.dataList = dataList;
            }
        }
    }

</script>