<script lang="ts" setup>
/**
 * @Name: DataTableSlot.vue
 * @Description: 商品列表-单元格插槽
 * @Author: Cheney
 */

import { useCountryInfoStore } from '/@/stores/countryInfo';
import { Message, Operation } from '@element-plus/icons-vue';
import { getTagType } from '/@/utils/useTagColor';
import PermissionButton from '/@/components/PermissionButton/index.vue';
import ProductInfo from '/@/views/product-manage/product-list/component/ProductInfo.vue';


const props = defineProps<{
  row: any,
  field: any
}>();
const { row, field } = props;

const emit = defineEmits([ 'edit-row', 'handle-notice', 'handle-monitor' ]);

const countryInfoStore = useCountryInfoStore();
const country = countryInfoStore.Countries.find(c => c.code == row.country_code);
const color = country ? country.color : '#3875F6';

const statusText = row.status === 1 ? '在售' : '停售';
const statusType = row.status === 1 ? 'success' : 'info';

function handleEdit() {
  emit('edit-row', row);
}

function handleNotice() {
  emit('handle-notice', row);
}

function handleMonitor() {
  emit('handle-monitor', row);
}
</script>

<template>
  <div class="font-medium">
    <div v-if="field === 'is_monitor'">
      <el-switch v-model=row.is_monitor @change="handleMonitor" />
    </div>
    <div v-else-if="field === 'product_info'">
      <ProductInfo :img-width="50" :item="row" />
    </div>
    <div v-else-if="field === 'country_code'">
      <el-tag :disable-transitions="true" :style="{ color: color, borderColor: color }" effect="plain" round>
        {{ country ? country.name : '-' }}
      </el-tag>
    </div>
    <div v-else-if="field === 'shop_name'">
      <el-tag v-if="row.shop_name" :disable-transitions="true" :type=getTagType(row.shop_name)>
        {{ row.shop_name }}
      </el-tag>
      <div v-else>-</div>
    </div>
    <div v-else-if="field === 'tag'">
      <el-tag v-if="row.tag" :disable-transitions="true" :type=getTagType(row.tag)>
        {{ row.tag }}
      </el-tag>
      <div v-else>-</div>
    </div>
    <div v-else-if="field === 'brand'">
      <el-tag v-if="row.brand" :disable-transitions="true" :type=getTagType(row.brand) effect="plain" round>
        {{ row.brand }}
      </el-tag>
      <div v-else>-</div>
    </div>
    <div v-else-if="field === 'price_info'">
      <div v-if="row.price >= 0" class="font-medium">
        <p>现 价：{{ row.currency_code + '‎' + row.price }}</p>
        <p>折 扣：{{ row.discount > 0 ? row.discount + '%' : '-' }}</p>
        <p>优惠劵：{{ !row || row.coupon <= 0 ? '-' : row.currency_code + '‎' + row.coupon }}</p>
      </div>
    </div>
    <div v-else-if="field === 'show_price'">
      <div class="font-medium">
        <p>展示价格：{{ row.show_price ? row.currency_code + row.show_price : '-' }}</p>
        <p>平时活动售价：{{ row.activity_price ? row.currency_code + row.activity_price : '-' }}</p>
        <p>最低活动售价：{{ row.minimum_price ? row.currency_code + row.minimum_price : '-' }}</p>
      </div>
    </div>
    <div v-else-if="field === 'status'">
      <el-tag :disable-transitions="true" :type=statusType>
        {{ statusText }}
      </el-tag>
    </div>
    <div v-else-if="field === 'operate'">
      <div class="flex justify-center gap-2">
        <PermissionButton circle plain type="warning" @click="handleEdit">
          <el-icon>
            <Operation />
          </el-icon>
        </PermissionButton>
        <PermissionButton circle plain type="info" @click="handleNotice">
          <el-icon>
            <Message />
          </el-icon>
        </PermissionButton>
      </div>
    </div>
    <div v-else>
      {{ row[field] || '-' }}
    </div>
  </div>
</template>

<style scoped>

</style>
