This commit is contained in:
Paolo Arena
2021-01-18 00:48:53 +01:00
parent 9828f4818a
commit d02044ae17
49 changed files with 1318 additions and 142 deletions

View File

@@ -44,7 +44,7 @@ const state: IGlobalState = {
mobileMode: false,
menuCollapse: true,
leftDrawerOpen: true,
RightDrawerOpen: false,
rightDrawerOpen: false,
rightCartOpen: false,
stateConnection: stateConnDefault,
networkDataReceived: false,
@@ -83,7 +83,8 @@ const state: IGlobalState = {
mypage: [],
calzoom: [],
producers: [],
storehouses: []
storehouses: [],
sharewithus: []
}
async function getConfig(id) {
@@ -204,6 +205,8 @@ namespace Getters {
return GlobalStore.state.producers
else if (table === 'storehouses')
return GlobalStore.state.storehouses
else if (table === 'sharewithus')
return GlobalStore.state.sharewithus
else if (table === 'paymenttypes')
return GlobalStore.state.paymenttypes
else if (table === 'bookings')
@@ -1093,8 +1096,9 @@ namespace Actions {
if (res.data.cart)
Products.state.cart = (res.data.cart) ? {...res.data.cart} : {}
else
Products.state.cart = {}
Products.state.cart = { items: [], totalPrice: 0, totalQty: 0, userId: ''}
Products.state.orders = (res.data.orders) ? [...res.data.orders] : []
if (showall) {
GlobalStore.state.newstosent = (res.data.newstosent) ? [...res.data.newstosent] : []
@@ -1121,7 +1125,7 @@ namespace Actions {
// Fai Logout
console.log('Fai Logout', 'islogged', islogged)
UserStore.actions.logout()
GlobalStore.state.RightDrawerOpen = true
GlobalStore.state.rightDrawerOpen = true
return false
}
}

View File

@@ -1,11 +1,11 @@
import { ICart, IOrder, IProduct, IProductsState } from 'model'
import { ICart, IOrder, IOrderCart, IProduct, IProductsState } from 'model'
import { storeBuilder } from './Store/Store'
import Api from '@api'
import { tools } from './tools'
import { lists } from './lists'
import * as ApiTables from './ApiTables'
import { GlobalStore, Todos, UserStore } from '@store'
import { GlobalStore, Products, Todos, UserStore } from '@store'
import globalroutines from './../../globalroutines/index'
import { Mutation } from 'vuex-module-decorators'
import { serv_constants } from '@src/store/Modules/serv_constants'
@@ -15,10 +15,12 @@ import { costanti } from '@src/store/Modules/costanti'
import { IAction } from '@src/model'
import * as Types from '@src/store/Api/ApiTypes'
import { static_data } from '@src/db/static_data'
import { shared_consts } from '@src/common/shared_vuejs'
const state: IProductsState = {
products: [],
cart: null,
cart: { items: [], totalPrice: 0, totalQty: 0, userId: '' },
orders: []
}
// const listFieldsToChange: string [] = ['descr', 'statustodo', 'category', 'expiring_at', 'priority', 'id_prev', 'pos', 'enableExpiring', 'progress', 'phase', 'assigned_to_userId', 'hoursplanned', 'hoursworked', 'start_date', 'completed_at', 'themecolor', 'themebgcolor']
@@ -36,7 +38,7 @@ function createOrderByProduct(product: IProduct, order: IOrder): IOrder {
idapp: process.env.APP_ID,
idProduct: product._id,
idProducer: product.idProducer,
status: tools.OrderStatus.IN_CART,
status: shared_consts.OrderStatus.IN_CART,
price: product.price,
color: product.color,
size: product.size,
@@ -71,7 +73,15 @@ namespace Getters {
return state.cart
}, 'getCart')
const getOrdersCart = b.read((stateparamf: IProductsState) => (tipoord: string): IOrderCart[] => {
if (tipoord === 'incorso')
return state.orders.filter((rec) => rec.status <= shared_consts.OrderStatus.CHECKOUT_CONFIRMED)
else
return state.orders.filter((rec) => rec.status < shared_consts.OrderStatus.RECEIVED && rec.status > shared_consts.OrderStatus.CHECKOUT_CONFIRMED)
}, 'getOrdersCart')
const existProductInCart = b.read((stateparamf: IProductsState) => (idproduct): boolean => {
// console.log('.state.cart.items', state.cart.items)
const ris = state.cart.items.filter((item) => item.order.idProduct === idproduct).reduce((sum, rec) => sum + 1, 0)
return ris > 0
}, 'existProductInCart')
@@ -83,18 +93,21 @@ namespace Getters {
const objproduct: IProduct = {
// _id: tools.getDateNow().toISOString(), // Create NEW
descr: '',
idProducer: '',
idStorehouses: [],
producer: null,
storehouses: null,
code: '',
name: '',
description: '',
department: '',
category: '',
price: 0.0,
color: '',
size: '',
quantityAvailable: 0,
canBeShipped: false,
canBeBuyOnline: false,
weight: 0,
stars: 0,
date: tools.getDateNow(),
@@ -114,6 +127,9 @@ namespace Getters {
get getCart() {
return getCart()
},
get getOrdersCart() {
return getOrdersCart()
},
get existProductInCart() {
return existProductInCart()
},
@@ -151,9 +167,9 @@ namespace Actions {
state.products = []
}
console.log('ARRAY PRODUCTS = ', state.products)
// console.log('ARRAY PRODUCTS = ', state.products)
if (process.env.DEBUG === '1') {
console.log('dbLoad', 'state.products', state.products)
// console.log('dbLoad', 'state.products', state.products)
}
return res
@@ -169,6 +185,39 @@ namespace Actions {
return ris
}
async function loadProduct(context, { code }) {
console.log('loadProduct', code)
if (!static_data.functionality.ENABLE_ECOMMERCE)
return null
console.log('getProduct', 'code', code)
// if (UserStore.state.my._id === '') {
// return new Types.AxiosError(0, null, 0, '')
// }
let ris = null
ris = await Api.SendReq('/products/' + code, 'POST', { code })
.then((res) => {
console.log('product', res.data.product)
if (res.data.product) { // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories)
return res.data.product
} else {
return null
}
})
.catch((error) => {
console.log('error getProduct', error)
UserStore.mutations.setErrorCatch(error)
return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, tools.ERR_GENERICO, error)
})
return ris
}
async function loadCart(context) {
console.log('loadCart')
@@ -189,7 +238,7 @@ namespace Actions {
if (res.data.cart) { // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories)
state.cart = res.data.cart
} else {
state.cart = null
state.cart = { items: [], totalPrice: 0, totalQty: 0, userId: '' }
}
return res
@@ -212,7 +261,7 @@ namespace Actions {
if (res.data.cart) { // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories)
state.cart = res.data.cart
} else {
state.cart = null
state.cart = { items: [], totalPrice: 0, totalQty: 0, userId: '' }
}
return res
@@ -240,7 +289,7 @@ namespace Actions {
if (res.data.cart) { // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories)
state.cart = res.data.cart
} else {
state.cart = null
state.cart = { items: [], totalPrice: 0, totalQty: 0, userId: '' }
}
return res
@@ -270,7 +319,7 @@ namespace Actions {
state.cart = res.data.cart
if (!!res.data.qty) {
// const ind = state.cart.items.findIndex((rec) => rec.order._id === order._id)
// state.cart.items[ind].order.quantity = res.data.qty
// state.cart.items[ind].order.quantity = res.data.qty
return res.data.qty
}
@@ -288,11 +337,41 @@ namespace Actions {
return ris
}
async function UpdateStatusCart(context, { cart_id, status }) {
if (!static_data.functionality.ENABLE_ECOMMERCE)
return null
// console.log('addSubQtyToItem', 'userid=', UserStore.state.my._id, order)
let ris = null
ris = await Api.SendReq('/cart/' + UserStore.state.my._id + '/cartstatus', 'POST', { cart_id, status })
.then((res) => {
if (res.data.status === shared_consts.OrderStatus.CHECKOUT_CONFIRMED) {
ProductsModule.state.cart = {}
if (res.data.orders)
Products.state.orders = res.data.orders
}
return res.data.status
})
.catch((error) => {
console.log('error UpdateStatusCart', error)
UserStore.mutations.setErrorCatch(error)
return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, tools.ERR_GENERICO, error)
})
return ris
}
export const actions = {
// loadCart: b.dispatch(loadCart),
loadProduct: b.dispatch(loadProduct),
loadProducts: b.dispatch(loadProducts),
addToCart: b.dispatch(addToCart),
addSubQtyToItem: b.dispatch(addSubQtyToItem),
UpdateStatusCart: b.dispatch(UpdateStatusCart),
removeFromCart: b.dispatch(removeFromCart),
}

View File

@@ -45,6 +45,9 @@ export const DefaultUser: IUserFields = {
saw_and_accepted: false,
qualified: false,
qualified_2invitati: false,
socio: false,
socioresidente: false,
myshares: [],
},
downline: [],
calcstat: DefaultCalc,
@@ -54,7 +57,8 @@ export const DefaultUser: IUserFields = {
userId: '',
items: [],
totalPrice: 0,
totalQty: 0
totalQty: 0,
note: '',
}
}
@@ -80,6 +84,9 @@ export const DefaultProfile: IUserProfile = {
saw_zoom_presentation: false,
ask_zoom_partecipato: false,
saw_and_accepted: false,
socio: false,
socioresidente: false,
myshares: [],
paymenttypes: [],
qualified: false,
qualified_2invitati: false,

View File

@@ -167,12 +167,19 @@ export const colTableProducer = [
AddCol({ name: 'name', label_trans: 'producer.name' }),
AddCol({ name: 'description', label_trans: 'producer.description' }),
AddCol({ name: 'referent', label_trans: 'producer.referent' }),
AddCol({ name: 'username', label_trans: 'producer.username' }),
AddCol({ name: 'region', label_trans: 'producer.region' }),
AddCol({ name: 'city', label_trans: 'producer.city' }),
AddCol({ name: 'img', label_trans: 'producer.img' }),
AddCol({ name: 'website', label_trans: 'producer.website' }),
]
export const colTableShareWithUs = [
AddCol({ name: 'description', label_trans: 'share.description' }),
AddCol({ name: 'numshared', label_trans: 'share.numshared', fieldtype: tools.FieldType.number }),
AddCol({ name: 'rating', label_trans: 'share.rating', fieldtype: tools.FieldType.number }),
]
export const colTableStorehouse = [
AddCol({ name: 'name', label_trans: 'store.name' }),
AddCol({ name: 'description', label_trans: 'store.description' }),
@@ -185,6 +192,7 @@ export const colTableStorehouse = [
]
export const colTableProducts = [
AddCol({ name: 'code', label_trans: 'products.code' }),
AddCol({ name: 'name', label_trans: 'products.name' }),
AddCol({ name: 'description', label_trans: 'products.description' }),
AddCol({ name: 'icon', label_trans: 'products.icon' }),
@@ -208,6 +216,8 @@ export const colTableProducts = [
AddCol({ name: 'color', label_trans: 'products.color' }),
AddCol({ name: 'size', label_trans: 'products.size' }),
AddCol({ name: 'quantityAvailable', label_trans: 'products.quantityAvailable', fieldtype: tools.FieldType.number }),
AddCol({ name: 'canBeShipped', label_trans: 'products.canBeShipped', fieldtype: tools.FieldType.boolean }),
AddCol({ name: 'canBeBuyOnline', label_trans: 'products.canBeBuyOnline', fieldtype: tools.FieldType.boolean }),
AddCol({ name: 'weight', label_trans: 'products.weight', fieldtype: tools.FieldType.number }),
AddCol({ name: 'stars', label_trans: 'products.stars', fieldtype: tools.FieldType.number }),
AddCol({ name: 'date', label_trans: 'products.date', fieldtype: tools.FieldType.date }),
@@ -723,6 +733,12 @@ export const fieldsTable = {
label_trans: 'reg.manage_telegram',
fieldtype: tools.FieldType.boolean
}),
AddCol({
name: 'profile.myshares',
field: 'profile',
subfield: 'myshares',
label_trans: 'reg.myshares'
}),
AddCol({ name: 'profile.img', field: 'profile', subfield: 'img', label_trans: 'reg.img', sortable: false }),
AddCol({ name: 'date_reg', label_trans: 'reg.date_reg', fieldtype: tools.FieldType.date }),
AddCol({ name: 'lasttimeonline', label_trans: 'reg.lasttimeonline', fieldtype: tools.FieldType.date }),
@@ -733,7 +749,7 @@ export const fieldsTable = {
AddCol(DuplicateRec)
],
colTableUsersSIP: [
colTableUsersCNM: [
// AddCol({ name: '_id', label_trans: 'reg.id' }),
AddCol({ name: 'ind_order', label_trans: 'reg.ind_order' }),
AddCol({ name: 'sospeso', label_trans: 'reg.sospeso', fieldtype: tools.FieldType.boolean }),
@@ -744,7 +760,7 @@ export const fieldsTable = {
AddCol({ name: 'email', label_trans: 'reg.email' }),
AddCol({ name: 'made_gift', label_trans: 'reg.made_gift', fieldtype: tools.FieldType.boolean }),
AddCol({ name: 'note', label_trans: 'reg.note' }),
AddCol({ name: 'aportador_solidario', label_trans: 'reg.aportador_solidario' }),
// AddCol({ name: 'aportador_solidario', label_trans: 'reg.aportador_solidario' }),
AddCol({ name: 'verified_email', label_trans: 'reg.verified_email', fieldtype: tools.FieldType.boolean }),
AddCol({
name: 'profile.special_req',
@@ -816,6 +832,20 @@ export const fieldsTable = {
label_trans: 'reg.manage_telegram',
fieldtype: tools.FieldType.boolean
}),
AddCol({
name: 'profile.socio',
field: 'profile',
subfield: 'socio',
label_trans: 'reg.socio',
fieldtype: tools.FieldType.boolean
}),
AddCol({
name: 'profile.socioresidente',
field: 'profile',
subfield: 'socioresidente',
label_trans: 'reg.socioresidente',
fieldtype: tools.FieldType.boolean
}),
AddCol({ name: 'profile.chisei', field: 'profile', subfield: 'chisei', label_trans: 'reg.chisei' }),
AddCol({
name: 'profile.iltuoimpegno',
@@ -827,7 +857,7 @@ export const fieldsTable = {
name: 'profile.come_aiutare',
field: 'profile',
subfield: 'come_aiutare',
label_trans: 'reg.iltuoimpegno'
label_trans: 'reg.come_aiutare'
}),
AddCol({
name: 'profile.paymenttypes',
@@ -909,6 +939,13 @@ export const fieldsTable = {
colkey: '_id',
collabel: (rec) => rec.name + ' (' + rec.city + ')'
},
{
value: 'sharewithus',
label: 'Condividi con Noi',
columns: colTableShareWithUs,
colkey: '_id',
collabel: 'description'
},
{
value: 'wheres',
label: 'Luoghi',

View File

@@ -112,6 +112,7 @@ export const tools = {
TABCALZOOM: 'calzoom',
TABTEMPLEMAIL: 'templemail',
TABOPZEMAIL: 'opzemail',
TABSHAREWITHUS: 'sharewithus',
MAX_CHARACTERS: 60,
projects: 'projects',
@@ -164,16 +165,6 @@ export const tools = {
PRIORITY_LOW: 0
},
OrderStatus: {
NONE: 0,
IN_CART: 1,
CHECKOUT_CONFIRMED: 2,
PAYED: 3,
DELIVEDED: 4,
RECEIVED: 5,
CANCELED: 10,
},
Status: {
NONE: 0,
OPENED: 1,
@@ -1775,7 +1766,7 @@ export const tools = {
}
},
async saveFieldToServer(myself: any, table, id, mydata) {
async saveFieldToServer(myself: any, table, id, mydata, notif = true) {
const mydatatosave = {
id,
table,
@@ -1785,7 +1776,8 @@ export const tools = {
GlobalStore.actions.saveFieldValue(mydatatosave).then((ris) => {
if (ris) {
tools.showPositiveNotif(myself.$q, myself.$t('db.recupdated'))
if (notif)
tools.showPositiveNotif(myself.$q, myself.$t('db.recupdated'))
} else {
tools.showNegativeNotif(myself.$q, myself.$t('db.recfailed'))
}
@@ -1898,7 +1890,7 @@ export const tools = {
if (!(static_data.arrLangUsed.includes(mylang))) {
// console.log('non incluso ', mylang)
// mylang = static_data.arrLangUsed[0]
mylang = 'enUs'
mylang = 'it'
// Metti come default
UserStore.mutations.setlang(mylang)
@@ -2620,7 +2612,7 @@ export const tools = {
if (GlobalStore.state.leftDrawerOpen)
myw -= 300
if (!this.isMobile())
if (GlobalStore.state.RightDrawerOpen)
if (GlobalStore.state.rightDrawerOpen)
myw -= 300
maxh2 = (myw / coeff) + 20
@@ -3040,7 +3032,7 @@ export const tools = {
tools.showNotif(mythis.$q, mythis.$t('login.errato'), { color: 'negative', icon: 'notifications' })
mythis.iswaitingforRes = false
if (ispageLogin) {
GlobalStore.state.RightDrawerOpen = true
GlobalStore.state.rightDrawerOpen = true
// mythis.$router.push('/signin')
}
})
@@ -3060,7 +3052,7 @@ export const tools = {
tools.showNotif(mythis.$q, mythis.$t('login.subaccount'), { color: 'negative', icon: 'notifications' })
mythis.iswaitingforRes = false
if (ispageLogin) {
GlobalStore.state.RightDrawerOpen = true
GlobalStore.state.rightDrawerOpen = true
// mythis.$router.push('/signin')
}
})
@@ -3177,7 +3169,7 @@ export const tools = {
}
,
async createNewRecord(mythis, table, data) {
async createNewRecord(mythis, table, data, withnotif = true) {
const mydata = {
table,
@@ -3187,10 +3179,12 @@ export const tools = {
return await
GlobalStore.actions.saveTable(mydata)
.then((record) => {
if (record) {
tools.showPositiveNotif(mythis.$q, mythis.$t('db.recupdated'))
} else {
tools.showNegativeNotif(mythis.$q, mythis.$t('db.recfailed'))
if (withnotif) {
if (record) {
tools.showPositiveNotif(mythis.$q, mythis.$t('db.recupdated'))
} else {
tools.showNegativeNotif(mythis.$q, mythis.$t('db.recfailed'))
}
}
return record
})
@@ -3208,7 +3202,7 @@ export const tools = {
}
if (withright)
if (GlobalStore.state.RightDrawerOpen)
if (GlobalStore.state.rightDrawerOpen)
myw -= 300
return myw