setup.ts 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * 登记相关
  3. *
  4. * 采购 - 待点价 - 点价登记
  5. * 采购 - 履约交收 - (交收登记, 款项登记, 发票登记, 入库登记)
  6. *
  7. */
  8. import { commonResultInfo, getRequestResultInfo } from "@/common/methods/request";
  9. import { operationContractReq } from "@/services/proto/contract";
  10. import {
  11. ErmcpContractOperateApplyReq,
  12. FundsReq,
  13. InvoiceReq,
  14. SettlementReq,
  15. SomePriceReq
  16. } from "@/services/proto/contract/interface";
  17. import { objectToUint8Array } from "@/utils/objHandle";
  18. import { purchaseStateSign } from "@/views/business/purchase/setup";
  19. import Long from "long";
  20. import { Ref } from "vue";
  21. /**
  22. * 这里负责 点价登记, 交收登记, 款项登记, 发票登记, 入库登记
  23. */
  24. /**
  25. * 点价登记
  26. * @param spotcontractid 合同id
  27. * @param req 点价价格以及数量
  28. */
  29. export function somePriceReq(spotcontractid: string, req: SomePriceReq, loading: Ref<boolean>): Promise<string> {
  30. return operationContractRsp(1,
  31. operationContractReqBuilder(req, spotcontractid, 1),
  32. loading)
  33. }
  34. /**
  35. * 交收登记
  36. */
  37. export function settlementReq(spotcontractid: string, req: SettlementReq, loading: Ref<boolean>): Promise<string> {
  38. return operationContractRsp(2,
  39. operationContractReqBuilder(req, spotcontractid, 2),
  40. loading)
  41. }
  42. /**
  43. * 款项登记
  44. */
  45. export function fundsReq(spotcontractid: string, req: FundsReq, loading: Ref<boolean>, Remark: String): Promise<string> {
  46. return operationContractRsp(3,
  47. operationContractReqBuilder(req, spotcontractid, 3),
  48. loading)
  49. }
  50. /**
  51. * 发票登记
  52. */
  53. export function invoiceReq(spotcontractid: string, req: InvoiceReq, loading: Ref<boolean>): Promise<string> {
  54. return operationContractRsp(4,
  55. operationContractReqBuilder(req, spotcontractid, 4),
  56. loading)
  57. }
  58. /**
  59. * 请求报文组装
  60. * @param req 特定的请求包结构
  61. * @param id 操作的合同id
  62. * @param type 操作类型
  63. */
  64. export function operationContractReqBuilder(req: Object, id: string, type: number, Remark?: String): ErmcpContractOperateApplyReq {
  65. return {
  66. OperateType: 1, // uint32 操作类型-1:登记2:确认3:拒绝4:撤销
  67. Remark: '',
  68. Info: {
  69. OperateApplyType: type, // uint32 操作申请类型-1:点价2:结算3:款项4:发票
  70. RelatedID: Long.fromString(id), // uint64 现货合同ID(602+Unix秒时间戳(10位)+xxxxxx)
  71. DetailJson: objectToUint8Array(req), // bytes 明细JSON {}
  72. },
  73. } as ErmcpContractOperateApplyReq
  74. }
  75. /**
  76. * 登记返回处理
  77. * @param type 登记类型
  78. * @param req 请求数据
  79. * @param loading
  80. */
  81. export function operationContractRsp(type: number, req: ErmcpContractOperateApplyReq, loading: Ref<boolean>): Promise<string> {
  82. const sign = getRequestResultInfo(purchaseStateSign, type) // 接口请求后的返回提示 这里统一进行管理
  83. const result = operationContractReq(req)
  84. return commonResultInfo(result, sign, loading)
  85. }