fix aud search on center
This commit is contained in:
347
frontend/app.js
347
frontend/app.js
@@ -5,6 +5,7 @@ const api = {
|
||||
oboruds: (audId) => `/oboruds/?aud_id=${encodeURIComponent(audId)}`,
|
||||
allOboruds: "/oboruds/?sort_by_inv=true",
|
||||
owners: "/owners/",
|
||||
zametki: "/zametki/",
|
||||
};
|
||||
|
||||
async function fetchJSON(url) {
|
||||
@@ -21,6 +22,8 @@ createApp({
|
||||
selectedAudId: '',
|
||||
oboruds: [],
|
||||
allOboruds: [],
|
||||
unassignedOboruds: [],
|
||||
totalOboruds: 0,
|
||||
status: '',
|
||||
error: '',
|
||||
printTitle: '',
|
||||
@@ -33,6 +36,33 @@ createApp({
|
||||
newAudName: '',
|
||||
owners: [],
|
||||
newOwnerName: '',
|
||||
zametki: [],
|
||||
newZametkaText: '',
|
||||
equipmentTypes: [],
|
||||
newTypeName: '',
|
||||
newEquipment: {
|
||||
invNumber: null,
|
||||
nazvanie: '',
|
||||
raspologenie: '',
|
||||
kolichestvo: 1,
|
||||
aud_id: '',
|
||||
type_id: '',
|
||||
owner_id: ''
|
||||
},
|
||||
// Inspection
|
||||
activeInspection: null,
|
||||
inspectionAudId: '',
|
||||
scannedBarcode: '',
|
||||
lastScanResult: null,
|
||||
inspectionStats: {
|
||||
total_checked: 0,
|
||||
total_expected: 0,
|
||||
total_unknown: 0,
|
||||
progress_percent: 0
|
||||
},
|
||||
checkedEquipment: [],
|
||||
unknownBarcodes: [],
|
||||
inspectionHistory: []
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
@@ -117,6 +147,27 @@ createApp({
|
||||
this.view = 'allEquipment';
|
||||
await this.loadAllOboruds();
|
||||
},
|
||||
async loadUnassigned() {
|
||||
this.status = 'Загрузка нераспределённого оборудования…';
|
||||
this.error = '';
|
||||
try {
|
||||
const [oboruds, stats] = await Promise.all([
|
||||
fetchJSON('/oboruds/?unassigned=true&sort_by_inv=true'),
|
||||
fetchJSON('/oboruds/stats')
|
||||
]);
|
||||
this.unassignedOboruds = oboruds;
|
||||
this.totalOboruds = stats.total;
|
||||
this.status = '';
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
this.error = 'Не удалось загрузить данные';
|
||||
this.status = '';
|
||||
}
|
||||
},
|
||||
async showUnassigned() {
|
||||
this.view = 'unassigned';
|
||||
await this.loadUnassigned();
|
||||
},
|
||||
getAuditoryName(audId) {
|
||||
if (!audId) return '';
|
||||
const aud = this.auditories.find(a => a.id === audId);
|
||||
@@ -129,6 +180,120 @@ createApp({
|
||||
window.print();
|
||||
});
|
||||
},
|
||||
printAllEquipment() {
|
||||
window.print();
|
||||
},
|
||||
async loadZametki() {
|
||||
this.status = 'Загрузка заметок…';
|
||||
this.error = '';
|
||||
try {
|
||||
this.zametki = await fetchJSON(api.zametki);
|
||||
this.status = '';
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
this.error = 'Не удалось загрузить заметки';
|
||||
this.status = '';
|
||||
}
|
||||
},
|
||||
async showZametki() {
|
||||
this.view = 'zametki';
|
||||
await this.loadZametki();
|
||||
},
|
||||
async createZametka() {
|
||||
if (!this.newZametkaText.trim()) {
|
||||
this.status = 'Введите текст заметки';
|
||||
return;
|
||||
}
|
||||
try {
|
||||
this.status = 'Добавление заметки…';
|
||||
await this.fetchAuth(api.zametki, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ txtzam: this.newZametkaText }),
|
||||
});
|
||||
this.newZametkaText = '';
|
||||
await this.loadZametki();
|
||||
this.status = 'Заметка добавлена';
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
this.error = 'Не удалось добавить заметку';
|
||||
this.status = '';
|
||||
}
|
||||
},
|
||||
async resolveZametka(id) {
|
||||
try {
|
||||
this.status = 'Отметка заметки как решённой…';
|
||||
await this.fetchAuth(`/zametki/${id}/resolve`, { method: 'PATCH' });
|
||||
await this.loadZametki();
|
||||
this.status = 'Заметка отмечена как решённая';
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
this.error = 'Не удалось отметить заметку';
|
||||
this.status = '';
|
||||
}
|
||||
},
|
||||
formatDate(dateStr) {
|
||||
if (!dateStr) return '';
|
||||
const d = new Date(dateStr);
|
||||
return d.toLocaleString('ru-RU');
|
||||
},
|
||||
async loadEquipmentTypes() {
|
||||
try {
|
||||
this.equipmentTypes = await fetchJSON('/equipment-types/');
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
},
|
||||
async createEquipmentType() {
|
||||
if (!this.newTypeName.trim()) {
|
||||
this.status = 'Введите название типа';
|
||||
return;
|
||||
}
|
||||
try {
|
||||
this.status = 'Добавление типа…';
|
||||
await this.fetchAuth('/equipment-types/', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ name: this.newTypeName }),
|
||||
});
|
||||
this.newTypeName = '';
|
||||
await this.loadEquipmentTypes();
|
||||
this.status = 'Тип добавлен';
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
this.error = 'Не удалось добавить тип';
|
||||
this.status = '';
|
||||
}
|
||||
},
|
||||
async createEquipment() {
|
||||
if (!this.newEquipment.nazvanie.trim()) {
|
||||
this.status = 'Введите название оборудования';
|
||||
return;
|
||||
}
|
||||
try {
|
||||
this.status = 'Добавление оборудования…';
|
||||
const data = {
|
||||
nazvanie: this.newEquipment.nazvanie,
|
||||
invNumber: this.newEquipment.invNumber || null,
|
||||
raspologenie: this.newEquipment.raspologenie || null,
|
||||
kolichestvo: this.newEquipment.kolichestvo || null,
|
||||
aud_id: this.newEquipment.aud_id || null,
|
||||
type_id: this.newEquipment.type_id || null,
|
||||
owner_id: this.newEquipment.owner_id || null,
|
||||
};
|
||||
await this.fetchAuth('/oboruds/', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
this.newEquipment = { invNumber: null, nazvanie: '', raspologenie: '', kolichestvo: 1, aud_id: '', type_id: '', owner_id: '' };
|
||||
this.status = 'Оборудование добавлено';
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
this.error = 'Не удалось добавить оборудование';
|
||||
this.status = '';
|
||||
}
|
||||
},
|
||||
async saveOwner(item) {
|
||||
try {
|
||||
this.status = 'Сохранение владельца…';
|
||||
@@ -235,6 +400,187 @@ createApp({
|
||||
this.error = 'Не удалось добавить аудиторию';
|
||||
this.status = '';
|
||||
}
|
||||
},
|
||||
|
||||
// Inspection methods
|
||||
async showInspection() {
|
||||
this.view = 'inspection';
|
||||
this.status = '';
|
||||
this.error = '';
|
||||
},
|
||||
|
||||
async startInspection() {
|
||||
try {
|
||||
this.status = 'Начало проверки…';
|
||||
this.error = '';
|
||||
const response = await this.fetchAuth('/inspections/sessions', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
aud_id: this.inspectionAudId || null
|
||||
})
|
||||
});
|
||||
|
||||
this.activeInspection = response;
|
||||
await this.loadInspectionStats();
|
||||
this.status = 'Проверка начата';
|
||||
|
||||
// Фокус на поле ввода
|
||||
this.$nextTick(() => {
|
||||
if (this.$refs.barcodeInput) {
|
||||
this.$refs.barcodeInput.focus();
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
this.error = 'Не удалось начать проверку: ' + e.message;
|
||||
this.status = '';
|
||||
}
|
||||
},
|
||||
|
||||
async checkBarcode() {
|
||||
if (!this.scannedBarcode.trim()) return;
|
||||
|
||||
try {
|
||||
this.status = 'Проверка штрихкода…';
|
||||
const response = await this.fetchAuth(`/inspections/sessions/${this.activeInspection.id}/check`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
inv_number: this.scannedBarcode
|
||||
})
|
||||
});
|
||||
|
||||
this.lastScanResult = response;
|
||||
|
||||
// Очистить поле и обновить данные
|
||||
this.scannedBarcode = '';
|
||||
await this.loadInspectionStats();
|
||||
await this.loadInspectionDetails();
|
||||
this.status = '';
|
||||
|
||||
// Автоматически скрыть уведомление через 3 секунды
|
||||
setTimeout(() => {
|
||||
this.lastScanResult = null;
|
||||
}, 3000);
|
||||
|
||||
// Вернуть фокус на поле ввода
|
||||
this.$nextTick(() => {
|
||||
if (this.$refs.barcodeInput) {
|
||||
this.$refs.barcodeInput.focus();
|
||||
}
|
||||
});
|
||||
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
this.error = 'Не удалось проверить штрихкод: ' + e.message;
|
||||
this.status = '';
|
||||
}
|
||||
},
|
||||
|
||||
async loadInspectionStats() {
|
||||
try {
|
||||
const response = await this.fetchAuth(`/inspections/sessions/${this.activeInspection.id}`);
|
||||
this.inspectionStats = response;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
this.error = 'Не удалось загрузить статистику';
|
||||
}
|
||||
},
|
||||
|
||||
async loadInspectionDetails() {
|
||||
try {
|
||||
const response = await this.fetchAuth(`/inspections/sessions/${this.activeInspection.id}/records`);
|
||||
this.checkedEquipment = response.records;
|
||||
this.unknownBarcodes = response.unknown_barcodes;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
this.error = 'Не удалось загрузить детали проверки';
|
||||
}
|
||||
},
|
||||
|
||||
async refreshInspectionData() {
|
||||
this.status = 'Обновление данных…';
|
||||
await this.loadInspectionStats();
|
||||
await this.loadInspectionDetails();
|
||||
this.status = 'Данные обновлены';
|
||||
},
|
||||
|
||||
async completeInspection() {
|
||||
if (!confirm('Завершить проверку?')) return;
|
||||
|
||||
try {
|
||||
this.status = 'Завершение проверки…';
|
||||
await this.fetchAuth(`/inspections/sessions/${this.activeInspection.id}/complete`, {
|
||||
method: 'POST'
|
||||
});
|
||||
|
||||
this.activeInspection = null;
|
||||
this.inspectionStats = {
|
||||
total_checked: 0,
|
||||
total_expected: 0,
|
||||
total_unknown: 0,
|
||||
progress_percent: 0
|
||||
};
|
||||
this.checkedEquipment = [];
|
||||
this.unknownBarcodes = [];
|
||||
this.lastScanResult = null;
|
||||
this.status = 'Проверка завершена';
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
this.error = 'Не удалось завершить проверку: ' + e.message;
|
||||
this.status = '';
|
||||
}
|
||||
},
|
||||
|
||||
cancelInspection() {
|
||||
if (confirm('Прервать проверку без сохранения?')) {
|
||||
this.activeInspection = null;
|
||||
this.inspectionStats = {
|
||||
total_checked: 0,
|
||||
total_expected: 0,
|
||||
total_unknown: 0,
|
||||
progress_percent: 0
|
||||
};
|
||||
this.checkedEquipment = [];
|
||||
this.unknownBarcodes = [];
|
||||
this.lastScanResult = null;
|
||||
this.status = 'Проверка отменена';
|
||||
}
|
||||
},
|
||||
|
||||
async loadInspectionHistory() {
|
||||
try {
|
||||
this.status = 'Загрузка истории проверок…';
|
||||
this.error = '';
|
||||
this.inspectionHistory = await this.fetchAuth('/inspections/sessions');
|
||||
this.status = `Загружено ${this.inspectionHistory.length} проверок`;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
this.error = 'Не удалось загрузить историю проверок: ' + e.message;
|
||||
this.status = '';
|
||||
}
|
||||
},
|
||||
|
||||
async viewHistoryDetails(sessionId) {
|
||||
try {
|
||||
this.status = 'Загрузка деталей проверки…';
|
||||
const [stats, details] = await Promise.all([
|
||||
this.fetchAuth(`/inspections/sessions/${sessionId}`),
|
||||
this.fetchAuth(`/inspections/sessions/${sessionId}/records`)
|
||||
]);
|
||||
|
||||
// Показать активную проверку с данными истории
|
||||
this.activeInspection = stats.session;
|
||||
this.inspectionStats = stats;
|
||||
this.checkedEquipment = details.records;
|
||||
this.unknownBarcodes = details.unknown_barcodes;
|
||||
this.status = '';
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
this.error = 'Не удалось загрузить детали: ' + e.message;
|
||||
this.status = '';
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
@@ -245,6 +591,7 @@ createApp({
|
||||
} catch {}
|
||||
this.loadAuditories();
|
||||
this.loadOwners();
|
||||
this.loadEquipmentTypes();
|
||||
if (this.isAdmin) {
|
||||
this.loadUsers();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user