<template>
  <div
    v-for="item in row.detailList?.slice(
      0,
      row.moreable || isDetail ? row.detailList.length : 2,
    )"
    :key="item.id"
    class="order-list-expand_item"
  >
    <div class="order-list-expand_item_img">
      <img :src="item.variantImage" style="width: 100%; height: 100%" />
    </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>
        <span class="order-list-expand_item_value">{{
          item.productName || '--'
        }}</span>
      </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="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.material || '--' }}
        </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.shopNumber || '&#45;&#45;' }}-->
      <!--          <el-icon class="icon" @click="copy(item.shopNumber || '')"-->
      <!--            ><DocumentCopy-->
      <!--          /></el-icon>-->
      <!--        </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.subOrderNumber || '&#45;&#45;'-->
      <!--          }}<el-icon class="icon" @click="copy(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>
    <div class="order-list-expand_item_price">
      <div
        :title="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.subOrderNumber || '--'
        }}</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.factorySubOrderNumber  || '&#45;&#45;'}}</span>-->
      <!--      </div>-->
      <div
        :title="String(item.shipmentNum || 0)"
        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 class="order-list-expand_item_value">{{-->
      <!--          (item.num || 0) - ((item.shipmentNum || 0) - (item.notPassNum || 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) - -->
      <!--          ((item.passNum || 0) + (item.notPassNum || 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.passNum || 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.notPassNum || 0-->
      <!--        }}</span>-->
      <!--      </div>-->
      <div
        v-if="
          (status === 3 || status === 4 || status === 2) &&
          (item.shipmentNum === 0 ||
            item.num !== (item.shipmentNum || 0) - (item.notPassNum || 0))
        "
        class="order-list-expand_item_info_title"
      >
        <el-button
          type="success"
          size="small"
          @click="downloadManuscriptBySubOrder(item)"
          >下载稿件</el-button
        >
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
import { DocumentCopy } from '@element-plus/icons-vue'
import { filePath } from '@/api/axios'
import { downloadOrder } from '@/api/order'
import { OrderData, ProductList } from '@/types/api/order'
import { PropType } from 'vue'

defineProps({
  row: {
    type: Object as PropType<OrderData>,
    default: () => {},
  },
  isDetail: {
    type: Boolean,
    default: false,
  },
  status: {
    type: Number,
  },
})
const downloadManuscriptBySubOrder = async (item: ProductList) => {
  try {
    const res = await downloadOrder(item.id)
    window.open(filePath + res.message)
  } catch (e) {
    // showError(e)
  }
}
const copy = (text: string) => {
  navigator.clipboard.writeText(text)
  ElMessage.success('复制成功')
}
</script>
<style lang="scss" scoped>
.order-list-expand_item {
  display: flex;
  border-bottom: 1px solid #eee;
  padding: 20px;
}

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

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