<template>
  <div
    v-for="item in row.productList?.slice(
      0,
      row.moreable || isDetail ? row.productList.length : 2,
    )"
    :key="item.id"
    class="order-list-expand_item"
  >
    <div class="order-list-expand_item_content">
      <div class="order-list-expand_item_img">
        <!-- <img :src="item.variantImage" style="width: 100%; height: 100%" /> -->
        <ImageView :src="item.variantImage" width="98px" height="98px" />
      </div>
      <div class="order-list-expand_item_info">
        <div
          :title="item?.productName || '--'"
          class="order-list-expand_item_info_title"
          style="font-weight: bold"
        >
          <span class="order-list-expand_item_label">商品名:</span>
          <div class="order-list-expand_item_value">
            {{ item?.productName || '--' }}&emsp;
            <img
              v-show="
                status == 4 &&
                item?.num !== undefined &&
                item?.shipmentNum !== undefined &&
                item?.notPassNum !== undefined &&
                (item.num || 0) -
                  ((item.shipmentNum || 0) - (item.notPassNum || 0)) >
                  0 &&
                item.notPassNum > 0
              "
              src="@/assets/images/jiaji.svg"
              alt=""
              width="24"
            />
          </div>
        </div>
        <div
          :title="item.baseSku || ''"
          class="order-list-expand_item_info_title"
        >
          <span class="order-list-expand_item_label">Base SKU:</span>
          <span class="order-list-expand_item_value"
            >{{ item.baseSku || '--'
            }}<el-icon class="icon" @click="copy(item.baseSku || '')"
              ><DocumentCopy /></el-icon
          ></span>
        </div>
        <div
          :title="item.variantSku || ''"
          class="order-list-expand_item_info_title"
        >
          <span class="order-list-expand_item_label">Variant SKU:</span>
          <span class="order-list-expand_item_value"
            >{{ item.variantSku || '--' }}
            <el-icon class="icon" @click="copy(item.variantSku || '')"
              ><DocumentCopy
            /></el-icon>
          </span>
        </div>
        <div
          :title="item.shopNumber || ''"
          class="order-list-expand_item_info_title"
        >
          <span class="order-list-expand_item_label">店铺单号:</span>
          <span class="order-list-expand_item_value"
            >{{ item.shopNumber || '--' }}
            <el-icon class="icon" @click="copy(item.shopNumber || '')"
              ><DocumentCopy
            /></el-icon>
          </span>
        </div>
        <div
          :title="
            isPod ? item.factorySubOrderNumber || '' : item.subOrderNumber || ''
          "
          class="order-list-expand_item_info_title"
        >
          <span class="order-list-expand_item_label">生产单号:</span>
          <span class="order-list-expand_item_value"
            >{{
              item.factorySubOrderNumber
            }}<el-icon
              class="icon"
              @click="
                copy(
                  isPod
                    ? item.factorySubOrderNumber || ''
                    : item.subOrderNumber || '',
                )
              "
              ><DocumentCopy
            /></el-icon>
          </span>
        </div>
        <div class="order-list-expand_item_info_title">
          <span class="order-list-expand_item_label">发货状态:</span>
          <span
            v-if="(item.shipmentNum || 0) - (item.notPassNum || 0) === item.num"
            class="order-list-expand_item_value"
          >
            <el-tag effect="dark" type="success"> 已发货 </el-tag>
          </span>
          <span
            v-if="
              item.num !== (item.shipmentNum || 0) - (item.notPassNum || 0) &&
              (item.shipmentNum || 0) > 0
            "
            class="order-list-expand_item_value"
          >
            <el-tag effect="dark"> 部分发货 </el-tag>
          </span>
          <span
            v-if="item.shipmentNum === 0"
            class="order-list-expand_item_value"
          >
            <el-tag effect="dark" type="danger"> 未发货 </el-tag>
          </span>
        </div>
        <div
          v-if="!isPod"
          :title="item.material || ''"
          class="order-list-expand_item_info_title"
        >
          <span class="order-list-expand_item_label">工艺:</span>
          <span class="order-list-expand_item_value"
            >{{ item.processName || '--' }}
          </span>
        </div>
        <div
          :title="item.remark || ''"
          class="order-list-expand_item_info_title"
        >
          <span class="order-list-expand_item_label">备注:</span>
          <span class="order-list-expand_item_value"
            >{{ item.remark || '--' }}
          </span>
        </div>
      </div>
      <div class="order-list-expand_item_price">
        <div class="order-list-expand_item_info_title">
          <span class="order-list-expand_item_label">单价:</span>
          <span class="order-list-expand_item_value">{{
            item.price || '--'
          }}</span>
        </div>
        <div class="order-list-expand_item_info_title font-bold">
          <span class="order-list-expand_item_label">购买数:</span>
          <span class="order-list-expand_item_value">{{ item.num || 0 }}</span>
        </div>
        <div class="order-list-expand_item_info_title">
          <span class="order-list-expand_item_label">已发数:</span>
          <span class="order-list-expand_item_value">{{
            item.shipmentNum || 0
          }}</span>
        </div>
        <div class="order-list-expand_item_info_title">
          <span class="order-list-expand_item_label">未发数:</span>
          <span v-if="!isPod" class="order-list-expand_item_value">{{
            (item.num || 0) - ((item.shipmentNum || 0) - (item.notPassNum || 0))
          }}</span>
          <span v-else class="order-list-expand_item_value">{{
            (item.num || 0) - (item.shipmentNum || 0)
          }}</span>
        </div>
        <div v-if="isPod" class="order-list-expand_item_info_title">
          <span class="order-list-expand_item_label">工艺:</span>
          <span class="order-list-expand_item_value">{{
            item?.processName || '--'
          }}</span>
        </div>
        <div v-if="isPod" class="order-list-expand_item_info_title">
          <span class="order-list-expand_item_label">工艺简称:</span>
          <span class="order-list-expand_item_value">{{
            item?.process || '--'
          }}</span>
        </div>
      </div>
    </div>
    <div class="operation">
      <slot name="operation" :product-item="item"></slot>
    </div>
  </div>
</template>
<script setup lang="ts">
import ImageView from '@/components/ImageView.vue'
import { DocumentCopy } from '@element-plus/icons-vue'
import { OrderData } from '@/types/api/order'
import { PropType } from 'vue'
defineProps({
  row: {
    type: Object as PropType<OrderData>,
    default: () => {},
  },
  isDetail: {
    type: Boolean,
    default: false,
  },
  status: {
    type: [Number, String],
  },
  isPod: {
    type: Boolean,
    default: false,
  },
})

const copy = (text: string) => {
  navigator.clipboard.writeText(text)
  ElMessage.success('复制成功')
}
</script>
<style lang="scss" scoped>
.order-list-expand_item {
  border-bottom: 1px solid #eee;
  padding: 20px;
  & .operation {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
  }
}
.order-list-expand_item_content {
  display: flex;
}
.order-list-expand_item:last-child {
  border-bottom: 0;
}

.order-list-expand_item_img {
  width: 100px;
  height: 100px;
  margin-right: 20px;
  border: 1px solid #eee;
}

.order-list-expand_item_info {
  flex: 1;
  margin-right: 20px;
}
.order-list-expand_item_price {
  width: 180px;
}

.order-list-expand_item_info_title {
  line-height: 26px;
  display: flex;
  align-items: center;
}

.order-list-expand_item_label {
  margin-right: 6px;
}
.order-list-expand_item_value {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: center;
}
</style>
