| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- import { QueryGoodsfGroup } from '@/services/go/ermcp/goodsInfo';
- import { Ermcp3GoodsGroup } from '@/services/go/ermcp/goodsInfo/interface';
- import { addDeliveryGoodsApply } from '@/services/proto/delivery';
- import { DeliveryGoodsApplyReq } from '@/services/proto/delivery/interface';
- import { message } from 'ant-design-vue';
- import { reactive, ref, UnwrapRef } from 'vue';
- import { FormState } from './interface';
- import {addDeliveryGoods} from "@/views/information/goods/components/setup";
- /**
- * 处理新增
- * @returns
- */
- export function handleAdd() {
- const loading = ref<boolean>(false);
- function addAction(param: FormState): Promise<string> {
- const unitid = param.unitid === undefined ? 0 : param.unitid
- const reqParam: DeliveryGoodsApplyReq = {
- deliverygoodscode: param.deliverygoodscode,
- deliverygoodsname: param.deliverygoodsname,
- deliverygoodsid: param.deliverygoodsid,
- unitid: unitid,
- type: 1,
- remark: param.remark,
- gldwrstandards: param.gldwrstandards.map(value => {
- const gldunitid = value.unitid === undefined ? 0 : value.unitid
- const convertfactors: any = value.convertfactor === null ? 0 : value.convertfactor
- return {
- wrstandardid: value.wrstandardid,
- wrstandardname: value.wrstandardname,
- unitid: gldunitid,
- convertfactor: (convertfactors as string) ? Number(convertfactors) : convertfactors
- }
- }),
- glddgfactoryItems: param.glddgfactoryItems,
- wrsconvertdetails: param.wrsconvertdetails.map(value => {
- const middlegoodsid = value.middlegoodsid === undefined ? 0 : value.middlegoodsid
- const convertratio: any = value.convertratio === null ? 0 : value.convertratio
- const wrsunitid = value.unitid === null ? 0 : value.unitid
- return {
- middlegoodsid: middlegoodsid,
- convertratio: (convertratio as string) ? Number(convertratio) : convertratio,
- unitid: wrsunitid
- }
- })
- }
- loading.value = true;
- loading.value = true;
- return addDeliveryGoods(reqParam, loading)
- }
- return { loading, addAction }
- }
- /**
- * 处理表单数据
- * @returns
- */
- export function handleFromState() {
- const formState: UnwrapRef<FormState> = reactive({
- deliverygoodscode: '', // string 交割商品代码(新增时有值)
- deliverygoodsname: '', // string 交割商品名称(新增时有值) // 可能没值 有值不能为中文
- deliverygoodsid: 0,// uint64 交割商品id(修改时有值)
- unitid: undefined, // uint64 单位ID
- type: 1,// int32 类型 1 新增 2 修改
- remark: '', // string 备注
- gldwrstandards: [
- { wrstandardname: '', unitid: undefined, convertfactor: null, }
- ], // GLDWRStandardEx 现货商品型号数据
- glddgfactoryItems: [
- { dgfactoryitemvalue: '', }
- ], // GLDDGFactoryItemEx 现货商品品牌数据
- wrsconvertdetails: [
- { middlegoodsid: undefined, unitid: null, unitidName: '', convertratio: null, }
- ], // WRSConvertDetailEx 现货商品折算配置明细数据
- });
- type Key = 'gldwrstandards' | 'glddgfactoryItems' | 'wrsconvertdetails'
- /**
- * 向动态表单里添加一条数据
- * @param key 'gldwrstandards' | 'glddgfactoryItems' | 'wrsconvertdetails'
- */
- function addOne(key: Key): void {
- if (key === 'gldwrstandards') {
- formState[key].push({ wrstandardname: '', unitid: undefined, convertfactor: null })
- } else if (key === 'glddgfactoryItems') {
- formState[key].push({ dgfactoryitemvalue: '', })
- } else if (key === 'wrsconvertdetails') {
- formState[key].push({ middlegoodsid: undefined, unitid: null, unitidName: '', convertratio: null, })
- }
- }
- /**
- * 删除动态表单一条数据
- * @param key
- * @param i
- */
- function deleteOne(key: Key, i: number): void {
- formState[key].splice(i, 1)
- }
- return { formState, addOne, deleteOne }
- }
- /**
- * 获取期货商品组
- * @returns
- */
- export function handleGoodsGroup() {
- const goodsGroup = ref<Ermcp3GoodsGroup[]>([])
- function getGoodsGroup() {
- QueryGoodsfGroup().then(res => {
- console.log('获取期货商品组', res);
- goodsGroup.value = res;
- }).catch(err => {
- message.error(err)
- })
- }
- return { goodsGroup, getGoodsGroup }
- }
|