<template>
	<el-drawer title="工艺图纸" :with-header="false" v-model="visible" direction="rtl" size="30%">
		<div class="form-container column-container">
			<div class="form-btns-container">
				<span class="title-label">
					<el-icon>
						<Document />
					</el-icon>
					<span>工艺图纸</span>
				</span>
				<div class="close-btn" @click="cancel">
					<i class="fa fa-times" aria-hidden="true" />
					<!-- <span>关闭</span> -->
				</div>
			</div>
	<!-- 渲染数据区 -->
			<div class="el-table-container" style="width: 100%;">
				<div class="el-table-inner-container">
					<el-table v-drawingLoading="drawingLoading" :data="drawingList" size="small" border height="100%">
						<el-table-column label="工序简称" align="center" prop="processAlias" width="104" />
						<el-table-column label="图纸" align="center" prop="drawingName"  />
						<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="64">
						<template #default="scope">
							<el-button link type="primary" @click="handleShowDrawing(scope.row)"> 图纸 </el-button>
						</template>
					</el-table-column>
					</el-table>
				</div>
			</div>
		</div>
	</el-drawer>
</template>
<script setup>
import { getDrawingDetail } from '@/api/business/outsourcedOrder'
const { proxy } = getCurrentInstance()
/** 字典数组区 */
/** 表单抽屉 页变量 */

const drawingLoading = ref(false)
const visible = ref(false)
const drawingUrl = ref("");
const webHost = import.meta.env.VITE_APP_BASE_API;
const fileUrl = import.meta.env.VITE_PREVIEW_API;
const hostUrl = import.meta.env.VITE_HOST_URL;

const inNet = import.meta.env.VITE_HOST_INNET;
const outNet = import.meta.env.VITE_HOST_OUTNET;
const hostIp = import.meta.env.VITE_HOST_IP;
const drawingList = ref([])

/***********************  方法区  ****************************/
/** 打开抽屉 */
const open = (data) => {
	console.log(data)
	drawingLoading.value = true
	visible.value = true
	getDrawingDetail({id:data.id}).then(res => {
		if(res.data && res.data.length > 0){
			res.data.forEach(element => {
				let itemUrl = document.location.origin;
    let fUrl = "";
    if (itemUrl.includes(hostIp)) {
      fUrl = inNet;
    } else {
      fUrl = outNet;
    }
	console.log(hostUrl,webHost,fUrl)
    element.drawingUrl =
      fUrl + encodeURIComponent(Base64.encode(hostUrl + webHost + element.url));
			});
			drawingList.value = res.data
		}else{
			drawingList.value = []
		}
		
	})
}
function handleShowDrawing(row){
	console.log(row.drawingUrl)
	window.open(row.drawingUrl);
}

/** 取消按钮 */
const cancel = () => {
	visible.value = false
	reset()
}
/** 暴露给父组件的方法 */
defineExpose({
	open
})
</script>
<style scoped>
:deep(.el-table-inner-container){
	position: absolute;
    top: 0;
    right: 0px;
    bottom: 0;
    left: 0px;
}

</style>
