<template>
  <div class="m-list-btns">
    <div class="busnavbar">
      <div class="busnavbar-items">
        <c-button
          style="margin-left: 7px"
          size="medium"
          type="primary"
          class="medium_bcs"
          v-for="(item, index) in navcode"
          v-bind:key="index"
          @click.native="onNarBtnClick(item.code, item.index)"
          :title="item.title"
          :disabled="item.isDis === 'N'"
          >{{ item.label }}</c-button
        >
      </div>
    </div>
  </div>
</template>
<script>
import Api from "~/service/Api";
import commonProcess from "~/mixin/commonProcess";

import _ from "~/utils/Lodash"

export default {
  props: {
    codes:{},
    ownref: {
      required: true,
    },
    trnCode: {
      required: true,
    },
    model: {
      required: true,
    },
    ownrefPath: {
      required: false,
      default: "didgrp",
    },
    tabIndex: {
      required: false,
      default: 1,
    },
     queryCode: {
      required: true,
    },
    branch:{
      required: true,
    },
  
  },
  components: {},
  mixins: [commonProcess], // 里面包含了Default、Check等的公共处理
  data() {
    return {
      navcode: [
        // {code:"",label:"",isDis:"",title:""},
      ],
      tState: []
    };
  },
  methods: {
    //各入口按钮请求
    async onNarBtnClick(code, i) {
        this.navcode = [];
        
        console.log("inr:" + this.model.inr)
        console.log("gidinr:" + this.model.gidinr)
        this.$emit("onChoose", code.toLowerCase(),this.model);
     
    },

    getCodelabel(value, codenam) {
          // console.log(this.codes)
          const codeobj = this.codes[codenam].find(obj => obj.value === value)
          return codeobj ? codeobj.label : value;
        
      },
    getIndex(module) {
      for (let i = 1; i <= 12; i++) {
        var temp = this.model.cfgfil[`subtxt${i}`];
        if (module == temp) {
          return i;
        }
      }
      return 1;
    },
    async queryTableList () {
      this.model.branch = this.branch
      let rtnmsg = await Api.post("/business/"+this.trnCode+"/"+ this.queryCode, this.model)
      if (rtnmsg.respCode == SUCCESS) {
        this.navcode = []
        const length = rtnmsg.data.length
        // console.log("length:" + length)
        let btnStr = rtnmsg.data;
        for (let i = 0; i < length; i++) {
          let arr = btnStr[i].split("|");
          // var index = this.getIndex(arr[1]);
          let newList = {
            code: arr[0],
            label: this.getCodelabel(arr[0],"buttonlabels"),
            isDis: arr[1],
            title: arr[2],
            index: i,
          };
          // console.log(newList)
          this.navcode.push(newList);
        }
        // console.log('opndat:',this.model.opndat)
      if('GJBH|GNBH|HGBH'.includes(this.model.opentyp)){
        if(this.model.opndat){
          this.navcode =  this.navcode.filter(item => {
            return !item.code.includes('OPN') && !item.code.includes('POP')
          })
        }else{
          this.navcode =  this.navcode.filter(item => {
             return item.code.includes('OPN') || item.code.includes('POP')
          })
         
        }
          // for(let j = 0; j < this.navcode.length; j++){
            
          //       console.log('code,',this.navcode[j])
          //   if(this.navcode[j].code.includes('PLB') || this.navcode[j].code.includes('PPL')){
          //       this.navcode[j].isDis = 'N'
          //       this.navcode[j].title = '该交易不可用!'
          //       console.log('code,',this.navcode[j])
          //   }
          // }
        }
      }
    }
  },

  
  mounted() {
    this.trnName = this.trnCode;
    this.queryTableList()
  },
};
</script>
<style>
</style>