<template>
	<view class="order view">
		<view class="status_bar" :style="navHeight"></view>
		<uni-list ref="list" class="listview" :enableBackToTop="true" :scroll-y="true">
			<uni-cell>
				<view class="content view">
					<view class="middle view">
						<view class="text-block">
							<text class="middle-date">计划类型</text>
							<view class="middle-date-des uni-list picker-year">
								<view class="uni-list-cell">
									<view class="uni-list-cell-db">
										<picker class="picker-block" @change="bindPickerChange" :value="index"
											:range="array">
											<text class="uni-input">{{array[index]}}</text>
										</picker>
									</view>
								</view>
								<image class="icon-arrow" src="@/static/image/arrow_down@3x.png" mode=""></image>
							</view>
						</view>
						<view class="text-block">
							<text class="middle-date">经销商</text>
							<text class="middle-date-des">新川商贸有限公司</text>
						</view>
						<view class="text-block">
							<text class="middle-date middle-billno">产品类别</text>
							<text class="middle-date-des">五粮液新品</text>
						</view>
						<view class="text-block">
							<text class="middle-date middle-billno">年度</text>
							<text class="middle-date-des">2021</text>
						</view>
					</view>
					<view class="bottom view">
						<view class="bottom-nav">
							<view class="bottom-nav-arrow" @click="handleShowDetail">
								<text class="arrow-des">明细</text>
								<image class="icon-arrow-d" :class="{'icon-arrow-rotate':ishowDetail}"
									src="@/static/image/arrow_up@3x.png" mode="aspectFit"></image>
							</view>
						</view>
						<view v-if="ishowDetail" class="bottom-content">
							<view class="table">
								<view class="table-head">
									<text class="th">产品描述</text>
									<text class="th"></text>
									<text class="th">原计划</text>
									<text class="th th-last">调整</text>
								</view>
								<view class="row" v-for="item in 12" :key="item">
									<text class="td">{{item}}月</text>
									<text class="td"></text>
									<text class="td">100</text>
									<view class="td td-last">
										<view class="stepper">
											<button v-if="isFocus && activeIndex == item" class="stepper__minus stepper__minus--disabled"
												@click="minus" :disabled='minusDisabled' type="default">-</button>
											<input class="stepper__input"
												:class="{'stepper__input--blur':isFocus,'stepper__input--focus':isFocus}"
												@focus="onFocus(item,$event)" :focus="isFocus && activeIndex == item" type="number" v-model="planNum" />
											<button v-if="isFocus && activeIndex == item" class="stepper__plus" @click="plus"
												:disabled="plusDisabled" type="default">+</button>
										</view>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</uni-cell>
		</uni-list>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'

	import uniList from '@/components/uni-list.vue';
	import uniCell from '@/components/uni-cell.vue';

	export default {
		components: {
			uniList,
			uniCell,
		},
		data() {
			return {
				ishowMore: false,
				ishowDetail: true,
				array: ['发货计划', '2020', '2019', '2018'],
				index: 0,
				planNum: 2,
				activeIndex:-1,
				isFocus: false,
				plusDisabled: false,
				minusDisabled: true
			}
		},
		computed: {
			navHeight() {
				return {
					'height': `${this.sysinfo.safeArea.top + 44}px`
				}
			},
			...mapState(['sysinfo'])
		},
		methods: {
			bindPickerChange(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				this.index = e.detail.value
			},
			click() {
				this.$emit('click');
			},
			close(e) {
				e.stopPropagation();
				this.$emit('close');
			},
			handleMore() {
				this.ishowMore = !this.ishowMore
			},
			handleShowDetail() {
				this.ishowDetail = !this.ishowDetail
			},
			plus() {
				this.planNum += 1
			},
			minus() {
				this.planNum -= 1
			},
			onFocus(index,e) {
				console.log('focus', e);
				this.isFocus = true;
				this.activeIndex = index;
			},
			onBlur(e) {
				this.isFocus = false;
			}
		}
	}
</script>

<style lang="scss" scoped>
	.view {
		flex-direction: column;
	}

	/* #ifndef APP-PLUS */
	page {
		width: 100%;
		min-height: 100%;
		display: flex;
		background: $background-color-1;
	}

	.status_bar {
		height: var(--status-bar-height);
	}

	/* #endif */

	.order {
		flex: 1;
		background: $background-color-1;
		padding: 0 8px;
	}

	.listview {
		flex: 1;
		flex-direction: column;
	}

	.content {
		flex: 1;
		background-color: #fff;
		padding: 64rpx 48rpx;
		margin-top: 18rpx;
		border-radius: 16rpx;
		box-shadow: 0px 2px 4px 0px #dbe4ee;
		margin-bottom: 60rpx;
	}

	.icon-more {
		width: 16px;
		height: 16px;
	}

	.middle {
		position: relative;
		margin-bottom: 48rpx;
	}

	.text-block {
		height: 64rpx;
		margin-bottom: 32rpx;
		align-items: center;
	}

	.middle-date {
		flex: 2;
		font-size: 28rpx;
		color: #999;
		margin-bottom: 8rpx;
	}

	.middle-date-des {
		flex: 3;
		font-size: 28rpx;
		color: $text-base-color;
	}

	.picker-year {
		position: relative;
		background: #f5f6f7;
		border-radius: 4px;
		align-items: center;
		height: 64rpx;
		padding-left: 14rpx;
	}

	.uni-list-cell {
		flex: 1;
	}

	.uni-list-cell-db {
		flex: 1;
	}

	.picker-block {
		flex: 1;
	}

	.uni-input {
		font-size: 14px;
		color: $text-base-color;
	}

	.icon-arrow {
		position: absolute;
		right: 22rpx;
		top: 24rpx;
		width: 7px;
		height: 4px;
		z-index: 10;
	}

	.bottom {
		flex: 1;
	}

	.bottom-nav {
		height: 40rpx;
		justify-content: flex-end;
		align-items: center;
	}

	.bottom-nav-arrow {
		align-items: center;
	}

	.arrow-des {
		font-size: 24rpx;
		color: #999;
	}

	.icon-arrow-d {
		width: 7px;
		height: 4px;
		margin-left: 12rpx;
		margin-top: 2px;
		transition-property: transform;
		transition-duration: 0.15s;
		transform: rotate(0deg);
	}

	.icon-arrow-rotate {
		transform: rotate(180deg);
		margin-top: 0;
	}

	.bottom-content {
		flex-direction: column;
		margin-top: 48rpx;
	}

	.table {
		overflow: hidden;
		flex-direction: column;
	}

	.table-head {
		height: 64rpx;
		margin-bottom: 40rpx;
	}

	.th {
		flex: 1;
		color: #999;
		font-weight: 400;
		font-size: 28rpx;
	}

	.th-last {
		flex: 2;
		text-align: right;
		;
	}

	.row {
		height: 64rpx;
		margin-bottom: 52rpx;
	}

	.td {
		flex: 1;
		font-size: 14px;
		color: $text-base-color;
	}

	.td-last {
		flex: 2;
		text-align: right;
		;
		justify-content: flex-end;
	}

	.stepper {
		height: 28px;
		align-items: center;
		border: 1px solid #cecfd0;
		border-radius: 4px;
		overflow: hidden;

	}

	.stepper__minus {
		position: relative;
		width: 28px;
		height: 28px;
		line-height: 28px;
		margin: 0;
		padding: 0;
		color: #323233;
		background-color: #fff;
		border-color: transparent;
		border-radius: 0;
	}

	.stepper__minus:after {
		border: 0;
	}

	.stepper__input {
		width: 32px;
		height: 28px;
		padding: 0;
		color: #323233;
		font-size: 14px;
		text-align: center;
		background-color: #fff;
		border: 1px solid #cecfd0;
		border-radius: 4px;
	}

	.stepper__input--blur {
		border-color: transparent;
	}

	.stepper__input--focus {
		border-color: #fff;
		border-radius: 0;
		border-left-color: #CECFD0;
		border-right-color: #CECFD0;
	}

	.stepper__plus {
		position: relative;
		width: 28px;
		height: 28px;
		line-height: 28px;
		margin: 0;
		padding: 0;
		color: #323233;
		background-color: #fff;
		border-color: transparent;
		border-radius: 0;
	}

	.stepper__plus:after {
		border: 0;
	}
</style>
