<template>
  <div class="eibs-tab">
    <c-col :span="12" class="col-left">
      <c-col :span="24">
        <el-form-item label="银行BIC">
            <c-input  v-model="model.biccod"  placeholder="" @change="BicRul"></c-input>
        </el-form-item>
      </c-col>
    </c-col>
 <!------------- 右 ---------->
    <c-col :span="12" class="col-right">
       <c-col :span="24">
        <el-form-item label="报文类型">
            <c-select v-model="model.msgtyp"  placeholder="" dbCode="GSPMSG"></c-select>
        </el-form-item>
       </c-col>
    </c-col>
    
    <c-col :span="12" class="col-left">
      <c-col :span="24">
        <el-form-item label="渠道信息">
            <c-select  v-model="model.chl"  placeholder="" :code="getCodesByKey('gimchl')"></c-select>
        </el-form-item>
      </c-col>
    </c-col>

    <c-col :span="24" style="text-align: right; height: 36.8px">
      <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 :span="24">
      <c-paging-table :data="gimgseData" :columns="gimgseColumns" :pageNumber="model.pageNum" :pageSize="model.pageSize"
        :total="model.total" v-on:queryFunc="queryFunc" :border="false" ref="tablelist">
      </c-paging-table>
    </c-col>
  </div>
</template>

<script>
import { queryByPage } from "~/service/manage/gimgse.js";
import Gimgse, { Pattern } from "./Gimgse.js";
import commonFunctions from '~/mixin/commonFunctions.js';
import codes from "~/config/CodeTable";

export default {
  props: ["data"],
  inject: ["root"],
  mixins: [commonFunctions],
  data() {
    return {
      rules:Pattern,
      model: new Gimgse().data,
      gimgseData: [],
      gimgseColumns: [
        { label: '银行BIC', prop: 'biccod', width: 'auto' },
        { label: '银行状态', prop: 'bnksta', width: 'auto' },
        { label: '报文类型', prop: 'msgtyp', width: 'auto' },
        { label: '银行BIC(前8位)', prop: 'biccod8', width: 'auto' },
        { label: '银行状态(前8位)', prop: 'bnksta8', width: 'auto' },
        { label: '可发送标志', prop: 'stscod', width: 'auto' },
        { label: '是否可发送', prop: 'issend', width: 'auto' },
      ],
    };
  },
  created() {
    // this.onInffrmSearch();
  },
  methods: {
    handleReset() {
        this.model.biccod = "";
        this.model.msgtyp = "";
    },
    onSearch() {
      this.model.pageSize=PageSize;
      this.model.pageNum = 1;
      if (this.model.chl == ""){
        this.$notify.error("渠道信息必填");
        return;
      }
      if (this.model.biccod != "") {
          if(this.model.biccod.length > 0 && this.model.biccod.length < 8) {
            this.$notify.error("行号至少输入8位");
          } else if(this.model.biccod.length > 11) {
            this.$notify.error("行号不得超过11位");
          } else {
            this.onInffrmSearch();
          }
      } else if(this.model.biccod == "") {
        this.onInffrmSearch();
      }
    },
    BicRul() {
      this.model.biccod = this.model.biccod.toUpperCase();
      if (this.model.biccod != "") {
          if(this.model.biccod.length > 0 && this.model.biccod.length < 8) {
            this.$notify.error("行号至少输入8位");
          }
        } 
    },
    onInffrmSearch() {
      const loading = this.loading();
      queryByPage(this.model).then(res => {
        if(res.respCode == SUCCESS) {
        const list = res.data.list
        this.gimgseData = list
        this.model.pageNum = res.data.pageNumber
        this.model.pageSize = res.data.pageSize
        this.model.total = res.data.total
        } else {
          this.$notify.error("列表查询失败");
        }
      })
      loading.close();
    },
    queryFunc(pageNumber, pageSize) {
      this.model.pageNum = pageNumber
      this.model.pageSize = pageSize
      this.onInffrmSearch()
    },

    getCodesByKey(key) {
      return codes[key] || [];
    },
  },
};
</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>