<template>
  <div class="app-container">
    <div class="filter-container">
      <div class="container_item">
        <span class="item_text">{{$t('stock.name')}}:</span>
        <el-input v-model="query.bondName" placeholder="" class="filter-item input_item"   />
      </div>
      <div class="container_item">
        <span class="item_text">{{$t('stock.date')}}:</span>
          <el-date-picker
            v-model="query.quoteDate"
            type="date"
            style="width:186px"
            value-format="yyyy-MM-dd"
            placeholder="选择日期"
            class="filter-item input_item" >
            </el-date-picker>
      </div>
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-my-search" @click="handleSearch">
        {{ $t('table.search') }}
      </el-button>
       <el-button v-waves class="filter-item" type="primary" icon="el-icon-my-reset" @click="handleReset">
        {{ $t('table.reset') }}
      </el-button>
    </div>
    <div class="wrapper_table">
      <el-table
        :data="tableData"
        fit
        stripe
        highlight-current-row
        style="width: 100%;"
        :header-cell-class-name="headerStyle"
        :max-height="tableHeight"
      >
        <el-table-column prop="bondName" :label="$t('stock.name')" header-align="center" show-overflow-tooltip></el-table-column>
        <el-table-column prop="bondCode" :label="$t('stock.code')" header-align="center"></el-table-column>
        <el-table-column prop="closingPrice" :label="$t('stock.currentPrice')" align="right" header-align="center"></el-table-column>
        <el-table-column prop="bpValue" :label="$t('stock.upDown')" align="right" header-align="center">
          <template slot-scope="{row}">
             <span :class="row.bpValue > 0 ? 'red':'green' " >{{row.bpValue}}</span>
           </template>
        </el-table-column>
        <el-table-column prop="stockType" :label="$t('stock.market')" header-align="center" align="right">
        </el-table-column>
        <el-table-column prop="quoteDate" :label="$t('bond.date')" header-align="center" align="right"></el-table-column>
      </el-table>
    </div>
    <pagination v-show="total>0" :total="total" :page.sync="pageNum" :limit.sync="pageSize" @pagination="getData" />
  </div>
</template>

<script>
import http from '@/api/http'
import waves from '@/directive/waves' // waves directive
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
export default {
  name: '',
  components: { Pagination },
  directives: { waves },
  data() {
    return {
      total: 0,
      query:{},
      tableData:[],
      pageSize:10,
      pageNum:1,
      tableHeight: 0,
    }
  },
  created() {
    this.getData()
  },
  mounted() {
    this.$nextTick(() => {
      this.tableHeight = window.innerHeight - 250
    })
  },
  methods: {
    // 01、市场股票列表
    getData() {
      http.post(`/market/data/pageSharesList`,{cpage:this.pageNum,pageSize:this.pageSize,...this.query}).then((res)=>{
          this.tableData = res.data.list;
          this.total = res.data.total || 0;
          this.tableData.forEach(item=>{
            item.quoteDate = item.quoteDate.slice(0,10)
            item.bpValue = item.bpValue.toFixed(2)
          })
      }).catch(err=>{});
    },
    handleSearch(){
      this.pageNum = 1
      this.getData()
    },
    handleReset(){
      this.query = {}
      this.pageNum = 1
      this.getData()
    },

    headerStyle() {
      return 'tableStyle'
    },
  }
}
</script>
<style scoped lang="scss">
  .el-table__header-wrapper{
    border-radius: 10px 10px 0 0;
  }
  .green{
    color: #17AE21;
  }
  .red{
    color: #F35555;
  }
   ::v-deep .el-table__body-wrapper{
    tr{
      td{
        &:nth-child(4),
        &:nth-child(3)
        {
          padding-right: 90px;
        }
        &:nth-child(1),
        &:nth-child(2),
        &:nth-child(6),
        &:nth-child(5){
          text-align: center;
        }
      }
    }
  }
</style>
