index.ts 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. import { reactive, ref, shallowRef, computed } from 'vue'
  2. import { v4 } from 'uuid'
  3. import { ClientType, EBuildType, EDelistingType, EListingSelectType, EOperateType, EOrderOperateType, EValidType, OrderSrc } from '@/constants/client'
  4. import { useLoginStore, useAccountStore } from '@/stores'
  5. import {
  6. spotPresaleDestingOrder,
  7. spotPresaleTransferCancel,
  8. spotPresaleTransferDesting,
  9. spotPresaleTransferListing,
  10. spotPresalePlayment,
  11. wrListingCancelOrder,
  12. spotPresaleDeliveryConfirm,
  13. wrOutApply,
  14. spotPresaleBreachOfContractApply,
  15. hdWROrder,
  16. hdWRDealOrder,
  17. thjProfitDrawApply,
  18. spotPresalePointPrice,
  19. cancelOrder,
  20. holderClose,
  21. order,
  22. offlineDeliveryApplyCancelOrder,
  23. offlineDelivery,
  24. modifyOrder,
  25. deposiTransferOperate,
  26. goodsInventoryApply
  27. } from '@/services/api/trade'
  28. import { formatDate } from "@/filters";
  29. import Long from 'long'
  30. import { BuyOrSell } from '@/constants/order'
  31. import eventBus from '@/services/bus'
  32. const loginStore = useLoginStore()
  33. const accountStore = useAccountStore()
  34. // 采购摘牌
  35. export function usePurchaseOrderDesting() {
  36. const loading = shallowRef(false)
  37. const formData = ref<Partial<Proto.SpotPresaleDestingOrderReq>>({
  38. UserID: loginStore.userId, // 用户ID,必填
  39. AccountID: accountStore.currentAccountId, // 资金账号,必填
  40. ClientType: ClientType.Web, // 终端类型
  41. UpdatorID: loginStore.loginId, // 操作人,必填
  42. })
  43. const formSubmit = async () => {
  44. try {
  45. loading.value = true
  46. return await spotPresaleDestingOrder({
  47. data: {
  48. ...formData.value,
  49. Qty: Number(formData.value.Qty),
  50. ClientSerialNo: v4() // 客户端流水号
  51. }
  52. })
  53. } finally {
  54. loading.value = false
  55. }
  56. }
  57. return {
  58. loading,
  59. formData,
  60. formSubmit,
  61. }
  62. }
  63. // 铁合金现货预售交收确认
  64. export function useSpotPresaleDeliveryConfirm() {
  65. const loading = shallowRef(false)
  66. const confirmSubmit = async (id: string) => {
  67. try {
  68. loading.value = true
  69. return await spotPresaleDeliveryConfirm({
  70. data: {
  71. UserID: loginStore.userId,
  72. Remark: '',
  73. WRTradeDetailID: Long.fromString(id),
  74. ClientSerialNo: v4(),
  75. ClientType: ClientType.Web // 终端类型
  76. }
  77. })
  78. } finally {
  79. loading.value = false
  80. }
  81. }
  82. return {
  83. loading,
  84. confirmSubmit
  85. }
  86. }
  87. // 铁合金现货预售违约申请
  88. export function useSpotPresaleBreachOfContractApply() {
  89. const loading = shallowRef(false)
  90. const applySubmit = async (id: string) => {
  91. try {
  92. loading.value = true
  93. return await spotPresaleBreachOfContractApply({
  94. data: {
  95. UserID: loginStore.userId,
  96. WRTradeDetailID: Long.fromString(id),
  97. ClientSerialNo: v4(),
  98. ClientType: ClientType.Web // 终端类型
  99. }
  100. })
  101. } finally {
  102. loading.value = false
  103. }
  104. }
  105. return {
  106. loading,
  107. applySubmit,
  108. }
  109. }
  110. // 铁合金现货预售付款处理接口
  111. export function useSpotPresalePlayment() {
  112. const loading = shallowRef(false)
  113. const formData = reactive<Partial<Proto.SpotPresalePlaymentReq>>({
  114. UserID: loginStore.userId, // 用户ID,必填
  115. ClientType: ClientType.Web, // 终端类型
  116. ClientSerialNo: v4(), // 客户端流水号
  117. })
  118. const playmentSubmit = async (id: string) => {
  119. try {
  120. loading.value = true
  121. return await spotPresalePlayment({
  122. data: {
  123. ...formData,
  124. WRTradeDetailID: Long.fromString(id),
  125. }
  126. })
  127. } finally {
  128. loading.value = false
  129. }
  130. }
  131. return {
  132. loading,
  133. playmentSubmit
  134. }
  135. }
  136. // 铁合金现货预售转让挂牌接口
  137. export function useSpotPresaleTransferListing() {
  138. const loading = shallowRef(false)
  139. const formData = reactive<Partial<Proto.SpotPresaleTransferListingReq>>({
  140. UserID: loginStore.userId, // 用户ID,必填
  141. ClientType: ClientType.Web, // 终端类型
  142. ClientSerialNo: v4(), // 客户端流水号
  143. })
  144. const listingSubmit = async (id: string) => {
  145. try {
  146. loading.value = true
  147. /// 转让价格不能为0
  148. if (!formData.TransferPrice) {
  149. return Promise.reject('转让价格不能为0')
  150. }
  151. return await spotPresaleTransferListing({
  152. data: {
  153. ...formData,
  154. WRTradeDetailID: Long.fromString(id),
  155. }
  156. })
  157. } finally {
  158. loading.value = false
  159. }
  160. }
  161. return {
  162. loading,
  163. formData,
  164. listingSubmit
  165. }
  166. }
  167. // 铁合金现货预售转让撤销接口请求
  168. export function useSpotPresaleTransferCancel() {
  169. const loading = shallowRef(false)
  170. const transferCancelSubmit = async (wrtradedetailid?: string) => {
  171. try {
  172. loading.value = true
  173. return await spotPresaleTransferCancel({
  174. data: {
  175. UserID: loginStore.userId,
  176. WRTradeDetailID: Long.fromString(wrtradedetailid ?? '0'),
  177. ClientSerialNo: v4(),
  178. ClientType: ClientType.Web // 终端类型
  179. }
  180. })
  181. } finally {
  182. loading.value = false
  183. }
  184. }
  185. return {
  186. loading,
  187. transferCancelSubmit
  188. }
  189. }
  190. // 铁合金现货预售转让摘牌接口请求
  191. export function useSpotPresaleTransferDesting() {
  192. const loading = shallowRef(false)
  193. const formData = reactive<Proto.SpotPresaleTransferDestingReq>({
  194. UserID: loginStore.userId,
  195. AccountID: accountStore.currentAccountId,
  196. TransferID: Long.fromNumber(0),
  197. ClientType: ClientType.Web // 终端类型
  198. })
  199. const destingSubmit = async () => {
  200. try {
  201. loading.value = true
  202. return await spotPresaleTransferDesting({
  203. data: {
  204. ...formData,
  205. ClientSerialNo: v4(), // 客户端流水号
  206. }
  207. })
  208. } finally {
  209. loading.value = false
  210. }
  211. }
  212. return {
  213. loading,
  214. formData,
  215. destingSubmit
  216. }
  217. }
  218. // 挂牌撤单请求接口
  219. export function useWrListingCancelOrder() {
  220. const loading = shallowRef(false)
  221. /// 接口请求
  222. const formData = reactive<Proto.WRListingCancelOrderReq>({
  223. UserID: loginStore.userId,
  224. AccountID: accountStore.currentAccountId,
  225. OperatorID: loginStore.loginId,
  226. OrderSrc: OrderSrc.ORDERSRC_CLIENT,
  227. ClientOrderTime: formatDate(new Date().toISOString()),
  228. ClientType: ClientType.Web,
  229. })
  230. const cancelSubmit = async () => {
  231. try {
  232. loading.value = true
  233. return await wrListingCancelOrder({
  234. data: {
  235. ClientSerialNo: v4(),
  236. ...formData,
  237. }
  238. })
  239. } finally {
  240. loading.value = false
  241. }
  242. }
  243. return {
  244. loading,
  245. formData,
  246. cancelSubmit
  247. }
  248. }
  249. // 仓单明细提货请求接口
  250. export function useWrOutInApply(holdlb: Model.HoldLBRsp) {
  251. const loading = shallowRef(false)
  252. const orderQty = shallowRef(0.0)
  253. const formData = reactive<Partial<Proto.WROutApplyReq>>({
  254. AppointmentRemark: '',
  255. UserID: loginStore.userId, // 用户ID,必填
  256. AccountID: accountStore.currentAccountId, // 申请人账户ID
  257. CreatorID: loginStore.loginId, // 创建人ID
  258. WRStandardID: holdlb.wrstandardid,
  259. WarehouseID: holdlb.warehouseid,
  260. AppointmentModel: 1,
  261. ClientSerialID: Date.now(), // 客户端流水号
  262. AppointmentDate: formatDate(new Date().toISOString(), 'YYYY-MM-DD'),
  263. })
  264. const applySubmit = async () => {
  265. try {
  266. loading.value = true
  267. return await wrOutApply({
  268. data: {
  269. ...formData,
  270. WROutInDetails: [{
  271. LadingBillID: holdlb.ladingbillid,
  272. SubNum: holdlb.subnum,
  273. Qty: orderQty.value,
  274. OutQty: orderQty.value,
  275. }]
  276. }
  277. })
  278. } finally {
  279. loading.value = false
  280. }
  281. }
  282. return {
  283. loading,
  284. formData,
  285. applySubmit,
  286. orderQty,
  287. }
  288. }
  289. // 仓单明细挂牌请求接口
  290. export function useHdWROrder() {
  291. const loading = shallowRef(false)
  292. const formData = reactive<Proto.HdWROrderReq>({
  293. IsSpecified: 0,
  294. PriceFactor: 1.0,
  295. FirstRatio: 0.0,
  296. CanBargain: 0,
  297. CanPart: 1,
  298. FixedPrice: 1,
  299. OrderQty: 1,
  300. UserID: loginStore.userId,
  301. AccountID: accountStore.currentAccountId,
  302. OperatorID: loginStore.loginId,
  303. ClientType: ClientType.Web,
  304. BuyOrSell: BuyOrSell.Sell,
  305. WRPriceType: 1,
  306. MarginFlag: 0,
  307. TimevalidType: 4,
  308. HasWr: 1,
  309. PerformanceTemplateID: -1,
  310. })
  311. const amount = computed(() => {
  312. const { OrderQty = 0, FixedPrice = 0 } = formData
  313. return (OrderQty * FixedPrice).toFixed(2)
  314. })
  315. const listingSubmit = async () => {
  316. try {
  317. loading.value = true
  318. const date = new Date().toISOString()
  319. return await hdWROrder({
  320. data: {
  321. ...formData,
  322. TradeDate: formatDate(date, 'YYYYMMDD'),
  323. ClientSerialNo: v4(),
  324. ClientOrderTime: formatDate(date),
  325. }
  326. })
  327. } finally {
  328. loading.value = false
  329. }
  330. }
  331. return {
  332. loading,
  333. formData,
  334. listingSubmit,
  335. amount
  336. }
  337. }
  338. // 仓单摘牌
  339. export function useHdWRDealOrder() {
  340. const loading = shallowRef(false)
  341. const formData = reactive<Proto.HdWRDealOrderReq>({
  342. UserID: loginStore.userId, // 用户ID
  343. AccountID: accountStore.currentAccountId, // 资金账号
  344. RelatedWRTradeOrderID: '0', // 关联委托单号(摘牌委托关联挂牌委托单ID)
  345. WRTransferUserID: loginStore.userId, // 仓单受让用户
  346. OrderQty: 0, // 委托数量
  347. OrderSrc: OrderSrc.ORDERSRC_CLIENT, // 委托来源
  348. ClientSerialNo: '', // 客户端流水号
  349. ClientOrderTime: '', // 客户端委托时间
  350. ClientType: ClientType.Web, // 终端类型
  351. OperatorID: loginStore.loginId, // 操作员账号ID
  352. TradeDate: '', // 交易日
  353. HasWr: 1, // 是否有仓单-0:没有仓单1:有仓单
  354. IsFinancing: 0, // 是否融资购买(买摘牌时有效)-0:否1:是
  355. })
  356. const formSubmit = async () => {
  357. try {
  358. loading.value = true
  359. const date = new Date().toISOString()
  360. return await hdWRDealOrder({
  361. data: {
  362. ...formData,
  363. TradeDate: formatDate(date, 'YYYYMMDD'),
  364. ClientSerialNo: v4(),
  365. ClientOrderTime: formatDate(date),
  366. }
  367. })
  368. } finally {
  369. loading.value = false
  370. }
  371. }
  372. return {
  373. loading,
  374. formData,
  375. formSubmit,
  376. }
  377. }
  378. // 铁合金收益支取申请接口
  379. export function useTHJProfitDrawApplyReq() {
  380. const loading = shallowRef(false)
  381. const formData = reactive<Proto.THJProfitDrawApplyReq>({
  382. UserID: loginStore.userId, // 用户ID
  383. ApplySrc: ClientType.Web,
  384. ApplyerID: loginStore.loginId,
  385. ClientType: ClientType.Web
  386. })
  387. const onSubmit = async (drawMonth: string, amount: number) => {
  388. try {
  389. loading.value = true
  390. return await thjProfitDrawApply({
  391. data: {
  392. ...formData,
  393. DrawMonth: formatDate(drawMonth, 'YYYYMM'),
  394. DrawAmount: amount,
  395. ClientSerialNo: v4(),
  396. }
  397. })
  398. } finally {
  399. loading.value = false
  400. }
  401. }
  402. return {
  403. loading,
  404. formData,
  405. onSubmit,
  406. }
  407. }
  408. // 铁合金预售点价
  409. export function useSpotPresalePointPrice(WRTradeDetailID = '0') {
  410. const loading = shallowRef(false)
  411. const formData = reactive<Proto.SpotPresalePointPriceReq>({
  412. UserID: loginStore.userId, // 用户ID,必填
  413. WRTradeDetailID: Long.fromString(WRTradeDetailID), // 预售成交明细ID
  414. ClientType: ClientType.Web, // 终端类型
  415. ClientSerialNo: '' // 客户端流水号
  416. })
  417. const formSubmit = async () => {
  418. try {
  419. loading.value = true
  420. return await spotPresalePointPrice({
  421. data: {
  422. ...formData,
  423. ClientSerialNo: v4(),
  424. }
  425. })
  426. } finally {
  427. loading.value = false
  428. }
  429. }
  430. return {
  431. loading,
  432. formData,
  433. formSubmit,
  434. }
  435. }
  436. // 撤单请求接口
  437. export function useCancelOrder() {
  438. const loading = shallowRef(false)
  439. /// 参数信息
  440. const formData = reactive<Partial<Proto.CancelOrderReq>>({
  441. OperateType: EOperateType.OPERATETYPE_ORDERCANCEL,
  442. })
  443. const cancelSubmit = async () => {
  444. try {
  445. loading.value = true
  446. return await cancelOrder({
  447. data: formData
  448. })
  449. } finally {
  450. loading.value = false
  451. }
  452. }
  453. return {
  454. loading,
  455. cancelSubmit,
  456. formData
  457. }
  458. }
  459. // 按单平仓
  460. export function useHolderClose() {
  461. const loading = shallowRef(false)
  462. /// 参数信息
  463. const formData = reactive<Partial<Proto.HolderCloseReq>>({
  464. ClientSerialNo: v4(),
  465. ClientOrderTime: formatDate(new Date().toISOString()),
  466. ClientType: ClientType.Web,
  467. LoginID: loginStore.loginId,
  468. AccountID: accountStore.currentAccountId,
  469. OrderSrc: OrderSrc.ORDERSRC_CLIENT,
  470. OperatorID: loginStore.loginId,
  471. })
  472. const holderCloseSubmit = async () => {
  473. try {
  474. loading.value = true
  475. return await holderClose({
  476. data: {
  477. ...formData
  478. }
  479. })
  480. } finally {
  481. loading.value = false
  482. }
  483. }
  484. return {
  485. formData,
  486. loading,
  487. holderCloseSubmit
  488. }
  489. }
  490. // 交易委托
  491. export function useOrder() {
  492. const loading = shallowRef(false)
  493. const formData = reactive<Partial<Proto.OrderReq>>({
  494. ClientType: ClientType.Web,
  495. BuyOrSell: BuyOrSell.Buy,
  496. OperateType: EOrderOperateType.ORDEROPERATETYPE_NORMAL,
  497. OrderSrc: OrderSrc.ORDERSRC_CLIENT,
  498. ListingSelectType: EListingSelectType.LISTINGSELECTTYPE_DELISTING,
  499. DelistingType: EDelistingType.DELISTINGTYPE_SELECTED,
  500. BuildType: EBuildType.BUILDTYPE_OPEN,
  501. TimevalidType: EValidType.VALIDTYPE_DR,
  502. OrderFlag: 1,
  503. OrderQty: 1,
  504. })
  505. const formSubmit = async () => {
  506. try {
  507. loading.value = true
  508. const res = await order({
  509. data: {
  510. ...formData,
  511. LoginID: loginStore.loginId,
  512. OperatorID: loginStore.loginId,
  513. AccountID: accountStore.currentAccountId,
  514. ClientSerialNo: v4(),
  515. ClientOrderTime: formatDate(new Date().toISOString()),
  516. }
  517. })
  518. // 推送委托回应通知
  519. eventBus.$emit('OrderRsp', res)
  520. return res
  521. } finally {
  522. loading.value = false
  523. }
  524. }
  525. return {
  526. loading,
  527. formData,
  528. formSubmit
  529. }
  530. }
  531. // 修改订单接口
  532. export function useModifyOrder() {
  533. const loading = shallowRef(false)
  534. const formData = reactive<Partial<Proto.ModifyOrderReq>>({})
  535. const formSubmit = async () => {
  536. try {
  537. loading.value = true
  538. const res = await modifyOrder({
  539. data: {
  540. ...formData
  541. }
  542. })
  543. return res
  544. } finally {
  545. loading.value = false
  546. }
  547. }
  548. return {
  549. loading,
  550. formData,
  551. formSubmit
  552. }
  553. }
  554. // 线下交收
  555. export function useOfflineDelivery() {
  556. const loading = shallowRef(false)
  557. const formData = reactive<Partial<Proto.OfflineDeliveryReq>>({})
  558. /// 提交
  559. const formSubmit = async () => {
  560. try {
  561. loading.value = true
  562. return await offlineDelivery({
  563. data: {
  564. ...formData
  565. }
  566. })
  567. } finally {
  568. loading.value = false
  569. }
  570. }
  571. return {
  572. loading,
  573. formData,
  574. formSubmit
  575. }
  576. }
  577. // 线下交收申请撤销接口
  578. export function useCanceofflineDeliveryApplyCancelOrderlOrder() {
  579. const loading = shallowRef(false)
  580. const formData = reactive<Partial<Proto.OfflineDeliveryApplyCancelOrderReq>>({})
  581. const cancelSubmit = async () => {
  582. try {
  583. loading.value = true
  584. return await offlineDeliveryApplyCancelOrder({
  585. data: {
  586. ...formData
  587. }
  588. })
  589. } finally {
  590. loading.value = false
  591. }
  592. }
  593. return {
  594. loading,
  595. formData,
  596. cancelSubmit
  597. }
  598. }
  599. // 定金转让持仓操作
  600. export function useDeposiTransferOperate() {
  601. const loading = shallowRef(false)
  602. const formData = reactive<Partial<Proto.DepositTransferOperateReq>>({})
  603. const onSubmit = async () => {
  604. try {
  605. loading.value = true
  606. return await deposiTransferOperate({
  607. data: {
  608. ...formData
  609. }
  610. })
  611. } finally {
  612. loading.value = false
  613. }
  614. }
  615. return {
  616. loading,
  617. formData,
  618. onSubmit
  619. }
  620. }
  621. // 用户出入库申请请求
  622. export function useGoodsInventoryApply() {
  623. const loading = shallowRef(false)
  624. const formData = reactive<Partial<Proto.GoodsInventoryApplyReq>>({})
  625. const formSubmit = async () => {
  626. try {
  627. loading.value = true
  628. return await goodsInventoryApply({
  629. data: {
  630. ...formData
  631. }
  632. })
  633. } finally {
  634. loading.value = false
  635. }
  636. }
  637. return {
  638. loading,
  639. formData,
  640. formSubmit
  641. }
  642. }