<template>
  <view>
    <view class="card">
      <view class="text-[#7A7A7A]">订单号：{{ goodInfo.oid }}</view>
      <view class="line"></view>
      <view
        class="container"
        v-for="(item, index) in goodInfo.OrderGoods"
        :key="index">
        <image class="image" :src="item.Goods.cover"></image>
        <view class="info">
          <view class="title">{{ item.Goods.name }}</view>
          <view class="text-[#7A7A7A] text-[22px]">{{
            item.Goods.profile || '此商品暂无描述'
          }}</view>
        </view>
        <view class="text-[#9C9C9C]">x{{ item.number }}</view>
      </view>
      <view class="line"></view>
      <view
        class="flex justify-between items-center mt-3 mb-2 text-[25px]"
        style="text-align: right">
        <text class="text-[#9C9C9C] text-left"
          >共{{ goodInfo.count }}件商品</text
        >
        <text class="flex-1"
          >{{ goodInfo.status !== 0 ? '实' : '应' }}付款{{
            goodInfo.pay_type === 1 ? '(元): ' : '(积分): '
          }}{{
            goodInfo.pay_type === 1 ? goodInfo.price : goodInfo.exchange
          }}</text
        >
      </view>
      <!-- <view class="line"></view> -->
      <!-- <view class="cz">
        <nut-button size="small" type="primary" @click="subVerify"
          >确定核销</nut-button
        >
      </view> -->
    </view>
    <nut-cell-group>
      <nut-cell title="订单信息"></nut-cell>
      <nut-cell
        title="下单时间:"
        :desc="goodInfo.add_time?.slice(0, 19)"></nut-cell>
      <nut-cell title="下单号码:" :desc="goodInfo.User?.phone"></nut-cell>
      <nut-cell title="下单用户:" :desc="goodInfo.User?.nickName"></nut-cell>
      <nut-cell
        title="付款方式:"
        :desc="getPayType(goodInfo.pay_type)"></nut-cell>
    </nut-cell-group>

    <view class="w-[90%] mt-[40px] m-auto">
      <nut-button type="primary" shape="square" block @click="subVerify"
        >确定核销</nut-button
      >
    </view>
  </view>
</template>

<script setup lang="ts">
import Taro from '@tarojs/taro';
import {getActiveVerifyList, activeOrderVerify} from '@/api/admin';
import {ref} from 'vue';

const opt = ref<any>({});

Taro.useLoad(options => {
  opt.value = options;
  getData(options);
});

const goodInfo = ref<any>({});

const getData = async (options: any) => {
  const merInfo = Taro.getStorageSync("userInfo");
  const res = await getActiveVerifyList({
    oid: options.oid,
    bid: merInfo.data.bid,
  });
  if (!res.data.data.oid) {
    Taro.showToast({
      title: '没有此订单',
      icon: 'none',
    });
    setTimeout(() => {
      Taro.navigateBack({
        delta: 1,
      });
    }, 3000);
  }
  goodInfo.value = res.data.data;
};

const subVerify = async () => {
  try {
    const res = await activeOrderVerify({
      oid: goodInfo.value.oid,
      bid: goodInfo.value.bid,
    });
    Taro.showToast({
      title: res.msg,
      icon: 'none',
    });
    setTimeout(() => {
      Taro.navigateBack({
        delta: 1,
      });
    }, 3000);
  } catch (error) {
    Taro.showToast({
      title: error.msg,
      icon: 'none',
    });
    throw error;
  }
};

const getPayType = (type: number) => {
  switch (type) {
    case 1:
      return '微信线上支付';
    case 2:
      return '平台积分支付';
    case 3:
      return '天才小猪支付';
    default:
      return '未知';
  }
};
</script>

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