<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 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>
</template>
<script>
import Api from "~/service/Api";
import commonProcess from "~/mixin/commonProcess";

export default {
  props: {
    "ownref": {
        required: true,
    }, 
    "trnCode": {
        required: true,
    }, 
    "model": {
        required: true,
    }, 
    "ownrefPath": {
        required: false,
        default: "didgrp"
    },
    "tabIndex": {
        required: false,
        default: 1
    },
  },
  components: {},
  mixins: [commonProcess], // 里面包含了Default、Check等的公共处理
  data() {
    return {
      navcode: [
        // {code:"",label:"",isDis:"",title:""},
      ],
    };
  },
  methods: {
    //各入口按钮请求
    async onNarBtnClick(code, i) {
      this.model.cfgfil[`subtrn${i}`] = code;
      let rtnmsg = await this.executeRule(`cfgfil.hotsub${i}`);
      if (rtnmsg.respCode == SUCCESS) {
        this.navcode = [];
        this.$emit("onChoose", code.toLowerCase());
      } else {
        this.$notify.error({ title: "错误", message: "服务请求失败！" });
      }
    },
    getIndex(module) {
      for (let i = 1; i <= 12; i++) {
        var temp = this.model.cfgfil[`subtxt${i}`];
        if (module == temp) {
          return i;
        }
      }
      return 0;
    },
  },
  mounted() {
    this.trnName = this.trnCode
    this.$nextTick(function () {
      this.$on("childmethods", async function () {

        let res = await this.executeRule(`cfgfil.hotreg${this.tabIndex}`);
        if (res.respCode == SUCCESS) {
            this.updateModel(res.data);
        } else {
            this.$notify.error({
                title: "错误",
                message: "服务请求失败！",
            });
        }

        this.navcode = [];
        //请求按钮数据
        this.model[this.ownrefPath].rec.ownref = this.ownref;
        let rtnmsg = await this.executeRule(this.ownrefPath+".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;
          for (let i = 0; i < length; i++) {
            let arr = btnStr[i].split("\t");
            var index = this.getIndex(arr[1]);
            let newList = {
              code: arr[0],
              label: arr[1],
              isDis: arr[2],
              title: arr[3],
              index: index,
            };
            this.navcode.push(newList);
          }
        } else {
          this.navcode = [];
          this.$notify.error({ title: "错误", message: "服务请求失败！" });
        }
      });
    });
  },
};
</script>
<style>
</style>
