jhzh
2024-03-23 b94e487fb76488bec6f78da1c820a634b199dd83
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
<template>
  <div>
    <div class="table">
      <el-table
        stripe
        v-loading="loading"
        :data="list.list"
        @row-click='toTransaction'
        style="width: 100%">
        <el-table-column
          prop="name"
          width="200px"
          label="名称">
          <template slot-scope="scope">
            <div class="tab-name">
              <p>{{scope.row.name}}</p>
              <span class="code">
                {{scope.row.code}}
            </span>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="nowPrice"
          width="130px"
          align='right'
          label="现价">
          <template slot-scope="scope">
            <div class="price">
              <div :class="scope.row.hcrate<0?'green':scope.row.hcrate==0?'':'red'">
                <span v-if="scope.row.nowPrice === 0">-</span>
                <span v-else>{{Number(scope.row.nowPrice).toFixed(2)}}</span>
                <i v-if="scope.row.hcrate>0" class="iconfont icon-up"></i>
                <i v-if="scope.row.hcrate<0" class="iconfont icon-down"></i>
              </div>
            </div>
            <!-- <div v-if="scope.row.now_price" :class="changeTextClass[scope.$index] === true?'heartBeat  tab-number':' tab-number'">
              <p :class="scope.row.now_price - scope.row.buyOrderPrice < 0?'green bounceIn':scope.row.now_price - scope.row.buyOrderPrice > 0?'bounceIn red':'bounceIn'">
                {{scope.row.now_price === 0?'-':scope.row.now_price}}
              </p>
            </div> -->
          </template>
        </el-table-column>
        <el-table-column
          prop="hcrate"
          align='right'
          label="涨跌幅">
          <template slot-scope="scope">
            <div class="price">
 
              <div :class="scope.row.hcrate<0?'green':scope.row.hcrate==0?'':'red'">
                <span v-if="scope.row.nowPrice === 0">-</span>
                <span v-else>{{Number(scope.row.hcrate).toFixed(2)}}%</span>
                <!-- <i v-if="scope.row.hcrate>0" class="iconfont icon-up"></i>
                <i v-if="scope.row.hcrate<0" class="iconfont icon-down"></i> -->
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="today_max"
          align='right'
          label="最高">
          <!-- <template slot-scope="scope">
              <div :class="scope.row.hcrate<0?'green':scope.row.hcrate==0?'':'red'">{{scope.row.today_max}}</div>
          </template> -->
        </el-table-column>
        <el-table-column
          prop="today_min"
          align='right'
          label="最低">
          <!-- <template slot-scope="scope">
              <div :class="scope.row.hcrate<0?'green':scope.row.hcrate==0?'':'red'">{{scope.row.today_min}}</div>
          </template> -->
        </el-table-column>
        <el-table-column
          class="tab-name"
          align='center'
          label="走势图"
          width="370px"
        >
          <template slot-scope="scope">
            <chart-box :code="scope.row.code"></chart-box>
          </template>
        </el-table-column>
      </el-table>
      <div class="page-box text-center">
        <a @click="toTransaction" class="more-btn" href="javascript:;">
          加载更多
          <i class="iconfont icon-xiasanjiao"></i>
        </a>
        <!-- <el-pagination
        class="pull-right"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="list.pageNum"
            :page-sizes="[10, 20, 30, 40,50]"
            :page-size="list.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="list.total">
          </el-pagination> -->
      </div>
 
    </div>
  </div>
 
</template>
 
<script>
  import * as api from '../../../axios/api'
  import ChartBox from './chart'
 
  export default {
    components: {
      ChartBox
    },
    props: {},
    data () {
      return {
        loading: false,
        form: {
          pageNum: 1,
          pageSize: 15
        },
        list: {
          list: []
        },
        timer: null,
        refresh: false, // 刷新中
        changeTextClass: {} // 表格中的数据变化
      }
    },
    watch: {},
    computed: {},
    created () {
      this.timer = setInterval(this.refreshList, 60000)
    },
    beforeDestroy () {
      clearInterval(this.timer)
    },
    mounted () {
      this.getList()
    },
    methods: {
      handleSizeChange (val) {
        this.form.pageSize = val
        this.getList()
      },
      handleCurrentChange (val) {
        this.form.pageNum = val
        this.getList()
      },
      async refreshList () {
        if (this.refresh || this.loading) {
          return
        }
        this.refresh = true
        this.changeTextClass = {}
        // 获取表格数据
        let data = await api.getStock()
        this.refresh = false
        if (data.status === 0) {
          data.data.list.forEach((element, i) => {
            this.changeTextClass[i] = ''
            if (data.data.list[i].nowPrice !== this.list.list[i].nowPrice) {
              this.changeTextClass[i] = true // 设置对应的动画过滤
              this.list.list[i].nowPrice = data.data.list[i].nowPrice // 现价
              this.list.list[i].hcrate = data.data.list[i].hcrate // 涨跌幅
              this.list.list[i].today_max = data.data.list[i].today_max // 最高
              this.list.list[i].today_min = data.data.list[i].today_min // 最低
            }
          })
        } else {
          this.$message.error(data.msg)
        }
      },
      onSubmit () {
        // 查询表格
        this.getList()
      },
      async getList () {
        // 获取表格数据
        let opt = {
          pageNum: this.form.pageNum,
          pageSize: 15
        }
        this.loading = true
        let data = await api.getStock(opt)
        if (data.status === 0) {
          // data.data.list.forEach(element => {
          //     this.list.push(element)
          // });
          this.list = data.data
        } else {
          this.$message.error(data.msg)
        }
        this.loading = false
      },
      toTransaction (row, column, event) {
        // 去交易界面
        this.$router.push({
          path: '/transaction',
          query: {
            code: row.code
          }
        })
      }
    }
  }
</script>
<style lang="less" scoped>
  .table {
    .code {
      color: #6d718b;
      font-size: 12px;
    }
 
    .more-btn {
      text-align: center;
      color: #8f92a3;
    }
 
    /*/deep/ th.el-table_1_column_1 {*/
      /*padding-left: 50px;*/
    /*}*/
 
    /deep/ .el-table th>.cell {
      padding-left: 60px;
    }
  }
</style>