diff --git a/src/router/index.js b/src/router/index.js index a51d080..a776390 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -37,11 +37,12 @@ const routes = [ { path: '/history', name: 'history', + props: true, component: () => import('../views/History.vue'), children: [ { // при совпадении пути с шаблоном /history/:id - path: ':id', + path: ':wallet(\\d{20})', props: true, component: () => import('../views/Table.vue'), }, diff --git a/src/store/modules/currency.js b/src/store/modules/currency.js index d735e9f..1b4d315 100644 --- a/src/store/modules/currency.js +++ b/src/store/modules/currency.js @@ -6,6 +6,7 @@ const currency = { currencies: [], wallets: [], rates: [], + history: [], }, getters: { @@ -13,6 +14,7 @@ const currency = { allWallets: state => state.wallets, fee: state => state.settings.fee, rates: state => state.rates, + history: state => state.history, }, mutations: { @@ -28,6 +30,9 @@ const currency = { SET_ALL_WALLETS: (state, payload) => { state.wallets = payload.wallets || state.wallets; }, + SET_HISTORY: (state, payload) => { + state.history = payload.history || state.history; + }, }, actions: { @@ -52,6 +57,13 @@ const currency = { console.log('[Rates] response: ', JSON.stringify(response)); }, + History: async ({ commit }, payload) => { + console.log('[History]'); + const response = await request('/history', payload); + await commit('SET_HISTORY', response); + console.log('[History] response: ', JSON.stringify(response)); + }, + AllWallets: async ({ commit }) => { console.log('[Currencies]'); const response = await request('/wallets/all'); diff --git a/src/store/modules/user.js b/src/store/modules/user.js index 3ca0881..ce933c1 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -40,7 +40,7 @@ const user = { actions: { ForAuthorized: async ({ commit, dispatch }, payload) => { console.log('[ForAuthorized]', payload); - await commit('SET_USER_INFO', payload.user); + await commit('SET_USER_INFO', payload.user || {}); await dispatch('UserWallets'); await dispatch('AllWallets'); }, diff --git a/src/views/History.vue b/src/views/History.vue index 2b925c4..11fa64f 100644 --- a/src/views/History.vue +++ b/src/views/History.vue @@ -7,17 +7,55 @@
History
+ + + + + + + + + + + +
+ - + @@ -33,20 +71,46 @@ export default { 'allWallets', 'fee', ]), + dateRangeText() { + return this.dates.join(' ~ '); + }, }, data: () => ({ - from: '', + wallet: '', + search: '', + dates: ['2019-08-25', '2019-11-25'], + menuDates: false, }), + watch: { + menuDates(val) { + if (!val) this.onChange(); + }, + }, created() { - this.fetchData(); + this.wallet = this.$route.params.wallet || ''; + this.onChange(); }, - /* watch: { - // при изменениях маршрута запрашиваем данные снова - $route: 'fetchData'; - }, */ methods: { - fetchData() { - console.log(`fetchData ${this.from}`); + onChange() { + if (this.wallet === '') { + return; + } + + const options = { + year: 'numeric', + month: 'numeric', + day: 'numeric', + }; + + const date1 = this.dates[0] ? new Date(this.dates[0]) : Date.now(); + const date2 = this.dates[1] ? new Date(this.dates[1]) : date1; + + this.$store.dispatch('History', { + wallet: this.wallet, + datefrom: (date1 < date2 ? date1 : date2).toLocaleString('ru', options), + dateto: (date1 < date2 ? date2 : date1).toLocaleString('ru', options), + }); + this.$router.push(`/history/${this.wallet}`); }, }, }; diff --git a/src/views/Table.vue b/src/views/Table.vue index 97acc98..913ed2f 100644 --- a/src/views/Table.vue +++ b/src/views/Table.vue @@ -1,8 +1,10 @@