frontend/src/views/AddMerchView.vue

87 lines
2 KiB
Vue
Raw Normal View History

2025-09-17 21:26:51 +03:00
<script setup>
import router from '@/router/index.js'
2025-09-17 22:15:32 +03:00
import { computed, ref } from 'vue'
2025-09-22 19:41:47 +03:00
import { useMerchApi } from '@/api/merch.js'
2025-10-12 14:21:37 +03:00
import { BASE_MANDARAKE_LINK } from '@/main.js'
2025-09-22 19:41:47 +03:00
const { addMerch } = useMerchApi()
2025-09-12 20:23:58 +03:00
2025-09-17 22:15:32 +03:00
const name = ref('')
// surugaya block
2025-09-18 21:04:23 +03:00
const surugayaLink = ref('')
2025-09-17 22:15:32 +03:00
// mandarake block
const checkAutoComplete = ref(true)
const customLink = ref('')
const mandarakeAutocomplete = computed(() => {
2025-10-12 14:21:37 +03:00
return `${BASE_MANDARAKE_LINK}${name.value}`
2025-09-17 22:15:32 +03:00
})
2025-09-18 21:04:23 +03:00
const mandarakeResultLink = computed({
2025-09-17 22:15:32 +03:00
get() {
return checkAutoComplete.value ? mandarakeAutocomplete.value : customLink.value
},
set(newValue) {
if (!checkAutoComplete.value) {
customLink.value = newValue
}
2025-09-18 21:04:23 +03:00
},
})
// payload
const payload = computed(() => {
return {
merch_uuid: null,
name: name.value,
origin_mandarake: {
link: mandarakeResultLink.value,
},
origin_surugaya: {
link: surugayaLink.value,
},
2025-09-17 22:15:32 +03:00
}
})
2025-09-18 21:04:23 +03:00
2025-09-22 19:41:47 +03:00
const addNewMerch = async () => {
try {
await addMerch(payload)
} catch (error) {
console.log(error)
2025-09-18 21:04:23 +03:00
}
2025-09-22 19:41:47 +03:00
router.push({ name: "collection" })
2025-09-18 21:04:23 +03:00
}
2025-09-12 20:23:58 +03:00
</script>
<template>
2025-09-17 21:26:51 +03:00
<n-card title="Add merch">
<n-form>
<n-divider title-placement="left">Main</n-divider>
<div class="mb-20">
<h3>Name</h3>
2025-09-17 22:15:32 +03:00
<n-input class="mt-10" clearable placeholder="Name" v-model:value="name" />
2025-09-17 21:26:51 +03:00
</div>
2025-09-12 20:23:58 +03:00
2025-09-17 21:26:51 +03:00
<n-divider title-placement="left">Origins</n-divider>
<div>
<h3>Surugaya</h3>
2025-09-18 21:04:23 +03:00
<n-input class="mt-10" clearable placeholder="Link" v-model:value="surugayaLink" />
2025-09-17 21:26:51 +03:00
</div>
<div>
<h3>Mandarake</h3>
2025-09-18 21:04:23 +03:00
<n-input v-model:value="mandarakeResultLink" class="mt-10" clearable placeholder="Link" />
2025-09-17 22:15:32 +03:00
<n-checkbox v-model:checked="checkAutoComplete">Auto-complete link</n-checkbox>
2025-09-17 21:26:51 +03:00
</div>
<div class="mt-10 c-center">
2025-09-22 19:41:47 +03:00
<n-button class="w360" type="primary" @click="addNewMerch">Add</n-button>
2025-09-17 21:26:51 +03:00
</div>
</n-form>
</n-card>
</template>
2025-09-12 20:23:58 +03:00
2025-09-17 21:26:51 +03:00
<style scoped></style>