<template>
  <div class="app-container">
    <div class="filter-container">
      <div class="container_item">
        <span class="item_text">{{$t('bond.name')}}：</span>
        <el-input v-model="query.bondName" placeholder="" class="filter-item input_item"   />
      </div>
      <div class="container_item">
        <span class="item_text">{{$t('bond.code')}}：</span>
        <el-input v-model="query.bondCode" placeholder="" class="filter-item input_item"   />
      </div>
      <div class="container_item">
        <span class="item_text">{{$t('bond.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('bond.name')"  show-overflow-tooltip   align="left" ></el-table-column>
        <el-table-column prop="bondCode" :label="$t('bond.code')" show-overflow-tooltip  align="left"></el-table-column>
        <el-table-column prop="closingPrice" :label="$t('bond.price')"  align="right" width="180"></el-table-column>
        <el-table-column prop="bondYields" :label="$t('bond.rate')"   align="right"> </el-table-column>
        <el-table-column prop="bpValue" :label="$t('bond.upDown')" align="right" width="180">
           <template slot-scope="{row}">
             <span :class="row.bpValue > 0 ? 'red':'green' ">{{row.bpValue}}</span>
           </template>
        </el-table-column>
        <el-table-column prop="quoteDate" :label="$t('bond.date')"  align="center"></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 { toThousandFilter } from '@/filters'
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: {
    getData() {
      http.post(`/market/data/pageBondList`,{cpage:this.pageNum,pageSize:this.pageSize,...this.query}).then((res)=>{
          let { list, total } = res.data
          this.tableData = list;
          this.total = total || 0;
          this.tableData.forEach(item=>{
             item.quoteDate = item.quoteDate.slice(0,10)
             item.closingPrice = item.closingPrice ? item.closingPrice.toFixed(2): 0
             item.bondYields = (item.bondYields * 100).toFixed(2)
             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">
  // .tableStyle{
  //   background: url('../../assets/images/tabhead.png') no-repeat;
  //   background-position: 10% 0;
  //   height: 36px;
  //   font-size: 13px;
  //   font-family: "SourceHanSansCN";
  //   font-weight: 500;
  //   color: #FFFFFF;
  //   line-height: 26px;
  //   text-shadow: 0px 1px 1px #252F60;
  //   background-size: auto 110%;
  // }
  .green{
    color: #17AE21;
  }
  .red{
    color: #F35555;
  }
  .el-table__header-wrapper{
    border-radius: 10px 10px 0 0;
    tr{
      th{
        text-align: center;
      }
    }
  }
  ::v-deep .el-table__body-wrapper{
    tr{
      td{
        &:nth-child(4){
          padding-left: 90px;
        }
      }
    }
  }

</style>
