<template>
	<button @click="onButton">支付按钮</button>
</template>

<script setup>
import { ref } from 'vue';
import {apiImageUrl} from '../../API/api'
	/* 	const onButton = () => {
	  my.request({
	    url: 'http://localhost:9999/api/Alipay/trade',
	    method: 'GET',
	    success: (result) => {
	      console.log(result);
	      if (result.data.code === 0) { // 假设 0 表示成功
	        my.tradePay({
	          tradeNo: result.data.data,
	          success: (res) => {
	            my.navigateTo({
	              url: '/pages/index/index'
	            });
	            console.log('成功');
	          },
	          fail: (res) => {
	            my.alert({
	              content: JSON.stringify(res),
	            });
	            console.log('失败');
	            console.log(res);
	          }
	        });
	      } else {
	        console.error('请求失败:', result.data.message);
	      }
	    },
	    fail: (error) => {
	      console.error('请求失败:', error);
	    }
	  });
	}; */
	const onButton = () => {
		my.request({
			url: apiImageUrl+'/api/Alipay/trade',
			method: 'GET',
			success: function(result) {
				console.log(result);
				console.log(result.data.data);
				my.tradePay({
					tradeNO: result.data.data,
					success: (res) => {
						console.log('成功调用')
						// my.navigateTo({
						// 	url: '/pages/index/index',
						// })
						console.log(res);
					},
					fail: (res) => {
						my.alert({
							content: JSON.stringify(res),
						})
						console.log('失败');
						console.log(res);
					}

				})
			}
		})
	}

	/* const onButton=()=>{
		uni.request({
			url:'http://localhost:9999/api/Alipay/trade',
			method:'GET',
			success:function(result){
				console.log(result);
				my.tradePay ({
				  // 调用统一收单交易创建接口（alipay.trade.create），获得返回字段支付宝交易号 trade_no
				 url:'http://localhost:9999/api/Alipay/trade',
				 method:'GET',
				  tradeNO: '201711152100110410533667792',
				  success: res => {
				    my.alert ({
				      content: JSON.stringify (res),
				    });
				  },
				  fail: error => {
				    console.error('调用 my.tradePay 失败: ', JSON.stringify(error));
				  },
				});

		}
		})
	} */
</script>