<template>
	<view>
		<view class="keyword-view clearfix">
			<u-search disabled @custom="clearValue" @search="searchConfirm()" action-text="重置" :clearabled="true"
				placeholder="请选择客户" v-model="customer_name" @click="goPage('/pagesT/customer/selCustomer')"></u-search>
		</view>
		<view class="logs-ul">
			<view class="logs-li clearfix" v-for="(item, index) in order_list" :key="index">
				<view class="clearfix logs-goods">
					<view class="float_left goods-img">
						<image :src="item.goodsImages" mode="aspectFill"></image>
					</view>
					<view class="float_left goods-info">
						<view class="goods-name ellipsis">{{ item.goodsName }}</view>
						<view class="date-time">
							{{ item.unitName }};
							<text v-for="(sku, skuI) in item.specGroup" :key="skuI">{{ sku.specValueName }};</text>
						</view>
						<view class="other-info">
							<view class="info-li">单价:{{ $utils.formattedNumber(item.price) }}</view>
							<view class="info-li">购买:{{ item.buyNum }}{{ item.unitName }}</view>
							<view class="info-li">发货:{{ $utils.formatNub(item.outNum) }}{{ item.unitName }}</view>
						</view>
					</view>
					<view class="price">{{ $utils.formattedNumber(item.totalMoney) }}</view>
				</view>
				<view class="bottom clearfix">
					<view class="float_left">
						<view class="cutomer ellipsis">{{item.customerName}}</view>
					</view>
					<view class="float_right">
						<view class="date">{{ $u.timeFormat(item.createTime, 'yyyy-mm-dd hh:MM:ss') }}</view>
					</view>
				</view>
			</view>
			<u-loadmore :status="load_status" />
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				load_status: 'nomore',
				page: 1,
				pageSize: 10,
				total: 0,
				order_list: [],
				customer_name: '',
				customer_id: 0,
				customerData: []
			};
		},
		watch: {
			customerData(val) {
				if (val) {
					this.customer_name = val.name;
					this.customer_id = val.userCenterId;
					this.page = 1;
					this.searchCustomerBuyLog();
				}
			}
		},
		onLoad() {
			this.searchCustomerBuyLog();
		},
		onPullDownRefresh() {
			this.page = 1;
			this.searchCustomerBuyLog();
		},
		onReachBottom() {
			if (this.total / this.pageSize > this.page) {
				this.page += 1;
				this.searchCustomerBuyLog();
			}
		},
		methods: {
			clearValue() {
				this.customer_name = '';
				this.customer_id = 0;
				this.page = 1;
				this.searchCustomerBuyLog();
			},
			searchConfirm(){
				this.page = 1;
				this.searchCustomerBuyLog();
			},
			searchCustomerBuyLog() {
				let params = {
					page: this.page,
					pageSize: this.pageSize,
					userCenterId: this.customer_id
				};
				this.$u.api.searchCustomerBuyLog(params).then(res => {
					if (this.page === 1) {
						this.order_list = res.data;
					} else {
						this.order_list = this.order_list.concat(res.data);
					}
					this.load_status = this.$utils.loadStatus(this.page, this.pageSize, res.pageTotal);
					this.total = res.pageTotal;
				});
			}
		}
	};
</script>

<style lang="scss" scoped>
	.keyword-view {
		position: fixed;
		width: 100%;
		top: 0;
		left: 0;
		padding: 20rpx 24rpx;
		background-color: #ffffff;
		z-index: 9;

		.float_left {
			width: 640rpx;
		}

		.float_right {
			line-height: 64rpx;
			width: 50rpx;
			text-align: center;
			color: #666666;
		}
	}

	.logs-ul {
		padding-top: 100rpx;

		.logs-li {
			width: 710rpx;
			margin: 20rpx auto;
			background-color: #ffffff;
			border-radius: 20rpx;
			padding: 24rpx;

			.logs-goods {
				position: relative;

				.price {
					position: absolute;
					color: $uni-color-error;
					top: 50%;
					right: 0;
					transform: translateY(-50%);
				}
			}

			.goods-img {
				position: relative;
				width: 120rpx;
				height: 120rpx;
				border-radius: 20rpx;
				overflow: hidden;
				margin-right: 20rpx;
				border: 1px solid #f5f5f5;

				image {
					width: 100%;
					height: 100%;
					display: block;
				}
			}

			.goods-info {
				width: 520rpx;

				.goods-name {
					font-weight: bold;
				}

				.date-time {
					font-size: 22rpx;
				}

				.other-info {
					padding-top: 10rpx;
					display: flex;
					font-size: 22rpx;

					.info-li {
						flex: 3;
						display: inline-block;
						color: #6c6c6c;
					}
				}
			}
		}

		.bottom {
			padding-top: 24rpx;
			border-top: 1px solid #eeeeee;
			margin-top: 24rpx;

			.float_left {
				width: 320rpx;

				.cutomer {
					font-weight: bold;
					font-size: 26rpx;
					padding-bottom: 6rpx;
				}


			}

			.float_right {
				.date {
					font-size: 22rpx;
					color: #666666;
				}

				.btn-li {
					display: inline-block;
					border-radius: 10rpx;
					margin-left: 16rpx;
					width: 140rpx;
					line-height: 54rpx;
					font-size: 24rpx;
					text-align: center;
					border: 1px solid $uni-color-primary;
					color: $uni-color-primary;

					&:last-child {
						background-color: $uni-color-primary;
						color: #ffffff;
					}
				}
			}
		}
	}
</style>
