<template>
	<view class=" goods">

		<view class="u-flex">
			<up-image width="126rpx" height="126rpx" :src="data.pic" :radius="6"></up-image>
			<view class=" u-p-l-16  u-flex u-p-r-16 u-flex-1 u-col-top">
				<view class="u-flex-1">
					<view class="color-333 font-bold" style="word-wrap: break-word;word-break: normal;white-space: normal;">{{data.name}}</view>
					<view class="color-999 u-m-t-20">
						<text class="">排序:</text>
						<text class="u-m-l-10">{{data.sort}}</text>
					</view>
				</view>
				<view class="u-flex" style="flex-shrink: 0;">
					<text class="u-font-28 color-666" @click="changeClick">修改排序</text>
				</view>
			</view>
		</view>

		<view class="u-m-t-24 u-flex u-row-between">
			<view>
				<view class="u-flex">
					<view class="u-m-r-18 color-999">是否启用</view>
					<my-switch v-model="status" @change="statusChange"></my-switch>
				</view>
			</view>
			<view class="u-m-t-24 u-flex u-row-right">
				<view class="btn-default btn" @click="del">删除</view>
				<view class="btn-primary btn u-m-l-38" @click="toEdit">编辑</view>
			</view>
		</view>

	</view>
</template>

<script setup>
	import { computed, ref, watch, watchEffect } from 'vue';
	import mySwitch from '@/components/my-components/my-switch.vue'
	import go from '@/commons/utils/go.js';


	const emits = defineEmits([ 'changeClick', 'del', 'statusChange'])

	const props = defineProps({
		index: {
			type: Number
		},
		data: {
			type: Object,
			default: () => {
				return {
					status: true
				}
			}
		}
	})
	let status = ref(props.data.status)
	watch(() => props.data.status, (newval) => {
		status.value = newval
	})

	function statusChange() {
		console.log(status.value);
		emits('statusChange', {
			...props.data,
			status: status.value
		})
	}

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

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

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

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

	.btn {
		padding: 6rpx 28rpx;
		border-radius: 100rpx;
		font-size: 24rpx;
		border: 1px solid transparent;
	}

	.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;
	}

	.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;
	}

	.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: 28rpx 42rpx;

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

			.skds {
				gap: 10rpx 50rpx;
			}

			.skd {
				padding: 14rpx 40rpx;
				background: #F0F2F5;
				border-radius: 4rpx;
				position: relative;
				color: #666;
				overflow: hidden;

				.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;
				}
			}


		}
	}
</style>