<template>
  <div class="good-list-con">
    <Card>
      <div class="search-con">
        <Input
          placeholder="请输入流水号"
          class="search-input"
          v-model="searchContent.flowId"
          style="width: 200px"
          clearable
        />
        <Select
          placeholder="请选择资产类型"
          class="search-input"
          v-model="searchContent.coin"
          style="width: 200px"
        >
          <Option value>全部</Option>
          <Option
            v-for="(item, index) of assetType"
            :value="item.series_id"
            :key="'series-option-' + index"
            >{{ item.series_name }}</Option
          >
        </Select>
        <Select
          placeholder="请选择记录类型"
          class="search-input"
          v-model="searchContent.type"
          style="width: 200px"
        >
          <Option value>全部</Option>
          <Option
            v-for="(item, index) of FinancialState"
            :value="item"
            :key="'series-option-' + index"
            >{{FinancialStateObj[item].label}}</Option
          >
        </Select>
        <ButtonGroup class="search-btngroup">
          <Button @click="handleSearch" type="primary">搜索</Button>
          <Button type="primary" @click="handleRefresh">
            <Icon type="md-refresh" />
          </Button>
        </ButtonGroup>
      </div>
      <tables
        ref="tables"
        editable
        pagable
        v-model="tableData"
        :columns="columns"
        :currentPage="searchContent.pageNum"
        :pageSize="searchContent.pageSize"
        :totalSize="totalSize"
        :loading="loading"
        @on-change="handleCurrentChange"
      />
    </Card>
  </div>
</template>

<script>
import Tables from '_c/tables'
import { formatTime } from '@/libs/tools'
import { FinancialState, FinancialStateObj, TransferStatus, TransferStateObj } from '@/enums'
export default {
  inject: ['reload'],
  components: {
    Tables
  },
  computed: {

  },
  data () {
    return {
      FinancialState,
      FinancialStateObj,
      searchContent: {
        flowId: '',
        coin: '',
        pageNum: 1,
        pageSize: 10,
        type: ''
      },
      assetType: [],
      columns: [
        { title: '流水号', key: 'flowId', minWidth: 180, align: 'left' },
        { title: '资产类型', key: 'assetsType', minWidth: 90, align: 'center' },
        { title: '金额', key: 'amount', minWidth: 80, align: 'center' },
        { title: '对方', key: 'otherSide', minWidth: 180, align: 'left' },
        { title: '记录类型',
          key: 'type',
          minWidth: 160,
          align: 'center',
          render: (h, params) => {
            let obj = FinancialStateObj[params.row.type]
            return h(
              'Tag',
              {
                props: {
                  color: obj.color
                }
              },
              obj.label
            )
          } },
        { title: '转账结果',
          key: 'status',
          minWidth: 130,
          align: 'center',
          render: (h, params) => {
            let obj = TransferStateObj[params.row.status]
            return h(
              'Tag',
              {
                props: {
                  color: obj.color
                }
              },
              obj.label
            )
          } },
        {
          title: '记录时间',
          align: 'center',
          width: 180,
          render: (h, params) => {
            return h('span', formatTime(params.row.createTime))
          }
        }
      ],
      tableData: [],
      totalSize: 0,
      loading: false
    }
  },
  methods: {
    // 获取资产类型
    getAssetsType () {
      let type = {}
      this.assetType = []
      this.api({
        apiName: 'assetsType',
        success: (res) => {
          res.data.forEach(item => {
            type = {
              series_name: item,
              series_id: item
            }
            this.assetType.push(type)
          })
        }
      })
    },
    platRequestData () {
      this.loading = true
      this.api({
        apiName: 'platAssetRecordList',
        postdata: this.searchContent,
        complete: () => {
          this.loading = false
        },
        success: (res) => {
          this.tableData = res.data.records
          this.totalSize = res.data.total
        }
      })
    },
    handleSearch () {
      this.searchContent.pageNum = 1
      this.platRequestData()
    },
    handleRefresh () {
      this.reload()
    },
    handleCurrentChange (pageNum) {
      this.searchContent.pageNum = pageNum
      this.platRequestData()
    }
  },
  created () {
    this.platRequestData()
    this.getAssetsType()
  }
}
</script>

<style lang="less">
.good-list-con .search-con {
  padding: 10px 0;
  .search {
    &-col {
      display: inline-block;
      width: 150px;
      margin-right: 5px;
    }
    &-input {
      display: inline-block;
      width: 150px;
      margin-right: 5px;
    }
    &-date {
      margin-right: 5px;
    }
    &-btngroup {
      margin-right: 5px;
    }
  }
}
</style>
