Untitled
unknown
plain_text
2 years ago
6.4 kB
4
Indexable
import { FormActionType, FormSchemaModel } from '/@/components/Form'; import { MAX_LENGTH_TEXT_FIELD_KINH_PHI, MAX_LENGTH_TEXT_FIELD_LG, MAX_LENGTH_SDT, } from '/@/const/rules'; import { useI18n } from '/@/hooks/web/useI18n'; import { maxLength, regexOnlyNumber } from '/@/utils/ruleUtil'; import { CHECK_TRANG_THAI, DAM_BAO_KINH_PHI, HINH_THUC_THANH_TOAN, THAM_SO_HE_THONG, } from '/@/const/const'; import { useThamSoHeThongStore } from '/@/store/modules/danh-muc/thamSoHeThong'; import { yesNoOptions } from '/@/const/options'; import { IFormKinhPhiBaoHiem } from './type'; const fieldNameOptionHinhThucThanhToan = { label: 'tenDanhMuc', value: 'id', }; const storeThamSoHeThong = await useThamSoHeThongStore(); const optionsHinhThucThanhToan = storeThamSoHeThong.getByKey(THAM_SO_HE_THONG.HINH_THUC_THANH_TOAN); const optionsDamBaoKinhPhi = storeThamSoHeThong.getByKey(THAM_SO_HE_THONG.DAM_BAO_KINH_PHI); const filterOptionsHinhThucChiTra = optionsHinhThucThanhToan?.filter( (item) => item.id !== HINH_THUC_THANH_TOAN.SEC_DU_LICH, ); let getIdCoQuanHinhThucChiTra = undefined; getIdCoQuanHinhThucChiTra = (optionsDamBaoKinhPhi && optionsDamBaoKinhPhi?.find( (item: Recordable) => item.id === DAM_BAO_KINH_PHI.CO_QUAN_TO_CHUC_CA_NHAN, ).id) ?? undefined; const { t } = useI18n(); export const getFormSchema = (): FormSchemaModel<IFormKinhPhiBaoHiem>[] => [ { field: 'kinhPhiDuTinh', component: 'Input', label: `${t('domain.thi_thuc.kinh_phi_du_tinh')}`, componentProps: { placeholder: t('domain.thi_thuc.kinh_phi_du_tinh', { msg: t('domain.thi_thuc.kinh_phi_du_tinh'), }), }, rules: [ maxLength(MAX_LENGTH_TEXT_FIELD_KINH_PHI, t('domain.thi_thuc.kinh_phi_du_tinh')), regexOnlyNumber( t('validate.only_number', { fieldName: t('domain.thi_thuc.kinh_phi_du_tinh'), }), ), ], }, { field: 'fkNguoiDamBaoKp', component: 'SelectThamSoHeThong', label: t('domain.thi_thuc.nguoi_dam_bao_kinh_phi'), componentProps: ({ formActionType, formModel, }: { formActionType: FormActionType; formModel: IFormKinhPhiBaoHiem; }) => { return { loaiDanhMuc: THAM_SO_HE_THONG.DAM_BAO_KINH_PHI, placeholder: t('domain.thi_thuc.nguoi_dam_bao_kinh_phi', { msg: t('domain.thi_thuc.nguoi_dam_bao_kinh_phi'), }), onChange: async (value) => { if (formModel.hinhThucChiTra === HINH_THUC_THANH_TOAN.SEC_DU_LICH) { await formActionType.setFieldsValue({ hinhThucChiTra: undefined }); } if (value !== getIdCoQuanHinhThucChiTra) { await formActionType.clearValidate([ 'tenCoQuanBaoHiem', 'diaChiBaoHiem', 'diaChiBaoHiem', 'sdtbaoHiem', ]); } }, }; }, }, { field: 'tenCoQuanBaoHiem', component: 'Input', label: t('domain.common.ten_co_quan_to_chuc_ca_nhan'), dynamicRules: ({ model }) => [ maxLength(MAX_LENGTH_TEXT_FIELD_LG, t('domain.common.ten_co_quan_to_chuc_ca_nhan')), getIdCoQuanHinhThucChiTra && model.fkNguoiDamBaoKp && model.fkNguoiDamBaoKp === getIdCoQuanHinhThucChiTra ? { required: true, message: t('validate.inputText', { fieldName: t('domain.common.ten_co_quan_to_chuc_ca_nhan'), }), } : {}, ], componentProps: { placeholder: t('domain.common.ten_co_quan_to_chuc_ca_nhan', { msg: t('domain.common.ten_co_quan_to_chuc_ca_nhan'), }), }, }, { field: 'diaChiBaoHiem', label: t('domain.info.dia_chi'), component: 'Input', componentProps: { placeholder: t('domain.info.dia_chi', { msg: t('domain.info.dia_chi'), }), }, dynamicRules: ({ model }) => [ maxLength(MAX_LENGTH_TEXT_FIELD_LG, t('domain.info.dia_chi')), getIdCoQuanHinhThucChiTra && model.fkNguoiDamBaoKp && model.fkNguoiDamBaoKp === getIdCoQuanHinhThucChiTra ? { required: true, message: t('validate.inputText', { fieldName: t('domain.info.dia_chi'), }), } : {}, ], }, { field: 'sdtbaoHiem', component: 'Input', label: t('domain.info.so_dien_thoai'), componentProps: { placeholder: t('domain.info.so_dien_thoai', { msg: t('domain.info.so_dien_thoai'), }), }, dynamicRules: ({ model }) => [ maxLength(MAX_LENGTH_SDT, t('domain.info.dia_chi')), getIdCoQuanHinhThucChiTra && model.fkNguoiDamBaoKp && model.fkNguoiDamBaoKp === getIdCoQuanHinhThucChiTra ? { required: true, message: t('validate.inputText', { fieldName: t('domain.info.so_dien_thoai'), }), } : {}, ], }, { field: 'hinhThucChiTra', component: 'Select', label: t('domain.thi_thuc.hinh_thuc_chi_tra'), componentProps: ({ formModel }: { formModel: IFormKinhPhiBaoHiem }) => { return { placeholder: t('domain.thi_thuc.hinh_thuc_chi_tra', { msg: t('domain.thi_thuc.hinh_thuc_chi_tra'), }), fieldNames: fieldNameOptionHinhThucThanhToan, options: getIdCoQuanHinhThucChiTra && formModel.fkNguoiDamBaoKp && formModel.fkNguoiDamBaoKp === getIdCoQuanHinhThucChiTra ? filterOptionsHinhThucChiTra : optionsHinhThucThanhToan, }; }, }, { field: 'muaBaoHiem', component: 'RadioGroup', label: t('domain.thi_thuc.tung_mua_bao_hiem'), componentProps: { options: yesNoOptions, }, colProps: { xxl: 24, xl: 24, md: 24, }, defaultValue: CHECK_TRANG_THAI.NO, }, { field: 'thongTinCuThe', component: 'FormTungMuaBaoHiem', label: '', colProps: { xxl: 24, xl: 24, md: 24, }, ifShow: ({ model }) => { return (model as IFormKinhPhiBaoHiem).muaBaoHiem === CHECK_TRANG_THAI.YES; }, slot: 'FormTungMuaBaoHiem', }, ];
Editor is loading...