index.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { shallowRef, reactive } from 'vue'
  2. import { v4 } from 'uuid'
  3. import { formatDate } from '@/filters'
  4. import { ClientType } from '@/constants/client'
  5. import { BuyOrSell } from '@/constants/order'
  6. import { order } from '@/services/api/presale'
  7. import { useLoginStore, useAccountStore } from '@/stores'
  8. const loginStore = useLoginStore()
  9. const accountStore = useAccountStore()
  10. export function useOrder(selectedRow: Model.PresaleAuctionsRsp) {
  11. const loading = shallowRef(false)
  12. const formData = reactive<Partial<Proto.OrderReq>>({
  13. ClientType: ClientType.Web, // 终端类型
  14. LoginID: loginStore.loginId, // 登陆账号
  15. AccountID: accountStore.accountId, // 交易账号
  16. GoodsID: selectedRow.goodsid, // 商品ID
  17. MarketID: 48201, // 市场ID
  18. ValidType: 1, // 校验类型
  19. BuyOrSell: BuyOrSell.Buy, // 买卖方向
  20. DelistingType: 2, // 摘牌类型
  21. })
  22. const formSubmit = async () => {
  23. try {
  24. loading.value = true
  25. return await order({
  26. data: {
  27. ClientSerialNo: v4(),
  28. ClientOrderTime: formatDate(new Date().toISOString(), 'YYYY-MM-DD HH:mm:ss'),
  29. ...formData,
  30. }
  31. })
  32. } finally {
  33. loading.value = false
  34. }
  35. }
  36. return {
  37. loading,
  38. formData,
  39. formSubmit,
  40. }
  41. }