<template>
	<uni-swipe-action-item :right-options="rightOptions" @click.stop="swipeClick">
		<view class="receiving-info" @click.stop="handleClick">
			<view class="receiving-info-content">
				<text class="receiving-info-content-left">箱码</text>
				<text class="receiving-info-content-right">{{ detail.productCode }}</text>
			</view>
			<view class="receiving-info-content">
				<text class="receiving-info-content-left">状态</text>
				<text class="receiving-info-content-right" :style="{ color: statusColor }">{{ takeStatusLabel }}</text>
			</view>
		</view>
	</uni-swipe-action-item>
</template>

<script>
import { statusColorOptions } from '@/common/optinos/mine/received.js';
import { takeDetailStatusOptions } from '@/common/optinos/mine/inventory.js';
import { showModal,myFilter } from '@/common/common.js';
export default {
	name: 'ReceivingInfo',
	props: {
		detail: {
			type: Object,
			default: () => {}
		},
		/* 品牌类型 */
		options: {
			type: Array | null,
			default: () => []
		}
	},
	data() {
		return {
			takeDetailStatusOptions,
			statusColorOptions,
			rightOptions: [
				{
					text: '取消',
					style: {
						backgroundColor: '#007aff'
					}
				},
				{
					text: '删除',
					style: {
						backgroundColor: '#dd524d'
					}
				}
			]
		};
	},
	computed: {
		statusColor() {
			return this.statusColorOptions[this.takeStatusLabel] || '';
		},
		takeStatusLabel(){
			return myFilter(this.detail.status, this.takeDetailStatusOptions);
		},
		brandLabel() {
			return myFilter(this.detail.brand, this.options);
		}
	},
	created() {},
	methods: {
		/*  index 为 当前所在的下标*/
		/*  index1 为 按钮的下标*/
		swipeClick(e) {
			let { text } = e.content;
			console.log('点击了' + (e.position === 'left' ? '左侧' : '右侧') + e.content.text + '按钮');
			if (e.position === 'right' && text === '删除') {
				this.openDelete();
			}
		},

		handleClick() {
			this.$emit('handleClick', this.detail.detailId);
		},
		openDelete(index) {
			showModal({
				content: '是否删除该数据？',
				success: res => {
					if (res.confirm) {
						this.$emit('handleDelete', this.detail.detailId);
					}
				}
			});
		}
	}
};
</script>

<style lang="scss" scoped>
.receiving-info {
	background-color: #ffffff;
	border-radius: 12rpx;
	padding: 20rpx 30rpx;
	// margin-bottom: 20rpx;
	font-size: 24rpx;
	color: #666666;
	.hover-class {
		background-color: #dddddd;
	}
	&-content {
		display: flex;
		justify-content: space-between;
		line-height: 36rpx;
		margin-bottom: 12rpx;
		&:last-child {
			margin-bottom: 0;
		}
		&-left {
			width: 100rpx;
		}
		&-right {
			text-align: right;
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
			width: 80%;
		}
	}
}
</style>
