import {url} from '../request'
Page({
  data:{
    
  },
  onLoad(options) {
    const commoditiesImage = options.commoditiesImage
    const commoditiesName = options.commoditiesName
    const commoditiesPrice = options.commoditiesPrice
    const quantity = options.quantity
    const orderNumber = options.ordernumber
    const orderid = options.orderid
    console.log(orderid,orderNumber,quantity,commoditiesPrice,commoditiesName,commoditiesImage);
  this.setData({
    orderNumber:orderNumber,
    commoditiesImage:commoditiesImage,
    quantity:quantity,
    commoditiesPrice:commoditiesPrice,
    commoditiesName:commoditiesName,
    orderid:orderid
  })
  },
  
  paymoney(){
    console.log(this.data.orderid,'hhhhhhh');
    console.log(this.data.orderNumber);
    my.getStorage({
      key: 'userInfo',
      success: (res) => {
        const userInfo = res.data;
        this.setData({
          id: userInfo.id, // 获取 id
        });
  
        if (userInfo && userInfo.cookie) {
          my.request({
            url: url + '/api/Alipay/create/alipay',
            method: 'POST',
            data: {
              userId: userInfo.id,
              id: this.data.orderid
            },
            headers: {
              'content-type': 'application/json',
            },
            dataType: 'json',
            success: (res) => {
              console.log(res.data.data,'asjkdaskjhdakjs');
              const noma = res.data.data
              console.log(noma,'noma');
              my.tradePay({
              tradeNO: noma,
              success: (res) => {
                console.log(JSON.stringify (res),'zheshichenggongderes');
                  console.log(res); 
                  my.alert({content:'支付成功'})
                  my.navigateBack();
              },
              fail: (res) => {
                my.alert({
                  content: "支付失败",
                });
              }
            });    
   },
            fail: (error) => {
              my.alert({ content: '支付失败' });
              console.log(res);
            },
          });
        } else {
          my.alert({
            content: '您未登录，请先登录。',
            success: () => {
              my.navigateTo({
                url: '/pages/denglu/denglu',
              });
            },
          });
        }
      },
    });
  }
});
