import { url } from '../request';
Page({
  data: {
      current: 0,
      businessName:'',
  },
  onLoad() {
    my.getStorage({
        key: 'userInfo',
        success: (res) => {
            const userInfo = res.data;
            this.setData({ id: userInfo.id });

            if (userInfo) {
                my.request({
                    url: url + '/api/orders/my/page',
                    method: 'POST',
                    data: {
                        claimStatus: 0,
                        current: 1,
                        pageSize: 1000,
                        userId: userInfo.id,
                        userRole: 0,
                    },
                    headers: { 'content-type': 'application/json' },
                    dataType: 'json',
                    success: async (res) => {
                      console.log(res,'rwssss');
                        if (res.data.code === 0) {
                            // 生成包含 appointmentId 的订单列表
                            let orders = res.data.data.records.map(order => ({
                                id:order.id,
                                businessAvatar:order.businessVO.businessAvatar,
                                serviceMode: order.serviceMode,
                                businessName: order.businessVO.businessName || '未知店铺',
                                commoditiesImage: order.orderItemsVOList[0].commoditiesVO.commoditiesImage || '',
                                commoditiesName: order.orderItemsVOList[0].commoditiesVO.commoditiesName || '未知商品',
                                orderNumber: order.orderNumber,
                                totalPrice: order.totalPrice,
                                paymentStatus: order.paymentStatus,
                                status: '', 
                                appointmentId: order.appointmentId,
                                phone:order.phone,
                                username:order.userName,
                                businessId:order.businessVO.id,
                                quantity:order.orderItemsVOList.quantity,
                                createTime:order.createTime,
                                manicuristid:order.manicuristVO ? order.manicuristVO.id : '',
                                manicuristName:order.manicuristVO? order.manicuristVO.manicuristName : '',
                                manicuristAvatar:order.manicuristVO? order.manicuristVO.manicuristAvatar : '',
                            }));
                            this.setData({ dingdan: orders });
                            console.log(this.data.dingdan);
                        } else if (res.data.code === 40100) {
                            my.alert({ content: '登录信息已过期，请重新登录' });
                            my.navigateTo({ url: '/pages/denglu/denglu' });
                        }
                    },
                    fail: (error) => {
                        console.error('请求失败: ', JSON.stringify(error));
                        my.alert({ content: '请求失败，请稍后重试' });
                    },
                });
            } else {
                my.alert({
                    content: '您未登录，请先登录。',
                    success: () => my.navigateTo({ url: '/pages/denglu/denglu' }),
                });
            }
        },
    });
},
pingjia(item){
  const id = item.target.dataset.num
  console.log(id);
  const businessName =id.businessName
  const businessAvatar = id.businessAvatar
  const manicuristName = id.manicuristName||''
  const manicuristid = id.manicuristid||''
  const manicuristAvatar = id.manicuristAvatar||''
  const businessId =id.businessId
  const orderid = id.id
  console.log('======>传过去的',orderid,businessId,manicuristAvatar,businessAvatar,manicuristid,businessName,manicuristName,);
      my.navigateTo({
          url:`/pages/pingjia/pingjia?&&businessName=${businessName}
          &&businessAvatar=${businessAvatar}
          &&manicuristName=${manicuristName}
          &&manicuristid=${manicuristid}
          &&manicuristAvatar=${manicuristAvatar}
          &&businessId=${businessId}
          &&orderid=${orderid}`
      })
  },
});

