setup.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import { QueryGoodsfGroup } from '@/services/go/ermcp/goodsInfo';
  2. import { Ermcp3GoodsGroup } from '@/services/go/ermcp/goodsInfo/interface';
  3. import { addDeliveryGoodsApply } from '@/services/proto/delivery';
  4. import { DeliveryGoodsApplyReq } from '@/services/proto/delivery/interface';
  5. import { message } from 'ant-design-vue';
  6. import { reactive, ref, UnwrapRef } from 'vue';
  7. import { FormState } from './interface';
  8. import {addDeliveryGoods} from "@/views/information/goods/components/setup";
  9. /**
  10. * 处理新增
  11. * @returns
  12. */
  13. export function handleAdd() {
  14. const loading = ref<boolean>(false);
  15. function addAction(param: FormState): Promise<string> {
  16. const unitid = param.unitid === undefined ? 0 : param.unitid
  17. const reqParam: DeliveryGoodsApplyReq = {
  18. deliverygoodscode: param.deliverygoodscode,
  19. deliverygoodsname: param.deliverygoodsname,
  20. deliverygoodsid: param.deliverygoodsid,
  21. unitid: unitid,
  22. type: 1,
  23. remark: param.remark,
  24. gldwrstandards: param.gldwrstandards.map(value => {
  25. const gldunitid = value.unitid === undefined ? 0 : value.unitid
  26. const convertfactors: any = value.convertfactor === null ? 0 : value.convertfactor
  27. return {
  28. wrstandardid: value.wrstandardid,
  29. wrstandardname: value.wrstandardname,
  30. unitid: gldunitid,
  31. convertfactor: (convertfactors as string) ? Number(convertfactors) : convertfactors
  32. }
  33. }),
  34. glddgfactoryItems: param.glddgfactoryItems,
  35. wrsconvertdetails: param.wrsconvertdetails.map(value => {
  36. const middlegoodsid = value.middlegoodsid === undefined ? 0 : value.middlegoodsid
  37. const convertratio: any = value.convertratio === null ? 0 : value.convertratio
  38. const wrsunitid = value.unitid === null ? 0 : value.unitid
  39. return {
  40. middlegoodsid: middlegoodsid,
  41. convertratio: (convertratio as string) ? Number(convertratio) : convertratio,
  42. unitid: wrsunitid
  43. }
  44. })
  45. }
  46. loading.value = true;
  47. loading.value = true;
  48. return addDeliveryGoods(reqParam, loading)
  49. }
  50. return { loading, addAction }
  51. }
  52. /**
  53. * 处理表单数据
  54. * @returns
  55. */
  56. export function handleFromState() {
  57. const formState: UnwrapRef<FormState> = reactive({
  58. deliverygoodscode: '', // string 交割商品代码(新增时有值)
  59. deliverygoodsname: '', // string 交割商品名称(新增时有值) // 可能没值 有值不能为中文
  60. deliverygoodsid: 0,// uint64 交割商品id(修改时有值)
  61. unitid: undefined, // uint64 单位ID
  62. type: 1,// int32 类型 1 新增 2 修改
  63. remark: '', // string 备注
  64. gldwrstandards: [
  65. { wrstandardname: '', unitid: undefined, convertfactor: null, }
  66. ], // GLDWRStandardEx 现货商品型号数据
  67. glddgfactoryItems: [
  68. { dgfactoryitemvalue: '', }
  69. ], // GLDDGFactoryItemEx 现货商品品牌数据
  70. wrsconvertdetails: [
  71. { middlegoodsid: undefined, unitid: null, unitidName: '', convertratio: null, }
  72. ], // WRSConvertDetailEx 现货商品折算配置明细数据
  73. });
  74. type Key = 'gldwrstandards' | 'glddgfactoryItems' | 'wrsconvertdetails'
  75. /**
  76. * 向动态表单里添加一条数据
  77. * @param key 'gldwrstandards' | 'glddgfactoryItems' | 'wrsconvertdetails'
  78. */
  79. function addOne(key: Key): void {
  80. if (key === 'gldwrstandards') {
  81. formState[key].push({ wrstandardname: '', unitid: undefined, convertfactor: null })
  82. } else if (key === 'glddgfactoryItems') {
  83. formState[key].push({ dgfactoryitemvalue: '', })
  84. } else if (key === 'wrsconvertdetails') {
  85. formState[key].push({ middlegoodsid: undefined, unitid: null, unitidName: '', convertratio: null, })
  86. }
  87. }
  88. /**
  89. * 删除动态表单一条数据
  90. * @param key
  91. * @param i
  92. */
  93. function deleteOne(key: Key, i: number): void {
  94. formState[key].splice(i, 1)
  95. }
  96. return { formState, addOne, deleteOne }
  97. }
  98. /**
  99. * 获取期货商品组
  100. * @returns
  101. */
  102. export function handleGoodsGroup() {
  103. const goodsGroup = ref<Ermcp3GoodsGroup[]>([])
  104. function getGoodsGroup() {
  105. QueryGoodsfGroup().then(res => {
  106. console.log('获取期货商品组', res);
  107. goodsGroup.value = res;
  108. }).catch(err => {
  109. message.error(err)
  110. })
  111. }
  112. return { goodsGroup, getGoodsGroup }
  113. }