
<template>
	<lay-container fluid="true" class="content-box">
		<lay-button size="sm" type="primary" @click="_downSAP()">导出SAP</lay-button>
		<lay-button size="sm" type="primary" @click="_downMateialView()">导出视图</lay-button>
		<lay-table height="360px" v-if="dataColumn.length > 0" :columns="dataColumn" :data-source="dataList"
			:cellStyle="cellStyle">
		</lay-table>
	</lay-container>
</template>

<style scoped>
.content-box {
	height: 400px;
	margin: 20px 10px;
	display: block;
	position: relative;
	clear: both;
	float: none;
}
</style>
<script>
import {
	ref
} from 'vue';
import {
	getPageList
} from "/src/api/api/common";
import {
	DownMateialView,
	DownSAP
} from "/src/api/api/material";
export default {
	setup() {
		const dataColumn = ref([]);
		const dataList = ref([]);
		const cellStyle = function (row, column, rowIndex, columnIndex) {
			return column.style || "";
		}
		return {
			dataColumn,
			dataList,
			cellStyle
		}
	},
	props: {
		objInfoObj: {
			type: Object,
			default: () => { },
		}
	},
	mounted() {
		this._getViewList();
	},
	methods: {
		async _downMateialView() {
			let result = await DownMateialView({
				FID: this.objInfoObj.FID,
				FName: this.objInfoObj.FName
			});
			if (result.Code == "200") {
				window.location.href = result.Data
			}
		},
		async _downSAP() {
			let result = await DownSAP({
				FID: this.objInfoObj.FID,
				FName: this.objInfoObj.FName
			});
			if (result.Code == "200") {
				window.location.href = result.Data
			}
		},
		//获取角色集合
		async _getViewList() {
			let result = await getPageList({
				FType: "2",
				FPageSize: 999
			}, "Field") || {};

			let result3 = await getPageList({
				FType: "5",
				FPageSize: 999
			}, "Field") || {};

			let materialType = await await getPageList({
				FPageSize: 999
			}, "MaterialType") || {};


			let arrSort = result.Data.List.sort(function (i1, i2) {
				return i1.FOrder - i2.FOrder;
			})

			let arrSort1 = result3.Data.List.sort(function (i1, i2) {
				return i1.FOrder - i2.FOrder;
			})

			let fields = arrSort1.concat(arrSort);

			// let fields = arr.sort(function (i1, i2) {
			// 	return i1.FOrder - i2.FOrder;
			// });

			let fieldList = [{ "key": "FTypeID1", "value": "FTypeName1" }, { "key": "FTypeID2", "value": "FTypeName2" }];

			let dataColumn = [];
			let kName = "";
			let cName = "";
			let cStyle = "color:#1E9FFF;";
			fields.forEach((item) => {
				if (item.FName.indexOf('.') != -1) {
					let names = item.FName.split('.');
					let name = names.shift();


					if (kName != name) {
						kName = name;
						cName = cName == cStyle ? "color:#009688" : cStyle;
					}
					name = names.join('.');

					dataColumn.push({
						width: name == "物料描述" ? "320px" : "160px",
						align: "center",
						title: name,
						style: cName,
						key: item.FColumnFIeld
					});
				}
				else if (item.FType == 5) {

					dataColumn.push({
						width: item.FName == "物料描述" ? "320px" : "160px",
						align: "center",
						title: item.FName,
						style: "color:#1E9FFF;background:#ccc !important",
						key: item.FColumnFIeld
					});
				}
			});
			this.dataColumn = dataColumn;
			let result2 = await getPageList({
				FPageSize: 99,
				FDataId: this.objInfoObj.FID
			}, "View") || {};


			




			this.dataList = result2.Data.List.map(function(item){
                 item["FTypeName1"]=materialType.Data.List.find(m=>m.FID==item.FTypeID1)?materialType.Data.List.find(m=>m.FID==item.FTypeID1).FName:"";
				 item["FTypeName2"]=materialType.Data.List.find(m=>m.FID==item.FTypeID2)?materialType.Data.List.find(m=>m.FID==item.FTypeID2).FName:"";
				 debugger
				 item.FType=materialType.Data.List.find(m=>m.FID==item.FType)?materialType.Data.List.find(m=>m.FID==item.FType).FName:"";
				 item["FSAPCode"]=item.FCode;
				 item["FSAPDescription"]=item.FName;
				 item["FBaseMaterialDesc"]=item.FDesc;
				 item["FBaseMaterialDesc"]=item.FVersionCode;
				 item["FBaseMaterialDesc"]=item.FFactoryCode;
				 item["FBaseMaterialDesc"]=item.FSupplyCode;
				 item["FBaseMaterialGroup"]=item.FGroupCode;
				 item["FBaseWeightUnit"]=item.FBaseUnit;
				 item["FCraftExplain"]=item.FCraftDesc;
				 return item;
			}) || [];
		},
		cancelClick() {
			this.$emit('cancelClick', false);
		}
	}
}
</script>
