zzzz
2024-04-19 35f3f260f3d3c51ac2256899ade3b9a144b46b28
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
<template>
  <!-- 永续合约,交割合约公共头部 -->
  <div>
    <div class="contract-header">
      <div class="pl-30 pr-30">
        <div class="flex justify-between pt-45">
          <div class="flex">
            <img
              v-if="isReturn"
              :src="require(`@/assets/theme/${theme}/image/icon_back.png`)"
              class="w-40 h-40 back mr-50"
              alt=""
              @click="
                kineType
                  ? $router.push(`/trade/${symbol}`)
                  : $router.push(`/perpetualContract/${symbol}`)
              "
            />
            <!-- <img
              :src="require(`@/assets/theme/${theme}/image/convert.png`)"
              alt="convert-img"
              class="w-35 h-35"
              @click="onSidebar"
            /> -->
            <div class="flex flex-col pl-21" @click="onSidebar">
              <div class="font-35 textColor">
                {{ (symbol && symbol.toUpperCase()) || "--" }}/USDT
              </div>
            </div>
            <div
              v-if="range"
              class="pl-30"
              :class="{ 'text-green': range > 0, 'text-red': range <= 0 }"
            >
              {{ range > 0 ? "+" : "" }}{{ range || "--" }}%
            </div>
          </div>
          <div class="flex items-center" v-if="islevel">
            <img
              @click="changeModel()"
              class="w-32 h-35"
              :src="require(`@/assets/theme/${theme}/image/sun.png`)"
              alt=""
            />
            <img
              :src="
                require(`@/assets/image/icon-star${
                  collected === '1' ? '_active' : ''
                }.png`)
              "
              class="w-30 h-30 mr-10 ml-20"
              @click="onCollect"
            />
            <img
              src="@/assets/image/public/record.png"
              class="w-32 h-35 ml-20"
              @click="openRecord()"
            />
          </div>
          <img
            v-if="isTrade"
            :src="require(`@/assets/3x/names14.png`)"
            class="w-44 h-44 right"
            alt=""
            @click="$router.push(`/trendDetails/${symbol}?kineType=trade`)"
          />
        </div>
      </div>
    </div>
    <!-- 左侧边弹出菜单 -->
    <van-popup
      class="popup"
      round
      v-model="show"
      close-icon-position="top-left"
      position="left"
      @closed="onClose"
    >
      <div class="pl-42 pr-40">
        <div class="flex justify-between mb-42 mt-53">
          <div class="flex items-center text-grey">
            <div class="mr-12">{{ $t("名称") }}</div>
          </div>
          <div class="flex text-grey">
            <div class="flex items-center">
              <div>{{ $t("最新价格") }}</div>
            </div>
            <div class="flex items-center">
              <div class="mr-12">/24H{{ $t("涨跌") }}</div>
            </div>
          </div>
        </div>
        <div
          class="flex justify-between mb-50"
          v-for="item in list"
          :key="item.name"
          @click="onRoute(item)"
        >
          <div>
            <!-- {{ JSON.stringify(item) }} -->
            <div class="font-700 textColor">
              {{
                item.name
                  ? item.symbol.toUpperCase() + "/" + item.name.split("/")[1]
                  : "--"
              }}
            </div>
            <div v-if="!kineType" class="text-grey mt-10">{{ title }}</div>
          </div>
          <div class="text-right">
            <div class="textColor">{{ item.close || "--" }}</div>
            <div
              class="mt-10"
              :class="item.change_ratio > 0 ? 'text-green' : 'text-red'"
            >
              {{ item.change_ratio || (item.change_ratio === 0 ? 0 : "--") }}%
            </div>
          </div>
        </div>
      </div>
    </van-popup>
  </div>
</template>
    
<script>
import { setStorage } from "@/utils/utis";
import { Popup } from "vant";
import { mapGetters, mapMutations } from "vuex";
import {
  _getHomeList,
  _collect,
  _deleteCollect,
  _checkIsInCollect,
} from "@/API/home.api";
export default {
  name: "contractHeader",
  props: {
    tabIndex: {
      type: String,
      default: null,
    },
    backFunc: {
      type: Function,
      default: null,
    },
    symbol: {
      type: String,
      default: "",
    },
    range: {
      type: String,
      defalult: "",
    },
    islevel: {
      type: Boolean,
      defalult: false,
    },
    title: {
      type: String,
      defalult: "--",
    },
    isReturn: {
      type: Boolean,
      defalult: false,
    },
    isTrade: {
      type: Boolean,
      defalult: false,
    },
    kineType: {
      type: String,
      defalult: "",
    },
  },
  components: {
    [Popup.name]: Popup,
  },
  computed: {
    ...mapGetters({
      coinList: "home/coinList",
      theme: "home/theme",
      newcoinArr: "home/newcoinArr",
    }),
  },
  data() {
    const arr = [];
    for (let i = 0; i < 10; i++) {
      arr.push({ id: i });
    }
    return {
      //   selectIndex2:this.selectIndex,
      show: false,
      timeout: null,
      collected: "0",
      // title: '',
      list: arr, //[
      // { name:"BTC/USDT",close:"22042.28",change_ratio:"2.21"},
      // { name:"XTZ/USDT",close:"1.568",change_ratio:"-7.1"},
      // { name:"ADA/USDT",close:"0.493085",change_ratio:"-4.08"},
      //]
    };
  },
  mounted() {
    this.NEW_CION_LIST();
  },
  watch: {
    symbol(val) {
      if (this.islevel) {
        this.$emit("changeLine", true);
      }
      if (this.islevel && this.$store.state.user.userInfo.token) {
        let symbol = this.$route.params.symbol;
        _checkIsInCollect(symbol).then((data) => {
          const { status } = data;
          this.collected = status;
        });
      }
    },
  },
  created() {
    // this.coins = this.coinList.map(item => item.symbol)
    // console.log('this.coins', this.coins)
    if (this.islevel && this.$store.state.user.userInfo.token) {
      let symbol = this.$route.params.symbol;
      _checkIsInCollect(symbol).then((data) => {
        const { status } = data;
        this.collected = status;
      });
    }
  },
  methods: {
    ...mapMutations("home", ["SET_THEME", "NEW_CION_LIST"]),
    onRoute(item) {
      if (this.islevel) {
        if (this.$route.params.symbol !== item.symbol) {
          this.$router.push(`/trendDetails/${item.symbol}`);
          if (this.kineType) {
            setStorage("tradeSymbol", item.symbol);
          } else {
            setStorage("symbol", item.symbol);
          }
          this.$emit("update-coin", item.symbol);
          this.onClose();
          this.$forceUpdate();
        }
      } else {
        if (this.$route.params.symbol !== item.symbol) {
          this.$router.push(`/trade/${item.symbol}`);
          setStorage("tradeSymbol", item.symbol);
          this.$emit("update-coin", item.symbol);
          this.$forceUpdate();
        }
      }
      this.show = false;
    },
    onSidebar() {
      // 侧边栏打开
      console.log(this.userInfo);
      this.coins = this.coinList.map((item) => item.symbol);
      this.show = true;
      this.fetchList();
    },
    fetchList() {
      // 获取行情
      const mainArray = this.coins.filter(
        (item) => !this.newcoinArr.includes(item)
      );
      _getHomeList(mainArray.join(",")).then((list) => {
        // console.log(list)
        this.list = list;
        if (this.timeout) {
          clearTimeout(this.timeout);
          this.timeout = null;
        }
        this.timeout = setTimeout(() => {
          this.fetchList();
        }, 1000);
      });
    },
    onClose() {
      if (this.timeout) {
        clearTimeout(this.timeout);
        this.timeout = null;
      }
    },
    jump() {
      this.$router.push(`/trendDetails/${this.symbol}`);
    },
    changeTab(index) {
      this.$emit("tab", index);
      // this.selectIndex2 = index;
    },
    goBack() {
      if (this.backFunc) {
        this.backFunc();
      } else {
        this.$router.go(-1);
      }
    },
    goRouter(params) {
      this.$router.push(params);
    },
    onCollect() {
      // 收藏,取消收藏
      let _api = _collect;
      if (this.collected === "1") {
        _api = _deleteCollect;
      }
      _api(this.symbol).then((res) => {
        if (this.$store.state.user.userInfo.token) {
          this.collected = this.collected === "1" ? "0" : "1";
          if (this.collected === "1") {
            this.$toast.success(this.$t("收藏成功"));
          } else {
            this.$toast.success(this.$t("取消收藏"));
          }
        }
      });
    },
    goHistory() {
      const url =
        this.tabIndex * 1 == 1 ? "perpetualHistory" : "deliveryContractHistory";
      this.$router.push({
        path: `/${url}?symbol=${this.symbol}`,
      });
    },
    changeModel() {
      let type = "";
      if (this.theme == "light") {
        type = "dark";
      } else {
        type = "light";
      }
      this.SET_THEME(type);
    },
    //打开订单
    openRecord() {
      this.$emit("openRecord");
    },
  },
};
</script>
    
<style lang="scss" scoped>
// .contract-header{
//     background-color:#F5F5F5;
// }
 
.wallet-background {
  background-color: #e8e8e8;
}
 
.no-select {
  background-color: #e8e8e8;
  color: #868d9a;
}
 
// 弹出层样式
.popup {
  height: 100%;
  width: 670px;
 
  @include themify() {
    background: themed("main_background");
  }
}
 
.night {
  color: #fff;
}
</style>