<template>
  <div class="padding-20">
    <div class="search-box">
      <el-form
        ref="form"
        :inline="true"
        :model="searchForm"
        clearable
        class="mt-10">
        <el-form-item label="订单编号:">
          <el-input v-model="searchForm.order_number" placeholder="请输入订单编号" clearable></el-input>
        </el-form-item>
        <el-form-item label="用户ID:">
          <el-input v-model="searchForm.user_id" placeholder="请输入用户ID" clearable></el-input>
        </el-form-item>
        <el-form-item label="订单创建时间:">
          <el-date-picker
            :editable="false"
            v-model="time"
            @change="timearr => {timearr ? (searchForm.start_created_at = timearr[0] + ' 00:00:00', searchForm.end_created_at = timearr[1] + ' 23:59:59') : searchForm.start_created_at = searchForm.end_created_at = undefined}"
            type="daterange"
            value-format="yyyy-MM-dd"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
          ></el-date-picker>
        </el-form-item>
        <el-form-item class="ml-10">
          <el-button icon="el-icon-search" type="primary" @click="searchSubmit">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div>
      <span style="font-weight: bold;">收入总额：</span>
      <span>￥{{ total_price | fen2Yuan }}</span>
    </div>
    <el-table
      :data="tableData"
      stripe
      v-loading="tableLoading"
      class="marginT-10 order-table"
      border
      :max-height="vheight">
      <el-table-column label="流水号" prop="record_number"></el-table-column>
      <el-table-column label="收入/退款" prop="record_type" sortable>
        <template slot-scope="scope">
          <p>{{ ['', '收入', '退款'][scope.row.record_type]}}</p>
        </template>
      </el-table-column>
      <el-table-column label="金额" prop="record_price" sortable>
        <template slot-scope="scope">
          <p>{{ scope.row.record_price | fen2Yuan }}</p>
        </template>
      </el-table-column>
      <el-table-column label="订单类型" prop="order_type"></el-table-column>
      <el-table-column label="流水时间" prop="created_at" width="160"></el-table-column>
      <el-table-column label="订单编号" prop="order_number"></el-table-column>
      <el-table-column label="用户名称" prop="user_name"></el-table-column>
    </el-table>
    <el-pagination
      class="marginT-20"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :hide-on-single-page="true"
      :current-page="page"
      :page-size="page_size"
      :page-sizes="[10, 20, 100, 200, 300, 400]"
      background
      layout="total, sizes, prev, pager, next, jumper"
      :total="totalCount"/>
  </div>
</template>

<script>
import page from '@/mixin/page'

export default {
  mixins: [page],
  data () {
    return {
      time: [],
      searchForm: {},
      tableData: [],
      tableUrl: '/v1/user/record/price/List',
      total_price: 0
    }
  },
  mounted () {
    const userId = this.$route.query.user_id
    if (userId) {
      this.$set(this.searchForm, 'user_id', userId)
    }
    this.init()
  }
}
</script>

<style lang="scss" scoped>
</style>
