<template>
|
<tr class="m-color b-font" style="text-align: center">实验所用的试剂或材料</tr>
|
<tr>
|
<td class="w-14 m-color required">实验材料</td>
|
<td class="w-14 m-color">耗材ID</td>
|
<td class="w-14 m-color">材料类型</td>
|
<td class="w-14 m-color">材料储存</td>
|
<td class="w-14 m-color">计量单位</td>
|
<td class="w-14 m-color required">使用数量</td>
|
<td class="w-14 m-color">操作</td>
|
</tr>
|
<tr v-for="(item,index) in selectMaterialState.materialList" :key="index">
|
<td class="w-14">
|
<el-select :disabled="selectMaterialState.disabled" filterable v-model="item.stuffId" @change="giveOtherMaterialValue($event, index)" @focus="checkAllMaterial($event, index)">
|
<el-option
|
v-for="item in selectMaterialState.allMaterialList"
|
:key="item.id"
|
:value="item.id"
|
:label="item.stuffName"
|
>
|
</el-option>
|
</el-select>
|
</td>
|
<td class="w-14">
|
<el-input disabled v-model="item.stuffCode" />
|
</td>
|
<td class="w-14">
|
<!-- <el-input :disabled="selectMaterialState.disabled" v-model="item.stuffType" />-->
|
<div>{{selectMaterialState.stuffTypeList.find(i=>i.id == item.stuffType)?.name}}</div>
|
</td>
|
<td class="w-14">
|
<!-- <el-input :disabled="selectMaterialState.disabled" v-model="item.stuffStorage" />-->
|
<div>{{selectMaterialState.stuffStorageList.find(i=>i.id == item.stuffStorage)?.name}}</div>
|
</td>
|
<td class="w-14">
|
<!-- <el-input :disabled="selectMaterialState.disabled" v-model="item.stuffUnit" />-->
|
<div>{{selectMaterialState.stuffUnitList.find(i=>i.id == item.stuffUnit)?.name}}</div>
|
</td>
|
<td class="w-14">
|
<el-input type="number" :disabled="selectMaterialState.disabled" v-model="item.stuffUseCount" />
|
</td>
|
<td class="w-14">
|
<el-button type="danger" :disabled="selectMaterialState.disabled" @click="deleteMaterialItem(index)">删除</el-button>
|
</td>
|
</tr>
|
<tr style="text-align: center">
|
<el-button :disabled="selectMaterialState.disabled" type="primary" shape="round" @click="addMaterialItem()">
|
添加现有实验材料
|
</el-button>
|
<el-button :disabled="selectMaterialState.disabled" shape="round" @click="addNewMaterial('新增', {})">
|
新增实验材料配置
|
</el-button>
|
</tr>
|
<material-dialog ref="materialDialogRef"></material-dialog>
|
</template>
|
|
<script setup lang="ts">
|
import {defineAsyncComponent, onMounted, reactive, ref, watchEffect} from "vue";
|
import { materialApi } from "/@/api/basic/material";
|
import {ElMessage} from "element-plus";
|
let props = defineProps({
|
disabled: Boolean,
|
data: Array<AllMaterialListType>
|
});
|
const MaterialDialog = defineAsyncComponent(() => import('/@/views/basic/material/components/materialDialog.vue'));
|
const selectMaterialState = reactive<SelectMaterialType>({
|
disabled: false,
|
materialList: [],
|
allMaterialList: [],
|
stuffTypeList: [
|
{id: 1, name: '化学试剂'},
|
{id:2, name: '基础材料'}
|
],
|
stuffStorageList: [
|
{id:1, name: '智能试剂柜'},
|
{id:2, name: '普通储存柜'},
|
],
|
stuffUnitList: [
|
{id:1, name: 'g'},
|
{id:2, name: 'kg'},
|
{id:3, name: 'ml'},
|
{id:4, name: 'l'},
|
]
|
})
|
const materialDialogRef = ref();
|
|
const addMaterialItem = () => {
|
selectMaterialState.materialList.push({stuffId: null, stuffUseCount: null, stuffName: '',stuffCode:'',stuffType: '', stuffStorage: '', stuffUnit: ''});
|
};
|
|
watchEffect(() => {
|
console.log(selectMaterialState.materialList,'selectMaterialState.materialList')
|
selectMaterialState.materialList = props.data as Array<AllMaterialListType>
|
selectMaterialState.disabled = props.disabled
|
});
|
|
const deleteMaterialItem = (index: number) => {
|
selectMaterialState.materialList.splice(index,1);
|
};
|
|
const addNewMaterial = (title: string, value: MaterialType) => {
|
materialDialogRef.value.showMaterialDialog(title, value);
|
}
|
|
const checkAllMaterial = () => {
|
getAllMaterial()
|
}
|
|
const getAllMaterial = async () => {
|
let res = await materialApi().getAllMaterial();
|
if(res.data.code === 100){
|
selectMaterialState.allMaterialList = JSON.parse(JSON.stringify(res.data.data));
|
}else{
|
ElMessage({
|
type: 'warning',
|
message: res.data.msg
|
})
|
}
|
};
|
|
const giveOtherMaterialValue = (value: number, index:number) => {
|
const data = selectMaterialState.allMaterialList.find(item => item.id === value) as AllMaterialListType
|
selectMaterialState.materialList[index] = {
|
stuffId: data.id,
|
stuffUseCount: data.stuffUseCount,
|
stuffName: data.stuffName,
|
stuffCode: data.stuffCode,
|
stuffType: data.stuffType,
|
stuffStorage: data.stuffStorage,
|
stuffUnit: data.stuffUnit
|
};
|
};
|
|
const formatList = (formatList: Array<AllMaterialListType>) => {
|
selectMaterialState.materialList = formatList
|
};
|
|
defineExpose({
|
dataList: selectMaterialState.materialList,
|
formatList
|
});
|
|
|
onMounted(() => {
|
getAllMaterial();
|
});
|
</script>
|
|
<style scoped lang="scss">
|
.site-layout-background {
|
background: #fff;
|
}
|
|
.report-table {
|
width: 100%;
|
border-collapse: collapse;
|
border: 1px solid #337ecc;
|
margin: 20px 0;
|
|
th {
|
padding: 10px 0;
|
border: 1px solid #337ecc;
|
border-left: none;
|
}
|
|
tr {
|
width: 100%;
|
height: 44px;
|
line-height: 42px;
|
border-bottom: 1px solid #ccc;
|
|
&:last-of-type {
|
border-bottom: none;
|
}
|
|
td {
|
border-right: 1px solid #ccc;
|
display: inline-block;
|
height: 44px;
|
vertical-align: middle;
|
text-align: center;
|
line-height: 42px;
|
|
&:last-of-type {
|
border-right: none;
|
}
|
|
&.required {
|
&::before {
|
content: "*";
|
display: inline-block;
|
color: red;
|
}
|
}
|
|
&.w-14 {
|
width: calc((100/7)/100 * 100%);
|
}
|
|
&.w-16 {
|
width: calc((100/6)/100 * 100%);
|
}
|
|
&.w-18 {
|
width: 16.59%;
|
}
|
|
&.w-20 {
|
width: 20%;
|
}
|
|
&.w-25 {
|
width: 25%;
|
}
|
|
&.w-50 {
|
width: 50%;
|
}
|
|
&.w-75 {
|
width: 75%;
|
}
|
|
.ant-input {
|
height: 100%;
|
border: none;
|
background: #f5f7fa;
|
}
|
|
.ant-picker {
|
width: 100%;
|
height: 100%;
|
}
|
:deep(.el-input__wrapper ){
|
box-shadow: none;
|
}
|
}
|
}
|
|
.b-font {
|
font-size: 16px;
|
font-weight: bolder;
|
}
|
}
|
|
.m-color {
|
color: #0c4995;
|
}
|
</style>
|