<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :model="queryParams" size="small" :inline="true" label-width="88px">
      <el-form-item label="类型" prop="orderType">
        <el-select v-model="queryParams.orderType" clearable placeholder="全部">
          <el-option label="充值" :value="0" />
          <el-option label="退款" :value="1" />
        </el-select>
      </el-form-item>
      <el-form-item label="订单编号" prop="orderNum">
        <el-input v-model="queryParams.orderNum" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row class="mb8"><right-toolbar :show-search.sync="showSearch" @queryTable="getList" /></el-row>
    <el-table v-loading="loading" :data="list">
      <el-table-column label="ID" prop="id" width="70" />
      <el-table-column label="团队" prop="deptName" min-width="100" show-overflow-tooltip />
      <el-table-column label="类型" width="90">
        <template slot-scope="s">{{ typeLabel(s.row.orderType) }}</template>
      </el-table-column>
      <el-table-column label="金额" prop="money" width="90" />
      <el-table-column label="积分" prop="amount" width="90" />
      <el-table-column label="时间" width="160"><template slot-scope="s">{{ parseTime(s.row.createTime) }}</template></el-table-column>
      <el-table-column label="备注" prop="remark" min-width="120" show-overflow-tooltip />
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
  </div>
</template>

<script>
import { listSubteamChargeOrder } from '@/api/subteam'
export default {
  name: 'SubteamChargeOrder',
  data() {
    return {
      loading: true,
      showSearch: true,
      dateRange: [],
      list: [],
      total: 0,
      queryParams: { pageNum: 1, pageSize: 10, orderType: undefined, orderNum: undefined }
    }
  },
  created() { this.getList() },
  methods: {
    typeLabel(t) {
      const m = { 0: '充值', 1: '退款', 2: '手动修改' }
      return m[t] != null ? m[t] : '—'
    },
    getList() {
      this.loading = true
      listSubteamChargeOrder(this.addDateRange(this.queryParams, this.dateRange, 'CreateTime')).then(res => {
        this.list = res.rows
        this.total = res.total
        this.loading = false
      })
    },
    handleQuery() { this.queryParams.pageNum = 1; this.getList() },
    resetQuery() {
      this.dateRange = []
      this.resetForm('queryForm')
      this.handleQuery()
    }
  }
}
</script>
