<template>
  <view class="app-container">
    <view class="input-code-container">
      <input
        class="input-code-input"
        v-model="code"
        placeholder="请输入核销码"
        placeholder-style="color: #d9d9d9;"
      />
    </view>

    <view class="button-container">
      <button class="u-btn-two" @click.stop="handleSubmit">确认验证</button>
    </view>
  </view>
</template>

<script setup>
import { ref } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import { shopOrderValid_Api } from "@/api/order";
import { integralVerifierValid_Api } from "@/api/index";

const pageType = ref("1"); // 1：订单核销，2：积分核销
const code = ref("");

const handleSubmit = () => {
  console.log("提交验证", code.value);
  if (!code.value) {
    return uni.showToast({ title: "请输入核销码", icon: "none" });
  }
  uni.showLoading({ title: "提交验证中", mask: true });
  let url =
    pageType.value == "1" ? shopOrderValid_Api : integralVerifierValid_Api;
  url({
    verificationCode: code.value,
  })
    .then((res) => {
      uni.hideLoading();
      if (res.code == 200) {
        uni.redirectTo({ url: `/pages/shop/writeOff/result?code=${code.value}&pageType=${pageType.value}` });
      }
    })
    .catch((err) => {
      // uni.hideLoading();
    });
};

onLoad((options) => {
  pageType.value = options.pageType || "1";
});
</script>

<style lang="scss" scoped>
.app-container {
  min-height: 100vh;
  box-sizing: border-box;
  padding: 200rpx 58rpx;
  .input-code-container {
    margin: 0 20rpx 60rpx 20rpx;
    background-color: #f8f8f8;
    text-align: center;
    border-radius: 16rpx;
    padding: 20rpx 10rpx;
    box-sizing: border-box;
  }
  .button-container {
    .u-btn-two {
      height: 91rpx;
      line-height: 91rpx;
    }
  }
}
</style>
