123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <template>
- <BasicModal v-bind="$attrs" @register="registerModal" :title="getTitle" width="550px" @ok="handleSubmit">
- <BasicForm @register="registerForm" @submit="handleSubmit" style="margin-top: 26px" />
- </BasicModal>
- </template>
- <script lang="ts" setup>
- import { ref, computed, unref,onMounted } from 'vue';
-
- import { useForm, BasicForm, FormSchema } from '/@/components/Form';
- import { BasicModal, useModalInner } from '/@/components/Modal';
- import { saveOrUpdateDict } from '../api/productCassification.api';
- import { defHttp } from '/@/utils/http/axios';
- const emit = defineEmits(['register', 'success']);
- const isUpdate = ref(true);
- const rowId = ref('');
- let classOption = ref([])
-
- const [registerModal, { closeModal, setModalProps }] = useModalInner(
- async (data) => {
-
- await resetFields();
- setModalProps({ confirmLoading: false});
- isUpdate.value = !!data?.isUpdate;
- getOptions(isUpdate,data.record)
- if (unref(isUpdate)) {
- rowId.value = data.record.id;
-
- await setFieldsValue({
- ...data.record,
- });
- }
- }
- )
- function getOptions(isUpdate,data) {
- defHttp
- .get({ url: 'baseCode/baseProductClass/list'}, { isTransformResponse: false })
- .then((res) => {
- if (res.success) {
- var option = []
- res.result.records.forEach(element => {
- var obj = {
- label: element.name,
- value: element.id
- };
- option.push(obj)
- });
- classOption.value = []
- if(unref(isUpdate)){
- var row = JSON.parse(JSON.stringify(data))
- option.map(item=>{
- if(item.label!=row.parentId){
- classOption.value.push(item)
- }
- })
- }else{
- classOption.value = option
- }
- }
- })
- .finally(() => {
-
- });
- }
-
- const getTitle = computed(() => {
- return (!unref(isUpdate) ? '新增产品分类(add)' : '编辑产品分类(edit)');
- })
-
- const formSchemas: FormSchema[] = [
- {
-
- label: '上级分类(parent)',
-
- field: 'parentId',
-
- component: 'JSelectInput',
- componentProps:{
- options: classOption,
- },
- },
- {
- label: '编码(code)',
- field: 'code',
- component: 'Input',
-
- componentProps:{
- AutoComplete:'off',
- placeholder:'请输入,为空则自动生成'
- },
- },
- {
- label: '名称(name)',
- field: 'name',
- component: 'Input',
- required: true,
- componentProps:{
- AutoComplete:'off'
- },
- },
- {
- label: '毛利率(gross margin)',
- field: 'grossMargin',
- component: 'Input',
- componentProps:{
- AutoComplete:'off',
- addonAfter:"%",
- },
- },
- {
- label: '税率(tax rate)',
- field: 'taxRate',
- component: 'Input',
- componentProps:{
- AutoComplete:'off',
- addonAfter:"%",
- },
- },
- {
- label: '',
- field: 'id',
- component: 'Input',
- show: false
- },
- ];
-
- const [registerForm, { resetFields, setFieldsValue, validate }] = useForm({
-
- schemas: formSchemas,
-
- autoSubmitOnEnter: true,
-
- showResetButton: false,
- showSubmitButton:false,
- labelCol: { style: { width: '150px'} },
- labelAlign:'right'
-
- });
-
-
- async function handleSubmit() {
- try {
- let values = await validate();
- setModalProps({ confirmLoading: true });
-
- await saveOrUpdateDict(values, isUpdate.value);
-
-
- closeModal();
-
- emit('success', { isUpdate: unref(isUpdate), values: { ...values, id: rowId.value } });
- } finally {
- setModalProps({ confirmLoading: false });
- }
- }
-
- </script>
|