添加主数据代码
This commit is contained in:
618
src/views/mdm/product/Form.vue
Normal file
618
src/views/mdm/product/Form.vue
Normal file
@@ -0,0 +1,618 @@
|
||||
<template>
|
||||
<BasicPopup v-bind="$attrs" @register="registerPopup" showOkBtn destroyOnClose
|
||||
:cancelText="t('common.cancelText','取消')"
|
||||
:okText="t('common.okText','确定')"
|
||||
@ok="handleSubmit" :closeFunc="onClose">
|
||||
<template #title>
|
||||
<a-space :size="10">
|
||||
<div class="text-16px font-medium">{{ title }}</div>
|
||||
<a-space-compact size="small" block v-if="dataForm.id">
|
||||
<a-tooltip :title="t('common.prevRecord')">
|
||||
<a-button size="small" :disabled="getPrevDisabled" @click="handlePrev">
|
||||
<i class="icon-ym icon-ym-caret-left text-10px"></i>
|
||||
</a-button>
|
||||
</a-tooltip>
|
||||
<a-tooltip :title="t('common.nextRecord')">
|
||||
<a-button size="small" :disabled="getNextDisabled" @click="handleNext">
|
||||
<i class="icon-ym icon-ym-caret-right text-10px"></i>
|
||||
</a-button>
|
||||
</a-tooltip>
|
||||
</a-space-compact>
|
||||
</a-space>
|
||||
</template>
|
||||
<template #insertToolbar>
|
||||
<yunzhupaasCheckboxSingle v-model:value="submitType" :label="continueText" v-if="showContinueBtn" />
|
||||
</template>
|
||||
<a-row class="p-10px dynamic-form " :style="{ margin: '0 auto', width: '100%' }">
|
||||
<a-form :colon="false" size="middle" layout= "horizontal"
|
||||
labelAlign= "right"
|
||||
:labelCol="{ style: { width: '100px' } }" :model="dataForm" :rules="dataRule" ref="formRef" >
|
||||
<a-row :gutter="15">
|
||||
<!-- 具体表单 -->
|
||||
<a-col :span="12" class="ant-col-item" >
|
||||
<a-form-item
|
||||
name="product_code" >
|
||||
<template #label>商品编码
|
||||
</template> <YunzhupaasInput v-model:value="dataForm.product_code" @change="changeData('product_code',-1)"
|
||||
placeholder="系统自动生成" readonly :style='{"width":"100%"}' >
|
||||
</YunzhupaasInput>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="12" class="ant-col-item" >
|
||||
<a-form-item
|
||||
name="product_name" >
|
||||
<template #label>商品名称
|
||||
</template> <YunzhupaasInput v-model:value="dataForm.product_name" @change="changeData('product_name',-1)"
|
||||
placeholder="请输入" :allowClear='true' :style='{"width":"100%"}' :maskConfig = "maskConfig.product_name" :showCount = "false" >
|
||||
</YunzhupaasInput>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="12" class="ant-col-item" >
|
||||
<a-form-item
|
||||
name="product_type" >
|
||||
<template #label>商品类型
|
||||
</template> <YunzhupaasSelect v-model:value="dataForm.product_type" @change="changeData('product_type',-1)"
|
||||
placeholder="请选择" :templateJson="state.interfaceRes.product_type" :allowClear='true' :style='{"width":"100%"}' :showSearch='false' :options="optionsObj.product_typeOptions" :fieldNames="optionsObj.product_typeProps"
|
||||
>
|
||||
</YunzhupaasSelect>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="12" class="ant-col-item" >
|
||||
<a-form-item
|
||||
name="product_category" >
|
||||
<template #label>商品分类
|
||||
</template> <YunzhupaasCascader v-model:value="dataForm.product_category" @change="changeData('product_category',-1)"
|
||||
placeholder="请选择" :templateJson="state.interfaceRes.product_category" :allowClear='true' :style='{"width":"100%"}' :showSearch='true' :options="optionsObj.product_categoryOptions" :fieldNames="optionsObj.product_categoryProps"
|
||||
>
|
||||
</YunzhupaasCascader>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="12" class="ant-col-item" >
|
||||
<a-form-item
|
||||
name="short_name" >
|
||||
<template #label>商品简称
|
||||
</template> <YunzhupaasInput v-model:value="dataForm.short_name" @change="changeData('short_name',-1)"
|
||||
placeholder="请输入" :allowClear='true' :style='{"width":"100%"}' :maskConfig = "maskConfig.short_name" :showCount = "false" >
|
||||
</YunzhupaasInput>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="12" class="ant-col-item" >
|
||||
<a-form-item
|
||||
name="brand" >
|
||||
<template #label>品牌
|
||||
</template> <YunzhupaasInput v-model:value="dataForm.brand" @change="changeData('brand',-1)"
|
||||
placeholder="请输入" :allowClear='true' :style='{"width":"100%"}' :maskConfig = "maskConfig.brand" :showCount = "false" >
|
||||
</YunzhupaasInput>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="12" class="ant-col-item" >
|
||||
<a-form-item
|
||||
name="product_model" >
|
||||
<template #label>规格型号
|
||||
</template> <YunzhupaasInput v-model:value="dataForm.product_model" @change="changeData('product_model',-1)"
|
||||
placeholder="请输入" :allowClear='true' :style='{"width":"100%"}' :maskConfig = "maskConfig.product_model" :showCount = "false" >
|
||||
</YunzhupaasInput>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="12" class="ant-col-item" >
|
||||
<a-form-item
|
||||
name="color" >
|
||||
<template #label>颜色
|
||||
</template> <YunzhupaasInput v-model:value="dataForm.color" @change="changeData('color',-1)"
|
||||
placeholder="请输入" :allowClear='true' :style='{"width":"100%"}' :maskConfig = "maskConfig.color" :showCount = "false" >
|
||||
</YunzhupaasInput>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="12" class="ant-col-item" >
|
||||
<a-form-item
|
||||
name="product_size" >
|
||||
<template #label>尺寸/规格
|
||||
</template> <YunzhupaasInput v-model:value="dataForm.product_size" @change="changeData('product_size',-1)"
|
||||
placeholder="请输入" :allowClear='true' :style='{"width":"100%"}' :maskConfig = "maskConfig.product_size" :showCount = "false" >
|
||||
</YunzhupaasInput>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="12" class="ant-col-item" >
|
||||
<a-form-item
|
||||
name="weight" >
|
||||
<template #label>重量
|
||||
</template> <YunzhupaasInput v-model:value="dataForm.weight" @change="changeData('weight',-1)"
|
||||
placeholder="请输入" :allowClear='true' :style='{"width":"100%"}' :maskConfig = "maskConfig.weight" :showCount = "false" >
|
||||
</YunzhupaasInput>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="12" class="ant-col-item" >
|
||||
<a-form-item
|
||||
name="min_order_quantity" >
|
||||
<template #label>最小起订量
|
||||
</template> <YunzhupaasInputNumber v-model:value="dataForm.min_order_quantity" @change="changeData('min_order_quantity',-1)"
|
||||
placeholder="请输入" :style='{"width":"100%"}' :step="1" :precision="4" :controls="false" >
|
||||
</YunzhupaasInputNumber>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="12" class="ant-col-item" >
|
||||
<a-form-item
|
||||
name="standard_sales_price" >
|
||||
<template #label>标准销售单价
|
||||
</template> <YunzhupaasInputNumber v-model:value="dataForm.standard_sales_price" @change="changeData('standard_sales_price',-1)"
|
||||
placeholder="请输入" :style='{"width":"100%"}' :step="1" :precision="2" addonAfter="元" :controls="false" >
|
||||
</YunzhupaasInputNumber>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="12" class="ant-col-item" >
|
||||
<a-form-item
|
||||
name="gross_weight" >
|
||||
<template #label>毛重
|
||||
</template> <YunzhupaasInputNumber v-model:value="dataForm.gross_weight" @change="changeData('gross_weight',-1)"
|
||||
placeholder="请输入" :style='{"width":"100%"}' :step="1" :precision="4" addonAfter="KG" :controls="false" >
|
||||
</YunzhupaasInputNumber>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="12" class="ant-col-item" >
|
||||
<a-form-item
|
||||
name="net_weight" >
|
||||
<template #label>净重
|
||||
</template> <YunzhupaasInputNumber v-model:value="dataForm.net_weight" @change="changeData('net_weight',-1)"
|
||||
placeholder="请输入" :style='{"width":"100%"}' :step="1" :precision="4" addonAfter="KG" :controls="false" >
|
||||
</YunzhupaasInputNumber>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="12" class="ant-col-item" >
|
||||
<a-form-item
|
||||
name="unit_name" >
|
||||
<template #label>单位名称
|
||||
</template> <YunzhupaasInput v-model:value="dataForm.unit_name" @change="changeData('unit_name',-1)"
|
||||
placeholder="请输入" :allowClear='true' :style='{"width":"100%"}' :maskConfig = "maskConfig.unit_name" :showCount = "false" >
|
||||
</YunzhupaasInput>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="12" class="ant-col-item" >
|
||||
<a-form-item
|
||||
name="packagesize" >
|
||||
<template #label>包装尺寸
|
||||
</template> <YunzhupaasInput v-model:value="dataForm.packagesize" @change="changeData('packagesize',-1)"
|
||||
placeholder="请输入" :allowClear='true' :style='{"width":"100%"}' :maskConfig = "maskConfig.packagesize" :showCount = "false" >
|
||||
</YunzhupaasInput>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="12" class="ant-col-item" >
|
||||
<a-form-item
|
||||
name="tax_rate" >
|
||||
<template #label>税率
|
||||
</template> <YunzhupaasInputNumber v-model:value="dataForm.tax_rate" @change="changeData('tax_rate',-1)"
|
||||
placeholder="请输入" :style='{"width":"100%"}' :step="1" :precision="2" addonAfter="%" :controls="false" >
|
||||
</YunzhupaasInputNumber>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="12" class="ant-col-item" >
|
||||
<a-form-item
|
||||
name="cost_price" >
|
||||
<template #label>成本价
|
||||
</template> <YunzhupaasInputNumber v-model:value="dataForm.cost_price" @change="changeData('cost_price',-1)"
|
||||
placeholder="请输入" :style='{"width":"100%"}' :step="1" :precision="2" addonAfter="元" :controls="false" >
|
||||
</YunzhupaasInputNumber>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="12" class="ant-col-item" >
|
||||
<a-form-item
|
||||
name="warranty_period" >
|
||||
<template #label>保修期
|
||||
</template> <YunzhupaasInputNumber v-model:value="dataForm.warranty_period" @change="changeData('warranty_period',-1)"
|
||||
placeholder="请输入" :style='{"width":"100%"}' :step="1" addonAfter="月" :controls="false" >
|
||||
</YunzhupaasInputNumber>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="12" class="ant-col-item" >
|
||||
<a-form-item
|
||||
name="tax_code" >
|
||||
<template #label>税收分类
|
||||
</template> <YunzhupaasCascader v-model:value="dataForm.tax_code" @change="changeData('tax_code',-1)"
|
||||
placeholder="请选择" :templateJson="state.interfaceRes.tax_code" :allowClear='true' :style='{"width":"100%"}' :showSearch='false' :options="optionsObj.tax_codeOptions" :fieldNames="optionsObj.tax_codeProps"
|
||||
>
|
||||
</YunzhupaasCascader>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="24" class="ant-col-item" >
|
||||
<a-form-item
|
||||
name="warranty_terms" >
|
||||
<template #label>保修条款
|
||||
</template> <YunzhupaasTextarea v-model:value="dataForm.warranty_terms" @change="changeData('warranty_terms',-1)"
|
||||
placeholder="请输入" :allowClear='true' :style='{"width":"100%"}' :autoSize='{"minRows":3,"maxRows":4}' :showCount = "false" >
|
||||
</YunzhupaasTextarea>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="24" class="ant-col-item" >
|
||||
<a-form-item
|
||||
name="remark" >
|
||||
<template #label>备注
|
||||
</template> <YunzhupaasTextarea v-model:value="dataForm.remark" @change="changeData('remark',-1)"
|
||||
placeholder="请输入" :allowClear='true' :style='{"width":"100%"}' :autoSize='{"minRows":2,"maxRows":4}' :showCount = "false" >
|
||||
</YunzhupaasTextarea>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<!-- 表单结束 -->
|
||||
</a-row>
|
||||
</a-form>
|
||||
</a-row>
|
||||
</BasicPopup>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { create, update, getInfo } from './helper/api';
|
||||
import { reactive, toRefs, nextTick, ref, unref, computed,toRaw, inject } from 'vue';
|
||||
import { BasicPopup, usePopup } from '@/components/Popup';
|
||||
import { yunzhupaasRelationForm } from '@/components/yunzhupaas';
|
||||
import { useMessage } from '@/hooks/web/useMessage';
|
||||
import { useI18n } from '@/hooks/web/useI18n';
|
||||
import { useUserStore } from '@/store/modules/user';
|
||||
import type { FormInstance } from 'ant-design-vue';
|
||||
import { thousandsFormat , getDateTimeUnit, getTimeUnit} from '@/utils/yunzhupaas';
|
||||
import { getDictionaryDataSelector } from '@/api/systemData/dictionary';
|
||||
import { getDataInterfaceRes } from '@/api/systemData/dataInterface';
|
||||
import dayjs from 'dayjs';
|
||||
// 表单权限
|
||||
import { usePermission } from '@/hooks/web/usePermission';
|
||||
import { cloneDeep } from 'lodash-es';
|
||||
import { buildUUID } from '@/utils/uuid';
|
||||
import { CaretRightOutlined } from '@ant-design/icons-vue';
|
||||
|
||||
|
||||
interface State {
|
||||
dataForm: any;
|
||||
tableRows: any;
|
||||
dataRule: any;
|
||||
optionsObj: any;
|
||||
childIndex: any;
|
||||
isEdit: any;
|
||||
interfaceRes: any;
|
||||
//可选范围默认值
|
||||
ableAll: any;
|
||||
//掩码配置
|
||||
maskConfig:any;
|
||||
//定位属性
|
||||
locationScope:any;
|
||||
extraOptions: any;
|
||||
title: string;
|
||||
continueText: string; allList: any[];
|
||||
currIndex: number;
|
||||
isContinue: boolean;
|
||||
submitType: number;
|
||||
showContinueBtn: boolean;
|
||||
}
|
||||
|
||||
const emit = defineEmits(['reload']);
|
||||
const getLeftTreeActiveInfo: (() => any) | null = inject('getLeftTreeActiveInfo', null);
|
||||
const userStore = useUserStore();
|
||||
const userInfo = userStore.getUserInfo;
|
||||
const { createMessage, createConfirm } = useMessage();
|
||||
const { t } = useI18n();
|
||||
const [registerPopup, { openPopup, setPopupProps }] = usePopup();
|
||||
const formRef = ref<FormInstance>();
|
||||
const state = reactive<State>({
|
||||
dataForm: {
|
||||
product_code:undefined,
|
||||
product_name:undefined,
|
||||
product_type:'',
|
||||
product_category:[],
|
||||
short_name:undefined,
|
||||
brand:undefined,
|
||||
product_model:undefined,
|
||||
color:undefined,
|
||||
product_size:undefined,
|
||||
weight:undefined,
|
||||
min_order_quantity:undefined,
|
||||
standard_sales_price:undefined,
|
||||
gross_weight:undefined,
|
||||
net_weight:undefined,
|
||||
unit_name:undefined,
|
||||
packagesize:undefined,
|
||||
tax_rate:undefined,
|
||||
cost_price:undefined,
|
||||
warranty_period:undefined,
|
||||
tax_code:[],
|
||||
warranty_terms:undefined,
|
||||
remark:undefined,
|
||||
version: 0,
|
||||
},
|
||||
|
||||
tableRows:{
|
||||
},
|
||||
|
||||
dataRule: {
|
||||
product_name: [
|
||||
{
|
||||
required: true,
|
||||
message: t('sys.validate.textRequiredSuffix','不能为空'),
|
||||
trigger: 'blur'
|
||||
},
|
||||
],
|
||||
product_type: [
|
||||
{
|
||||
required: true,
|
||||
message: t('sys.validate.arrayRequiredPrefix ','请至少选择一个'),
|
||||
trigger: 'change'
|
||||
},
|
||||
],
|
||||
product_category: [
|
||||
{
|
||||
required: true,
|
||||
message: t('sys.validate.arrayRequiredPrefix ','请至少选择一个'),
|
||||
trigger: 'change'
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
optionsObj:{
|
||||
product_typeOptions:[],
|
||||
product_typeProps:{"label":"fullName","value":"id" },
|
||||
product_categoryOptions:[],
|
||||
product_categoryProps:{"label":"fullName","value":"id" ,"children":"children" },
|
||||
tax_codeOptions:[],
|
||||
tax_codeProps:{"label":"fullName","value":"enCode" ,"children":"children" },
|
||||
},
|
||||
|
||||
childIndex: -1,
|
||||
isEdit: false,
|
||||
interfaceRes: {"standard_sales_price":[],"color":[],"product_size":[],"weight":[],"remark":[],"product_code":[],"product_name":[],"net_weight":[],"min_order_quantity":[],"tax_rate":[],"unit_name":[],"warranty_period":[],"tax_code":[],"warranty_terms":[],"product_type":[],"short_name":[],"gross_weight":[],"packagesize":[],"brand":[],"product_category":[],"product_model":[],"cost_price":[]},
|
||||
//可选范围默认值
|
||||
ableAll:{
|
||||
},
|
||||
|
||||
//掩码配置
|
||||
maskConfig:{
|
||||
product_name: {"prefixType":1,"useUnrealMask":false,"maskType":1,"unrealMaskLength":1,"prefixLimit":0,"suffixLimit":0,"filler":"*","prefixSpecifyChar":"","suffixType":1,"ignoreChar":"","suffixSpecifyChar":""} ,
|
||||
short_name: {"prefixType":1,"useUnrealMask":false,"maskType":1,"unrealMaskLength":1,"prefixLimit":0,"suffixLimit":0,"filler":"*","prefixSpecifyChar":"","suffixType":1,"ignoreChar":"","suffixSpecifyChar":""} ,
|
||||
brand: {"prefixType":1,"useUnrealMask":false,"maskType":1,"unrealMaskLength":1,"prefixLimit":0,"suffixLimit":0,"filler":"*","prefixSpecifyChar":"","suffixType":1,"ignoreChar":"","suffixSpecifyChar":""} ,
|
||||
product_model: {"prefixType":1,"useUnrealMask":false,"maskType":1,"unrealMaskLength":1,"prefixLimit":0,"suffixLimit":0,"filler":"*","prefixSpecifyChar":"","suffixType":1,"ignoreChar":"","suffixSpecifyChar":""} ,
|
||||
color: {"prefixType":1,"useUnrealMask":false,"maskType":1,"unrealMaskLength":1,"prefixLimit":0,"suffixLimit":0,"filler":"*","prefixSpecifyChar":"","suffixType":1,"ignoreChar":"","suffixSpecifyChar":""} ,
|
||||
product_size: {"prefixType":1,"useUnrealMask":false,"maskType":1,"unrealMaskLength":1,"prefixLimit":0,"suffixLimit":0,"filler":"*","prefixSpecifyChar":"","suffixType":1,"ignoreChar":"","suffixSpecifyChar":""} ,
|
||||
weight: {"prefixType":1,"useUnrealMask":false,"maskType":1,"unrealMaskLength":1,"prefixLimit":0,"suffixLimit":0,"filler":"*","prefixSpecifyChar":"","suffixType":1,"ignoreChar":"","suffixSpecifyChar":""} ,
|
||||
unit_name: {"prefixType":1,"useUnrealMask":false,"maskType":1,"unrealMaskLength":1,"prefixLimit":0,"suffixLimit":0,"filler":"*","prefixSpecifyChar":"","suffixType":1,"ignoreChar":"","suffixSpecifyChar":""} ,
|
||||
packagesize: {"prefixType":1,"useUnrealMask":false,"maskType":1,"unrealMaskLength":1,"prefixLimit":0,"suffixLimit":0,"filler":"*","prefixSpecifyChar":"","suffixType":1,"ignoreChar":"","suffixSpecifyChar":""} ,
|
||||
},
|
||||
|
||||
//定位属性
|
||||
locationScope:{
|
||||
},
|
||||
|
||||
extraOptions:{
|
||||
},
|
||||
|
||||
title: "",
|
||||
continueText: "", allList: [],
|
||||
currIndex: 0,
|
||||
isContinue: false,
|
||||
submitType: 0,
|
||||
showContinueBtn: true ,
|
||||
});
|
||||
const { title, continueText, showContinueBtn, dataRule, dataForm, optionsObj, ableAll, maskConfig,submitType } = toRefs(state);
|
||||
|
||||
const getPrevDisabled = computed(() => state.currIndex === 0);
|
||||
const getNextDisabled = computed(() => state.currIndex === state.allList.length - 1);
|
||||
// 表单权限
|
||||
const { hasFormP } = usePermission();
|
||||
|
||||
defineExpose({ init });
|
||||
|
||||
function init(data) {
|
||||
state.submitType = 0;
|
||||
state.isContinue = false;
|
||||
state.title = !data.id ? t('common.add2Text','新增') : t('common.editText','编辑');
|
||||
state.continueText = !data.id ? t('common.continueAndAddText','确定并新增') : t('common.continueText','确定并继续'); setFormProps({ continueLoading: false });
|
||||
state.dataForm.id = data.id;
|
||||
openPopup();
|
||||
state.allList = data.allList;
|
||||
state.currIndex = state.allList.length && data.id ? state.allList.findIndex((item) => item.id === data.id) : 0;
|
||||
nextTick(() => {
|
||||
getForm().resetFields();
|
||||
setTimeout(initData, 0);
|
||||
});
|
||||
}
|
||||
function initData() {
|
||||
changeLoading(true);
|
||||
if (state.dataForm.id) {
|
||||
getData(state.dataForm.id);
|
||||
} else {
|
||||
//初始化options
|
||||
getproduct_typeOptions();
|
||||
getproduct_categoryOptions();
|
||||
gettax_codeOptions();
|
||||
|
||||
// 设置默认值
|
||||
state.dataForm={
|
||||
product_code:undefined,
|
||||
product_name:undefined,
|
||||
product_type:'',
|
||||
product_category:[],
|
||||
short_name:undefined,
|
||||
brand:undefined,
|
||||
product_model:undefined,
|
||||
color:undefined,
|
||||
product_size:undefined,
|
||||
weight:undefined,
|
||||
min_order_quantity:undefined,
|
||||
standard_sales_price:undefined,
|
||||
gross_weight:undefined,
|
||||
net_weight:undefined,
|
||||
unit_name:undefined,
|
||||
packagesize:undefined,
|
||||
tax_rate:undefined,
|
||||
cost_price:undefined,
|
||||
warranty_period:undefined,
|
||||
tax_code:[],
|
||||
warranty_terms:undefined,
|
||||
remark:undefined,
|
||||
version: 0,
|
||||
};
|
||||
if (getLeftTreeActiveInfo) state.dataForm = {...state.dataForm, ...(getLeftTreeActiveInfo() || {}) };
|
||||
state.childIndex = -1;
|
||||
changeLoading(false);
|
||||
}
|
||||
}
|
||||
function getForm() {
|
||||
const form = unref(formRef);
|
||||
if (!form) {
|
||||
throw new Error('form is null!');
|
||||
}
|
||||
return form;
|
||||
}
|
||||
function getData(id) {
|
||||
getInfo(id).then((res) => {
|
||||
state.dataForm = res.data || {};
|
||||
getproduct_typeOptions();
|
||||
getproduct_categoryOptions();
|
||||
gettax_codeOptions();
|
||||
|
||||
state.childIndex = -1;
|
||||
changeLoading(false);
|
||||
});
|
||||
}
|
||||
async function handleSubmit(type) {
|
||||
try {
|
||||
const values = await getForm()?.validate();
|
||||
if (!values) return;
|
||||
|
||||
|
||||
setFormProps({ confirmLoading: true });
|
||||
const formMethod = state.dataForm.id ? update : create;
|
||||
formMethod(state.dataForm)
|
||||
.then((res) => {
|
||||
createMessage.success(res.msg);
|
||||
setFormProps({ confirmLoading: false });
|
||||
if (state.submitType == 1) {
|
||||
initData();
|
||||
state.isContinue = true;
|
||||
} else {
|
||||
setFormProps({ open: false });
|
||||
emit('reload');
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
setFormProps({ confirmLoading: false });
|
||||
});
|
||||
} catch (_) {}
|
||||
}
|
||||
function handlePrev() {
|
||||
state.currIndex--;
|
||||
handleGetNewInfo();
|
||||
}
|
||||
function handleNext() {
|
||||
state.currIndex++;
|
||||
handleGetNewInfo();
|
||||
}
|
||||
function handleGetNewInfo() {
|
||||
changeLoading(true);
|
||||
getForm().resetFields();
|
||||
const id = state.allList[state.currIndex].id;
|
||||
getData(id);
|
||||
}
|
||||
function setFormProps(data) {
|
||||
setPopupProps(data);
|
||||
}
|
||||
function changeLoading(loading) {
|
||||
setPopupProps({ loading });
|
||||
}
|
||||
async function onClose() {
|
||||
if (state.isContinue) emit('reload');
|
||||
return true;
|
||||
}
|
||||
|
||||
function changeData(model, index) {
|
||||
state.isEdit = false
|
||||
state.childIndex = index
|
||||
for (let key in state.interfaceRes) {
|
||||
if (key != model) {
|
||||
let faceReList = state.interfaceRes[key]
|
||||
for (let i = 0; i < faceReList.length; i++) {
|
||||
let relationField = faceReList[i].relationField;
|
||||
if(relationField){
|
||||
let modelAll = relationField.split('-');
|
||||
let faceMode = '';
|
||||
let faceMode2 = modelAll.length == 2?modelAll[0].substring(0, modelAll[0].length-4) +modelAll[1]:""
|
||||
for (let i = 0; i < modelAll.length; i++) {
|
||||
faceMode += modelAll[i];
|
||||
}
|
||||
if (faceMode == model || faceMode2 == model ) {
|
||||
let options = 'get' + key + 'Options';
|
||||
eval(options)(true);
|
||||
changeData(key, index)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function changeDataFormData(type, data, model,index,defaultValue) {
|
||||
if(!state.isEdit) {
|
||||
if (type == 2) {
|
||||
for (let i = 0; i < state.dataForm[data].length; i++) {
|
||||
if (index == -1) {
|
||||
state.dataForm[data][i][model] = defaultValue
|
||||
} else if (index == i) {
|
||||
state.dataForm[data][i][model] = defaultValue
|
||||
}
|
||||
}
|
||||
} else {
|
||||
state.dataForm[data] = defaultValue
|
||||
}
|
||||
}
|
||||
}
|
||||
//数据选项--数据字典初始化方法
|
||||
function getproduct_typeOptions() {
|
||||
getDictionaryDataSelector('productType').then(res => {
|
||||
state.optionsObj.product_typeOptions = res.data.list
|
||||
})
|
||||
}
|
||||
//数据选项--数据字典初始化方法
|
||||
function getproduct_categoryOptions() {
|
||||
getDictionaryDataSelector('productCategory').then(res => {
|
||||
state.optionsObj.product_categoryOptions = res.data.list
|
||||
})
|
||||
}
|
||||
//数据选项--数据字典初始化方法
|
||||
function gettax_codeOptions() {
|
||||
getDictionaryDataSelector('taxCode').then(res => {
|
||||
state.optionsObj.tax_codeOptions = res.data.list
|
||||
})
|
||||
}
|
||||
function getRelationDate(timeRule, timeType, timeTarget, timeValueData, dataValue) {
|
||||
let timeDataValue: any = null;
|
||||
let timeValue = Number(timeValueData);
|
||||
if (timeRule) {
|
||||
if (timeType == 1) {
|
||||
timeDataValue = timeValue;
|
||||
} else if (timeType == 2) {
|
||||
timeDataValue = dataValue;
|
||||
} else if (timeType == 3) {
|
||||
timeDataValue = new Date().getTime();
|
||||
} else if (timeType == 4 || timeType == 5) {
|
||||
const type = getTimeUnit(timeTarget);
|
||||
const method = timeType == 4 ? 'subtract' : 'add';
|
||||
timeDataValue = dayjs()[method](timeValue, type).valueOf();
|
||||
}
|
||||
}
|
||||
return timeDataValue;
|
||||
}
|
||||
function getRelationTime(timeRule, timeType, timeTarget, timeValue, formatType, dataValue) {
|
||||
let format = formatType == 'HH:mm' ? 'HH:mm:00' : formatType;
|
||||
let timeDataValue: any = null;
|
||||
if (timeRule) {
|
||||
if (timeType == 1) {
|
||||
timeDataValue = timeValue || '00:00:00';
|
||||
if (timeDataValue.split(':').length == 3) {
|
||||
timeDataValue = timeDataValue;
|
||||
} else {
|
||||
timeDataValue = timeDataValue + ':00';
|
||||
}
|
||||
} else if (timeType == 2) {
|
||||
timeDataValue = dataValue;
|
||||
} else if (timeType == 3) {
|
||||
timeDataValue = dayjs().format(format);
|
||||
} else if (timeType == 4 || timeType == 5) {
|
||||
const type = getTimeUnit(timeTarget + 3);
|
||||
const method = timeType == 4 ? 'subtract' : 'add';
|
||||
timeDataValue = dayjs()[method](timeValue, type).format(format);
|
||||
}
|
||||
}
|
||||
return timeDataValue;
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user