<template>
  <div class="merchant-assets-page">
    <Card>
      <div class="search-con">
        <Input placeholder="请输入商户编号" class="search-input" v-model="searchContent.merchantId" style="width: 200px"/>
        <Input placeholder="请输入商户登录编号" class="search-input" v-model="searchContent.account" style="width: 200px"/>
        <Select class="search-input"  v-model="searchContent.type" placeholder="请选择资产类型" style="width: 200px">
          <Option value="">全部</Option>
          <Option v-for="(item, index) in assetsData"
            :value="item"
            :key="'series-option-' + index"
          >
            {{item}}
          </Option>
        </Select>
        <ButtonGroup class="search-btngroup">
          <Button type="primary" style="margin-left: 20px" @click="handleSearch">查 找</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'
export default {
  inject: ['reload'],
  components: {
    Tables
  },
  data () {
    return {
      searchContent: {
        merchantId: null,
        account: null,
        type: null,
        pageNum: 1,
        pageSize: 10
      },
      assetsData: [],
      tableData: [],
      columns: [
        { title: '商户编号', key: 'merchantId', align: 'left', minWidth: 180 },
        { title: '商户登录账号', key: 'loginAccount', align: 'center', minWidth: 130 },
        { title: '商户名称', key: 'merchantName', align: 'center', width: 110 },
        { title: '账户', key: 'account', align: 'left', minWidth: 150 },
        { title: '资产类型', key: 'assetsType', align: 'center', width: 100 },
        { title: '可用余额', key: 'amount', align: 'center', width: 90 },
        { title: '冻结余额', key: 'frozen', align: 'center', width: 90 },
        { title: '更新时间',
          key: 'updateTime',
          align: 'center',
          width: 180,
          render: (h, params) => {
            return h('span', formatTime(params.row.updateTime))
          }
        }
        // { title: '操作',
        //   key: 'index',
        //   align: 'center',
        //   minWidth: 150,
        //   render: (h, params) => {
        //     let rechargeBtn = h(
        //       'Button',
        //       {
        //         props: {
        //           type: 'primary',
        //           size: 'small'
        //         },
        //         on: {
        //           click: this.handleRecharge(params.row)
        //         },
        //         style: {
        //           marginRight: '5px'
        //         }
        //       },
        //       '充 值'
        //     )
        //     let deductionBtn = h(
        //       'Button',
        //       {
        //         props: {
        //           type: 'primary',
        //           size: 'small'
        //         },
        //         on: {
        //           click: this.handleDeduction(params.row)
        //         },
        //         style: {
        //           marginRight: '5px'
        //         }
        //       },
        //       '扣 除'
        //     )
        //     return h('div', [rechargeBtn, deductionBtn])
        //   }
        // }
      ],
      loading: false,
      totalSize: 0
    }
  },
  methods: {
    requestData () {
      this.loading = true
      this.api({
        apiName: 'merchantAssetsPage',
        postdata: this.searchContent,
        complete: () => {
          this.loading = false
        },
        success: (res) => {
          this.tableData = res.data.records
          this.totalSize = res.total
        }
      })
    },
    requestMerchantAssetsType () {
      this.api({
        apiName: 'merchantAssetsType',
        success: (res) => {
          this.assetsData = res.data
        }
      })
    },
    handleSearch () {
      this.requestData()
    },
    handleRefresh () {
      this.reload()
    },
    handleCurrentChange (pageNum) {
      this.searchContent.pageNum = pageNum
      this.requestData()
    },
    handleRecharge () {
      return () => {

      }
    },
    handleDeduction () {
      return () => {

      }
    }
  },
  created () {
    this.requestMerchantAssetsType()
    this.requestData()
  }
}
</script>
<style scoped lang="less">
.merchant-assets-page .search-con {
  display: flex;
  padding: 10px 0;
  .search-input {
    width: 300px;
    margin-right: 10px;
  }
}
</style>
