setup.ts 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { getAreaUserId } from "@/services/bus/user";
  2. import {
  3. GldErmcpSpotContractOperateReq,
  4. GldSpotContractInfo
  5. } from "@/services/proto/spotcontract/interface";
  6. import { objectToUint8Array } from "@/utils/objHandle";
  7. import { orderContractControl } from "@/views/information/spot-contract/components/setup";
  8. import moment from 'moment';
  9. import { Ref } from 'vue';
  10. import { FormState } from "../interface";
  11. /**
  12. * 新增现货合同 表单提交
  13. */
  14. export function addContractReq() {
  15. /**
  16. * @param form 表单信息
  17. * @Param type 1: 保存草稿 2: 提交申请
  18. */
  19. function sendReq(form: FormState, loading: Ref<boolean>, OperateType: 1 | 2): Promise<string> {
  20. loading.value = true
  21. const info: GldSpotContractInfo = {
  22. UserID: getAreaUserId(),// 机构ID
  23. ProductType: 1, // 产品类型 产品类型-1:标准仓单2:等标3:非标
  24. ContractNo: form.ContractNo, // 现货合同编号
  25. ContractType: form.ContractType, // 现货合同类型-1:采购-1:销售
  26. BuyUserID: form.BuyUserID, // 采购方ID
  27. SellUserID: form.SellUserID,// 客户ID
  28. DeliveryGoodsID: form.DeliveryGoodsID as number,// 现货品种ID
  29. WrStandardID: form.WrStandardID as number,// 品类ID
  30. SpotGoodsBrandID: form.SpotGoodsBrandID as number,// 品牌ID
  31. ConvertFactor: form.ConvertFactor as number, // 标仓系数
  32. SpotGoodsDesc: form.SpotGoodsDesc, // 商品规格
  33. PriceType: form.PriceType,// 定价类型
  34. CurrencyID: form.CurrencyID as number,// 结算币种
  35. Qty: Number(form.Qty), // 数量
  36. Price: Number(form.Price), // 价格
  37. TradeDate: moment().format("YYYYMMDD"),// 交易日
  38. SignDate: moment().format("YYYY-MM-DD HH:mm:ss"), // 签订日期
  39. // 以上必填
  40. // 以下选填
  41. BizType: form.BizType, // 业务类型 - 1:套保 2:套利
  42. Remark: form.Remark, // 合同备注
  43. ContractMargin: form.ContractMargin ? Number(form.ContractMargin) : 0, // 合同保证金
  44. Amount: [1, 3].includes(form.PriceType) ? Number(form.Price) * Number(form.Qty) : 0, // 金额
  45. PriceMove: Number(form.PriceMove as number), // 升贴水
  46. StartDate: form.StartDate, // 点价开始时间
  47. EndDate: form.EndDate, // 点价结束时间
  48. DeliveryStartDate: form.DeliveryStartDate,// 交收期开始
  49. DeliveryEndDate: form.DeliveryEndDate, // 交收期结束
  50. GoodsID: form.GoodsID as number, // 点价合约ID-0:为现货,其它为期货商品合约ID[2:点价3:暂定价]
  51. MerUserID: form.MerUserID || 0, // 跟单员ID
  52. TradeUserID: form.TradeUserID || 0, // 交易员ID
  53. SaleUserID: form.SaleUserID || 0,// 业务员id
  54. }
  55. // 合同附件
  56. info.ContractAttachment = form.ContractAttachment ? objectToUint8Array(form.ContractAttachment) : new Uint8Array()
  57. const params: GldErmcpSpotContractOperateReq = {
  58. SpotContractID: '0',
  59. OperateType,
  60. Remark: '',
  61. Info: info,
  62. }
  63. return orderContractControl(params, loading)
  64. .then(res => {
  65. return Promise.resolve(res);
  66. })
  67. .catch(err => {
  68. return Promise.reject(err);
  69. })
  70. }
  71. return { sendReq }
  72. }