<template>
  <div style="text-align: center">
    <el-button v-for="(btn,index) in btns" type="primary" :key="index" size="mini" @click="submit(index)">{{btn.name}}</el-button>
  </div>
</template>

<script>
  export default {
    name: 'FootBtns',
    props:{
      btns:{
        type: Array,
        default(){
          return []
        }
      },
      data:{
        type: Object,
        default(){
          return {}
        }
      }
    },
    methods:{
      // 确定
      async submit(i) {
        if(this.btns[i].type === 'link'){
          let href = this.btns[i].apiurl
          if(href.indexOf('http:') === -1){
            href = href.substr(0,href.indexOf('?'))
            const arr = this.$tool.getUrlparams(this.btns[i].apiurl)
            this.$router.push({name: href ,query:{ pname:arr[0],tname:arr[1]}})
          }else{
            window.location.href = this.btns[i].apiurl
          }
        }else if(this.btns[i].type === 'add' || this.btns[i].type === 'edit'){
          alert(JSON.stringify(this.data))
          return;
          await this.$metiiAPI.formSubmit(this.btns[i].apiurl, this.data)
        }
      }
    },
  }
</script>

<style lang="stylus" scoped>

</style>
