refactor: add agentUserId

This commit is contained in:
Thanaphon Frappet 2024-10-28 13:01:46 +07:00
parent 76a371ef4a
commit ee752b9169
3 changed files with 63 additions and 15 deletions

View file

@ -209,7 +209,7 @@ withDefaults(
v-model:email="item.email" v-model:email="item.email"
v-model:contact-tel="item.contactTel" v-model:contact-tel="item.contactTel"
v-model:office-tel="item.officeTel" v-model:office-tel="item.officeTel"
v-model:agent="item.agent" v-model:agent-user-id="item.agentUserId"
/> />
</q-tab-panel> </q-tab-panel>
<q-tab-panel name="attachment"> <q-tab-panel name="attachment">

View file

@ -1,4 +1,14 @@
<script lang="ts" setup> <script lang="ts" setup>
import useUserStore from 'stores/user';
import { ref } from 'vue';
import { useI18n } from 'vue-i18n';
import SelectInput from 'src/components/shared/SelectInput.vue';
import { QSelect } from 'quasar';
const userStore = useUserStore();
const { locale } = useI18n({ useScope: 'global' });
defineProps<{ defineProps<{
readonly?: boolean; readonly?: boolean;
prefixId?: string; prefixId?: string;
@ -8,6 +18,43 @@ const email = defineModel<string>('email');
const contactTel = defineModel<string>('contactTel'); const contactTel = defineModel<string>('contactTel');
const officeTel = defineModel<string>('officeTel'); const officeTel = defineModel<string>('officeTel');
const agent = defineModel<string>('agent'); const agent = defineModel<string>('agent');
const agentUserId = defineModel<string>('agentUserId');
const agentOptions = ref<{ id: string; label: string; labelEN: string }[]>([]);
async function fetchAgentOptions(query: string) {
const res = await userStore.fetchList({
includeBranch: true,
query: query,
pageSize: 99999,
userType: 'DELEGATE',
status: 'ACTIVE',
});
if (res) {
agentOptions.value = res.result.map((v) => ({
id: v.id,
label: v.firstName + ' ' + v.lastName,
labelEN: v.firstNameEN + ' ' + v.lastNameEN,
}));
}
}
async function filter(val: string, update: (...args: unknown[]) => void) {
update(
async () => {
await fetchAgentOptions(val);
},
(ref: QSelect) => {
if (val !== '' && ref.options && ref.options?.length > 0) {
ref.setOptionIndex(-1);
ref.moveOptionSelection(1, true);
}
},
);
}
</script> </script>
<template> <template>
@ -106,17 +153,18 @@ const agent = defineModel<string>('agent');
</template> </template>
</q-input> </q-input>
<q-input <SelectInput
:for="`${prefixId}-input-telephone`" @click="fetchAgentOptions"
:id="`${prefixId}-input-telephone`" :readonly
dense incremental
outlined v-model="agentUserId"
:readonly="readonly" id="quotation-branch"
hide-bottom-space
class="col-md-6 col-12" class="col-md-6 col-12"
:option="agentOptions"
:label="$t('customer.form.agent')" :label="$t('customer.form.agent')"
:model-value="readonly ? agent || '-' : agent" option-value="id"
@update:model-value="(v) => (typeof v === 'string' ? (agent = v) : '')" :option-label="locale === 'eng' ? 'labelEN' : 'label'"
@filter="(val: string, update) => filter(val, update)"
/> />
</div> </div>
</template> </template>

View file

@ -194,7 +194,7 @@ export const useCustomerForm = defineStore('form-customer', () => {
homeCode: v.homeCode, homeCode: v.homeCode,
contactTel: v.contactTel, contactTel: v.contactTel,
officeTel: v.officeTel, officeTel: v.officeTel,
agent: v.agent, agentUserId: v.agentUserId,
customerName: v.customerName, customerName: v.customerName,
authorizedName: v.authorizedName, authorizedName: v.authorizedName,
authorizedNameEN: v.authorizedNameEN, authorizedNameEN: v.authorizedNameEN,
@ -294,7 +294,8 @@ export const useCustomerForm = defineStore('form-customer', () => {
email: currentFormData.value.customerBranch?.at(0)?.email || '', email: currentFormData.value.customerBranch?.at(0)?.email || '',
contactTel: currentFormData.value.customerBranch?.at(0)?.contactTel || '', contactTel: currentFormData.value.customerBranch?.at(0)?.contactTel || '',
officeTel: currentFormData.value.customerBranch?.at(0)?.officeTel || '', officeTel: currentFormData.value.customerBranch?.at(0)?.officeTel || '',
agent: currentFormData.value.customerBranch?.at(0)?.agent || '', agentUserId:
currentFormData.value.customerBranch?.at(0)?.agentUserId || '',
status: 'CREATED', status: 'CREATED',
customerName: customerName:
@ -421,7 +422,7 @@ export const useCustomerBranchForm = defineStore('form-customer-branch', () => {
email: '', email: '',
contactTel: '', contactTel: '',
officeTel: '', officeTel: '',
agent: '', agentUserId: undefined,
status: 'CREATED', status: 'CREATED',
customerName: '', customerName: '',
@ -508,13 +509,12 @@ export const useCustomerBranchForm = defineStore('form-customer-branch', () => {
wageRateText: _data.wageRateText, wageRateText: _data.wageRateText,
contactTel: _data.contactTel, contactTel: _data.contactTel,
officeTel: _data.officeTel, officeTel: _data.officeTel,
agent: _data.agent, agentUserId: _data.agentUserId,
codeCustomer: _data.codeCustomer, codeCustomer: _data.codeCustomer,
customerName: _data.customerName, customerName: _data.customerName,
homeCode: _data.homeCode, homeCode: _data.homeCode,
authorizedName: _data.authorizedName, authorizedName: _data.authorizedName,
authorizedNameEN: _data.authorizedNameEN, authorizedNameEN: _data.authorizedNameEN,
statusSave: false,
file: [], file: [],
}; };