<template>
  <div class="good-list-con">
    <Card>
      <div class="search-con">
        <Input
          placeholder="请输入流水号"
          class="search-input"
          v-model="searchContent.flowId"
          style="width: 200px"
          clearable
        />
        <Input
          placeholder="请输入商户编号"
          class="search-input"
          v-model="searchContent.merchantId"
          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: '',
        merchantId: '',
        coin: '',
        type: '',
        pageNum: 1,
        pageSize: 10
      },
      assetType: [],
      columns: [
        { title: '流水号', key: 'flowId', minWidth: 180, align: 'left' },
        { title: '商户编号', key: 'merchantId', minWidth: 180, align: 'left' },
        { title: '商户登录账号', key: 'loginAccount', minWidth: 150, align: 'center' },
        { title: '资产类型', key: 'assetsType', minWidth: 100, 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: 160,
          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,
      selectCount: 0
    }
  },
  methods: {
    // 获取资产类型
    getAssetsType () {
      let type = {}
      this.assetType = []
      this.api({
        apiName: 'assetsType',
        success: (res) => {
          // console.log('res', res)
          // this.assetType = res.data
          res.data.forEach(item => {
            type = {
              series_name: item,
              series_id: item
            }
            this.assetType.push(type)
          })
        }
      })
    },
    businessFlow () {
      this.loading = true
      this.api({
        apiName: 'merchantAssetsFlowList',
        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.businessFlow()
    },
    handleRefresh () {
      this.reload()
    },
    handleCurrentChange (pageNum) {
      this.searchContent.pageNum = pageNum
      this.businessFlow()
    }
  },
  created () {
    console.log(this.type)
    this.businessFlow()
    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>
