setup.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import { getGoodsUnitEnumItemName } from "@/common/constants/enumsName";
  2. import APP from '@/services';
  3. import { QueryDeliveryGoods } from "@/services/go/ermcp/goodsInfo";
  4. import { Ermcp3Brand, Ermcp3Wrstandard, ErmcpDeliveryGoodsDetailEx, ErmcpDeliveryGoodsRsp } from "@/services/go/ermcp/goodsInfo/interface";
  5. import { QueryWareHouse } from "@/services/go/ermcp/warehouse-info/index";
  6. import { ErmcpWareHouseInfo } from "@/views/information/warehouse-info/list";
  7. import { message } from "ant-design-vue";
  8. import { reactive, ref, UnwrapRef } from "vue";
  9. import { FormState } from "./interface";
  10. // 表单
  11. export function handleFormState() {
  12. const formRef = ref();
  13. function initFormData(): FormState {
  14. return {
  15. InOutType: 7, // int32 出入库类型 - 1:采购入库 2:销售出库 3:生产入库 4:生产出库
  16. WRStandardID: undefined, // uint64 现货商品ID
  17. SpotGoodsBrandID: undefined, // uint64 现货品牌ID
  18. DeliveryGoodsID: undefined, // uint64 现货品种ID
  19. WarehouseInfo: undefined, // uint64 现货仓库ID
  20. Qty: null, // double 数量
  21. }
  22. }
  23. const formState: UnwrapRef<FormState> = reactive(initFormData())
  24. const rules = {
  25. WRStandardID: [{ required: true, message: '请选择现货商品' }],
  26. SpotGoodsBrandID: [{ required: true, message: '请选择现货品牌' }],
  27. DeliveryGoodsID: [{ required: true, message: '请选择现货品种' }],
  28. WarehouseInfo: [{ required: true, message: '请选择现货仓库' }],
  29. Qty: [{ required: true, message: '请输入数量' }],
  30. }
  31. return { rules, formState, formRef, initFormData }
  32. }
  33. // 仓库类别
  34. export function handleWarehouseType(formState: UnwrapRef<FormState>) {
  35. const warehouseType = [
  36. { name: '生产入库', key: 7 },
  37. { name: '生产出库', key: 8 },
  38. ]
  39. /**
  40. *
  41. * 是否入库
  42. * @return true: 入库; false:出库
  43. */
  44. function isIn(): boolean {
  45. return formState.InOutType === 7
  46. }
  47. function inOrOut() {
  48. return isIn() ? '入库' : '出库'
  49. }
  50. return { warehouseType, inOrOut }
  51. }
  52. // 仓库列表
  53. export function handleWarehouseList() {
  54. const wareHouseList = ref<ErmcpWareHouseInfo[]>([]);
  55. function getWarehouseList() {
  56. QueryWareHouse('1').then((res) => {
  57. wareHouseList.value = res;
  58. });
  59. }
  60. return { wareHouseList, getWarehouseList }
  61. }
  62. /**
  63. * 处理现货商品
  64. */
  65. export function handleDeliveryGoods(formState: UnwrapRef<FormState>) {
  66. // 现货品种
  67. const deliveryGoodsList = ref<ErmcpDeliveryGoodsRsp[]>([])
  68. // 品牌
  69. const gblist = ref<Ermcp3Brand[]>([])
  70. // 品类列表
  71. const gmlist = ref<Ermcp3Wrstandard[]>([])
  72. // 查询现货商品
  73. function getDeliveryGoods() {
  74. QueryDeliveryGoods({}).then(res => {
  75. console.log('查询现货商品', res);
  76. deliveryGoodsList.value = res.filter(x=>x.isvalid === 1);
  77. }).catch(err => {
  78. message.error(err)
  79. })
  80. }
  81. // 切换现货商品
  82. function deliveryGoodsChange(value: number | undefined) {
  83. if (value !== undefined) {
  84. getDeliveryGoodsDetail(value)
  85. } else {
  86. gblist.value.length = 0
  87. gmlist.value.length = 0
  88. }
  89. formState.WRStandardID = undefined;
  90. formState.SpotGoodsBrandID = undefined;
  91. }
  92. // 查询现货商品详情
  93. function getDeliveryGoodsDetail(deliverygoodsid: number) {
  94. const temp = APP.get('DeliveryGoodsList').find((e: ErmcpDeliveryGoodsDetailEx) => e.data.deliverygoodsid === deliverygoodsid && e.data.isvalid == 1)
  95. if (temp) {
  96. gblist.value = temp.gblist
  97. gmlist.value = temp.gmlist
  98. }
  99. }
  100. const numberUnit = ref<string>('')
  101. // 品类变更
  102. function WrStandardChange(value: number) {
  103. const obj = gmlist.value.find((e) => e.wrstandardid === value);
  104. if (obj) {
  105. //标仓系数
  106. // 单位
  107. numberUnit.value = getGoodsUnitEnumItemName(obj.unitid)
  108. }
  109. }
  110. return {
  111. deliveryGoodsList,
  112. gblist,
  113. gmlist,
  114. numberUnit,
  115. WrStandardChange,
  116. getDeliveryGoods,
  117. getDeliveryGoodsDetail,
  118. deliveryGoodsChange
  119. }
  120. }