<template>
	<view class="content">
		<view class=" bg-white sticky top-0 z-50">
			<div class="flex items-center">
				<view class="flex-1">
					<wd-search @search="search" @clear="search({ value: '' })" v-model="params.keywords" hide-cancel>
						<template #prefix>
							<wd-popover v-model="popover" mode="menu" :content="menu" @menuclick="changeSearchType">
								<view class="search-type">
									<text>{{ searchType }}</text>
									<wd-icon custom-class="icon-arrow" name="fill-arrow-down"></wd-icon>
								</view>
							</wd-popover>
						</template>
					</wd-search>
				</view>
			</div>
			<wd-tabs @change="(e) => {
				params.coupon_type = e.index
				search({ value: params.keywords })
			}" v-model="params.coupon_type">
				<wd-tab v-for="item in status" :key="item" :title="`${item.content}`"></wd-tab>
			</wd-tabs>
		</view>

		<view class="goodsBox p-2">
			<yList ref="yListRef" :apiObj="couponApi.UserGetList" :params="{ ...params }">
				<template #default="{ list }">
					<view>
						<view v-for="item of list" class="goods">
							<wd-card type="rectangle">
								<template #title>
									<view class="title">

										<view>
											<span class="mr-2">用户：{{ item?.user_info?.nickname }}</span>
										</view>

										<view class="title-tip">
											<span style="font-size: 24rpx;margin-left: 8px;">券ID：{{ item.coupon?.id }}</span>
										</view>
									</view>
								</template>

								<view class="bg-gray-50 p-2 mb-2 flex justify-between" style="font-size: 22rpx;">
									<view>券：<text class="text-black">{{ item.coupon?.name || 0 }}</text></view>
								</view>

								<view class="bg-gray-50 p-2 mb-2 flex justify-between" style="font-size: 22rpx;">
									<view>满减金额：<text class="text-red-600">￥ {{ item.coupon?.full_price || 0 }}</text></view>
									<view>优惠金额：<text class="text-red-600">￥ {{ item.coupon?.price || 0 }}</text></view>
								</view>

								<template #footer>
									<!-- <view class="bg-gray-50 p-2 mb-2.5 flex justify-between" style="font-size: 22rpx;">
										<view>
											售后状态:
											
										</view>
									</view> -->

									<view class="flex justify-between items-center">
										<!-- <view class="font-bold">实付: {{ item.pay_price }} 元</view> -->
										<view>
											<wd-button :round="false" size="small"
												:type="['warning', 'success', 'warning', 'success', 'info'][item.coupon.coupon_type]">
												<div>{{ ["优惠券", "商品", "分类", "当面付"][item.coupon.coupon_type] }} · 可用</div>
											</wd-button>
										</view>
										<view class="flex-1 flex justify-end">

											<!-- <view v-if="item.apply_cancel === 1" class="mr-2">
												<wd-button type="error" @click="orderApproval(item)" size="small">退款</wd-button>
											</view>

											<view class="mr-2">
												<wd-button @click="printing(item)" size="small">小票打印</wd-button>
											</view>
											<view class="mr-2">
												<wd-button @click="orderNotes(item)" size="small">备注</wd-button>
											</view>
											<view v-if="item.status == 1" class="">
												<wd-button @click="shipments(item)" size="small">发货</wd-button>
											</view> -->

										</view>

									</view>
								</template>
							</wd-card>
						</view>
					</view>
				</template>
			</yList>
		</view>
		<wd-toast />

	</view>
</template>

<script setup>
import utils from '@/utils/utils.js';
import couponApi from '@/api/store/coupon.js';
import yList from "/components/yList/index.vue";
import { useMessage } from '@/uni_modules/wot-design-uni';
import { useToast } from '@/uni_modules/wot-design-uni';
import { ref } from 'vue';

const message = useMessage('wd-message-box-slot');
const toast = useToast();

const params = ref({
	keywords: "",
	coupon_type: 0,
});

const yListRef = ref(null);

const search = ({ value }) => {
	yListRef.value.upData({
		keywords: value,
		coupon_type: params.value.coupon_type
	});
};

const searchType = ref('券名');
const popover = ref(false);

const status = ref([
	{ content: '全部' },
	{ content: '商品' },
	{ content: '分类' },
	{ content: '当面付' },
]);

const menu = ref([
	{ content: '券名' },
	{ content: '券金额' },
]);

/**
 * 切换搜索类型
 * @param {Object} item - 切换的项
 */
function changeSearchType({ item, index }) {
	if (searchType.value == '券名') {
		yListRef.value.upData({
			name: params.value.keywords,
		});
	} else if (searchType.value == '券金额') {
		yListRef.value.upData({
			price: params.value.keywords
		});
	} else {
		yListRef.value.upData({});
	}
}
</script>

<style lang="scss" scoped>
.search-type {
	position: relative;
	height: 30px;
	line-height: 30px;
	padding: 0 8px 0 10px;
	font-size: 22rpx;
	color: rgba(0, 0, 0, .45);
}

.search-type::after {
	position: absolute;
	content: '';
	width: 1px;
	right: 0;
	top: 5px;
	bottom: 5px;
	background: rgba(0, 0, 0, 0.25);
}

.search-type {
	:deep(.icon-arrow) {
		display: inline-block;
		font-size: 20px;
		vertical-align: middle;
	}
}

.goodsBox {

	.content,
	.title {
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		align-items: center;
	}

	.content {
		justify-content: flex-start;
	}

	.title {
		justify-content: space-between;
	}

	.title-tip {
		color: rgba(0, 0, 0, 0.25);
		font-size: 12px;
	}
}
</style>
