step 51 : master data add mobile

This commit is contained in:
sindhu
2025-04-04 09:34:49 +07:00
parent a552d0d4f6
commit e6b2c874d6
6 changed files with 422 additions and 6 deletions

View File

@@ -342,6 +342,11 @@ document.addEventListener('alpine:init', () => {
}
this.showDialogEdit = false
},
editMobilePage(item){
var json = JSON.stringify(item);
localStorage.setItem('itemEditMobile', json);
window.location.href = "master_data_mobile_edit.html"
},
// 2. Fungsi End
}))
})

View File

@@ -0,0 +1,149 @@
document.addEventListener('alpine:init', () => {
Alpine.data('masterDataPageMobileAdd', () => ({
// 0. Init dijalankan sebelum inisialisasi
init() {
},
// 1. Inisialisasi Start
dataAssay: [
{
idAssay: 1,
namaAssay: 'Xn500'
},
{
idAssay: 2,
namaAssay: 'HGB'
},
{
idAssay: 3,
namaAssay: 'WBC'
},
{
idAssay: 4,
namaAssay: 'RBC'
},
{
idAssay: 5,
namaAssay: 'PLT'
},
],
dataAlat: [
{
idAlat: 1,
namaAlat: 'Hema 01',
},
{
idAlat: 2,
namaAlat: 'Axsym',
},
{
idAlat: 3,
namaAlat: 'Cobas C311',
},
],
kodeAdd: '',
namaAdd: '',
hargaAdd: '',
formAddArray: [],
objForm: {
nama: '',
kode: '',
harga: '',
alat: {},
assay: []
},
// 1. Inisialisasi End
// 2. Fungsi Start
formDetail(action) {
if (action === 'add') {
const lastId = this.formAddArray.length;
this.formAddArray.push({
idForm: lastId + 1,
openAlat: false,
dataAlatForm: this.dataAlat,
selectedAlat: {
idAlat: -1,
namaAlat: 'Alat'
},
selectedAssay: [],
searchAssay: "",
filterItemAssay: this.dataAssay,
dataAssayForm: this.dataAssay,
openAssayAdd: false,
})
}
},
filterItemAssay(idx, formItem, action) {
if (action === 'add') {
let formId = formItem.idForm
// console.log('formItem ',formItem)
let targetForm = this.formAddArray.find(e => e.idForm === formId);
if (targetForm) {
targetForm.openAssayAdd = true
let searchTerm = targetForm.searchAssay ? targetForm.searchAssay.toLowerCase() : "";
targetForm.filterItemAssay = targetForm.dataAssayForm.filter(item =>
item.namaAssay.toLowerCase().includes(searchTerm)
);
// targetForm.dataAssayForm = targetForm.filterItemAssay
console.log('Filtered Assay:', targetForm.filterItemAssay);
} else {
console.warn('Tidak match ID Form nya');
}
}
},
addItemAssayToForm(item, idForm, action) {
if (action === 'add') {
let form = this.formAddArray.find(f => f.idForm === idForm);
if (form) {
let exists = form.selectedAssay.some(a => a.idAssay === item.idAssay);
if (!exists) {
form.selectedAssay.push(item);
} else {
console.warn("Item sudah dipilih:", item);
}
}
}
},
removeItemAssayToForm(idForm, index, action) {
if (action === 'add') {
let form = this.formAddArray.find(f => f.idForm === idForm);
if (!form) return;
form.selectedAssay.splice(index, 1);
}
},
saveA() {
this.objForm.alat = this.formAddArray.map(form => form.selectedAlat);
this.objForm.assay = this.formAddArray.map(form => form.selectedAssay);
console.log('Data yang disimpan:', this.objForm);
},
onChangeInstrument(item, idForm, action) {
if (action === 'add') {
let form = this.formAddArray.find(f => f.idForm === idForm);
if (!form) return;
form.selectedAlat = {
idAlat: item.idAlat,
namaAlat: item.namaAlat
}
form.openAlat = false
}
},
onChangeNamaAdd() {
this.objForm.nama = this.namaAdd;
},
onChangeKodeAdd() {
this.objForm.kode = this.kodeAdd;
},
onChangeHargaAdd() {
this.objForm.harga = this.hargaAdd;
},
}))
})

View File

View File

@@ -296,8 +296,10 @@
<li class="py-2 px-3 text-gray-500 text-center">Data
tidak ada</li>
</template>
<template x-for="item in form.dataAlatForm" :key="item.idAlat">
<li :id="item.idAlat" @click="onChangeInstrument(item, form.idForm, 'add')"
<template x-for="item in form.dataAlatForm"
:key="item.idAlat">
<li :id="item.idAlat"
@click="onChangeInstrument(item, form.idForm, 'add')"
class="py-2 px-3 hover:bg-blue-100 cursor-pointer text-gray-700">
<button x-text="item.namaAlat"></button>
</li>
@@ -315,7 +317,8 @@
<div
class="flex items-center bg-blue-100 text-blue-700 text-sm px-2 py-1 rounded-md">
<span x-text="item.namaAssay"></span>
<button @click="removeItemAssayToForm(form.idForm, idx, 'add')"
<button
@click="removeItemAssayToForm(form.idForm, idx, 'add')"
class="ml-2 focus:outline-none">
<svg class="w-4 h-4 text-blue-500 hover:text-blue-700"
fill="none" stroke="currentColor"
@@ -505,8 +508,10 @@
<li class="py-2 px-3 text-gray-500 text-center">Data
tidak ada</li>
</template>
<template x-for="item in form.dataAlatForm" :key="item.idAlat">
<li :id="item.idAlat" @click="onChangeInstrument(item, form.idForm, 'edit')"
<template x-for="item in form.dataAlatForm"
:key="item.idAlat">
<li :id="item.idAlat"
@click="onChangeInstrument(item, form.idForm, 'edit')"
class="py-2 px-3 hover:bg-blue-100 cursor-pointer text-gray-700">
<button x-text="item.namaAlat"></button>
</li>
@@ -524,7 +529,8 @@
<div
class="flex items-center bg-blue-100 text-blue-700 text-sm px-2 py-1 rounded-md">
<span x-text="item.namaAssay"></span>
<button @click="removeItemAssayToForm(form.idForm, idx, 'edit')"
<button
@click="removeItemAssayToForm(form.idForm, idx, 'edit')"
class="ml-2 focus:outline-none">
<svg class="w-4 h-4 text-blue-500 hover:text-blue-700"
fill="none" stroke="currentColor"
@@ -611,6 +617,47 @@
</div>
</div>
<!-- modal edit desktop -->
<!-- Kiri Mobile -->
<div class="bg-[#F2F9FF] h-5 flex justify-between space-x-2 lg:hidden">
<h2 class="text-black/87 font-medium text-xl mb-4">Master Data</h2>
<a href="master_data_mobile_add.html">
<span class="material-symbols-outlined text-[#2196F3]">add</span>
</a>
</div>
<!-- Bagian MOBILE (LIST MASTER DATA) START -->
<div class="w-full lg:hidden rounded-lg flex flex-col flex-1 overflow-auto">
<!-- table become list in mobile -->
<div class="flex flex-row mb-6 lg:hidden lg:mb-0">
<div class="flex flex-col w-full lg:flex-row mb-5">
<template x-for="item in dataMaster" :key="item.idMaster">
<div class="bg-white mr-0 mb-5 rounded-md lg:mr-5 p-2 w-full lg:w-1/2 lg:mb-0 relative">
<div class="flex justify-between">
<h2 class="text-black/87 font-medium text-xl mb-4" x-text="item.kode"></h2>
<div class="relative flex h-4 w-4">
<button @click="editMobilePage(item)"><span
class="material-symbols-outlined text-[#2196F3]">edit</span></button>
</div>
</div>
<div class="flex justify-between">
<p class="text-[#00000099] font-normal text-sm mb-2">Nama Pemeriksaan</p>
<p class="text-black/87 font-normal text-sm mb-2" x-text="item.namaPemeriksaan"></p>
</div>
<div class="flex justify-between">
<p class="text-[#00000099] font-normal text-sm mb-2">Harga</p>
<p class="text-black/87 font-normal text-sm mb-2" x-text="item.harga"></p>
</div>
<div class="flex justify-between">
<p class="text-[#00000099] font-normal text-sm mb-2">Assay Format</p>
<p class="text-black/87 font-normal text-sm mb-2" x-text="item.pemeriksaanStr"></p>
</div>
</div>
</template>
</div>
</div>
</div>
<!-- Bagian MOBILE (LIST MASTER DATA) END -->
</div>
<script src="js/master_data.js"></script>

View File

@@ -0,0 +1,215 @@
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Master Data XPORT</title>
<!-- tailwind cdn -->
<script src="https://unpkg.com/@tailwindcss/browser@4"></script>
<!-- alpine cdn -->
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.14.8/dist/cdn.min.js"></script>
<!-- material Symbols -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined" />
</head>
<body class="bg-white h-screen flex flex-col">
<!-- appbar -->
<div class="bg-white h-15 flex items-center justify-start px-6">
<a href="master_data.html">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 text-black/87" fill="none" viewBox="0 0 24 24"
stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7" />
</svg>
</a>
<h3 class="font-medium text-xl text-black/87 ml-3">Add</h3>
</div>
<!-- appbar -->
<!-- konten utama -->
<div class="flex-1 flex flex-col lg:flex-row px-5 pt-6 overflow-auto h-[calc(100vh-60px)]"
x-data="masterDataPageMobileAdd">
<div class="relative w-full">
<!-- Kode -->
<label for="Kode"
class="relative block rounded-md border border-gray-400 focus-within:border-blue-600 focus-within:ring-1 focus-within:ring-blue-600">
<input type="text" id="Kode" autocomplete="off" x-model="kodeAdd" @change="onChangeKodeAdd()"
class="peer pl-2 border-none py-3 bg-transparent placeholder-transparent focus:border-transparent focus:ring-0 focus:outline-hidden"
placeholder="Kode" />
<span
class="pointer-events-none absolute start-2.5 top-0 -translate-y-1/2 bg-white p-0.5 text-xs text-gray-700 transition-all peer-placeholder-shown:top-1/2 peer-placeholder-shown:text-sm peer-focus:top-0 peer-focus:text-xs">
Kode
</span>
</label>
<!-- space 20 -->
<div class="mb-5"></div>
<!-- Nama -->
<label for="Nama"
class="relative block rounded-md border border-gray-400 focus-within:border-blue-600 focus-within:ring-1 focus-within:ring-blue-600">
<input type="text" id="Nama" autocomplete="off" x-model="namaAdd" @change="onChangeNamaAdd()"
class="peer pl-2 border-none py-3 bg-transparent placeholder-transparent focus:border-transparent focus:ring-0 focus:outline-hidden"
placeholder="Nama" />
<span
class="pointer-events-none absolute start-2.5 top-0 -translate-y-1/2 bg-white p-0.5 text-xs text-gray-700 transition-all peer-placeholder-shown:top-1/2 peer-placeholder-shown:text-sm peer-focus:top-0 peer-focus:text-xs">
Nama
</span>
</label>
<!-- space 20 -->
<div class="mb-5"></div>
<!-- Harga -->
<label for="Harga"
class="relative block rounded-md border border-gray-400 focus-within:border-blue-600 focus-within:ring-1 focus-within:ring-blue-600">
<input type="text" id="Harga" autocomplete="off" x-model="hargaAdd" @change="onChangeHargaAdd()"
class="peer pl-2 border-none py-3 bg-transparent placeholder-transparent focus:border-transparent focus:ring-0 focus:outline-hidden"
placeholder="Harga" />
<span
class="pointer-events-none absolute start-2.5 top-0 -translate-y-1/2 bg-white p-0.5 text-xs text-gray-700 transition-all peer-placeholder-shown:top-1/2 peer-placeholder-shown:text-sm peer-focus:top-0 peer-focus:text-xs">
Harga
</span>
</label>
<!-- space 20 -->
<div class="mb-5"></div>
<!-- form alat, assay start -->
<div class="pl-2">
<div class="flex justify-between">
<h2 class="text-black/87 font-medium text-sm mb-4">Alat & Assay</h2>
<div class="relative flex h-4 w-4">
<button @click="formDetail('add')">
<span class="material-symbols-outlined text-black">add</span>
</button>
</div>
</div>
<div class="mt-3">
<template x-for="(form, index) in formAddArray" :key="form.idForm">
<div class="mt-3 mb-3">
<div class="flex">
<!-- alat -->
<div class="relative w-full">
<fieldset @click.outside="form.openAlat = false"
class="relative border border-gray-400 rounded-md focus-within:border-blue-500 focus-within:ring-1 focus-within:ring-blue-500 px-3 pt-2 pb-2">
<span
x-text="form.selectedAlat.idAlat != -1 ? 'Alat' : form.selectedAlat.namaAlat"
class="pointer-events-none absolute start-2.5 top-0 -translate-y-1/2 bg-white p-0.5 text-xs text-gray-700 transition-all peer-placeholder-shown:top-1/2 peer-placeholder-shown:text-sm peer-focus:top-0 peer-focus:text-xs">
</span>
<button @click="form.openAlat = !form.openAlat" type="button"
class="w-full flex items-center justify-between bg-transparent text-gray-900 py-0.5 focus:outline-none">
<span x-text="form.selectedAlat.namaAlat" class="text-left"></span>
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 transition-transform"
:class="{ 'rotate-180': form.openAlat }" fill="none" viewBox="0 0 24 24"
stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M19 9l-7 7-7-7" />
</svg>
</button>
</fieldset>
<div x-show="form.openAlat"
class="absolute bg-white w-full border border-gray-300 rounded-md shadow-lg z-10 max-h-[200px] overflow-y-auto">
<ul>
<template x-if="form.dataAlatForm.length === 0">
<li class="py-2 px-3 text-gray-500 text-center">Data
tidak ada</li>
</template>
<template x-for="item in form.dataAlatForm" :key="item.idAlat">
<li :id="item.idAlat"
@click="onChangeInstrument(item, form.idForm, 'add')"
class="py-2 px-3 hover:bg-blue-100 cursor-pointer text-gray-700">
<button x-text="item.namaAlat"></button>
</li>
</template>
</ul>
</div>
</div>
</div>
<div class="w-full">
<div>
<!-- List Assay yang Dipilih -->
<div class="flex flex-wrap gap-2 mb-2 mt-2">
<template x-for="(item, idx) in form.selectedAssay" :key="item.idAssay">
<div
class="flex items-center bg-blue-100 text-blue-700 text-sm px-2 py-1 rounded-md">
<span x-text="item.namaAssay"></span>
<button @click="removeItemAssayToForm(form.idForm, idx, 'add')"
class="ml-2 focus:outline-none">
<svg class="w-4 h-4 text-blue-500 hover:text-blue-700" fill="none"
stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round"
d="M6 18L18 6M6 6l12 12"></path>
</svg>
</button>
</div>
</template>
</div>
<!-- Input Search Assay -->
<label
class="relative block border rounded-md border-gray-400 focus-within:border-blue-600 focus-within:ring-1 focus-within:ring-blue-600">
<input type="text" autocomplete="off" x-model="form.searchAssay"
@input="filterItemAssay(index, form, 'add')"
@click="form.openAssayAdd = true"
class="w-full peer pl-2 border-none py-3 bg-transparent placeholder-transparent focus:border-transparent focus:ring-0 focus:outline-hidden"
placeholder="Cari Assay" />
<span
class="pointer-events-none absolute start-2.5 top-0 -translate-y-1/2 bg-white p-0.5 text-xs text-gray-700 transition-all peer-placeholder-shown:top-1/2 peer-placeholder-shown:text-sm peer-focus:top-0 peer-focus:text-xs">
Cari Assay
</span>
</label>
<!-- Dropdown List -->
<div x-show="form.openAssayAdd" @click.away="form.openAssayAdd = false"
class="absolute left-0 mt-2 w-full bg-white border border-gray-300 rounded-lg shadow-lg z-10 max-h-48 overflow-y-auto transition-all duration-200">
<template x-if="form.filterItemAssay.length === 0">
<div class="p-2 text-gray-500 text-sm text-center">Tidak ada
hasil</div>
</template>
<template x-for="(item, idxAssayForm) in form.filterItemAssay"
:key="item.idAssay">
<div @click="addItemAssayToForm(item, form.idForm, 'add')"
class="cursor-pointer p-2 hover:bg-blue-100 flex items-center justify-between"
:class="form.selectedAssay.some(p => p.idAssay === item.idAssay) ? 'bg-yellow-100 text-yellow-800' : ''">
<span x-text="item.namaAssay"></span>
<svg x-show="form.selectedAssay.some(p => p.idAssay === item.idAssay)"
class="w-4 h-4 text-yellow-500" fill="none" stroke="currentColor"
stroke-width="2" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round"
d="M5 13l4 4L19 7">
</path>
</svg>
</div>
</template>
</div>
</div>
</div>
<!-- border bottom -->
<div class="border-b-1 border-dashed border-black mt-3"></div>
</div>
</template>
</div>
</div>
<!-- form alat, assay end -->
<!-- space bottom -->
<div class="mt-30"></div>
<!-- button save -->
<div
class="fixed bottom-0 left-0 w-full bg-white h-15 flex items-center align-middle shadow-[0px_0px_2px_0px_rgba(145,158,171,0.24),-20px_20px_40px_-4px_rgba(145,158,171,0.24)] p-4">
<button class="hover:text-white hover:bg-[#2196F3] font-bold text-sm uppercase px-4 py-2 rounded-[4px] transition duration-200
bg-[#1976D2] text-white w-full" @click="saveA()">
Save
</button>
</div>
</div>
<!-- konten utama -->
<script src="js/master_data_mobile_add.js"></script>
</body>

View File