<template>
  <div class="detail-header">
    <el-row>
      <el-col :span="12" class="left">
        <h4>
          <el-button
            circle
            icon="el-icon-back"
            v-if="hasBackButton"
            @click.stop="doAction('itemBack')"
          ></el-button>
          {{ title }}
          <span>{{ !nowStatus ? '' : labels.receiptStatus + '：' }}</span>
          <span class="status">{{ status[nowStatus] }}</span>
        </h4>
      </el-col>
      <el-col class="buttons" :span="12">
        <button-group :option="buttons" v-on="$listeners"></button-group>
      </el-col>
    </el-row>
    <el-divider v-if="!hideLine" class="header-line"></el-divider>
  </div>
</template>
<script>
import { getDic } from '@qqt-vue/core/dist/lib/api/index';
import { ft } from '../../../lib/utils.js';

const LABELS = {
  receiptStatus: ft('i18n_common_receipt_status', '单据状态')
};

export default {
  name: 'PageDetailHeader',
  props: {
    buttons: {
      type: Array,
      default: () => {
        return [
          {
            name: 'btn-add',
            i18nKey: '',
            label: LABELS.new,
            icon: 'el-icon-plus',
            size: 'small',
            disabled: false,
            round: false,
            type: 'primary',
            action: 'addItem',
            align: 'btn-right',
            class: ''
          }
        ];
      }
    },

    dicProp: {
      type: String,
      default: ''
    },

    hideLine: {
      type: Boolean,
      default: false
    },

    hasBackButton: {
      type: Boolean,
      default: true
    },

    nowStatus: {
      type: String,
      default: ''
    },

    title: {
      type: String,
      default: ''
    }
  },

  data() {
    return {
      labels: LABELS,
      loading: true,
      status: {}
    };
  },

  created() {
    this.getDicData();
  },

  methods: {
    doAction(action) {
      this.$emit('do-action', action);
      this.$emit(action);
      // this.$message.success(action)
    },
    getDicData() {
      if (this.dicProp) {
        getDic(this.dicProp).then((res) => {
          res.data.data.forEach((item) => {
            this.status[item.value] = item.label;
          });
        });
      }
    }
  }
};
</script>
<style scoped>
.detail-header {
  padding: 0;
  margin: 0;
}
.detail-header h4 {
  padding: 0 24px;
  /* margin-left: 8px; */
  border-left: none;
  font-size: 1.1em;
  color: #262626;
  font-weight: bold;
  font-size: 20px;
  margin: 0;
  height: 50px;
  box-sizing: border-box;
  /* margin-bottom: 16px; */
}
.detail-header .el-button.is-circle {
  font-size: 22px !important;
  color: #262626 !important;
  margin-top: -5px !important;
}
.detail-header .el-button.is-circle {
  border: 0;
  background-color: transparent;
  color: #409eff;
  padding: 0;
  font-size: 1.6em;
  vertical-align: middle;
}
.detail-header .header-line {
  /* margin: 0 0 8px 0 !important; */
  background-color: #b1b6c0;
}
.detail-header .buttons {
  text-align: right;
  margin: 0;
  height: 50px;
  box-sizing: border-box;
  line-height: 50px;
}
/* .detail-header .buttons .btns-right {
  padding: 0 8px;
  float: right;
} */

.left {
  margin: 0;
  height: 50px;
  line-height: 50px;
}
h4 span {
  font-size: 14px;
  color: rgba(0, 0, 0, 0.45);
  font-weight: 400;
  display: inline-block;
  margin-left: 10px;
  line-height: 50px;
}
.status {
  color: #ff4d4f;
  margin-left: 0;
}
</style>
