paged
This commit is contained in:
parent
64b3271c35
commit
0aafb8c7aa
|
@ -1,6 +1,6 @@
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
|
||||||
from rest_framework import viewsets
|
from rest_framework import viewsets, filters
|
||||||
|
|
||||||
from .models import BaseCustomField, CustomTable, Territory, TerritoryItem
|
from .models import BaseCustomField, CustomTable, Territory, TerritoryItem
|
||||||
from .serializers import (
|
from .serializers import (
|
||||||
|
@ -17,14 +17,18 @@ class BaseCustomFieldViewSet(viewsets.ModelViewSet):
|
||||||
|
|
||||||
|
|
||||||
class CustomTableViewSet(viewsets.ModelViewSet):
|
class CustomTableViewSet(viewsets.ModelViewSet):
|
||||||
|
page_size_query_param = "size"
|
||||||
queryset = CustomTable.objects.all()
|
queryset = CustomTable.objects.all()
|
||||||
serializer_class = CustomTableSerializer
|
serializer_class = CustomTableSerializer
|
||||||
|
|
||||||
|
|
||||||
class TerritoryItemViewSet(viewsets.ModelViewSet):
|
class TerritoryItemViewSet(viewsets.ModelViewSet):
|
||||||
page_size_query_param = 'size'
|
page_size_query_param = "size"
|
||||||
queryset = TerritoryItem.objects.all()
|
queryset = TerritoryItem.objects.all()
|
||||||
serializer_class = TerritoryItemSerializer
|
serializer_class = TerritoryItemSerializer
|
||||||
|
|
||||||
|
filter_backends = [filters.SearchFilter]
|
||||||
|
search_fields = ["name"]
|
||||||
|
|
||||||
|
|
||||||
class TerritoryViewSet(viewsets.ModelViewSet):
|
class TerritoryViewSet(viewsets.ModelViewSet):
|
||||||
|
|
|
@ -1,17 +1,49 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
type location = { id: number, name: string }
|
||||||
|
type tmc_field = { name: string, comment: string, id: number, text: string, file_id: string, image_aws_url: string, }
|
||||||
|
|
||||||
|
type api_field = {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
comment: string;
|
||||||
|
}
|
||||||
|
type api_tmc_field = {
|
||||||
|
id: number;
|
||||||
|
text: string;
|
||||||
|
file_id?: any;
|
||||||
|
image_aws_url?: any;
|
||||||
|
field: api_field;
|
||||||
|
}
|
||||||
|
type api_tmc_list = {
|
||||||
|
id: number;
|
||||||
|
name?: any;
|
||||||
|
field: api_tmc_field[];
|
||||||
|
tmc: {
|
||||||
|
id: number,
|
||||||
|
name: string,
|
||||||
|
fields: api_field[]
|
||||||
|
}
|
||||||
|
}
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const item = ref()
|
const item = ref()
|
||||||
const ter = ref()
|
|
||||||
const terdeep = ref()
|
const terdeep = ref()
|
||||||
const state = reactive({} as { name?: string, location?: { id: number, name: string } })
|
const state = reactive({} as
|
||||||
|
{
|
||||||
|
id: string, name?: string,
|
||||||
|
location: location,
|
||||||
|
tmc: {
|
||||||
|
name: string, id: number,
|
||||||
|
fields: tmc_field[]
|
||||||
|
}[]
|
||||||
|
})
|
||||||
|
|
||||||
const loadData = async () => {
|
const loadData = async () => {
|
||||||
const items_data = await apiCall<any>(`tgbot/${route.params.id}/`)
|
const items_data = await apiCall<any>(`tgbot/${route.params.id}/`)
|
||||||
item.value = items_data
|
item.value = items_data
|
||||||
state.id = items_data.id
|
state.id = items_data.id
|
||||||
state.name = items_data.name
|
state.name = items_data.name
|
||||||
state.location = items_data.location.id
|
state.location = items_data.location
|
||||||
state.tmc = items_data.tmc.map(el => {
|
state.tmc = items_data.tmc.map((el: api_tmc_list) => {
|
||||||
return {
|
return {
|
||||||
name: el.tmc.name,
|
name: el.tmc.name,
|
||||||
id: el.id,
|
id: el.id,
|
||||||
|
@ -28,22 +60,17 @@ const loadData = async () => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
const loadTer = async () => {
|
|
||||||
const terdeep_data = await apiCall<ApiPaged<{ id: number, name: string }>>(`tmc/terdeep/?size=1000`)
|
const search = async (q: string) => {
|
||||||
terdeep.value = terdeep_data.results
|
const terdeep_data = await apiCall<ApiPaged<{ id: number, name: string }>>(`tmc/terdeep/?search=${q}`)
|
||||||
}
|
terdeep.value = [toRaw(state.location), ...terdeep_data.results]
|
||||||
const search = (q: string) => {
|
return terdeep.value
|
||||||
if (q) {
|
|
||||||
return terdeep.value.filter((el: any) => el.name.toLowerCase().indexOf(q.toLowerCase()) !== -1).slice(0, 10)
|
|
||||||
} else {
|
|
||||||
return terdeep.value.slice(0, 10)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await loadData()
|
await loadData()
|
||||||
loadTer()
|
terdeep.value = [toRaw(state.location)]
|
||||||
})
|
})
|
||||||
const patchField = async (field) => {
|
const patchField = async (field: { id: number, text: string }) => {
|
||||||
await apiCall(`tgbot/items/${field.id}/`, 'patch', { text: field.text })
|
await apiCall(`tgbot/items/${field.id}/`, 'patch', { text: field.text })
|
||||||
}
|
}
|
||||||
const patchItem = async () => {
|
const patchItem = async () => {
|
||||||
|
@ -52,15 +79,21 @@ const patchItem = async () => {
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<UForm :state="state" v-if="item">
|
<UForm :state="state" v-if="item">
|
||||||
<div class="grid grid-cols-4 gap-2 items-end w-1/2">
|
<div class="grid grid-cols-4 gap-2 items-end">
|
||||||
<UFormGroup label="Название" class="col-span-3">
|
<div class="col-span-2">
|
||||||
<UInput v-model="state.name" />
|
<div class="flex items-end gap-2">
|
||||||
</UFormGroup>
|
<UFormGroup label="Название" class="grow">
|
||||||
<UButton @click="patchItem">Сохранить</UButton>
|
<UInput v-model="state.name" />
|
||||||
<UFormGroup label="Локация" class="col-span-3">
|
</UFormGroup>
|
||||||
<USelectMenu v-model="state.location" :options="terdeep" :searchable="search" value-attribute="id"
|
<UButton @click="patchItem">Сохранить</UButton>
|
||||||
option-attribute="name" />
|
</div>
|
||||||
</UFormGroup>
|
</div>
|
||||||
|
<div class="col-span-2">
|
||||||
|
<UFormGroup label="Локация" class="col-span-3">
|
||||||
|
<USelectMenu v-model="state.location.id" :options="terdeep" :searchable="search"
|
||||||
|
value-attribute="id" option-attribute="name" :disabled="true" />
|
||||||
|
</UFormGroup>
|
||||||
|
</div>
|
||||||
<UFormGroup label="ТМЦ" v-if="state.tmc" class="col-span-4">
|
<UFormGroup label="ТМЦ" v-if="state.tmc" class="col-span-4">
|
||||||
<div v-for="el in state.tmc" class="ml-4">
|
<div v-for="el in state.tmc" class="ml-4">
|
||||||
<strong>{{ el.name }}</strong>
|
<strong>{{ el.name }}</strong>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const items = ref()
|
const items = ref()
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
const items_data = await apiCall<ApiPaged<TmcItem>>(`tmc/items/`)
|
const items_data = await apiCall<ApiPaged<TmcItem>>(`tmc/items/?size=30`)
|
||||||
items.value = items_data.results
|
items.value = items_data.results
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { apiBase } from '~/helpers';
|
import { apiBase } from '~/helpers';
|
||||||
|
|
||||||
export default async function <T>(path: string, method = 'GET', body = null) {
|
export default async function <T>(path: string, method = 'GET', body: any = null) {
|
||||||
const headers = new Headers();
|
const headers = new Headers();
|
||||||
headers.append("Content-Type", "application/json");
|
headers.append("Content-Type", "application/json");
|
||||||
return await $fetch<T>(`${apiBase}/${path}`, { method, headers, body })
|
return await $fetch<T>(`${apiBase}/${path}`, { method, headers, body })
|
||||||
|
|
Loading…
Reference in New Issue