<!--
 * @Descripttion:
 * @version:
 * @Author: kangkang
 * @Date: 2020-10-22 14:18:12
 * @LastEditors: kangkang
 * @LastEditTime: 2020-10-31 14:43:55
-->
<template>
<div style="height:95%">
  <el-button size=small type="primary" @click="$router.push('/order/finance')" plain>返回</el-button>
  <div style="float:right;">
    <el-select  size=small v-model="searchModel.ProductId"  placeholder="请选择产品">
      <el-option
        v-for="item in products"
        :key="item.Name"
        :label="item.Name"
        :value="item.Id">
      </el-option>
    </el-select>

    <el-select size=small v-model="searchModel.type" placeholder="请选择类型">
    <el-option
      v-for="item in types"
      :key="item.text"
      :label="item.text"
      :value="item.value">
    </el-option>
  </el-select>

  <el-date-picker
    size="small"
    v-model="dateRange"
    type="daterange"
    range-separator="至"
    start-placeholder="开始日期"
    end-placeholder="结束日期"
  ></el-date-picker>

   <el-button size="small" type="primary" @click="search()">搜索</el-button>
  </div>
  <el-table  :show-overflow-tooltip="true" :data="tableData" height="calc(100% - 150px)" style="width: 100%">
    <el-table-column prop="id" label="序号" width="150"> </el-table-column>
    <el-table-column prop="create_time" label="操作时间" width="150"> </el-table-column>
    <el-table-column prop="op_person" label="操作人" width="100"> </el-table-column>
    <el-table-column prop="product" label="原后台" width="100"> </el-table-column>
    <el-table-column prop="type" label="类型" width="100"> </el-table-column>
    <el-table-column prop="riqi" label="充退补日期"  width="100"> </el-table-column>
    <el-table-column prop="money" label="操作金额"  width="100"> </el-table-column>
    <el-table-column prop="remark" :show-overflow-tooltip="true" label="备注"> </el-table-column>
  </el-table>
  <el-pagination
    background
    v-if="count !== 0"
    :current-page="searchModel.page"
    style="top:91%"
    layout="prev, pager, next"
    :page-size = "50"
    @prev-click="prev_page"
    @next-click="next_page"
    @current-change="handleCurrentChange"
    :total="count">
  </el-pagination>


</div>
</template>

<script>
export default {
  data () {
    return {
      tableData: [],
      count: 0,
      pageNum: 1,
      products: [],
      dateRange:[],
      searchModel: {
        type:null,
        page:1,
        ProductId:null,
        Btime: "",
        Etime: ""
      },
      types: [
        { text: "充值", value: 1 },
        { text: "退款", value: 2 },
        { text: "补差价", value: 3 },
      ],
    }
  },

  created () {
    this.$store.commit('setCurrentNav', '订单管理>>原后台财务明细>>补遗记录')
    this.getData()
    this.$api.get("course/v1/product/page", this.searchModel).then(res => {
      this.products = res.Data;
    });
  },
  methods: {
    getData () {
      this.$api.get(this.$api.phpURL + 'order/FinanceCheck/buyiList').then(res => {
        this.tableData = res.data
        this.count = parseInt(res.count)
      })
    },
    prev_page () {
      this.$api.get(this.$api.phpURL + 'order/FinanceCheck/buyiList', this.searchModel).then(res => {
        this.tableData = res.data
      })
    },
    next_page () {
      this.$api.get(this.$api.phpURL + 'order/FinanceCheck/buyiList', this.searchModel).then(res => {
        this.tableData = res.data
      })
    },
    handleCurrentChange: function (currentPage) {
      this.searchModel.page = currentPage
      this.$api.get(this.$api.phpURL + 'order/FinanceCheck/buyiList', this.searchModel).then(res => {
        this.tableData = res.data
      })
    },
    search () {
      this.$api.post(this.$api.phpURL + 'order/FinanceCheck/search', {time: this.timeSearh}).then(res => {
        this.tableData = res.data
        this.count = 0
      })
    },
    buyi () {
      this.clickOk = true
      this.dialogFormVisible = false
      this.$api.post(this.$api.phpURL + 'order/FinanceCheck/buyi', {
        product: this.product,
        type: this.type,
        riqi: this.riqi,
        money: this.money,
        remark: this.remark
      }).then(res => {
        console.log(res)
      })
    },
    search () {
      if (this.dateRange && this.dateRange.length == 2) {
        this.searchModel.Btime = this.dateRange[0];
        this.searchModel.Etime = this.dateRange[1];
      }
      this.searchModel.page = 1
      this.$api.get(this.$api.phpURL + 'order/FinanceCheck/buyiList',this.searchModel).then(res => {
        this.tableData = res.data
        this.count = parseInt(res.count)
      })
    }
  }
}
</script>
