<!--
 * @Author: ISFP_T 68358856@qq.com
 * @Date: 2026-02-25 10:02:44
 * @LastEditors: ISFP_T 68358856@qq.com
 * @LastEditTime: 2026-03-04 10:22:25
 * @FilePath: \chef-link-uniapp\src\pages\home\components\tabbar-home\components\food-box\index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<script setup lang="ts">
// @ts-ignore - Vue SFC default export is provided by tooling
import Collection from "@/components/collection/index.vue";
import {appCollectCollectPost} from "@/service";
import {CollectionType} from "@/constant/enums";
const { t } = useI18n();
type FoodBoxItem = {
  id: number | string;
  merchantId?: string;
  isCollect?: boolean;
  dishImage?: string;
  logo?: string;
  dishName?: string;
  merchantName?: string;
  originalPrice?: string | number;
  [key: string]: any;
};
const props = defineProps<{
  item: FoodBoxItem;
}>();

function handleClickFood() {
  // uni.navigateTo({
  //   url: '/pages-store/pages/store/index?id=' + props.item.id
  // })
  let merchantId = ''
if(props.item.merchantId){
  merchantId = props.item.merchantId
  uni.navigateTo({
    url: '/pages-store/pages/store/dishes?id=' +props.item.id + '&storeId=' + props.item.merchantId,
  })
}else{
   uni.navigateTo({
    url: '/pages-store/pages/store/index?id=' + props.item.id
  })
}
  
}

function handleCollectionChange(value: boolean) {
  const isDish = !!props.item?.merchantId;
  appCollectCollectPost({
    body: {
      targetId: String(props.item.id),
      targetType: isDish ? CollectionType.DISH : CollectionType.STORE
    }
  }).then(res=> {
    props.item.isCollect = value;
  }).catch(err=> {
    props.item.isCollect = !value;
  })
}
</script>
<template>
  <view @click="handleClickFood" class="mb-52rpx">
    <image
        :src="item?.dishImage?.split(',')[0]||item?.logo"
      mode="aspectFill"
      class="w-100% h-400rpx rounded-24rpx bg-common"
    ></image>
    <view class="flex justify-between items-start mt-14rpx">
      <view>
        <text class="text-30rpx lh-30rpx text-#333 font-500 line-clamp-1"
          >{{ item?.dishName||item?.merchantName }}</text
        >
        <!-- <view v-if="+item.deliveryService === 1" class="text-#CE7138 text-24rpx lh-24rpx mt-12rpx">${{ item.deliveryFee }} {{ t('pages.home.deliveryFee') }}</view> -->
        <view class="text-24rpx lh-24rpx flex items-center mt-12rpx" v-if="item?.originalPrice">
          
          <image
            src="@img/chef/124.png"
            class="w-24rpx h-24rpx mx-4rpx mt-2rpx"
          ></image>
          <text class="text-#333 font-500">$US{{ item?.originalPrice }}</text>
          <!-- <text class="text-#7D7D7D">({{ item.commentCount }}) • {{ item.deliveryTime }}{{ t('common.minutes') }}</text> -->
        </view>
      </view>
      <collection :is-collected="item.isCollect" @collection-change="handleCollectionChange" />
    </view>
  </view>
</template>
