Cities (owner: as legacy) - City.parentId (self relation) replaces the flat `province` label; the migration turns each label into a parent row («استان …») first, so nothing is lost. - Admin pickers are legacy's tree (CityTreeSelect): the top level, the country, is a heading. The city form and grid get «والد». - Restored legacy _getP: a city without its own percent takes its ancestor's. Restored the omde-customer form's city → percent autofill. - Import copies legacy parents; delete refuses a city with children; a parent loop is refused. Permissions (owner approved the deletion) - dashboard / dashboard.omde / dashboard.tak rows become dashboard.view, then are deleted. - Import maps them the same way: legacy types 102, 104, 105, 108 and 135 had lost the dashboard. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
137 lines
5.1 KiB
Vue
137 lines
5.1 KiB
Vue
<template>
|
|
<!--
|
|
Ported from legacy henza_admin/src/views/city/cityList.vue.
|
|
The edit modal shows the city's OWN percents. Legacy filled it from
|
|
get-percent / get-percent-aux, which return the parent's percent when the
|
|
city has none — so saving silently copied the parent's onto the child.
|
|
-->
|
|
<div id="page-user-list">
|
|
<a-card title="لیست شهر ها">
|
|
<XTable ref="citiesTable" :model="model">
|
|
<template #add>
|
|
<ListPageHeader rid="cities.create" add-label="افزودن شهر" @add="addOpen = true" />
|
|
</template>
|
|
|
|
<template #parent_title="{ text }">
|
|
{{ text ?? '—' }}
|
|
</template>
|
|
|
|
<template #percent="{ text }">
|
|
{{ text ?? '-' }}
|
|
</template>
|
|
|
|
<template #percent_aux="{ text }">
|
|
{{ text ?? '-' }}
|
|
</template>
|
|
|
|
<template #opt="{ record }">
|
|
<a-tooltip v-if="hasPermission('cities.list.view.edit')" title="ویرایش">
|
|
<EditOutlined class="cursor-pointer mx-1 text-primary" @click="edit(record)" />
|
|
</a-tooltip>
|
|
|
|
<a-tooltip v-if="hasPermission('cities.list.remove')" title="حذف">
|
|
<a-popconfirm
|
|
placement="top"
|
|
ok-text="بله"
|
|
cancel-text="خیر"
|
|
@confirm="confirmDelete(`cities/${record.id}`)"
|
|
>
|
|
<template #title><p>آیا مطمئن به حذف شهر مورد نظر هستید ؟</p></template>
|
|
<DeleteOutlined class="cursor-pointer mx-1 text-danger" />
|
|
</a-popconfirm>
|
|
</a-tooltip>
|
|
</template>
|
|
</XTable>
|
|
|
|
<a-modal v-model:open="visible" title="ویرایش شهر" @ok="save">
|
|
<a-form layout="vertical">
|
|
<a-form-item label="نام شهر">
|
|
<a-input v-model:value="form.title" />
|
|
</a-form-item>
|
|
<a-form-item label="والد" help="خالی = سرشاخه، مثل کشور">
|
|
<CityTreeSelect
|
|
v-model:value="form.parent"
|
|
:cities="cities"
|
|
parent-picker
|
|
:exclude-id="tempRow?.id"
|
|
placeholder="والد را انتخاب کنید"
|
|
/>
|
|
</a-form-item>
|
|
<a-form-item label="درصد مشتری عمده">
|
|
<a-input-number v-model:value="form.percent" class="w-full" :step="0.1" />
|
|
</a-form-item>
|
|
<a-form-item label="درصد کارشناس فروش">
|
|
<a-input-number v-model:value="form.percent_aux" class="w-full" :step="0.1" />
|
|
</a-form-item>
|
|
</a-form>
|
|
</a-modal>
|
|
|
|
<CreateCity :open="addOpen" @update:open="addOpen = $event" @success="citiesTable?.fetch()" />
|
|
</a-card>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { reactive, ref } from 'vue';
|
|
import { message } from 'ant-design-vue';
|
|
import { DeleteOutlined, EditOutlined } from '@ant-design/icons-vue';
|
|
import XTable from '../../components/x-table/XTable.vue';
|
|
import ListPageHeader from '../../components/common/ListPageHeader.vue';
|
|
import CreateCity from './createCity.vue';
|
|
import { buildCityListModel } from './CityListModel';
|
|
import { useUsersStore } from '../../stores/users';
|
|
import { useDeleteHandler } from '../../composables/useDeleteHandler';
|
|
import api from '../../api/client';
|
|
import CityTreeSelect from '../../components/common/CityTreeSelect.vue';
|
|
|
|
const users = useUsersStore();
|
|
const hasPermission = (rid: string) => Boolean(users.hasPermission(rid));
|
|
|
|
const model = buildCityListModel();
|
|
const citiesTable = ref<{ fetch: () => Promise<void> } | null>(null);
|
|
const addOpen = ref(false);
|
|
const visible = ref(false);
|
|
const tempRow = ref<Record<string, any> | undefined>(undefined);
|
|
const form = reactive<Record<string, any>>({ title: '', parent: undefined, percent: null, percent_aux: null });
|
|
const cities = ref<{ id: string; title: string; parent?: string | null }[]>([]);
|
|
|
|
async function edit(row: Record<string, any>) {
|
|
tempRow.value = row;
|
|
form.title = row.title ?? '';
|
|
form.parent = row.parent ?? undefined;
|
|
form.percent = row.percent === null || row.percent === undefined ? null : Number(row.percent);
|
|
form.percent_aux = row.percent_aux === null || row.percent_aux === undefined ? null : Number(row.percent_aux);
|
|
try {
|
|
const { data } = await api.post('cities/list');
|
|
cities.value = data.rows ?? [];
|
|
} catch (e) {
|
|
console.log(e);
|
|
}
|
|
visible.value = true;
|
|
}
|
|
|
|
async function save() {
|
|
try {
|
|
await api.put(`cities/${tempRow.value?.id}`, {
|
|
title: form.title,
|
|
parent: form.parent ?? null,
|
|
percent: form.percent,
|
|
percent_aux: form.percent_aux,
|
|
});
|
|
message.success('تغییرات ثبت شد');
|
|
visible.value = false;
|
|
citiesTable.value?.fetch();
|
|
} catch (e: any) {
|
|
message.error(e?.response?.data?.message ?? 'خطا در ثبت تغییرات');
|
|
}
|
|
}
|
|
|
|
// The backend refuses while customers, branches or addresses reference it.
|
|
const { remove: confirmDelete } = useDeleteHandler({
|
|
onSuccess: () => citiesTable.value?.fetch(),
|
|
successMessage: 'شهر حذف شد',
|
|
fallbackErrorMessage: 'خطا در حذف شهر',
|
|
});
|
|
</script>
|
|
|