<template>
	<view>
		<template v-if="isBind">
			<view class="goods">

				<view class="u-flex u-row-between">
					<view class="u-flex">
						<view class="color-333">
							<text class="">排序</text>
							<text class="u-m-l-20">{{data.sort}}</text>
						</view>
						<view class="color-333 u-m-l-42 u-flex">
							<text class="stock u-m-l-4">库存:{{data.stockNumber}}</text>
						</view>
					</view>
				</view>


				<view class="u-m-t-32 u-flex u-col-top u-relative">
					<view v-if="props.showChecked">
						<label class="radio">
							<radio :color="ColorMain" style="transform: scale(0.7);" @click="radioClick"
								:checked="props.data.checked" /><text></text>
						</label>
					</view>
					<view class="img">
						<up--image :width="63" :height="63" :radius="3" :src="data.coverImg"></up--image>
					</view>
					<view class="w-full info u-p-l-30">
						<view class=" color-333  u-flex u-row-between">
							<view class="u-flex">
								<text class="u-m-r-24">{{data.name}}</text>
							</view>
							<view class="u-font-32">
								<text v-if="data.typeEnum=='单规格'">¥</text>
								<text>{{data.lowPrice}}</text>
							</view>
						</view>
						<view class="u-flex  u-m-t-10 u-row-right">
							<view class="btn-default btn" @tap="del">删除</view>
						</view>
					</view>
				</view>

			</view>
		</template>
		<template v-else>
			<view class=" u-flex  u-p-l-30 u-p-r-30  u-p-t-16 u-p-b-16" @click="goodsClick">
				<my-radio disabled @click.stop="goodsClick" :modelValue="data.checked"></my-radio>
				<view class="u-flex u-m-l-32">
					<text class="">{{data.name}}</text>
				</view>
			</view>
		</template>
	</view>

</template>

<script setup>
	import {
		ref,
		watch,
		watchEffect
	} from 'vue';
	import {
		$goodsIsHot,
		$tbProskuConV2,
		$updateProductData
	} from '@/http/yskApi/goods.js'
	import mySwitch from '@/components/my-components/my-switch.vue'
	import go from '@/commons/utils/go.js';
	import {
		ColorMain
	} from '@/commons/color.js'
	const emits = defineEmits(['goodsClick', 'changeClick', 'xiajia', 'del', 'changePrice', 'baosun', 'guigeClick',
		'editStock'
	])
	const props = defineProps({
		isBind: {
			type: Boolean,
			default: false
		},
		index: {
			type: Number
		},
		data: {
			type: Object,
			default: () => {
				return {
					checked:false,
				}
			}
		},
		showChecked: {
			type: Boolean,
			default: false
		},
		showDetail: {
			type: Boolean,
			default: false
		}
	})

	function goodsClick(){
		emits('goodsClick',props.index)
	}

	async function upDateGoods(par) {
		const res = await $updateProductData([{
			id: props.data.id,
			isSku: 0,
			shopId: uni.getStorageSync('shopId'),
			...par
		}])
		uni.showToast({
			title: '修改成功',
			icon: 'none'
		})
	}






	function radioClick() {
		console.log(props.index);
		emits('radioClick', props.index)
	}

	function changeClick() {
		emits('changeClick', props.index)
	}

	function xiajia() {
		emits('xiajia', props.index)
	}

	function del() {
		emits('del', props.index)
	}

	function changePrice() {
		emits('changePrice', props.index)
	}

	function baosun() {
		emits('baosun', props.index)
	}

	function guigeClick(guigeIndex) {
		emits('guigeClick', props.index, guigeIndex)
	}

	function editStock() {
		emits('editStock', props.index)
	}
	//携带参数type edit跳转到商品添加页面，编辑与添加同一页面，根据type值来判断
	function toEdit() {
		go.to('PAGES_PRODUCT_ADD', {
			type: 'edit',
			productId: props.data.id
		})
	}
</script>

<style lang="scss" scoped>
	$imgSize: 126rpx;
	$price-color: #F02C45;

	.btn {
		padding: 6rpx 28rpx;
		border-radius: 100rpx;
		border: 2rpx solid transparent;
	}

	.gap-10 {
		gap: 10rpx;
	}

	.btn-primary {
		border-color: $my-main-color;
		color: $my-main-color;
	}

	.btn-default {
		border-color: #999;
		color: #999;
	}

	.price {
		color: $price-color;
	}

	.h-100 {
		height: $imgSize;
	}

	.img {
		width: $imgSize;
		height: $imgSize;
	}

	.info-p-l {
		padding-left: 71px;
	}

	.icon-arrow-right {
		width: 32rpx;
		height: 32rpx;
	}

	.stock {
		// padding-right: 46rpx;
		position: relative;
	}

	.stock::after {
		// content: '';
		// position: absolute;
		// right: 10rpx;
		// top: 50%;
		// transform: translateY(-50%);
		// display: block;
		// width: 16rpx;
		// border: 2rpx solid #333333;
	}

	.color-red {
		color: #F0465B;
	}

	.goods {
		border-radius: 10rpx 10rpx 10rpx 10rpx;
		background-color: #fff;
		padding: 24rpx 28rpx 16rpx 28rpx;
		font-size: 28rpx;

		.skus {
			background: #F9F9F9;
			border-radius: 14rpx 14rpx 14rpx 14rpx;
			padding: 20rpx;

			.sku {
				color: #000;
				font-weight: 700;
				padding: 6rpx 40rpx;
			}

			.skds {
				gap: 10rpx 50rpx;
			}
		}
	}

	.skd {
		padding: 14rpx 40rpx 14rpx 20rpx;
		background: #F0F2F5;
		border-radius: 4rpx;
		position: relative;
		color: #666;
		overflow: hidden;
		margin-bottom: 10rpx;
		font-size: 24rpx;

		.tag {
			position: absolute;
			right: 0;
			top: 0;
			font-size: 12rpx;
			right: 0;
			padding: 2rpx 4rpx;
			border-radius: 0rpx 4rpx 4rpx 4rpx;
		}

		.tag-primary {
			background-color: $my-main-color;
			color: #fff;
		}

		.tag-gray {
			background-color: rgb(144, 147, 153);
			color: #fff;
		}
	}
</style>