<template>
  <div class="eibs-tab">
    <!-- 参照TD上infxxx,如infpty/infact交易的search panel面板,对应布局查询条件字段 -->
    <!-- ----------左 ---------->
    <c-col :span="12" class="col-left">
      <c-col :span="24">
        <!-- Account No. -->
        <el-form-item label="资金账号" prop="extkey">
            <c-input
                v-model="model.extkey"
                placeholder="请输入extkey"
            >
            </c-input>
        </el-form-item>
    </c-col>
    <c-col :span="24">
      <!-- Holding Party -->
        <el-form-item label="客户账户" prop="ptyExtkey">
            <c-input
                v-model="model.ptyExtkey"
                placeholder=""
            >
            </c-input>
        </el-form-item>
    </c-col>
      <c-col :span="24">
        <el-form-item label="账号类型" prop="typ">
          <c-select
            v-model="model.typ"
            placeholder=""
            style="width: 100%"
            :code="getCodesByKey('recgrptyp')"
          ></c-select>
        </el-form-item>
      </c-col>
    </c-col>
    <!-- =========================------------- 右 ----------======================= -->
    <c-col :span="12" class="col-right">
      <c-col :span="24">
        <el-form-item label="账号名称" prop="nam">
          <c-input
            v-model="model.nam"
            placeholder=""
          ></c-input>
        </el-form-item>
      </c-col>

      <c-col :span="24">
        <el-form-item label="国际银行账户号 " prop="iban">
          <c-input
            v-model="model.iban"
            maxlength="34"
            placeholder="请输入IBAN"
          ></c-input>
        </el-form-item>
      </c-col>

      <c-col :span="24">
        <el-form-item label="账号币种" prop="cur">
          <c-select
            v-model="model.cur"
            style="width: 100%"
            placeholder=""
            :code="getCodesByKey('infled_Cur')"
          >
          </c-select>
        </el-form-item>
      </c-col>
    </c-col>

    <c-col :span="24">
      <c-col :span="12" style="text-align: left">
        <el-button type="primary" size="small" @click="actAdd">新增</el-button>
      </c-col>
      <c-col :span="12" style="text-align: right">
        <el-button size="small" @click="handleReset">重置</el-button>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="small"
          @click="onInfactSearch()"
          >查询
        </el-button>
      </c-col>
    </c-col>
    <c-col :span="24">
      <c-paging-table 
        :data="actData"
        :columns="actColumns"
        :pageNumber="model.pageNum"
        :pageSize="model.pageSize"
        :total="model.total"
        v-on:queryFunc="queryFunc"
        :border="true"
      >
        <c-table-column fixed="right" prop="op" label="操作" width="240px">
          <template slot-scope="{ scope }">
            <c-button
              style="margin-left: 0"
              size="small"
              @click="actInfo(scope.$index, scope.row)"
              >详情</c-button
            >
            <c-button
              style="margin-left: 5px"
              size="small"
              type="primary"
              @click="actEdit(scope.$index, scope.row)"
              >修改</c-button
            >
            <c-button
              size="small"
              style="margin-left: 5px"
              @click="actDelete(scope.$index, scope.row)"
              >删除</c-button
            >
            <el-popover placement="top-start" width="50" trigger="click">
              <ul class="table-button-item-list">
                <li>
                  <c-button size="small" style="margin-left: 0">指派</c-button>
                </li>
                <li>
                  <c-button size="small" style="margin-left: 0">删除</c-button>
                </li>
              </ul>
              <a
                slot="reference"
                href="javascript:void(0)"
                style="margin-left: 5px"
              >
                <i class="el-icon-more"></i>
              </a>
            </el-popover>
          </template>
        </c-table-column>
      </c-paging-table>
    </c-col>
  </div>
</template>

<script>
import codes from "~/config/CodeTable";

import { queryByPage } from "~/service/test/act.js";

export default {
  name: "",
  props: ["model"],
  inject: ["root"],
  data() {
    return {
      actData: [],
      actColumns: [
        { label: 'HolPtyExtkey', prop: 'holPtyExtkey', width: '200' },
				{ label: 'SerPtyExtkey', prop: 'serPtyExtkey', width: '200' },
				{ label: '账号类型', prop: 'typ', width: '100' },
				{ label: '账号币种', prop: 'cur', width: '100' },
				{ label: '资金账号', prop: 'extkey', width: '200' },
				{ label: '账号开户机构的账号', prop: 'holacc', width: '200' },
				{ label: '账号提供机构的账号', prop: 'seracc', width: '200' },
			],
    };
  },
  computed: {
  },
  activated() {
    const { update } = this.$route.params
    if (update) {
      this.onInfactSearch()
    }
  },
  methods: {
    handleReset() {
      this.root.$refs.modelForm.resetFields();
    },
    onInfactSearch() {
			queryByPage(this.model).then(res => {
        /**
         * pageNumber: 0
         * pageSize:	0
         * total: 69
         * totalPage: 0
         */
        const list = res.list
        this.actData = list
        this.model.pageNum = res.pageNumber
        this.model.pageSize = res.pageSize
        this.model.total = res.total
      }) 
		},
    queryFunc(pageNumber, pageSize) {
      this.model.pageNum = pageNumber
      this.model.pageSize = pageSize
      this.onInfactSearch()
    },
    getCodesByKey(key) {
      return codes[key] ?? [];
    },
    actAdd() {
			this.$router.push(`/statics/dbaact`)
		},
    actInfo(index, row) {
			this.$router.push(`/statics/dbiact/${row.inr}`)
		},
    actEdit(index, row) {
			this.$router.push(`/statics/dbeact/${row.inr}`)
		},
    actDelete(index, row) {
			this.$router.push(`/statics/dbdact/${row.inr}`)
		},
  },
};
</script>

<style scoped>
.table-button-item-list {
  padding: 0;
  margin: 0;
}
.table-button-item-list li {
  list-style: none;
  padding: 5px 0;
  text-align: center;
  color: #606266;
  cursor: pointer;
}</style>