<template>
  <jx-empty title="暂无待配商品" v-if="skuList.length == 0" />
  <view class="good-list" v-else>
    <view
      class="good-item"
      @click="toGood(item)"
      v-for="(item, index) in skuList"
      :key="index"
    >
      <view class="left">
        {{ index + 1 }}
      </view>
      <view class="right">
        <view class="good-name">
          <image
            class="img"
            :src="item.img"
            mode="scaleToFill"
            @tap.stop="previewImage(item.img)"
          />
          <view class="name">{{ item.name }}</view>
        </view>
        <view class="good-info">
          <view class="good-count">数量: {{ item.sumCount }}</view>
          <view class="good-weight"
            >重量: {{ item.sumWeight }}g({{ item.sumWeight / 500 }}斤)</view
          >
        </view>
      </view>
    </view>
  </view>

  <!-- 公共组件 -->
  <jx-loading />
</template>

<script lang="ts" setup>
import merchant from '@/api/https/merchant'
import useGlobalFunc from '@/composables/useGlobalFunc'
import { getStorage } from '@/utils/storage'
import toast from '@/utils/toast'
import { onLoad } from '@dcloudio/uni-app'
import { ref } from 'vue'
const { previewImage } = useGlobalFunc()

/**
 * 获取待配商品
 */
onLoad(async () => {
  await GetOrdersAccept()
})
interface SkuListType {
  img: string
  name: string
  sumCount: number
  item: number
  sumWeight: number
  id: number
  nameID: number
  specQuality: string
  specUnit: string
}
const skuList = ref<Array<SkuListType>>([
  {
    img: '',
    name: '',
    sumCount: 0,
    item: 0,
    sumWeight: 0,
    id: 0,
    nameID: 0,
    specQuality: '',
    specUnit: '',
  },
])

async function GetOrdersAccept() {
  let data = {
    storeID: getStorage('storeID'),
  }
  let waitGoodsRes = await merchant.get_order_ders_accept(data)
  if (waitGoodsRes.code == 0) {
    if (waitGoodsRes.data == null) {
      skuList.value = []
    } else {
      skuList.value = waitGoodsRes.data.map((item: SkuListType) => ({
        name: item.name + item.specQuality + item.specUnit,
        sumCount: item.sumCount,
        sumWeight: item.sumWeight,
        id: item.id,
        nameID: item.nameID,
        img: item.img,
      }))
    }
  } else {
    toast('待配商品数据异常')
  }
}

/**
 * 商品详情
 */
function toGood(item: SkuListType) {
  uni.navigateTo({
    url: `/subPages/merchantChild/waitGoodsDetaile/waitGoodsDetaile?nameID=${item.nameID}&skuID=${item.id}`,
  })
}
</script>

<style lang="scss" scoped>
@import './waitGoods.scss';
</style>