| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- import { ref, computed } from 'vue'
- import { queryGoodsList } from '@/services/api/goods'
- import storageData from './storage'
- /**
- * 商品存储类
- */
- export default new (class {
- loading = ref(false)
- goodsList = ref<Ermcp.GoodsRsp[]>([]) // 商品列表
- quoteDayList = ref<Ermcp.QuoteDay[]>([]) // 盘面列表
- /**
- * 期货行情列表
- */
- quoteList = computed(() => {
- return this.goodsList.value.reduce((res, cur) => {
- const { goodscode, goodsname } = cur
- const quote = this.getQuoteDayInfoByCode(goodscode).value
- const item: Store.Quotation = {
- goodscode,
- goodsname,
- last: quote?.last ?? 0,
- amplitude: 0,
- change: 0,
- bid: quote?.bid ?? 0,
- ask: quote?.ask ?? 0,
- bidvolume: quote?.bidvolume ?? 0,
- askvolume: quote?.askvolume ?? 0,
- totalvolume: quote?.totalvolume ?? 0,
- lastvolume: quote?.lastvolume ?? 0,
- holdvolume: quote?.holdvolume ?? 0,
- holdincrement: quote?.holdincrement ?? 0,
- presettle: quote?.presettle ?? 0,
- totalturnover: quote?.totalturnover ?? 0,
- opened: quote?.opened ?? 0,
- highest: quote?.highest ?? 0,
- lowest: quote?.lowest ?? 0,
- }
- res.push(item)
- return res
- }, [] as Store.Quotation[])
- })
- /**
- * 获取商品列表
- */
- getGoodsList = () => {
- this.loading.value = true
- return queryGoodsList({
- data: {
- userid: storageData.getLoginInfo('UserID')
- },
- success: (res) => {
- this.goodsList.value = res.data
- },
- complete: () => {
- this.loading.value = false
- }
- })
- }
- /**
- * 通过 goodscode 获取盘面实时行情
- * @param goodscode
- * @returns
- */
- getQuoteDayInfoByCode = (goodscode: string) => {
- return computed(() => this.quoteDayList.value.find((e) => e.goodscode.toUpperCase() === goodscode.toUpperCase()))
- }
- /**
- * 通过 goodscode 获取商品实时报价
- * @param goodscode
- * @returns
- */
- getGoodsPriceByCode = (goodscode: string) => {
- return computed(() => {
- const quote = this.getQuoteDayInfoByCode(goodscode)
- return quote.value?.last ?? 0
- })
- }
- })
|