<template>
  <div id="cloud-balance" v-if="tableData">
    <section class="top">
      <!-- <h3>交易订单中心</h3> -->
      <section>
        <div class="type-boxs">
          <div>
            <span class="marginr30">待解冻金额：{{waitUnfrozenCoins}}</span>
            <span class="marginr30">冻结订单数：{{totalCount}}</span>
            <span class="marginr30">待解冻订单数：{{waitUnfrozenCount}}</span>
          </div>
        </div>
        <div class="type-boxs">
          <div class="inlineb">
            <span class>时间范围：</span>
            <el-date-picker
              v-model="timeRange"
              type="daterange"
              align="right"
              unlink-panels
              range-separator="到"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </div>
        </div>
        <div class="type-boxs">
          <div class="inlineb">
            <span class>用户:</span>
            <div class="inlineb">
              <el-input style="width: 180px;" v-model="user" placeholder="UID"></el-input>
            </div>
          </div>
          <div class="inlineb">
            <span class>订单ID:</span>
            <el-input style="width: 180px;" v-model="order_no" placeholder="输入订单ID"></el-input>
          </div>
          <div class="inlineb">
            <span class>状态:</span>
            <el-select v-model="orderStatus">
              <el-option
                v-for="item of statusList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </div>

          <el-button type="primary"  @click="clickSearchConfirm">筛选</el-button>
          <el-button>导出报表</el-button>
        </div>
      </section>
    </section>
    <div class>
      <!-- height="250" -->
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column label="项目名称">
          <template slot-scope="scope">
            <!-- @click="clickDev(scope.row.uid)"  -->
            <span class="lblue point">
              <a :href="scope.row.url" target="_blank">{{scope.row.name}}</a>
            </span>
          </template>
        </el-table-column>
        <el-table-column prop="name" label="用户">
          <template slot-scope="scope">
            <span class="lblue point"><a :href="scope.row.user_url" target="_blank">{{scope.row.nickname}}({{scope.row.uid}})</a></span>
          </template>
        </el-table-column>
        <el-table-column prop="name" label="关联订单ID">
          <template slot-scope="scope">
            <span>{{scope.row.order_no}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="name" label="类型">
          <template slot-scope="scope">
            <span>{{scope.row.target_type_name}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="name" label="冻结金额">
          <template slot-scope="scope">
            <span>{{scope.row.coins}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="name" label="冻结方式">
          <template slot-scope="scope">
            <span>{{scope.row.end_time_type_name}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="name" label="创建日期">
          <template slot-scope="scope">
            <span>{{scope.row.create_time}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="name" label="解冻日期">
          <template slot-scope="scope">
            <span>{{scope.row.end_time}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="name" label="当前状态">
          <template slot-scope="scope">
            <span>{{scope.row.status_name}}</span>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="order-footer">
      <el-pagination
        background
        @current-change="getTableData"
        @size-change="changePageSize"
        :current-page.sync="currentPage"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="20"
        layout="total, sizes, prev, pager, next, jumper"
        :total="searchCount"
      ></el-pagination>
    </div>
  </div>
</template>

<script>

export default {
  data() {
    return {
      count:1,
      user:'',
      statusList:[{id:0,name:'已解冻'},{id:1,name:'冻结中'}],
      order_no:'',
      timeRange: "",
      arriveTime: "",
      searchId: "",
      tableData: [],

      // 下发的总数据
      totalData: {},
      orderStatus: 1,
      currentPage: 1,
      currentPageSize: 20,
      waitUnfrozenCount: 0,
      searchCount: 0,
      waitUnfrozenCoins: 0,
      totalCoins: 0,
      totalCount: 0,
    };
  },
  mounted() {
    this.getTableData();
  },
  methods: {
    // 改变订单类型
    clickExport() {
      window.open("/api/admin/job/get_all_periods?action=export");
    },
    clickSearchConfirm() {
      this.currentPage = 1;
      this.getTableData();
    },
    changePageSize(pageSize) {
      this.currentPageSize = pageSize;
      this.getTableData();
    },
    // 获取列表数据
    async getTableData() {
      this.tableData = [];
      let url = "/api/admin/order/get_frozen_coins";
      let body = { page: this.currentPage, size: this.currentPageSize };
      if (this.user) body.user = this.user;
      if (this.orderStatus!=='') body.status = this.orderStatus;
      if (this.order_no) body.order_no = this.order_no;
      if (this.timeRange){
        body.start_time=this.timeRange[0]/1000;
        body.end_time=this.timeRange[1]/1000;
      }
      const res = await this.$post(url, body);
      this.tableData = res.data.list;
      this.totalCoins=res.data.totalCoins;
      this.totalCount=res.data.totalCount;
      this.waitUnfrozenCount=res.data.waitUnfrozenCount;
      this.searchCount=res.data.searchCount;
      this.waitUnfrozenCoins=res.data.waitUnfrozenCoins;
    },
  },
  created() {
    // console.log(process.env.NODE_ENV);
  }
};
</script>

<style scoped>
.order-footer {
  position: absolute;
  bottom: 10px;
  left: 10px;
}
#order-wrap {
  width: 100%;
}
#cloud-balance {
  white-space: nowrap;
  overflow-x: scroll;
  height: calc(100% - 40px);
}
.top {
  display: flex;
  flex-direction: column;
  justify-content: center;
  height: 160px;
}
.selector-box {
  /* margin-top: 10px; */
}
.selector-box {
  display: flex;
  justify-content: space-between;
}
/* .selector-box-left {
} */
.table {
  margin-top: 10px;
  height: calc(100% - 320px);
}
.order-table {
  /* height: calc(100% - 300px); */
}
.end-row {
  background: rgba(0, 0, 0, 0.1);
}
.inlineb {
  display: inline-block;
}
.vsub {
  vertical-align: sub;
}
.type-boxs {
  margin-bottom: 10px;
}
.green {
  color: rgba(37, 155, 36, 1);
}
.orange {
  color: rgba(255, 152, 0, 1);
}
.state-success {
  display: inline-block;
  padding: 0px 8px;
  text-align: center;
  border: 1px solid rgb(48, 142, 255);
}
.state-wait {
  display: inline-block;
  padding: 0px 8px;
  text-align: center;
  border: 1px solid rgb(134, 130, 130);
}

.state-load {
  display: inline-block;
  padding: 0px 8px;
  text-align: center;
  border: 1px solid rgb(37, 155, 36);
}
.state-faile {
  display: inline-block;
  padding: 0px 8px;
  text-align: center;
  border: 1px solid rgb(229, 28, 35);
}
</style>
