<template>
  <view>
    <view class="card">
      <view>订单号：{{ 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" mode="widthFix"></image>
        <view class="info">
          <view class="title">商品名称：{{ item.Goods.name }}</view>
          <view class="title">描述：{{ item.Goods.profile }}</view>
          <view class="num"
            >数量: <text style="color: red">{{ item.number }}</text></view
          >
        </view>
        <view></view>
      </view>
      <view class="line"></view>
      <text>支付方式：{{ goodInfo.pay_type === 1 ? "微信" : "积分" }}</text
      >，
      <text
        >总计：{{
          goodInfo.pay_type === 1 ? goodInfo.price : goodInfo.exchange
        }}</text
      >
      <view class="line"></view>
      <view class="cz">
        <nut-button size="small" type="primary" @click="subVerify"
          >确定核销</nut-button
        >
      </view>
    </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("mer_info");
  const res = await getActiveVerifyList({
    oid: options.oid,
    bid: merInfo.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;
  }
};
</script>

<style lang="scss">
.card {
  padding: 20rpx;
  background-color: #fff;
  margin: 10px auto;
  width: 90%;
  border-radius: 7px;

  .container {
    display: flex;

    image {
      width: 150px;
      height: 150px;
      border-radius: 7px;
      display: block;
    }

    .info {
      margin-left: 20px;
    }

    .title {
      margin-bottom: 10px;
    }
  }

  .line {
    width: 100%;
    height: 1px;
    background-color: #f5f5f5;
    margin: 10px 0;
  }

  .cz {
    text-align: right;
  }
}
</style>
