151 lines
3.8 KiB
TypeScript
151 lines
3.8 KiB
TypeScript
import { get } from 'lodash'
|
|
import type { Ref } from 'vue'
|
|
import type { Product, ProductVariant } from '@/model/product'
|
|
import { unref, computed } from 'vue'
|
|
// import noImage from '@/assets/img/logo.svg'
|
|
import type { UploadedFileInfo } from '@/model/uploadedFileInfo'
|
|
import {useConfigStore} from "@/store/configStore";
|
|
import {getConfigApp} from "@/utils/config";
|
|
const nameProject=getConfigApp('name')
|
|
|
|
export function useProduct(product: Ref<Product> | Product) {
|
|
const title = computed(() => {
|
|
return get(unref(product), 'title_fa', '')
|
|
})
|
|
|
|
const price = computed<number>(() => {
|
|
if (unref(product).price) return unref(product).price as number
|
|
return 0
|
|
})
|
|
|
|
const brand = computed(() => {
|
|
if (unref(product).brand) return unref(product).brand
|
|
return '-'
|
|
})
|
|
|
|
const country = computed(() => {
|
|
if (unref(product).country) return unref(product).country
|
|
return '-'
|
|
})
|
|
|
|
const gallery = computed(() => {
|
|
return get(unref(product), 'gallery', [])
|
|
})
|
|
|
|
const body = computed(() => {
|
|
return get(unref(product), 'body', '')
|
|
})
|
|
|
|
const typeUse = computed(() => {
|
|
return get(unref(product), 'type_use', '')
|
|
})
|
|
|
|
const pageDesign = computed(() => {
|
|
return get(unref(product), 'page_design', '-')
|
|
})
|
|
|
|
const motor = computed(() => {
|
|
return get(unref(product), 'page_design', '-')
|
|
})
|
|
|
|
const primaryAttributes = computed(() => {
|
|
return [
|
|
{ title: 'نوع کاربری', name: typeUse.value },
|
|
{ title: 'برند', name: brand.value },
|
|
{ title: 'کشور سازنده', name: country.value },
|
|
{ title: 'جنس بدنه', name: 'فلزی-آلومینیوم' },
|
|
]
|
|
})
|
|
|
|
const moreAttributes = computed(() => {
|
|
return [
|
|
{ title: 'جنسیت', name: gender.value },
|
|
{ title: 'موتور', name: motor.value },
|
|
{ title: 'شیشه', name: glass.value },
|
|
{ title: 'جنس قاب', name: frame.value },
|
|
{ title: 'جنس بند', name: wristlet.value },
|
|
{ title: 'نوع قفل بند', name: buckleType.value },
|
|
{ title: 'سال ساخت', name: yearCreate.value },
|
|
{ title: 'گارانتی', name: warranty.value },
|
|
{ title: 'طرح صفحه', name: pageDesign.value },
|
|
{ title: 'شکل قاب', name: frameShape.value },
|
|
]
|
|
})
|
|
|
|
const frame = computed(() => {
|
|
return get(unref(product), 'frame', '-')
|
|
})
|
|
|
|
const warranty = computed(() => {
|
|
return unref(product).warranty == 1 ? 'بله' : 'خیر'
|
|
})
|
|
|
|
const buckleType = computed(() => {
|
|
return get(unref(product), 'buckle_type', '-')
|
|
})
|
|
|
|
const variants = computed<ProductVariant[]>(() => {
|
|
return get(unref(product), 'variants', [])
|
|
})
|
|
|
|
const originalImage = computed<UploadedFileInfo | null>(() => {
|
|
//TODO: remove if not find default image
|
|
return get(unref(product), 'original_image', null)
|
|
})
|
|
|
|
function variantImage(variant: ProductVariant) {
|
|
const temp = variants.value.find((item) => item.id == variant.id)
|
|
if (temp && temp.file) {
|
|
return temp.file.src
|
|
}
|
|
return nameProject
|
|
}
|
|
|
|
const collection = computed(() => {
|
|
return get(unref(product), 'collection.title', '-')
|
|
})
|
|
|
|
const glass = computed(() => {
|
|
return get(unref(product), 'glass', '-')
|
|
})
|
|
|
|
const frameShape = computed(() => {
|
|
return get(unref(product), 'frame_shape', '-')
|
|
})
|
|
|
|
const wristlet = computed(() => {
|
|
return get(unref(product), 'wristlet', '-')
|
|
})
|
|
|
|
const gender = computed(() => {
|
|
return get(unref(product), 'gender_str', '-')
|
|
})
|
|
|
|
const yearCreate = computed(() => {
|
|
return get(unref(product), 'year_create', '-')
|
|
})
|
|
|
|
return {
|
|
title,
|
|
price,
|
|
brand,
|
|
country,
|
|
gallery,
|
|
body,
|
|
primaryAttributes,
|
|
variants,
|
|
originalImage,
|
|
variantImage,
|
|
moreAttributes,
|
|
typeUse,
|
|
pageDesign,
|
|
motor,
|
|
collection,
|
|
glass,
|
|
frameShape,
|
|
wristlet,
|
|
gender,
|
|
warranty,
|
|
}
|
|
}
|