<template>
	<lay-container>
		<div class="info">
			<h3 class="title">新销售号：{{dataInfoObj.FSaleCode}}</h3>
			<h3 class="title">配方选择：{{dataInfoObj.FFormulaName}}</h3>
			<h3 class="title">任务来源：{{dataInfoObj.FDesc}}</h3>
			<lay-button v-if="dataInfoObj.FCanEdit!=2" type="primary" style="margin-top: 20px" :disabled="isDisabled"
				@click="_downloadBOM">下载BOM清单</lay-button>
		</div>
		<OperateLog v-if="editDataInfo.FTeamID" ref="OperateLog" :dataInfoObj="editDataInfo"></OperateLog>
	</lay-container>
</template>
<style scoped>
	.info {
		width: 100%;
		text-align: center;
		margin: 40px auto 0;
	}

	.title {
		font-weight: bold;
		margin-top: 10px;
	}

	.empty-small2 {
		margin: 0 auto 20px;
		display: block;
	}
</style>
<script>
	import {
		ref
	} from 'vue';
	import {
		getPageList
	} from "/src/api/api/common";
	import {
		downloadBOM
	} from "/src/api/api/teamwork";
	import OperateLog from "./OperateLog.vue";

	export default {
		components: {
			OperateLog
		},
		setup() {
			const editDataInfo = ref({});
			const isDisabled = ref(false);
			return {
				editDataInfo,
				isDisabled
			}
		},
		props: {
			dataInfoObj: {
				type: Object,
				default: () => {},
			}
		},
		mounted() {
			this.editDataInfo = JSON.parse(JSON.stringify(this.dataInfoObj));
			console.log(this.editDataInfo)
		},
		methods: {
			cancelClick(isRefresh) {
				this.$emit('cancelClick', isRefresh !== undefined ? isRefresh : false);
			},
			//日期处理
			dateFormat(dataStr) {
				return dataStr.replace('T', ' ').split('.')[0];
			},
			async _downloadBOM() {
				let layerId = layer.load(3);
				let result = await downloadBOM(this.dataInfoObj.FTeamID);
				layer.close(layerId);
				if (result['Code'] === 200) {
					if (result['Data'] > 0) {
						layer.msg('下载成功', {
							icon: 1,
							time: 3000
						});
						this.isDisabled = true;
						this.cancelClick(true)
					} else {
						layer.msg('BOM下载失败，请稍后重试', {
							icon: 2,
							time: 3000
						});
						this.$refs.OperateLog._getPageList();
					}
				}
			}
		}
	}
</script>
