<template>
	<view
    class="uni-section"
    :style="{
      background: bg,
      height: height + 'rpx'
    }
    ">
		<view v-if="type" class="uni-section__head">
      <view :class="type" class="uni-section__head-tag" :style="{backgroundColor:styleMainColor}"></view>
		</view>
		<view class="uni-section__content">
			<text :class="{'distraction':!subTitle}" class="uni-section__content-title">{{ title }}</text>
			<text v-if="subTitle" class="uni-section__content-sub">{{ subTitle }}</text>
		</view>
		<slot />
	</view>
</template>

<script>
  import {
    getParentsStyle,
  } from '@/utils/xd.base';
	/**
	 * Section 标题栏
	 * @description 标题栏
	 * @property {String} type = [line|circle] 标题装饰类型
	 * 	@value line 竖线
	 * 	@value circle 圆形
	 * @property {String} title 主标题
	 * @property {String} subTitle 副标题
	 */

	export default {
		name: 'XdTitleSection',
		props: {
			type: {
				type: String,
				default: 'line'
			},
			title: {
				type: String,
				default: ''
			},
			subTitle: {
				type: String,
				default: ''
			},
      bg:{
        type: String,
        default: '#f8f8f8'
      },

      height: {
        type: Number,
        default: 80 //rpx
      }
		},
		data() {
			return {
        styleMainColor: null, //插件主题风格样式
			}
		},
		watch: {
			title(newVal) {
				if (uni.report && newVal !== '') {
					uni.report('title', newVal)
				}
			}
		},
    async created() {
      this.styleMainColor = await getParentsStyle(this.$parent, '$mainColor');
    },
		methods: {
			onClick() {
				this.$emit('click')
			}
		}
	}
</script>
<style lang="less" scoped>
	.uni-section {
		position: relative;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		margin-top: unit(20, rpx);
		flex-direction: row;
		align-items: center;
		padding: 0 unit(20, rpx);
		height: unit(80,rpx);
		background-color: @xd-bg-color-grey;
		/* #ifdef APP-NVUE */
		border-bottom-color: @xd-border-color;
		border-bottom-style: solid;
		border-bottom-width: 0.5px;
		/* #endif */
		font-weight: normal;
	}
	/* #ifndef APP-NVUE */
	.uni-section:after {
		position: absolute;
		bottom: 0;
		right: 0;
		left: 0;
		height: 1px;
		content: '';
		-webkit-transform: scaleY(.5);
		transform: scaleY(.5);
		background-color: @xd-border-color;
	}
	/* #endif */

	.uni-section__head {
		flex-direction: row;
		justify-content: center;
		align-items: center;
		margin-right: 10px;
	}

	.line {
		height: 15px;
		background-color: @xd-text-color-disable;
		border-radius: 5px;
		width: 3px;
	}

	.circle {
		width: 8px;
		height: 8px;
		border-top-right-radius: 50px;
		border-top-left-radius: 50px;
		border-bottom-left-radius: 50px;
		border-bottom-right-radius: 50px;
		background-color: @xd-text-color-disable;
	}

	.uni-section__content {
		flex-direction: column;
		flex: 1;
		color: @xd-text-color;
	}

	.uni-section__content-title {
		font-size: @xd-font-size-base+2;
		color: @xd-text-color;
	}

	.distraction {
		flex-direction: row;
		align-items: center;
	}

	.uni-section__content-sub {
		font-size: @xd-font-size-sm;
		color: @xd-text-color + 100;
    margin-left: unit(10,rpx);
	}
</style>
