<template>
  <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 codeList" v-bind:key="index" @click.native="onNarBtnClick(item.code,index)"   :title="item.title" :disabled="item.isDis==='N'">{{item.label}}</c-button>
     </div>
  </div>
</template>
<script>
import Api from "~/service/Api"
import CodeTable from "~/config/CodeTable"
import Cptsel from "~/model/Cptsel"
import commonProcess from "~/mixin/commonProcess"


export default { 
    props:["ownref"],
    components:{
       
    },
    mixins: [commonProcess],    // 里面包含了Default、Check等的公共处理
    data(){
        return {
            trnName:'cptsel',
            model:new Cptsel().data,
            navcode:[
               // {code:"",label:"",isDis:"",title:""},            
            ],
        }
    },
    methods:{
         //各入口按钮请求
     async  onNarBtnClick(code,i){
            this.model.cfgfil.subtrn1= code  
            let rtnmsg = await this.executeRule("cfgfil.hotsub1")
            if(rtnmsg.respCode == SUCCESS){
               this.navcode = []
               this.$emit("onChoose",code.toLowerCase());
            }else{
               this.$notify.error({ title: "错误", message: "服务请求失败!" });
            }
            
        },
    
     },
    computed:{
         codeList(){
              //将model中的数据映射成数组
              return this.navcode.map(item=>{
                  let entireItem = {...item}
                  this.navcode = [];
                  //TODO 根据数据判断当前的code,是否可以继续
               //    entireItem.enable = item.isDis
                  return entireItem
              })
         }
     },
     watch:{
        "ownref":async function(n, o){
            if(!this.ownref){
                 console.log("11111")
               //   onTigger()
                 return;
            }
        }
    },
    
    mounted(){
         this.$nextTick(function(){
              this.$on('childmethods',async function(){
                   this.navcode = []
                  //请求按钮数据
                  this.model.cpdgrp.rec.ownref = this.ownref  
                    let rtnmsg = await this.executeRule("cpdgrp.rec.ownref");//didgrp_rec_ownref
                    if(rtnmsg.respCode == SUCCESS){
                              //重置数组
                              this.navcode = []
                              this.updateModel(rtnmsg.data)
                              //this.model.cfgfil.btnstm = rtnmsg.data.cfgfil_btnstm.rows
                              //给inr赋值,后面弹窗里面的按钮请求会用到
                              //this.model.didgrp.rec.inr = rtnmsg.data.didgrp_rec_inr
                              const length = this.model.cfgfil.btnstm.rows.length
                              let btnStr = this.model.cfgfil.btnstm.rows
                              // let j = 0;
                              let m = 0;
                              // const buttonIndex = ['信用证修改','减额修改接受','到单','修改通知行']
                              for(let i=0;  i < length; i++){
                              //获取数组中每行的数据
                                   if(!( btnStr[i].indexOf("payment") >= 0) && !(btnStr[i].indexOf("境内外币") >= 0)){
                                        let arr = btnStr[i].split("\t");
                                        let newList = {
                                        code:arr[0],
                                        label:arr[1],
                                        isDis:arr[2],
                                        title:arr[3]                       
                                      }
                                      m++;
                                   //    j = buttonIndex.indexOf(arr[1].replace(/(^\s*)|(\s*$)/g, ""));
                                   //    if(j<0){
                                   //         j = m;
                                   //    }
                                   //    //添加到navcode数组中
                                      this.navcode.splice(m,0,newList)
                                   }
                                   // let arr = btnStr[i].split("\t");
                                   // let newList = {
                                   //      code:arr[0],
                                   //      label:arr[1],
                                   //      isDis:arr[2],
                                   //      title:arr[3]  
                                   // }
                                   // this.navcode.splice(i,0,newList)                   
                                   
                               }
                               this.navcode.push({code:"",label:"退汇",isDis:"N",title:""})
                               //屏蔽cptsel sptcpt
                               this.navcode.splice(1,2)   

                        
                         }else{
                              this.navcode = [] 
                              this.$notify.error({ title: "错误", message: "服务请求失败!" });
                         }
                        
                    })
              })
         }
    

}
</script>
<style>


</style>