This commit is contained in:
parent
0b18119c41
commit
42f975b025
|
@ -93,12 +93,14 @@ const exprBuilder = (param, value) => {
|
||||||
:label="t('customer.basicData.phone')"
|
:label="t('customer.basicData.phone')"
|
||||||
:rules="validate('client.phone')"
|
:rules="validate('client.phone')"
|
||||||
clearable
|
clearable
|
||||||
|
type="number"
|
||||||
v-model="data.phone"
|
v-model="data.phone"
|
||||||
/>
|
/>
|
||||||
<VnInput
|
<VnInput
|
||||||
:label="t('customer.basicData.mobile')"
|
:label="t('customer.basicData.mobile')"
|
||||||
:rules="validate('client.mobile')"
|
:rules="validate('client.mobile')"
|
||||||
clearable
|
clearable
|
||||||
|
type="number"
|
||||||
v-model="data.mobile"
|
v-model="data.mobile"
|
||||||
/>
|
/>
|
||||||
</VnRow>
|
</VnRow>
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
import { useStateStore } from 'src/stores/useStateStore';
|
import { computed } from 'vue';
|
||||||
import { computed, onMounted } from 'vue';
|
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import VnTable from 'src/components/VnTable/VnTable.vue';
|
import VnTable from 'src/components/VnTable/VnTable.vue';
|
||||||
import VnSelect from 'src/components/common/VnSelect.vue';
|
import VnSelect from 'src/components/common/VnSelect.vue';
|
||||||
|
@ -15,18 +14,36 @@ const columns = computed(() => [
|
||||||
align: 'left',
|
align: 'left',
|
||||||
name: primaryKey,
|
name: primaryKey,
|
||||||
label: t('primaryKey'),
|
label: t('primaryKey'),
|
||||||
|
create: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
align: 'left',
|
align: 'left',
|
||||||
name: field,
|
name: field,
|
||||||
label: t('defaultLang(en)'),
|
label: t('defaultLang(en)'),
|
||||||
component: 'input',
|
create: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
align: 'left',
|
align: 'left',
|
||||||
name: 'secondLang',
|
name: 'secondLang',
|
||||||
label: t('secondLang'),
|
label: t('secondLang'),
|
||||||
component: 'input',
|
component: 'input',
|
||||||
|
isEditable: true,
|
||||||
|
attrs: {
|
||||||
|
clearable: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
align: 'right',
|
||||||
|
label: '',
|
||||||
|
name: 'tableActions',
|
||||||
|
actions: [
|
||||||
|
{
|
||||||
|
title: t('View Summary'),
|
||||||
|
icon: 'save',
|
||||||
|
action: (row) => upsertI18n(row),
|
||||||
|
isPrimary: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -39,13 +56,11 @@ const field = computed(() => table.value.field);
|
||||||
const table = ref();
|
const table = ref();
|
||||||
const originalData = ref();
|
const originalData = ref();
|
||||||
const url = computed(() => table.value?.tableName + 's');
|
const url = computed(() => table.value?.tableName + 's');
|
||||||
// onMounted(() => {
|
|
||||||
// loadTable();
|
|
||||||
// });
|
|
||||||
|
|
||||||
async function loadTable() {
|
async function loadTable(changeLang) {
|
||||||
|
console.log('table: ', tableRef.value.CrudModelRef.formData);
|
||||||
const data = tableRef.value.CrudModelRef.formData;
|
const data = tableRef.value.CrudModelRef.formData;
|
||||||
if (!originalData.value) originalData.value = data;
|
if (!changeLang) originalData.value = data;
|
||||||
if (!originalData.value) return;
|
if (!originalData.value) return;
|
||||||
const en = originalData.value.filter((d) => d.lang === 'en');
|
const en = originalData.value.filter((d) => d.lang === 'en');
|
||||||
for (const translation of en) {
|
for (const translation of en) {
|
||||||
|
@ -64,8 +79,22 @@ function resetOriginalData() {
|
||||||
originalData.value = null;
|
originalData.value = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function upsertI18n() {
|
function upsertI18n(data) {
|
||||||
axios.patch(url.value, {});
|
const newData = { ...data };
|
||||||
|
newData[field.value] = newData.secondLang;
|
||||||
|
newData.lang = lang.value;
|
||||||
|
delete newData.secondLang;
|
||||||
|
delete newData.$index;
|
||||||
|
axios.patch(url.value, newData);
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteI18n(data) {
|
||||||
|
// const newData = { ...data };
|
||||||
|
// newData[field.value] = newData.secondLang;
|
||||||
|
// newData.lang = lang.value;
|
||||||
|
// delete newData.secondLang;
|
||||||
|
// delete newData.$index;
|
||||||
|
// axios.deleteById(url.value, newData);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -93,7 +122,7 @@ function upsertI18n() {
|
||||||
:options="langs"
|
:options="langs"
|
||||||
option-label="code"
|
option-label="code"
|
||||||
option-value="code"
|
option-value="code"
|
||||||
@update:model-value="loadTable()"
|
@update:model-value="loadTable(true)"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
</VnSubToolbar>
|
</VnSubToolbar>
|
||||||
|
@ -102,8 +131,13 @@ function upsertI18n() {
|
||||||
data-key="translations"
|
data-key="translations"
|
||||||
:url="url"
|
:url="url"
|
||||||
:columns="columns"
|
:columns="columns"
|
||||||
|
:create="{
|
||||||
|
urlCreate: url,
|
||||||
|
title: 'Create translation',
|
||||||
|
onDataSaved: () => tableRef.reload(),
|
||||||
|
formInitialData: { lang: 'en' },
|
||||||
|
}"
|
||||||
:right-search="false"
|
:right-search="false"
|
||||||
:is-editable="true"
|
|
||||||
@on-fetch="loadTable()"
|
@on-fetch="loadTable()"
|
||||||
:save-fn="upsertI18n"
|
:save-fn="upsertI18n"
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Reference in New Issue