351 lines
9.9 KiB
Vue
351 lines
9.9 KiB
Vue
<script setup>
|
|
const { $insertapi } = useNuxtApp();
|
|
|
|
const isPending = ref(false);
|
|
const body = ref({
|
|
name: null,
|
|
manufacturer: null,
|
|
os: null,
|
|
battery: null,
|
|
screen: null,
|
|
cpu: null,
|
|
gpu: null,
|
|
camera_system: null,
|
|
sim: null,
|
|
network_technology: null,
|
|
charging_technology: null,
|
|
external_storage: null,
|
|
ip_rating: null,
|
|
design: null,
|
|
});
|
|
|
|
function selected(field, data) {
|
|
if (data === null) body.value[field] = data;
|
|
else body.value[field] = data.id;
|
|
}
|
|
|
|
async function createProduct() {
|
|
isPending.value = true;
|
|
const res = await $insertapi("product", body.value);
|
|
isPending.value = false;
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<form class="fixed-grid has-12-cols">
|
|
<div class="grid">
|
|
<div class="cell is-col-span-8">
|
|
<div class="field">
|
|
<label class="label">Tên sản phẩm</label>
|
|
<div class="control">
|
|
<input
|
|
class="input"
|
|
v-model.trim="body.name"
|
|
type="text"
|
|
placeholder="Tên"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="cell is-col-span-4">
|
|
<div class="field">
|
|
<label class="label">OS</label>
|
|
<SearchBox
|
|
v-bind="{
|
|
api: 'OS',
|
|
field: 'name',
|
|
column: ['name'],
|
|
first: true,
|
|
clearable: true,
|
|
placeholder: 'OS',
|
|
addon: {
|
|
component: 'imports/addons/AddOS',
|
|
width: '70%',
|
|
height: 'auto',
|
|
title: 'Thêm hệ điều hành',
|
|
},
|
|
}"
|
|
@option="selected('os', $event)"
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div class="cell is-col-span-4">
|
|
<div class="field">
|
|
<label class="label">Hãng</label>
|
|
<SearchBox
|
|
v-bind="{
|
|
api: 'Manufacturer',
|
|
field: 'name',
|
|
column: ['name'],
|
|
first: true,
|
|
clearable: true,
|
|
placeholder: 'Hãng',
|
|
addon: {
|
|
component: 'imports/addons/AddManufacturer',
|
|
width: '70%',
|
|
height: 'auto',
|
|
title: 'Thêm hãng',
|
|
},
|
|
}"
|
|
@option="selected('manufacturer', $event)"
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div class="cell is-col-span-4">
|
|
<div class="field">
|
|
<label class="label">Pin</label>
|
|
<SearchBox
|
|
v-bind="{
|
|
api: 'Battery',
|
|
field: 'code',
|
|
column: ['code'],
|
|
first: true,
|
|
clearable: true,
|
|
placeholder: 'Pin',
|
|
addon: {
|
|
component: 'imports/addons/AddBattery',
|
|
width: '70%',
|
|
height: 'auto',
|
|
title: 'Thêm pin',
|
|
},
|
|
}"
|
|
@option="selected('battery', $event)"
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div class="cell is-col-span-4">
|
|
<div class="field">
|
|
<label class="label">Màn hình</label>
|
|
<SearchBox
|
|
v-bind="{
|
|
api: 'Screen',
|
|
field: 'label',
|
|
column: ['resolution', 'standard', 'technology'],
|
|
first: true,
|
|
clearable: true,
|
|
placeholder: 'Màn hình',
|
|
addon: {
|
|
component: 'imports/addons/AddScreen',
|
|
width: '70%',
|
|
height: 'auto',
|
|
title: 'Thêm màn hình',
|
|
},
|
|
}"
|
|
@option="selected('screen', $event)"
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div class="cell is-col-span-4">
|
|
<div class="field">
|
|
<label class="label">CPU</label>
|
|
<SearchBox
|
|
v-bind="{
|
|
api: 'CPU',
|
|
field: 'name',
|
|
column: ['name'],
|
|
first: true,
|
|
clearable: true,
|
|
placeholder: 'CPU',
|
|
addon: {
|
|
component: 'imports/addons/AddCPU',
|
|
width: '70%',
|
|
height: 'auto',
|
|
title: 'Thêm CPU',
|
|
},
|
|
}"
|
|
@option="selected('cpu', $event)"
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div class="cell is-col-span-4">
|
|
<div class="field">
|
|
<label class="label">GPU</label>
|
|
<SearchBox
|
|
v-bind="{
|
|
api: 'GPU',
|
|
field: 'name',
|
|
column: ['name'],
|
|
first: true,
|
|
clearable: true,
|
|
placeholder: 'GPU',
|
|
addon: {
|
|
component: 'imports/addons/AddGPU',
|
|
width: '70%',
|
|
height: 'auto',
|
|
title: 'Thêm GPU',
|
|
},
|
|
}"
|
|
@option="selected('gpu', $event)"
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div class="cell is-col-span-4">
|
|
<div class="field">
|
|
<label class="label">Camera</label>
|
|
<SearchBox
|
|
v-bind="{
|
|
api: 'Camera_System',
|
|
field: 'code',
|
|
column: ['code'],
|
|
first: true,
|
|
clearable: true,
|
|
placeholder: 'Camera',
|
|
addon: {
|
|
component: 'imports/addons/AddCamera',
|
|
width: '70%',
|
|
height: 'auto',
|
|
title: 'Thêm camera',
|
|
},
|
|
}"
|
|
@option="selected('camera_system', $event)"
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div class="cell is-col-span-4">
|
|
<div class="field">
|
|
<label class="label">SIM</label>
|
|
<SearchBox
|
|
v-bind="{
|
|
api: 'SIM',
|
|
field: 'code',
|
|
column: ['code'],
|
|
first: true,
|
|
clearable: true,
|
|
placeholder: 'SIM',
|
|
addon: {
|
|
component: 'imports/addons/AddSIM',
|
|
width: '70%',
|
|
height: 'auto',
|
|
title: 'Thêm SIM',
|
|
},
|
|
}"
|
|
@option="selected('sim', $event)"
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div class="cell is-col-span-4">
|
|
<div class="field">
|
|
<label class="label">Kết nối</label>
|
|
<SearchBox
|
|
v-bind="{
|
|
api: 'Network_Technology',
|
|
field: 'name',
|
|
column: ['name'],
|
|
first: true,
|
|
clearable: true,
|
|
placeholder: 'Kết nối',
|
|
addon: {
|
|
component: 'imports/addons/AddNetworkTechnology',
|
|
width: '70%',
|
|
height: 'auto',
|
|
title: 'Thêm kết nối',
|
|
},
|
|
}"
|
|
@option="selected('network_technology', $event)"
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div class="cell is-col-span-4">
|
|
<div class="field">
|
|
<label class="label">Công nghệ sạc</label>
|
|
<SearchBox
|
|
v-bind="{
|
|
api: 'Charging_Technology',
|
|
field: 'code',
|
|
column: ['code'],
|
|
first: true,
|
|
clearable: true,
|
|
placeholder: 'Công nghệ sạc',
|
|
addon: {
|
|
component: 'imports/addons/AddChargingTechnology',
|
|
width: '70%',
|
|
height: 'auto',
|
|
title: 'Thêm công nghệ sạc',
|
|
},
|
|
}"
|
|
@option="selected('charging_technology', $event)"
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div class="cell is-col-span-4">
|
|
<div class="field">
|
|
<label class="label">Bộ nhớ ngoài</label>
|
|
<SearchBox
|
|
v-bind="{
|
|
api: 'External_Storage',
|
|
field: 'code',
|
|
column: ['code'],
|
|
first: true,
|
|
clearable: true,
|
|
placeholder: 'Bộ nhớ ngoài',
|
|
addon: {
|
|
component: 'imports/addons/AddExternalStorage',
|
|
width: '70%',
|
|
height: 'auto',
|
|
title: 'Thêm bộ nhớ ngoài',
|
|
},
|
|
}"
|
|
@option="selected('external_storage', $event)"
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div class="cell is-col-span-4">
|
|
<div class="field">
|
|
<label class="label">Chỉ số IP</label>
|
|
<SearchBox
|
|
v-bind="{
|
|
api: 'IP_Rating',
|
|
field: 'name',
|
|
column: ['name'],
|
|
first: true,
|
|
clearable: true,
|
|
placeholder: 'Chỉ số IP',
|
|
addon: {
|
|
component: 'imports/addons/AddIPRating',
|
|
width: '70%',
|
|
height: 'auto',
|
|
title: 'Thêm chỉ số IP',
|
|
},
|
|
}"
|
|
@option="selected('ip_rating', $event)"
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div class="cell is-col-span-4">
|
|
<div class="field">
|
|
<label class="label">Chất liệu</label>
|
|
<SearchBox
|
|
v-bind="{
|
|
api: 'Design',
|
|
field: 'label',
|
|
column: ['frame_material', 'back_material'],
|
|
first: true,
|
|
clearable: true,
|
|
placeholder: 'Chất liệu',
|
|
addon: {
|
|
component: 'imports/addons/AddDesign',
|
|
width: '70%',
|
|
height: 'auto',
|
|
title: 'Thêm chất liệu',
|
|
},
|
|
}"
|
|
@option="selected('design', $event)"
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div class="cell is-col-span-12">
|
|
<button
|
|
:class="['button is-primary', { 'is-loading': isPending }]"
|
|
:disabled="Object.values(body).every((v) => v === null)"
|
|
@click.prevent="createProduct"
|
|
>
|
|
<span class="icon">
|
|
<Icon name="material-symbols:add-rounded" />
|
|
</span>
|
|
<span>Tạo sản phẩm</span>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</template>
|