<template>
  <div class="content-page">
    <div class="content-page__header">
      <div class="content-page__header-title">
        <span class="black_box">
          <Button type="text" class="blackup-btn" @click="returnbtn">返回/</Button>
          <span name="title">{{title2}}</span>
        </span>
        <span class="content-page__header-subtitle">
          <span name="sub-title">{{subTitle}}</span>
        </span>
      </div>
    </div>

    <div class="content-page__content" :style="contentStyle" ref="content" @scroll="resLisScroll">
      <div style="display: flex;height: 100%;justify-content: center;align-items: center;" v-if="loading">
        <Spin size="large"></Spin>
      </div>
      <slot v-else />
    </div>
  </div>
</template>

<script>

export default {
  name: 'ContentPage',
  data () {
    return {
      getScrollTop: 0,
      fromPath: '',
    }
  },
  props: {
    title: String,
    subTitle: String,
    contentPadding: [String, Number],
    loading: Boolean
  },
  watch: {
    '$route' (to, from) {
      this.fromPath = from.path
    }
  },
  computed: {
    title2 () {
      let _title = this.title || this.$route.meta.title
      return typeof _title === 'function' ? _title(this.$route) : _title
    },
    contentStyle () {
      if (this.contentPadding) {
        return {
          padding: typeof this.contentPadding === 'string' ? this.contentPadding : this.contentPadding + 'px'
        }
      }
      return ''
    },
  },
  created () {

  },
  activated () {
    if (this.fromPath === '/setImgGroup') {
      this.$refs.content.scrollTop = this.getScrollTop
    } else {
      this.$refs.content.scrollTop = 0
    }
  },
  methods: {
    returnbtn () {
      this.$router.go(-1)
    },
    resLisScroll () {
        this.getScrollTop = this.$refs.content.scrollTop
        this.$emit('contentScroll', this.getScrollTop)
    },
  }
}
</script>

<style scoped>
.content-page {
  height: 100%;
  padding: 0px 2px;
}

.content-page__content::-webkit-scrollbar {
  width: 4px;
  /* height: 4px; */
}
.content-page__content::-webkit-scrollbar-thumb {
  border-radius: 10px;
  -webkit-box-shadow: inset 0 0 5px #cfcfcf;
  background: #cfcfcf;
}
.content-page__content::-webkit-scrollbar-track {
  -webkit-box-shadow: inset 0 0 5px #ffffff;
  border-radius: 0;
  background: #ffffff;
}

.content-page__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  /* height: 40px; */
  color: #111827;
}
.content-page__header-title >>> .ivu-tabs-nav {
  color: #111827;
}

.content-page__header-title {
  font-size: 16px;
  /* margin-left: 45px; */
}

.content-page__header-subtitle {
  font-size: 12px;
  color: #999;
  margin-left: 12px;
}

.content-page__content {
  box-shadow: 0 12px 32px -12px #ffffff;
  border-radius: 8px 8px 0px 0px;
  /* overflow: hidden; */
  height: calc(100% - 63px);
  background-color: #fff;
  overflow-y: auto;
  scroll-behavior: smooth;
  padding: 20px;
}
/* tab样式 */

.content-page__header-title >>> .ivu-tabs {
  top: 10px;
}

.content-page__header-title >>> .ivu-tabs-ink-bar {
  height: 3px;
  /* width: 56px !important;
  left: 16px !important; */
}
.content-page__header-title >>> .ivu-tabs-bar {
  border-width: 0px;
  margin-bottom: 0;
}
/* 返回按钮前加上左箭头 */
.black_box{
    display: flex;
    align-items: center;
    margin-top: 15px;
}
.blackup-btn ::before {
  content: '<';
}
.blackup-btn{
    color: #5b21b6;
    cursor: pointer;
    font-size:16px;
    padding-left: 0px;
    padding-right: 5px;
}
</style>
