<template>
  <div v-loading="loading">
    <div class="heior_box">
      <el-button size="small" type="primary" icon="el-icon-sold-out" @click="dataExport">导出</el-button>
      <div class="search-box">
        <el-date-picker
          size="small"
          v-model="dateRange"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          @change=search
        ></el-date-picker>
         <el-select v-model="searchModel.ProductIds" placeholder="选择产品"  collapse-tags  clearable size="small" @change=search>
          <el-option v-for="item in products" :key="item.Name" :label="item.Name" :value="item.Id"></el-option>
        </el-select>
      </div>
    </div>
    <el-table :data="retData.Data"  row-key="Id" border size="medium" :height="$getHeight(100)">
      <el-table-column prop="CreateTime" label="创建日期" width="180"></el-table-column>
      <el-table-column prop="ProductName" label="产品"></el-table-column>
      <el-table-column prop="PackageName" label="套餐"></el-table-column>
      <el-table-column prop="ConnectCount" label="连接数"></el-table-column>
      <el-table-column prop="Accounts" label="账号"></el-table-column>
      <el-table-column prop="RefundRestTime" label="剩余时间"></el-table-column>
      <el-table-column prop="OrderState" label="退款状态">
         <template slot-scope="scope">          
           <span :class="{red:scope.row.OrderState==30}"> {{refundTypeFormat(scope.row.OrderState)}}</span>
         </template>
         </el-table-column>   
    </el-table>
    <div class="block">
      <!-- <el-pagination
        v-if="retData.Data.length>0"
        @current-change="get"
        :current-page.sync="searchModel.PageIndex"
        :page-size="50"
        layout="total,prev, pager, next"
        :total="retData.TotalCount"
      ></el-pagination> -->

      <el-pagination
        @current-change="get"
        :current-page.sync="searchModel.PageIndex"
        :page-size="50"
        layout="prev, pager, next, jumper"
        :total="retData.TotalCount">
      </el-pagination>
    </div>
  </div>
</template>
<script>
export default {
  name: 'treeTable',
  components: {
    phoneHide: () => import('@/components/common/phonehide')
  },
  data () {
    return {
      loading: false,
      retData: { TotalCount: 0, Data: [] },
      dateRange: [],
      products: [],
      searchModel: {
        OrderTypes: [],
        PageIndex: 1,
        keyWord: '',
        ProductIds: null
      }
    }
  },
  created () {
    this.$store.commit('setCurrentNav', '订单管理>>退款订单')
    this.get()
    this.getProduct()
  },
  methods: {
    search () {
      this.searchModel.PageIndex = 1
      this.get()
    },
    get () {
      this.loading = true
      if (this.dateRange && this.dateRange.length == 2) {
        this.searchModel.Btime = this.dateRange[0]
        this.searchModel.Etime = this.dateRange[1]
      }
      // this.$api.get('course/v1/order/OpenRefundOrders', this.searchModel).then(res => {
      //   this.retData = res
      // })
      this.$api.get(this.$api.phpURL + 'order/OpenRefund/getList', this.searchModel).then(res => {
        this.retData.Data = res.data.list
        this.retData.TotalCount = parseInt(res.data.count.count)
        this.loading = false
      })
    },
    getProduct () {
      // this.$api.get('course/v1/product/OpenPage', this.searchModel).then(res => {
      //   this.products = res.Data
      // })
      this.$api.get(this.$api.phpURL + 'product/OpenProduct/getOpenList').then(res => {
        this.products = res.Data = res.data
      })
    },
    refundTypeFormat(orderStatus){
        switch (orderStatus) {
          case '30':
            return "未自动退款";
          case '40':
            return "已人工处理";
          case '50':
            return "已自动退款";
          default:
            return "";        
        }
        return "";
       },
    dataExport () {
      this.$api.getDownloadFile(this.$api.phpURL + 'order/OpenRefund/export', this.searchModel, '退款.csv')
    }
  }
}
</script>
<style scoped>
.red{
  color: red;
}
</style>
