<template>
	<view class="lists">
		<view class="status_bar" :style="navHeight"></view>
		<view class="header-bg"></view>
		<view class="main">
			<view class="middle view">
				<view class="text-block">
					<text class="middle-date">客户编码</text>
					<input class="middle-date-des" type="text" value="" placeholder="请填写" />
				</view>
				<view class="text-block">
					<text class="middle-date">客户名称</text>
					<input class="middle-date-des" type="text" value="" placeholder="请填写" />
				</view>
				<view class="text-block text-block-last">
					<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_r@3x.png" mode=""></image>
					</view>
				</view>
			</view>

			<view class="planout-block">
				<button class="btn" type="default" @tap="search">
					<text class="btn-text">查询</text>
				</button>
			</view>

			<scroll-view class="scroll-area view" :scroll-top="scrollTop" scroll-y="true" :style="scrollHeight">
				<uni-swipe-action class="planout-block-lists">
					<uni-swipe-action-item v-for="(item,index) in lists" :key='item.id' :auto-close="false"
						:disabled='true' :show="isOpened" @click="handleClick">
						<template v-slot:left>
							<view class="swipe-right-block" @click="handleChecked($event,item, index)"><text
									class="swipe-right-block__text"
									:class="{'swipe-right-block__active':item.checked}"></text>
							</view>
						</template>
						<view class="middle view planout-block-item">
							<view class="item-block item-block-code">
								<text class="item-block-label">计划编码：100820638</text>
							</view>
							<view class="item-block item-block-name">
								<text class="item-block-label item-block__label">步步高</text>
								<text class="item-block__label item-block__value">电商配额酒年度计划(1-5月)</text>
							</view>
							<view class="item-block">
								<text class="item-block-label-des">名称</text>
								<text class="item-block-label-des item-block__value">类型</text>
							</view>
						</view>

					</uni-swipe-action-item>
				</uni-swipe-action>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'

	export default {
		data() {
			return {
				isOpened: 'none',
				array: ['2021', '2020', '2019', '2018'],
				index: 0,
				lists: [{
						id: 1,
						checked: false,
						product: '新品五粮液',
						quantity: 2,
						price: 100
					},
					{
						id: 2,
						checked: false,
						product: '新品五粮液91 52%',
						quantity: 4,
						price: 200
					},
					{
						id: 3,
						checked: false,
						product: '新品五粮液91 52%',
						quantity: 4,
						price: 200
					},
					{
						id: 4,
						checked: false,
						product: '新品五粮液91 52%',
						quantity: 4,
						price: 200
					},
					{
						id: 5,
						checked: false,
						product: '新品五粮液91 52%',
						quantity: 4,
						price: 200
					}
				],
				selectedGroupClient: {},
				scrollTop: 0
			}
		},
		computed: {
			...mapState(['sysinfo']),
			navHeight() {
				return {
					'height': `${this.sysinfo.safeArea.top + 44}px`
				}
			},
			scrollHeight() {
				return {
					'height': `${this.sysinfo.safeArea.height - 312 - 44}px`
				}
			},
		},
		onNavigationBarButtonTap(e) {
			// console.log('onNavigationBarButtonTap：', e, this.isOpened, this.selectedGroupClient);
			if (this.isOpened === 'left' && this.selectedGroupClient && this.selectedGroupClient.id) {
				uni.$emit('selectedGroupClient', {
					selectedGroupClient: this.selectedGroupClient
				})
				uni.navigateBack({})
				return
			}
			this.isOpened = this.isOpened === 'none' ? 'left' : 'none';
			// #ifdef APP-PLUS  
			let pages = getCurrentPages()
			let page = pages[pages.length - 1]
			let webView = page.$getAppWebview();
			console.log('webView', webView)
			webView.setTitleNViewButtonStyle(0, {
				text: this.isOpened === 'none' ? '选择' : '完成',
			});
			// let titleObj = webView.getStyle().titleNView;
			//  if(!titleObj.buttons){
			// 	 returnl
			//  }
			//  titleObj.buttons[0].text = 'dd';
			//  webView.setStyle({
			// 	 titleNView:titleObj
			//  })
			// #endif
		},
		methods: {
			search() {

			},
			bindPickerChange(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				this.index = e.detail.value
			},
			handleClick(e, content, index) {
				console.log('click当前索引：', e, content, index);
			},
			handleChecked(e, item, index) {
				console.log('当前索引：', e, index);
				this.lists.forEach((cur) => {
					if (cur.id === item.id) {
						cur.checked = !cur.checked
					} else {
						cur.checked = false
					}
				})

				if (item.checked === true) {
					// this.selectedGroupClient.push(item)
					this.selectedGroupClient = item
				} else {
					// const selectIndex = this.selectedGroupClient.findIndex((saleplan)=>{
					// 	return saleplan.id === item.id
					// })
					// this.selectedGroupClient.splice(selectIndex,1)
					this.selectedGroupClient = {}
				}
			},
			nextStep() {
				this.$emit('click', 'orderUpload')
			},
			preStep() {
				uni.switchTab({
					url: `/pages/go-order/go-order`
				})
			},
		}
	}
</script>

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

	page {
		background: #f0f4f5;
	}

	.header-bg {
		height: 284rpx;
		margin-top: -88rpx;
		background: linear-gradient(232deg, #f4e2e2 25%, #faf3f3 98%);
	}

	.lists {
		flex: 1;
		position: relative;
		flex-direction: column;
		background: #f0f4f5;
	}

	.main {
		flex-direction: column;
		margin-top: -164rpx;
		padding: 0 16rpx;
	}

	.middle {
		background-color: #fff;
		border-radius: 16rpx;
		padding: 32rpx 64rpx 40rpx 48rpx;
	}

	.text-block {
		display: flex;
		overflow: hidden;
		height: 96rpx;
		margin-bottom: 14rpx;
		border-bottom: 1px solid #f4f5f6;
	}

	.text-block-last {
		margin-bottom: 0;
		border-bottom: 0;
	}

	.middle-date {
		flex: 2;
		font-size: 28rpx;
		line-height: 96rpx;
		color: #333;
		margin-bottom: 8rpx;
	}

	.middle-date-des {
		flex: 3;
		font-size: 28rpx;
		line-height: 96rpx;
		height: 96rpx;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
		color: #888;
	}

	.picker-year {
		position: relative;
		border-radius: 4px;
		align-items: center;
	}

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

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

	.picker-block {
		flex: 1;
	}

	.icon-arrow {
		position: absolute;
		right: 0;
		top: 16px;
		width: 12rpx;
		height: 20rpx;
		z-index: 10;
	}

	.planout-block-lists {
		display: flex;
		flex-direction: column;
		overflow: hidden;
	}

	.uni-swipe {
		flex: 1;
		margin-bottom: 26rpx;
	}

	::v-deep  .uni-swipe_box {
		flex: 1;
	}

	.swipe-right-block {
		display: flex;
		width: 100rpx;
		justify-content: center;
		align-items: center;
	}

	.swipe-right-block__text {
		width: 52rpx;
		height: 52rpx;
		border-radius: 50%;
		background-color: #fff;
	}

	.swipe-right-block__active {
		width: 52rpx;
		height: 52rpx;
		border-radius: 50%;
		background-color: $wly-primary-color;
	}

	.planout-block {
		display: flex;
		justify-content: space-between;
		height: 84rpx;
		margin-top: 64rpx;
		margin-bottom: 48rpx;
		padding: 0 24rpx;
	}

	.planout-block-item {
		flex: 1;
		width: 750rpx;
	}

	.item-block {
		display: flex;
		justify-content: space-between;
		overflow: hidden;
	}

	.item-block-label {
		font-size: 24rpx;
		color: #888;
	}

	.item-block__label {
		flex: 1;
		text-align: left;
		font-size: 28rpx;
		color: #333;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	.item-block-code {
		padding-bottom: 16rpx;
		border-bottom: 1px solid #f4f5f6;
	}

	.item-block-name {
		padding-top: 24rpx;
		padding-bottom: 8rpx;
	}

	.item-block-label-des {
		flex: 1;
		text-align: left;
		font-size: 24rpx;
		color: #999;
	}

	.item-block__value {
		flex: 1.4;
	}

	.btn {
		flex: 1;
		height: 92rpx;
		background: $wly-primary-color;
		border-radius: 46rpx;
	}

	.btn-text {
		color: #fff;
		font-size: 34rpx;
	}

	.scroll-area {
		overflow: hidden;
	}
</style>
