feat: integrate request data into PropertiesExpansion for enhanced form handling

This commit is contained in:
puriphatt 2025-01-08 11:50:07 +07:00
parent 321a0a6048
commit a19e75e17d
2 changed files with 17 additions and 2 deletions

View file

@ -11,11 +11,14 @@ import {
PropString, PropString,
} from 'src/stores/product-service/types'; } from 'src/stores/product-service/types';
import { Attributes } from 'src/stores/request-list/types'; import { Attributes, RequestData } from 'src/stores/request-list/types';
import { getCustomerName } from 'src/stores/utils';
import useOptionStore from 'src/stores/options'; import useOptionStore from 'src/stores/options';
import { useRequestList } from 'src/stores/request-list'; import { useRequestList } from 'src/stores/request-list';
import { useI18n } from 'vue-i18n';
const { locale } = useI18n();
const optionStore = useOptionStore(); const optionStore = useOptionStore();
const requestListStore = useRequestList(); const requestListStore = useRequestList();
@ -24,6 +27,7 @@ const props = withDefaults(
id: string; id: string;
readonly?: boolean; readonly?: boolean;
propertiesToShow: (PropString | PropNumber | PropDate | PropOptions)[]; propertiesToShow: (PropString | PropNumber | PropDate | PropOptions)[];
requestListData: RequestData;
}>(), }>(),
{ {
id: '', id: '',
@ -31,6 +35,8 @@ const props = withDefaults(
}, },
); );
const readonlyField = ['quotationNo', 'contactPerson', 'telephone', 'employer'];
const formRemark = ref<string>(''); const formRemark = ref<string>('');
const formData = ref<{ const formData = ref<{
[field: string]: string | number | null | undefined; [field: string]: string | number | null | undefined;
@ -77,10 +83,18 @@ function triggerEdit() {
} }
function assignToForm() { function assignToForm() {
const requestData = props.requestListData;
formRemark.value = attributes.value?.remark || ''; formRemark.value = attributes.value?.remark || '';
formData.value = JSON.parse( formData.value = JSON.parse(
JSON.stringify(attributes.value?.properties || {}), JSON.stringify(attributes.value?.properties || {}),
); );
formData.value['quotationNo'] = requestData.quotation.code;
formData.value['contactPerson'] = requestData.quotation.contactName;
formData.value['telephone'] = requestData.quotation.contactTel;
formData.value['employer'] = getCustomerName(
requestData.quotation.customerBranch,
{ locale: locale.value },
);
} }
defineEmits<{ defineEmits<{
@ -143,7 +157,7 @@ defineEmits<{
{{ i + 1 }} {{ optionStore.mapOption(prop.fieldName) }} {{ i + 1 }} {{ optionStore.mapOption(prop.fieldName) }}
</article> </article>
<PropertiesToInput <PropertiesToInput
:readonly="!state.isEdit" :readonly="!state.isEdit || readonlyField.includes(prop.fieldName)"
:prop="prop" :prop="prop"
:placeholder="optionStore.mapOption(prop.fieldName)" :placeholder="optionStore.mapOption(prop.fieldName)"
v-model="formData[prop.fieldName]" v-model="formData[prop.fieldName]"

View file

@ -816,6 +816,7 @@ function goToQuotation(
" "
/> />
<PropertiesExpansion <PropertiesExpansion
:request-list-data="data"
:id="value.id" :id="value.id"
:readonly=" :readonly="
data.requestDataStatus === RequestDataStatus.Canceled data.requestDataStatus === RequestDataStatus.Canceled