Commit 48f015d9 authored by wanghuazhou's avatar wanghuazhou

refactor: 汇率页面bug修复

parent 81432c62
......@@ -3,7 +3,7 @@
<template slot="title">
<div class="el-dialog__title">{{ update ? '编辑' : '新增' }}</div>
</template>
<el-form label-width="100px" :rules="rules" :model="model" ref="form">
<el-form label-width="100px" :rules="rules" :model="model" ref="form" :disabled="loading">
<el-form-item :label="$t('币种')" prop="currencies">
<el-col :span="11">
<el-select v-model="model.sourceId" :placeholder="$t('请选择原币种')" :disabled="update" clearable style="width: 100%">
......@@ -46,7 +46,7 @@
</el-form-item>
<el-form-item :label="$t('有效期')" prop="expiration">
<el-col :span="11">
<el-date-picker v-model="model.expiration" type="datetime" :placeholder="$t('请选择有效期')" :picker-options="pickerOptions" style="width: 100%"/>
<el-date-picker v-model="model.expiration" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" :placeholder="$t('请选择有效期')" :picker-options="pickerOptions" style="width: 100%"/>
</el-col>
<el-col :span="2">&nbsp;</el-col>
<el-col :span="11">
......@@ -61,7 +61,7 @@
</el-form-item>
</el-form>
<template slot="footer">
<el-button type="primary" @click="submit">{{ $t('确定') }}</el-button>
<el-button type="primary" @click="submit" :disabled="loading">{{ $t('确定') }}</el-button>
<el-button @click="close">{{ $t('取消') }}</el-button>
</template>
</el-dialog>
......@@ -106,11 +106,11 @@ export default Vue.extend({
return dayjs(time).isBefore(dayjs().startOf('day').add(1, 'day'))
},
shortcuts: [
{ text: this.$t('一周'), onClick(picker) { picker.$emit('pick', dayjs().add(7, 'day')) }, },
{ text: this.$t('一个月'), onClick(picker) { picker.$emit('pick', dayjs().add(1, 'month')) }, },
{ text: this.$t('三个月'), onClick(picker) { picker.$emit('pick', dayjs().add(3, 'month')) }, },
{ text: this.$t('半年'), onClick(picker) { picker.$emit('pick', dayjs().add(6, 'month')) }, },
{ text: this.$t('一年'), onClick(picker) { picker.$emit('pick', dayjs().add(1, 'year')) }, },
{ text: this.$t('一周'), onClick(picker) { picker.$emit('pick', dayjs().add(7, 'day').toDate()) }, },
{ text: this.$t('一个月'), onClick(picker) { picker.$emit('pick', dayjs().add(1, 'month').toDate()) }, },
{ text: this.$t('三个月'), onClick(picker) { picker.$emit('pick', dayjs().add(3, 'month').toDate()) }, },
{ text: this.$t('半年'), onClick(picker) { picker.$emit('pick', dayjs().add(6, 'month').toDate()) }, },
{ text: this.$t('一年'), onClick(picker) { picker.$emit('pick', dayjs().add(1, 'year').toDate()) }, },
],
}
},
......@@ -127,6 +127,7 @@ export default Vue.extend({
data() {
return {
model: { ...modelDefaults, ...this.data, },
loading: false,
rules: {
currencies: { required: true, validator: this.validateCurrencies, },
amounts: { required: true, validator: this.validateAmounts, required: true, },
......@@ -143,10 +144,15 @@ export default Vue.extend({
},
async submit() {
if (await this.$refs['form'].validate().catch(() => {})) {
if (this.update) {
await updateCurrencyRate(this.model.id, this.model)
} else {
await createCurrencyRate(this.model)
this.loading = true
try {
if (this.update) {
await updateCurrencyRate(this.model.id, this.model)
} else {
await createCurrencyRate(this.model)
}
} finally {
this.loading = false
}
this.$emit('update:model', this.model)
......
......@@ -27,7 +27,7 @@
</el-table-column>
<el-table-column align="center" :label="$t('有效期')">
<template v-slot="{ row }">
{{ dayjs(row.expiration).format('YYYY-MM-DD HH:mm:ss') }}
{{ parseTime(row.expiration) }}
</template>
</el-table-column>
<el-table-column align="left" :label="$t('国家')" prop="countries" :formatter="countries"/>
......@@ -42,7 +42,11 @@
{{ parseTime(row.updateTime) }}
</template>
</el-table-column>
<el-table-column :label="$t('最后修改人')" prop="updater"/>
<el-table-column :label="$t('最后修改人')">
<template v-slot="{ row }">
{{ user(row.updater).nickname }}
</template>
</el-table-column>
<el-table-column align="center" :label="$t('操作')">
<template v-slot="{ row }">
<el-button size="mini" type="text" icon="el-icon-edit" v-hasPermi="['ecw:currency:rate:update']" @click="edit(row)">{{ $t('修改') }}</el-button>
......@@ -56,7 +60,7 @@
<pagination :total="query.result.total" :page.sync="query.params.page" :limit.sync="query.params.rows" @pagination="pagination"/>
<form-dialog :visible.sync="dialogs.form.visible" :id="dialogs.form.id" :data="dialogs.form.data" @update:model="pagination" :countries="dict.countries" :currencies="dict.currencies"/>
<logs-dialog :visible.sync="dialogs.logs.visible" :id="dialogs.logs.id" :source="dialogs.logs.source" :target="dialogs.logs.target"/>
<logs-dialog :visible.sync="dialogs.logs.visible" :id="dialogs.logs.id" :source="dialogs.logs.source" :target="dialogs.logs.target" :users="map.users" :countries="map.countries"/>
</div>
</template>
......@@ -71,6 +75,7 @@ import LogsDialog from './logs.vue'
import Query from './query.vue'
import Audit from './audit.vue'
import Decimal from 'decimal.js'
import { listAllSimpl } from '@/api/system/user'
const components = { FormDialog, LogsDialog, Query, Audit, }
......@@ -78,7 +83,7 @@ export default Vue.extend({
components,
data() {
return {
map: { countries: {}, currencies: {}, },
map: { users: {}, countries: {}, currencies: {}, },
dict: { countries: [], currencies: [], },
query: {
show: true,
......@@ -134,6 +139,9 @@ export default Vue.extend({
decimal(a) {
return new Decimal(a)
},
user(id) {
return this.map.users[id] || { id, }
},
country(id) {
return this.map.countries[id]
},
......@@ -144,9 +152,10 @@ export default Vue.extend({
return this.map.currencies[id]
},
},
async mounted() {
async created() {
this.dict.countries = await getCountryListAll().then(it => it.data)
this.dict.currencies = await getCurrencyList().then(it => it.data)
this.map.users = Array.prototype.reduce.apply(await listAllSimpl().then(it => it.data),[(m, e) => (m[e.id] = e, m), {}])
this.map.countries = this.dict.countries.reduce((m, e) => (m[e.id] = e, m), {})
this.map.currencies = this.dict.currencies.reduce((m, e) => (m[e.id] = e, m), {})
await this.pagination()
......
......@@ -6,7 +6,12 @@
<el-table class="logs" :data="list" v-loading="loading">
<el-table-column type="index" :label="$t('序号')" align="center"/>
<el-table-column :label="$t('修改人')">
<template v-slot="{ row }"><audit :row="row"/></template>
<template v-slot="{ row }">
<div>
<div><b>{{ (users[row.updater] || { nickname: row.updater }).nickname }}</b>: <i class="remarks">{{ row.remarks || $t('无') }}</i></div>
<div><i>{{ parseTime(row.updateTime) }}</i></div>
</div>
</template>
</el-table-column>
<el-table-column :label="$t('金额修改')" align="right">
<template v-slot="{ row }">
......@@ -30,14 +35,25 @@
</div>
</template>
</el-table-column>
<el-table-column :label="$t('国家变化')">
<template v-slot="{ row }">
<div v-if="countriesString(row.countries1) != countriesString(row.countries2)">
<div class="after">{{ countriesString(row.countries2) }}</div>
<div class="before">{{ countriesString(row.countries1) }}</div>
</div>
<div v-else>
<div>{{ countriesString(row.countries1) }}</div>
</div>
</template>
</el-table-column>
<el-table-column :label="$t('日期变化')">
<template v-slot="{ row }">
<div v-if="dayjs(row.sourceExpiration) != dayjs(row.targetExpiration)">
<div class="after">{{ dayjs(row.targetExpiration).format('YYYY-MM-DD HH:mm:ss') }}</div>
<div class="before">{{ dayjs(row.sourceExpiration).format('YYYY-MM-DD HH:mm:ss') }}</div>
<div v-if="row.expiration1 != row.expiration2">
<div class="after">{{ parseTime(row.expiration2) }}</div>
<div class="before">{{ parseTime(row.expiration1) }}</div>
</div>
<div v-else>
<div>{{ dayjs(row.sourceExpiration).format('YYYY-MM-DD HH:mm:ss') }}</div>
<div>{{ parseTime(row.expiration1) }}</div>
</div>
</template>
</el-table-column>
......@@ -48,7 +64,6 @@
<script>
import { getCurrencyRateLogs } from '@/api/ecw/currencyRate'
import dayjs from 'dayjs'
import Decimal from 'decimal.js'
import Vue from 'vue'
import Audit from './audit.vue'
......@@ -62,6 +77,8 @@ const props = {
visible: { type: Boolean, default: false, },
source: Object,
target: Object,
users: Object,
countries: Object,
}
export default Vue.extend({
......@@ -72,10 +89,12 @@ export default Vue.extend({
return { loading: false, page: 1, limit: 10, list: [], total: 0, }
},
methods: {
dayjs,
close() {
this.$emit('update:visible', false)
},
countriesString(list) {
return (list || []).map(e => this.countries[e]).filter(e => e).map(c => this.$l(c, 'name')).join(',')
},
decimal(a) {
return new Decimal(a)
},
......@@ -83,7 +102,7 @@ export default Vue.extend({
return `${this.source.fuhao} ${amount1} : ${this.target.fuhao} ${amount2}`
},
rate(amount1, amount2) {
return this.decimal(amount1).dividedBy(amount2).toFixed(8)
return this.decimal(amount2).dividedBy(amount1).toFixed(8)
},
async pagination() {
this.loading = true
......
......@@ -21,7 +21,7 @@
</el-select>
</el-form-item>
<el-form-item :label="$t('有效期')" prop="expiration">
<el-date-picker v-model="params.expiration" type="daterange" value-format="yyyy-MM-dd" :start-placeholder="$t('开始日期')" :end-placeholder="$t('结束日期')"/>
<el-date-picker v-model="params.expiration" type="datetimerange" value-format="yyyy-MM-dd HH:mm:ss" :start-placeholder="$t('开始日期')" :end-placeholder="$t('结束日期')"/>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" @click="submit">{{ $t('搜索') }}</el-button>
......@@ -48,12 +48,17 @@ export default Vue.extend({
params: this.value,
}
},
watch: {
value(v) {
this.params = v
}
},
methods: {
submit() {
this.$emit('query', this.params)
},
clear() {
this.$emit('update:value', this.params = {})
this.$emit('update', { expiration: ['', ''], countries: [], sourceId: '', targetId: '', expired: null,})
},
},
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment