<template>
	<view class="Datetime-Picker">
		<view class="Choose-Input" @tap="show = true">
			{{date}}
			<view class="arrow"></view>
		</view>
		<!-- 年月选择组件 -->
		<u-datetime-picker ref="datetimePicker" :minDate="GetUserInfor['store_join_time'] * 1000"
			:maxDate="new Date().getTime()" @cancel="show = false" :show="show" @confirm="confirm" v-model="value"
			mode="year-month">
		</u-datetime-picker>
	</view>
</template>

<script>
	import mixin from '@/static/js/mixin.js'
	export default {
		mixins: [mixin],
		name: "Datetime-Picker",
		data() {
			return {
				value: Number(new Date()),
				show: false,
				date: ''
			};
		},
		mounted() {
			this.DataConvert(new Date().getTime());
			// console.log(this['GetUserInfor']['store_join_time'], 'GetUserInfor');
		},
		methods: {
			/**
			 * @日期选择点击确认时触发事件
			 * */
			confirm(e) {
				this['show'] = false;
				this.DataConvert(e['value']);
			},

			/**
			 * @将时间戳转为年月
			 * @param {number} t 要转换的时间戳
			 * @param {number} bit 是否需要将十位时间戳转为13位
			 * */
			DataConvert(t, bit = false) {
				if (bit) {
					// 后台需要的是十位而前端需要的是十三位,所以需要转换一下
					t = t * 1000;
				};
				let d = new Date(t);
				let y = d.getFullYear();
				let m = d.getMonth() + 1;
				this['date'] = `${y}年${m}月`;
				// console.log(t);
				this.$emit('Change', Math.ceil(t / 1000));

			}

		}
	}
</script>

<style lang="scss">
	.Datetime-Picker {
		padding: 10rpx 55rpx 10rpx 32rpx;
		border: 1rpx solid #DEDEDE;
		box-sizing: border-box;
		border-radius: 15rpx;
		position: relative;

		.arrow {
			position: absolute;
			width: 40rpx;
			height: 100%;
			right: 10rpx;
			top: 0;

			&::after {
				content: '';
				position: absolute;
				left: 50%;
				bottom: 10%;
				transform: translateX(-50%);
				display: block;
				margin: 0 auto;
				width: 0;
				height: 0;
				border: 10rpx solid transparent;
				border-top-color: #DEDEDE;
			}

			&::before {
				content: '';
				position: absolute;
				left: 50%;
				top: 10%;
				transform: translateX(-50%);
				display: block;
				margin: 0 auto;
				width: 0;
				height: 0;
				border: 10rpx solid transparent;
				border-bottom-color: #DEDEDE;
			}
		}

	}
</style>
