<template>
  <div class="eibs-tab">
    <!-- ----------左 ---------->
    <c-col :span="12" class="col-left">
      <c-col :span="24">
        <el-form-item label="机构编码" prop="branch">
          <c-input
            v-model="model.branch"
            maxlength="8"
            placeholder="请输入机构编码"
          ></c-input>
        </el-form-item>
      </c-col>
      <c-col :span="24">
        <el-form-item label="实体" prop="etyexkey">
          <c-input
            v-model="model.etyexkey"
            maxlength="8"
            placeholder="请输入实体关键字"
          ></c-input>
        </el-form-item>
      </c-col>

    </c-col>
    <!------------- 右 ---------->
    <c-col :span="12" class="col-right">
      <c-col :span="24">
        <el-form-item label="经办行机构编码" prop="bchkey">
          <c-input
            v-model="model.bchkey"
            maxlength="8"
            placeholder="请输入经办行机构编码"
          ></c-input>
        </el-form-item>
      </c-col>

      <c-col :span="24">
        <el-form-item label="机构类型" prop="bchtyp">
            <c-select
                v-model="model.bchtyp"
                style="width: 100%"
                placeholder="请输入机构类型"
                :code="getCodesByKey('bchtyp')"
            >
            </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="bchAdd">新增</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="onSearch()"
          >查询
        </el-button>
      </c-col>
    </c-col>
    <c-col :span="24">
      <c-paging-table 
        :data="bchData"
        :columns="bchColumns"
        :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="bchInfo(scope.$index, scope.row)"
              >详情</c-button
            >
            <c-button
              style="margin-left: 5px"
              size="small"
              type="primary"
              @click="bchEdit(scope.$index, scope.row)"
              >修改</c-button
            >
            <c-button
              size="small"
              style="margin-left: 5px"
              @click="bchDelete(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/bch.js";

export default {
  name: "",
  props: ["model"],
  inject: ["root"],
  data() {
    return {
      bchData: [],
      bchColumns: [
				{ label: '机构编码', prop: 'branch', width: '120' },
				{ label: '中文名称', prop: 'bchname', width: '150' },
				{ label: '核心机构号', prop: 'accbch', width: '200' },
				{ label: '机构类型', prop: 'bchtyp', width: '100' },
				{ label: '经办行机构编码', prop: 'bchkey', width: '200' },
				{ label: '上级行机构编码', prop: 'upbranch', width: '200' },
				{ label: '收支申报号', prop: 'decnum', width: '200' },
				{ label: '印单局代码', prop: 'ydjcod', width: '200' },
				{ label: '实体', prop: 'etyexkey', width: '120' },
				{ label: '机构标识', prop: 'bchflg', width: '200' },
				{ label: '机构层次', prop: 'lev', width: '98' },
				{ label: '电证联行行号', prop: 'dzlhhh', width: '200' },
				{ label: '联行行号', prop: 'lhanum', width: '98' },
        { label: '联行名称', prop: 'lhanam', width: '98' },
			],
    };
  },
  computed: {
    
  },
  activated() {
    const { update } = this.$route.params
    if (update) {
      this.onInfBchSearch()
    }
  },
  methods: {
    handleReset() {
      this.root.$refs.modelForm.resetFields();
    },
    onSearch(){
        this.model.pageNum = 1;
        this.model.pageSize = 5;
        this.onInfBchSearch();
    },
    onInfBchSearch() {
			queryByPage(this.model).then(res => {
        /**
         * pageNumber: 0
         * pageSize:	0
         * total: 69
         * totalPage: 0
         */
        const list = res.list
        this.bchData = 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.onInfBchSearch()
    },
    getCodesByKey(key) {
      return codes[key] ?? [];
    },
    bchAdd() {
			this.$router.push(`/statics/dbabch`)
		},
    bchInfo(index, row) {
			this.$router.push(`/statics/dbibch/${row.inr}`)
		},
    bchEdit(index, row) {
			this.$router.push(`/statics/dbebch/${row.inr}`)
		},
    bchDelete(index, row) {
			this.$router.push(`/statics/dbdbch/${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>