<template>
  <view>
    <view class="card">
      <image
        class="image"
        @tap="scanCode"
        src="http://p1.meituan.net/csc/696924dda634f05689dabdfbb18e88cc13551.png" />
      <view class="mt-2 text-[#7A7A7A]">扫描二维码核销</view>
    </view>
  </view>
</template>

<script setup lang="ts">
import Taro from '@tarojs/taro';

// url参数转对象
// const urlParse = (url: string) => {
//     const obj: any = {};
//     const reg = /[?&][^?&]+=[^?&]+/g;
//     const arr = url.match(reg);
//     if (arr) {
//         arr.forEach((item) => {
//             const tempArr = item.substring(1).split("=");
//             const key = decodeURIComponent(tempArr[0]);
//             const val = decodeURIComponent(tempArr[1]);
//             obj[key] = val;
//         });
//     }
//     return obj;
// };

const scanCode = () => {
  Taro.scanCode({
    onlyFromCamera: true,
    scanType: ['qrCode'],
    success: async res => {
      try {
        Taro.navigateTo({
          url: `/pages/admin/verify/verify_list/index?oid=${res.result}`,
        });
      } catch (error) {
        Taro.showToast({
          title: error.msg,
          icon: 'none',
        });
      }
    },
  });
};
</script>

<style lang="scss">
page {
  background-color: #f5f5f5;
  background-image: url('http://p0.meituan.net/csc/e6ff5582788af2023f49241afe22fc89391851.png');
  background-repeat: no-repeat;
  background-size: 100% 25%;
}

.card {
  width: 690px;
  height: 300px;
  box-sizing: border-box;
  background-color: #fff;
  margin: 300px auto;
  border-radius: 33px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 100px;

  .image {
    width: 150px;
    height: 150px;
  }
}
</style>
