2025-03-21 19:51:55 +01:00
|
|
|
import type { PropType } from 'vue';
|
2025-04-04 18:15:14 +02:00
|
|
|
import { defineComponent, onMounted, ref, watch, computed} from 'vue'
|
2025-03-21 19:51:55 +01:00
|
|
|
import { tools } from '@tools'
|
|
|
|
|
import { useUserStore } from '@store/UserStore'
|
|
|
|
|
import { useRouter } from 'vue-router'
|
|
|
|
|
import { useGlobalStore } from '@store/globalStore'
|
|
|
|
|
import { useProducts } from '@store/Products'
|
|
|
|
|
import { useI18n } from 'vue-i18n'
|
|
|
|
|
import { toolsext } from '@store/Modules/toolsext'
|
|
|
|
|
import { useQuasar } from 'quasar'
|
|
|
|
|
import { costanti } from '@costanti'
|
|
|
|
|
|
|
|
|
|
import { shared_consts } from '@src/common/shared_vuejs'
|
|
|
|
|
import { CProductCard } from '@src/components/CProductCard'
|
|
|
|
|
|
|
|
|
|
import { CMySelect } from '@src/components/CMySelect'
|
|
|
|
|
import { CContainerCatalogoCard } from '@src/components/CContainerCatalogoCard'
|
|
|
|
|
import { CSelectUserActive } from '@src/components/CSelectUserActive'
|
|
|
|
|
import type {
|
2025-04-04 18:15:14 +02:00
|
|
|
IOptCatalogo,
|
|
|
|
|
IProduct, ISearchList
|
2025-03-21 19:51:55 +01:00
|
|
|
} from 'model';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { fieldsTable } from '@store/Modules/fieldsTable'
|
|
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
|
name: 'CSearchProduct',
|
|
|
|
|
components: { CContainerCatalogoCard, CProductCard, CSelectUserActive, CMySelect },
|
2025-04-04 18:15:14 +02:00
|
|
|
emits: ['insert', 'close', 'updateproductmodif'],
|
2025-03-21 19:51:55 +01:00
|
|
|
props: {
|
|
|
|
|
modelValue: {
|
|
|
|
|
type: Object as PropType<IOptCatalogo>,
|
2025-04-01 18:36:45 +02:00
|
|
|
required: false,
|
|
|
|
|
default: null,
|
|
|
|
|
},
|
|
|
|
|
idprodtoshow: {
|
|
|
|
|
type: String,
|
|
|
|
|
required: false,
|
|
|
|
|
default : '',
|
|
|
|
|
},
|
2025-04-04 18:15:14 +02:00
|
|
|
empty: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
required: false,
|
|
|
|
|
default: false,
|
|
|
|
|
},
|
2025-04-01 18:36:45 +02:00
|
|
|
nameLinkTemplate: {
|
|
|
|
|
type: String,
|
|
|
|
|
required: false,
|
|
|
|
|
default : '',
|
2025-03-21 19:51:55 +01:00
|
|
|
},
|
2025-04-04 18:15:14 +02:00
|
|
|
visu: {
|
|
|
|
|
type: Number,
|
|
|
|
|
required: false,
|
|
|
|
|
default: shared_consts.VISU_SEARCHPROD_MODE.VISU,
|
|
|
|
|
},
|
2025-03-21 19:51:55 +01:00
|
|
|
},
|
|
|
|
|
setup(props, { emit }) {
|
|
|
|
|
const userStore = useUserStore()
|
|
|
|
|
const globalStore = useGlobalStore()
|
|
|
|
|
const productStore = useProducts()
|
|
|
|
|
const router = useRouter()
|
|
|
|
|
const $q = useQuasar()
|
|
|
|
|
const { t } = useI18n()
|
|
|
|
|
|
|
|
|
|
const search = ref('')
|
2025-04-04 18:15:14 +02:00
|
|
|
const focus = ref(false)
|
2025-03-21 19:51:55 +01:00
|
|
|
|
|
|
|
|
const loadpage = ref(false)
|
|
|
|
|
const refreshpage = ref(false)
|
|
|
|
|
const show_hide = ref(false)
|
|
|
|
|
|
|
|
|
|
const mycolumns = ref([])
|
|
|
|
|
|
|
|
|
|
const idPage = ref('')
|
|
|
|
|
const selauthor = ref('')
|
|
|
|
|
|
2025-03-31 23:55:53 +02:00
|
|
|
const searchList = ref(<ISearchList[]>[])
|
2025-03-21 19:51:55 +01:00
|
|
|
|
|
|
|
|
const optcatalogo = ref<IOptCatalogo | null>(null);
|
|
|
|
|
|
|
|
|
|
const myproduct = ref(<IProduct>{})
|
|
|
|
|
|
|
|
|
|
const labelcombo = computed(() => (item: any) => {
|
|
|
|
|
let lab = item.label
|
|
|
|
|
if (item.showcount)
|
|
|
|
|
lab += ' (' + valoriopt.value(item, false, false).length + ')'
|
|
|
|
|
return lab
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const listaRicerca = computed(() => {
|
|
|
|
|
const mylist = searchList.value.find((rec: any) => rec.table === 'products' && rec.key === 'titolo')
|
|
|
|
|
|
|
|
|
|
return mylist
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const searchText = computed(() => {
|
|
|
|
|
const lista = listaRicerca.value
|
|
|
|
|
return lista && lista.value && tools.existProp(lista.value, 'name') ? lista.value.name : ''
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const valoriopt = computed(() => (item: any, addall: boolean, addnone: boolean = false) => {
|
|
|
|
|
// console.log('valoriopt', item.table)
|
|
|
|
|
return globalStore.getTableJoinByName(item.table, addall, addnone, item.filter)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
watch(() => searchText.value, (newval, oldval) => {
|
|
|
|
|
console.log('searchText=', searchText.value)
|
|
|
|
|
const id = getSearchId()
|
|
|
|
|
loadProduct(id)
|
2025-04-04 18:15:14 +02:00
|
|
|
|
|
|
|
|
})
|
|
|
|
|
watch(() => myproduct.value, (newval, oldval) => {
|
|
|
|
|
console.log('myproduct', myproduct.value)
|
|
|
|
|
// loadProduct(myproduct.value._id)
|
|
|
|
|
updateproductmodif(myproduct.value)
|
2025-03-21 19:51:55 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
async function loadProduct(id: string) {
|
|
|
|
|
// Carica il prodotto
|
2025-04-11 18:49:42 +02:00
|
|
|
console.log('loadProduct', id)
|
2025-03-21 19:51:55 +01:00
|
|
|
|
|
|
|
|
if (id) {
|
|
|
|
|
myproduct.value = await productStore.loadProductById(id)
|
|
|
|
|
} else {
|
|
|
|
|
myproduct.value = null
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-04 18:15:14 +02:00
|
|
|
saveSearch()
|
|
|
|
|
|
2025-03-31 23:55:53 +02:00
|
|
|
console.log('myproduct.value', myproduct.value)
|
|
|
|
|
|
2025-04-04 18:15:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function saveSearch() {
|
|
|
|
|
if (!props.idprodtoshow && !props.empty) {
|
2025-04-01 18:36:45 +02:00
|
|
|
if (myproduct.value) {
|
|
|
|
|
tools.setCookie(tools.COOK_LAST_PROD_SEARCH, myproduct.value._id.toString())
|
|
|
|
|
} else {
|
|
|
|
|
tools.setCookie(tools.COOK_LAST_PROD_SEARCH, '')
|
|
|
|
|
}
|
2025-03-21 19:51:55 +01:00
|
|
|
}
|
|
|
|
|
|
2025-04-04 18:15:14 +02:00
|
|
|
if (!myproduct.value) {
|
|
|
|
|
tools.setCookie(tools.COOK_LAST_PROD_SEARCH, '')
|
|
|
|
|
}
|
2025-03-21 19:51:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function resetSearch() {
|
|
|
|
|
const mialista = listaRicerca.value
|
|
|
|
|
if (mialista && mialista.value && tools.existProp(mialista.value, 'name')) {
|
|
|
|
|
mialista.value = null
|
|
|
|
|
}
|
|
|
|
|
search.value = ''
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getSearchId(): string {
|
|
|
|
|
const lista = listaRicerca.value
|
|
|
|
|
return lista && lista.value && lista.value._id ? lista.value._id : ''
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-01 18:36:45 +02:00
|
|
|
function populateDataWithlinkIdTemplate() {
|
2025-04-04 18:15:14 +02:00
|
|
|
// console.log('populateDataWithlinkIdTemplate')
|
2025-04-01 18:36:45 +02:00
|
|
|
|
|
|
|
|
if (optcatalogo.value) {
|
|
|
|
|
|
|
|
|
|
for (const recscheda of optcatalogo.value.arrSchede!) {
|
|
|
|
|
if (recscheda.scheda?.linkIdTemplate) {
|
|
|
|
|
// ricopia da Template:
|
|
|
|
|
const myscheda = globalStore.sovrascriviSchedaFromTemplate(recscheda.scheda?.linkIdTemplate, recscheda)
|
|
|
|
|
if (myscheda) {
|
|
|
|
|
recscheda.scheda = { ...myscheda }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// console.log(' FINE - populateDataWithlinkIdTemplate')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-03-21 19:51:55 +01:00
|
|
|
async function mounted() {
|
|
|
|
|
// console.log('mounted Catalogo')
|
|
|
|
|
|
2025-04-01 18:36:45 +02:00
|
|
|
if (props.modelValue) {
|
|
|
|
|
optcatalogo.value = props.modelValue
|
|
|
|
|
} else {
|
|
|
|
|
optcatalogo.value = globalStore.createCatalogoVuoto()
|
|
|
|
|
productStore.addNewScheda(optcatalogo.value)
|
|
|
|
|
|
|
|
|
|
if (props.nameLinkTemplate) {
|
|
|
|
|
const linkIdTemplate = globalStore.getLinkIdTemplateByName(props.nameLinkTemplate)
|
2025-04-11 18:49:42 +02:00
|
|
|
if (linkIdTemplate)
|
|
|
|
|
optcatalogo.value.arrSchede[0].scheda.linkIdTemplate = linkIdTemplate
|
2025-04-01 18:36:45 +02:00
|
|
|
} else {
|
|
|
|
|
optcatalogo.value.arrSchede[0].scheda.name = 'SEARCH_NEW'
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-21 19:51:55 +01:00
|
|
|
|
2025-04-04 18:15:14 +02:00
|
|
|
const id = props.idprodtoshow || (!props.empty ? tools.getCookie(tools.COOK_LAST_PROD_SEARCH, '') : '')
|
2025-04-01 18:36:45 +02:00
|
|
|
|
|
|
|
|
if (props.nameLinkTemplate) {
|
|
|
|
|
populateDataWithlinkIdTemplate()
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-04 18:15:14 +02:00
|
|
|
if (props.visu === shared_consts.VISU_SEARCHPROD_MODE.INSERT) {
|
|
|
|
|
focus.value = true
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-01 18:36:45 +02:00
|
|
|
loadpage.value = false
|
2025-03-21 19:51:55 +01:00
|
|
|
|
|
|
|
|
if (id) {
|
|
|
|
|
await loadProduct(id)
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-01 18:36:45 +02:00
|
|
|
|
2025-03-21 19:51:55 +01:00
|
|
|
mycolumns.value = fieldsTable.getArrColsByTable('products')
|
|
|
|
|
|
|
|
|
|
searchList.value = [
|
|
|
|
|
{
|
|
|
|
|
visible: true,
|
|
|
|
|
label: 'Ricerca',
|
|
|
|
|
table: 'products',
|
|
|
|
|
key: 'titolo',
|
|
|
|
|
type: costanti.FieldType.select_by_server,
|
2025-03-31 23:55:53 +02:00
|
|
|
value: myproduct.value,
|
|
|
|
|
collabel: collabel,
|
2025-03-21 19:51:55 +01:00
|
|
|
arrvalue: [],
|
|
|
|
|
useinput: true,
|
|
|
|
|
filter: null,
|
|
|
|
|
tablesel: 'products',
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
// Inizializza
|
|
|
|
|
loadpage.value = true
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function naviga(path: string) {
|
|
|
|
|
router.push(path)
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-31 23:55:53 +02:00
|
|
|
function collabel (rec: any) {
|
2025-04-04 18:15:14 +02:00
|
|
|
// console.log('Record:', rec)
|
2025-03-31 23:55:53 +02:00
|
|
|
let label = ''
|
|
|
|
|
if (rec && rec.productInfo) {
|
|
|
|
|
label = `${rec.productInfo.name} - ${rec.productInfo.authors.map((a: any) => a.name + ' ' + a.surname).join(', ')}`
|
2025-04-22 18:30:42 +02:00
|
|
|
if (rec.productInfo.idStatoProdotto) {
|
|
|
|
|
if (!productStore.isPubblicatoById(rec.productInfo.idStatoProdotto))
|
|
|
|
|
label += ' (' + productStore.getDescrStatiProdottoByIdStatoProdotto(rec.productInfo.idStatoProdotto || '') + ')'
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-04 18:15:14 +02:00
|
|
|
// console.log('Computed label:', label)
|
2025-03-31 23:55:53 +02:00
|
|
|
}
|
|
|
|
|
return label
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-04 18:15:14 +02:00
|
|
|
function insertProd() {
|
|
|
|
|
// console.log('insertProd')
|
|
|
|
|
emit('insert', myproduct.value)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function clickClose() {
|
|
|
|
|
searchList.value[0].value = ''
|
|
|
|
|
myproduct.value = null
|
|
|
|
|
emit('close')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateproductmodif(element: IProduct) {
|
2025-04-11 18:49:42 +02:00
|
|
|
console.log('CSEARCHPRODUCT: updateproductmodif')
|
2025-04-04 18:15:14 +02:00
|
|
|
emit('updateproductmodif', element)
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-22 18:30:42 +02:00
|
|
|
async function searchOnGM(mystr: string) {
|
|
|
|
|
// refreshSingleBookFromGM({usaDBGMLocale: false})
|
|
|
|
|
const options = {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
const ris = await globalStore.updateAllBookFromGM_T_Web_Articoli({ sku: '', isbn: mystr, ...options })
|
|
|
|
|
if (ris) {
|
|
|
|
|
|
|
|
|
|
const id = getSearchId()
|
|
|
|
|
loadProduct(id)
|
|
|
|
|
updateproductmodif(myproduct.value)
|
|
|
|
|
|
|
|
|
|
// await updateproduct(false)
|
|
|
|
|
tools.showPositiveNotif($q, t('dbgm.updateLocalDb_OK'))
|
|
|
|
|
// updatefromgm.value = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-21 19:51:55 +01:00
|
|
|
onMounted(mounted)
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
userStore,
|
|
|
|
|
costanti,
|
|
|
|
|
tools,
|
|
|
|
|
toolsext,
|
|
|
|
|
search,
|
|
|
|
|
shared_consts,
|
|
|
|
|
productStore,
|
|
|
|
|
t,
|
|
|
|
|
loadpage,
|
|
|
|
|
refreshpage,
|
|
|
|
|
show_hide,
|
|
|
|
|
searchList,
|
|
|
|
|
fieldsTable,
|
|
|
|
|
mycolumns,
|
|
|
|
|
naviga,
|
|
|
|
|
myproduct,
|
|
|
|
|
optcatalogo,
|
|
|
|
|
idPage,
|
|
|
|
|
selauthor,
|
|
|
|
|
valoriopt,
|
|
|
|
|
labelcombo,
|
|
|
|
|
searchText,
|
2025-04-04 18:15:14 +02:00
|
|
|
insertProd,
|
|
|
|
|
focus,
|
|
|
|
|
clickClose,
|
|
|
|
|
saveSearch,
|
|
|
|
|
updateproductmodif,
|
2025-04-22 18:30:42 +02:00
|
|
|
searchOnGM,
|
2025-03-21 19:51:55 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|