li.shaoyi 4 years ago
parent
commit
304e3b35a3

+ 11 - 5
src/common/components/echart/echart-timeline/setup.ts

@@ -84,11 +84,17 @@ export function handleEchart() {
                     color: '#4d535c',
                 },
                 formatter: (params: any) => {
-                    const i = params[0].dataIndex;
-                    let result = '<div class="tooltip-title">' + moment(times[i]).format('YYYY-MM-DD HH:mm') + '</div>';
-                    result += '<div class="tooltip-item"><span><i style="background-color:' + params[0].color + ';"></i>收盘</span><span>' + datas[i] + '</span></div>';
-                    result += '<div class="tooltip-item"><span><i style="background-color:' + params[2].color + ';"></i>均价</span><span>' + ma5[i] + '</span></div>';
-                    result += '<div class="tooltip-item"><span><i></i>涨幅</span><span>' + calcRatio(datas[i]) + '</span></div>';
+                    let result = '';
+                    params.forEach((item: any, index: number) => {
+                        if (index === 0) {
+                            result += '<div class="tooltip-title">' + moment(times[item.dataIndex]).format('YYYY-MM-DD HH:mm') + '</div>';
+                            result += '<div class="tooltip-item"><span><i style="background-color:' + item.color + ';"></i>收盘</span><span>' + item.value + '</span></div>';
+                        }
+                        if (index === 2) {
+                            result += '<div class="tooltip-item"><span><i style="background-color:' + item.color + ';"></i>均价</span><span>' + item.value + '</span></div>';
+                            result += '<div class="tooltip-item"><span><i></i>涨幅</span><span>' + calcRatio(item.value) + '</span></div>';
+                        }
+                    })
                     return result;
                 },
             },

+ 11 - 20
src/views/market/spot_trade/components/buy-sell-market/index.vue

@@ -57,7 +57,7 @@
                     </div>
                 </div>
             </div>
-            <a-button class="market" v-if="isFloat()" @click="openChartComponent">
+            <a-button class="market" v-if="isFloat()" @click="openComponent({ code: 'GoodsChart' })">
                 <div class="first">{{ selectedRow.goodscode }}</div>
                 <div class="last red">{{ getGoodsPrice() }}</div>
                 <LineChartOutlined />
@@ -77,8 +77,7 @@
                 <Buy :enumName="enumName" ref="buyRef" :time="time" :parantSelectedRow="selectedRow" :btnList="handleBtnList(buyMarket.btnList)" />
             </a-col>
         </a-row>
-        <GoodsChart v-if="showChartComponent" :enumName="enumName" :selectedRow="quoteDayInfo" @cancel="closeChartComponent" />
-        <component :is="componentId" v-if="componentId" :selectedRow="selectedRow" :goodsPrice="getGoodsPrice()" :enumName="enumName" :time="time" @cancel="closeComponent"> </component>
+        <component :is="componentId" v-if="componentId" :selectedRow="getSelectedRow()" :goodsPrice="getGoodsPrice()" :enumName="enumName" :time="time" @cancel="closeComponent"> </component>
     </div>
 </template>
 
@@ -135,9 +134,6 @@ export default defineComponent({
         const loading = ref<boolean>(false);
         const { visible, cancel } = _closeModal(context);
 
-        const showChartComponent = ref(false); // 显示/隐藏图表
-        const quoteDayInfo = ref<QueryQuoteDayRsp>(); // 盘口数据
-
         const { isWR, isFloat } = handleIs(props.enumName, BuyOrSell.buy);
         // 买卖大厅 配置数据
         // 表格操作按钮列表
@@ -194,17 +190,15 @@ export default defineComponent({
         // 单据挂牌成功 通知买大厅刷新数据
         Bus.$on('spotTrade', queryFn);
 
-        const openChartComponent = () => {
-            quoteDayInfo.value = getQuoteDayInfoByCode(props.selectedRow.goodscode);
-            if (quoteDayInfo.value) {
-                showChartComponent.value = true;
-            } else {
-                console.error('盘口数据获取失败');
+        const quote = getQuoteDayInfoByCode(props.selectedRow.goodscode);
+        // 切换组件数据
+        const getSelectedRow = () => {
+            if (componentId.value === 'GoodsChart') {
+                return quote;
+            }
+            if (componentId.value === 'HisChart') {
+                return props.selectedRow;
             }
-        };
-
-        const closeChartComponent = () => {
-            showChartComponent.value = false;
         };
 
         return {
@@ -225,10 +219,7 @@ export default defineComponent({
             handleBtnList,
             isWR,
             timeChange,
-            quoteDayInfo,
-            showChartComponent,
-            openChartComponent,
-            closeChartComponent,
+            getSelectedRow,
         };
     },
 });