马宇豪
2023-08-07 7ed4982b8f2a345bfad95a96070143c32142bc61
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<template>
    <tr class="m-color b-font" style="text-align: center">实验所用的仪器/设备</tr>
    <tr>
        <td class="w-16 m-color">设备名称</td>
        <td class="w-16 m-color">编号</td>
        <td class="w-16 m-color">额定功率</td>
        <td class="w-16 m-color">是否特种</td>
        <td class="w-16 m-color">设备数量</td>
        <td class="w-16 m-color">操作</td>
    </tr>
    <tr v-for="(item,index) in selectEquipmentState.equipmentList" :key="index">
        <td class="w-16">
            <el-select :disabled="selectEquipmentState.disabled" filterable v-model="item.deviceId" @change="giveOtherEquipmentValue($event, index)">
                <el-option
                    v-for="item in selectEquipmentState.allEquipmentList"
                    :key="item.id"
                    :value="item.id"
                    :label="item.deviceName"
                >
                </el-option>
            </el-select>
        </td>
        <td class="w-16">
            <el-input :disabled="selectEquipmentState.disabled" v-model="item.deviceCode" placeholder="请输入数量" />
        </td>
        <td class="w-16">
            <el-input :disabled="selectEquipmentState.disabled" v-model="item.devicePower" />
        </td>
        <td class="w-16">
            <el-radio-group :disabled="selectEquipmentState.disabled" v-model="item.specialDevice">
                <el-radio :label="1">是</el-radio>
                <el-radio :label="2">否</el-radio>
            </el-radio-group>
        </td>
        <td class="w-16">
            <el-input type="number" v-model="item.deviceUseCount" />
        </td>
        <td class="w-16">
            <el-button :disabled="selectEquipmentState.disabled" type="danger" @click="deleteEquipmentItem(index)">删除</el-button>
        </td>
    </tr>
    <tr style="text-align: center">
        <el-button :disabled="selectEquipmentState.disabled" type="primary" shape="round" @click="addEquipmentItem()">
            选择实验仪器
        </el-button>
    </tr>
</template>
 
<script setup lang="ts">
import {onMounted, reactive, watchEffect} from "vue";
import {ElMessage} from "element-plus";
import { equipmentApi } from "/@/api/basic/equipement";
 
let props = defineProps({
    disabled: Boolean,
    data: Array<AllEquipmentListType>
});
 
const selectEquipmentState = reactive<SelectEquipmentType>({
    disabled: false,
    equipmentList: [],
    allEquipmentList: [],
});
 
watchEffect(() => {
    selectEquipmentState.equipmentList = props.data as Array<AllEquipmentListType>
    selectEquipmentState.disabled = props.disabled
});
 
const addEquipmentItem = () => {
    selectEquipmentState.equipmentList.push({deviceId: null, deviceUseCount: null, deviceCode: '', deviceName: '', devicePower: '', specialDevice: '',});
};
 
const deleteEquipmentItem = (index: number) => {
    selectEquipmentState.equipmentList.splice(index,1);
};
 
const getAllEquipmentList = async () => {
    let res = await equipmentApi().getAllEquipment();
    if(res.data.code === 100){
        selectEquipmentState.allEquipmentList = JSON.parse(JSON.stringify(res.data.data));
    }else{
        ElMessage({
            type: 'warning',
            message: res.data.msg
        })
    }
};
 
const giveOtherEquipmentValue = (value: number, index:number) => {
    const data = selectEquipmentState.allEquipmentList.find(item => item.id === value) as AllEquipmentListType
    selectEquipmentState.equipmentList[index] = {
        deviceId: data.id,
        deviceUseCount: null,
        deviceCode: data.deviceCode,
        deviceName: data.deviceName,
        devicePower: data.devicePower,
        specialDevice: data.specialDevice
    }
};
 
const formatList = (formatList: Array<AllEquipmentListType>) => {
    selectEquipmentState.equipmentList = formatList
}
 
defineExpose({
    dataList: selectEquipmentState.equipmentList,
    formatList
});
 
onMounted(() => {
    getAllEquipmentList();
});
</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;
            }
 
            &.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%;
            }
        }
    }
 
    .b-font {
        font-size: 16px;
        font-weight: bolder;
    }
}
 
.m-color {
    color: #0c4995;
}
:deep(.el-input__wrapper ){
    box-shadow: none;
}
</style>