新大宝股票管理后台
1
jhzh
2025-07-06 659d5aa2617d09139b101062a2fb3f2c1181ed79
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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
<template>
  <page-header-wrapper>
    <a-card :bordered="false">
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="12" :lg="6" :sm="24">
              <a-form-item label="锁定状态">
                <a-select v-model="queryParam.lockState" placeholder="请选择锁定状态">
                  <a-select-option :value="0">正常</a-select-option>
                  <a-select-option :value="1">锁定</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            
            <a-col :md="12" :lg="6" :sm="24">
              <a-form-item label="股票市场">
                <a-select v-model="queryParam.stockGid" placeholder="请选择股票市场">
                  <a-select-option value="nse">nse</a-select-option>
                  <a-select-option value="bse">bse</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
 
            <a-col :md="12" :lg="6" :sm="24">
              <a-form-item label="显示状态">
                <a-select v-model="queryParam.showState" placeholder="请选择显示状态">
                  <a-select-option :value="0">显示</a-select-option>
                  <a-select-option :value="1">隐藏</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </a-row>
          <a-row :gutter="48">
            <a-col :md="12" :lg="6" :sm="24">
              <a-form-item label="股票代码">
                <a-input v-model="queryParam.code" style="width: 100%" placeholder="请输入股票代码" />
              </a-form-item>
            </a-col>
            <a-col :md="12" :lg="6" :sm="24">
              <a-form-item label="股票名称">
                <a-input v-model="queryParam.name" style="width: 100%" placeholder="请输入股票名称" />
              </a-form-item>
            </a-col>
            <a-col :md="12" :lg="6" :sm="24">
              <a-form-item>
                <span class="table-page-search-submitButtons">
                  <a-button @click="getqueryParam" icon="redo"> 重置</a-button>
                  <a-button
                    type="primary"
                    icon="search"
                    style="margin-left: 8px"
                    @click=";(queryParam.pageNum = 1), (pagination.current = 1), getlist()"
                    >查询
                  </a-button>
                </span>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </a-card>
 
    <a-card :bordered="false">
      <a-table
        bordered
        :loading="loading"
        :pagination="pagination"
        :columns="columns"
        :data-source="datalist"
        rowKey="id"
      >
        <span slot="stockName" slot-scope="text, record">
          <template>
            <div>
              <span style="margin-right: 10px">{{ record.stockName }}</span>
              <a-tag color="green">{{ record.stockCode }} </a-tag>
            </div>
 
            <!-- stockSpell -->
          </template>
        </span>
        <span slot="stockType" slot-scope="text, record">
          <template>
            <div>
              <a-tag color="red"
                >{{
                  record.stockType == 'sz'
                    ? '深股'
                    : record.stockType == 'sh'
                    ? '沪股'
                    : record.stockType == 'bj'
                    ? '京股'
                    : record.stockType == 'hk'
                    ? '港股'
                    : record.stockType == 'us'
                    ? '美股'
                    : ''
                }}
              </a-tag>
            </div>
          </template>
        </span>
        <span slot="nowPrice" slot-scope="text, record">
          <template>
            <div>
              <a-tag :color="record.hcrate < 0 ? 'green' : record.hcrate > 0 ? 'red' : ''"
                >{{ Number(record.nowPrice).toFixed(2) }}
              </a-tag>
            </div>
          </template>
        </span>
        <span slot="hcrate" slot-scope="text, record">
          <template>
            <div>
              <a-tag :color="record.hcrate < 0 ? 'green' : record.hcrate > 0 ? 'red' : ''">
                {{ record.hcrate }}%
              </a-tag>
            </div>
          </template>
        </span>
        <span slot="day3Rate" slot-scope="text, record">
          <template>
            <div>
              <a-tag :color="record.day3Rate < 0 ? 'green' : record.day3Rate > 0 ? 'red' : ''">
                {{ record.day3Rate }}%
              </a-tag>
            </div>
          </template>
        </span>
        <span slot="spreadRate" slot-scope="text, record">
          <template>
            <div>
              <a-tag :color="record.spreadRate < 0 ? 'green' : record.spreadRate > 0 ? 'red' : ''">
                {{ record.spreadRate * 100 }}%
              </a-tag>
            </div>
          </template>
        </span>
        <span slot="isShow" slot-scope="text, record">
          <template>
            <div>
              <a-tag :color="record.isShow == 0 ? 'green' : record.isShow == 1 ? 'red' : ''">
                {{ record.isShow == 0 ? '显示' : '隐藏' }}
              </a-tag>
            </div>
          </template>
        </span>
        <span slot="isLock" slot-scope="text, record">
          <template>
            <div>
              <a-tag :color="record.isLock == 0 ? 'green' : record.isLock == 1 ? 'red' : ''">
                {{ record.isLock == 0 ? '正常' : '锁定' }}
              </a-tag>
            </div>
          </template>
        </span>
 
        <template slot="action" slot-scope="text, record">
          <a slot="action" href="javascript:;" @click="getisShow(record.id, record.isShow)">{{
            record.isShow == 0 ? '隐藏股票' : '显示股票'
          }}</a>
          <a-divider type="vertical" />
          <a slot="action" href="javascript:;" @click="getisLock(record.id, record.isLock)">{{
            record.isLock == 0 ? '锁定股票' : '解锁股票'
          }}</a>
          <a-divider type="vertical" />
          <a slot="action" href="javascript:;" @click="geteditStock(record)">{{ '修改股票' }}</a>
        </template>
      </a-table>
    </a-card>
 
    <a-modal
      title="添加股票"
      :width="500"
      :visible="addUserdialog"
      :confirmLoading="addUserDialogloading"
      @ok="OkaddUserdialog"
      @cancel="CanceladdUserdialog"
    >
      <a-form :form="addUserform" ref="addUserform">
        <a-form-item label="股票名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input
            placeholder="请输入股票名称"
            v-decorator="['stockName', { rules: [{ required: true, message: '请输入股票名称' }] }]"
          />
        </a-form-item>
        <a-form-item label="股票代码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input
            placeholder="请输入股票代码"
            v-decorator="['stockSpell', { rules: [{ required: true, message: '请输入股票代码' }] }]"
          />
        </a-form-item>
        <a-form-item label="股票类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-select
            placeholder="请选择股票类型"
            v-decorator="['stockType', { rules: [{ required: true, message: '请选择股票类型' }] }]"
          >
            <a-select-option value="sh">沪股</a-select-option>
            <a-select-option value="sz">深股</a-select-option>
            <a-select-option value="bj">京股</a-select-option>
            <a-select-option value="hk">港股</a-select-option>
            <a-select-option value="us">美股</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="科创板股票" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-select
            placeholder="请选择科创板股票"
            v-decorator="['stockPlate', { rules: [{ required: true, message: '请选择科创板股票' }] }]"
          >
            <a-select-option value="A股">否</a-select-option>
            <a-select-option value="科创">是</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="锁定状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-select
            placeholder="请选择锁定状态"
            v-decorator="['isLock', { rules: [{ required: true, message: '请选择锁定状态' }] }]"
          >
            <a-select-option value="0">未锁定</a-select-option>
            <a-select-option value="1">锁定</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="显示状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-select
            placeholder="请选择显示状态"
            v-decorator="['isShow', { rules: [{ required: true, message: '请选择显示状态' }] }]"
          >
            <a-select-option value="0">显示</a-select-option>
            <a-select-option value="1">不显示</a-select-option>
          </a-select>
        </a-form-item>
      </a-form>
    </a-modal>
 
    <a-modal
      title="修改股票"
      :width="500"
      :visible="editStockdialog"
      :confirmLoading="editStockdialogloading"
      @ok="OkeditStockdialog"
      @cancel="CanceleditStockdialog"
    >
      <a-form :form="editStockform" ref="editStockform">
        <a-form-item label="股票名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input
            placeholder="请输入股票名称"
            v-decorator="['stockName', { rules: [{ required: true, message: '请输入股票名称' }] }]"
          />
        </a-form-item>
        <a-form-item label="点差费率" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input
            placeholder="请输入点差费率"
            v-decorator="['spreadRate', { rules: [{ required: true, message: '请输入点差费率' }] }]"
          />
        </a-form-item>
      </a-form>
    </a-modal>
  </page-header-wrapper>
</template>
<script>
import { stocklist, updateShow, updateLock, stockadd, stockupdateStock } from '@/api/product'
import moment from 'moment'
import pick from 'lodash.pick'
export default {
  name: 'Shares',
  data() {
    return {
      columns: [
        {
          title: '股票名称 / 股票代码',
          dataIndex: 'stockName',
          align: 'center',
          scopedSlots: { customRender: 'stockName' },
        },
        {
            title: '股票市场',
            dataIndex: 'stockGid',
            align: 'center',
            scopedSlots: { customRender: 'stockGid' }
        },
        {
          title: '现价',
          dataIndex: 'nowPrice',
          align: 'center',
          scopedSlots: { customRender: 'nowPrice' },
        },
        {
          title: '涨跌幅',
          dataIndex: 'hcrate',
          align: 'center',
          scopedSlots: { customRender: 'hcrate' },
        },
        // {
        //     title: '最近3天涨跌',
        //     dataIndex: 'day3Rate',
        //     align: 'center',
        //     scopedSlots: { customRender: 'day3Rate' }
        // },
        // {
        //     title: '点差费率',
        //     dataIndex: 'spreadRate',
        //     align: 'center',
        //     scopedSlots: { customRender: 'spreadRate' }
        // },
        {
          title: '显示状态',
          dataIndex: 'isShow',
          align: 'center',
          scopedSlots: { customRender: 'isShow' },
        },
        {
          title: '股票状态',
          dataIndex: 'isLock',
          align: 'center',
          scopedSlots: { customRender: 'isLock' },
        },
        {
          title: '添加时间',
          dataIndex: 'addTime',
          align: 'center',
          customRender: (text, row, index) => {
            return text ? moment(text).format('YYYY-MM-DD HH:mm:ss') : ''
          },
        },
        {
          title: '操作',
          key: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' },
        },
      ],
      // 表头
      pagination: {
        total: 0,
        current: 1,
        pageSize: 10, // 每页中显示10条数据
        showSizeChanger: true,
        pageSizeOptions: ['10', '20', '50', '100'], // 每页中显示的数据
        onShowSizeChange: (current, pageSize) => this.onSizeChange(current, pageSize), // 改变每页数量时更新显示
        onChange: (page, pageSize) => this.onPageChange(page, pageSize), // 点击页码事件
        showTotal: (total) => `共有 ${total} 条数据`, // 分页中显示总的数据
      },
      loading: false,
      queryParam: {
        pageNum: 1,
        pageSize: 10,
        code: '',
        name: '',
        stockPlate: 'A股',
        stockType: undefined,
        showState: undefined,
        lockState: undefined,
        stockGid: undefined
      },
      datalist: [],
      labelCol: {
        xs: { span: 24 },
        sm: { span: 7 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 13 },
      },
      addUserform: this.$form.createForm(this),
      addUserdialog: false,
      addUserDialogloading: false,
 
      editStockdialog: false,
      editStockdialogloading: false,
      editStockform: this.$form.createForm(this),
      fields: ['stockName', 'spreadRate'],
      currentid: '',
    }
  },
  created() {
    this.getlist()
  },
  methods: {
    geteditStock(val) {
      this.currentid = val.id
      this.editStockdialog = true
      this.fields.forEach((v) => this.editStockform.getFieldDecorator(v))
      this.editStockform.setFieldsValue(pick(val, this.fields))
    },
    CanceleditStockdialog() {
      this.editStockdialog = false
      const form = this.$refs.editStockform.form
      form.resetFields()
    },
    OkeditStockdialog() {
      const form = this.$refs.editStockform.form
      form.validateFields((errors, values) => {
        if (!errors) {
          this.editStockdialogloading = true
          values.id = this.currentid
          stockupdateStock(values).then((res) => {
            if (res.status == 0) {
              this.editStockdialog = false
              this.$message.success(res.msg)
              form.resetFields()
              this.getlist()
            } else {
              this.$message.error(res.msg)
            }
            this.editStockdialogloading = false
          })
        }
      })
    },
    // 新增用户取消弹窗
    CanceladdUserdialog() {
      this.addUserdialog = false
      const form = this.$refs.addUserform.form
      form.resetFields()
    },
    // 新增用户确定
    OkaddUserdialog() {
      const form = this.$refs.addUserform.form
      form.validateFields((errors, values) => {
        if (!errors) {
          this.addUserDialogloading = true
          values.stockPlate == 'A股' ? (values.stockPlate = '') : values.stockPlate
          stockadd(values).then((res) => {
            if (res.status == 0) {
              this.addUserdialog = false
              this.$message.success(res.msg)
              form.resetFields()
              this.getinit()
            } else {
              this.$message.error(res.msg)
            }
            this.addUserDialogloading = false
          })
        }
      })
    },
    getqueryParam() {
      this.queryParam = {
        pageNum: 1,
        pageSize: 10,
        code: '',
        name: '',
        stockPlate: 'A股',
        stockType: undefined,
        showState: undefined,
        lockState: undefined,
        stockGid:undefined
      }
    },
    getinit() {
      this.getqueryParam()
      this.pagination.current = 1
      this.getlist()
    },
    getlist() {
      this.loading = true
      this.queryParam.stockPlate == 'A股' ? (this.queryParam.stockPlate = '') : this.queryParam.stockPlate
      stocklist(this.queryParam).then((res) => {
        this.datalist = res.data.list
        this.pagination.total = res.data.total
        this.queryParam.stockPlate == '' ? (this.queryParam.stockPlate = 'A股') : this.queryParam.stockPlate
        this.loading = false
      })
    },
    // 股票的显示隐藏
    getisShow(idval, isShowval) {
      updateShow({ stockId: idval }).then((res) => {
        if (res.status === 0) {
          this.getlist()
          if (isShowval == 0) {
            this.$message.success({ content: '隐藏成功', duration: 2 })
          } else {
            this.$message.success({ content: '显示成功', duration: 2 })
          }
        } else {
          this.$message.error({ content: res.msg, duration: 2 })
        }
      })
    },
    // 股票的锁定解锁
    getisLock(idval, isLockval) {
      updateLock({ stockId: idval }).then((res) => {
        if (res.status === 0) {
          this.getlist()
          if (isLockval == 0) {
            this.$message.success({ content: '锁定成功', duration: 2 })
          } else {
            this.$message.success({ content: '解锁成功', duration: 2 })
          }
        } else {
          this.$message.error({ content: res.msg, duration: 2 })
        }
      })
    },
    onPageChange(page, pageSize) {
      this.queryParam.pageNum = page
      this.pagination.current = page
      this.getlist()
    },
    onSizeChange(current, pageSize) {
      this.queryParam.pageNum = current
      this.pagination.current = page
      this.queryParam.pageSize = pageSize
      this.getlist()
    },
  },
}
</script>