import { Post } from "../../../../lib/request/method";
Page({
  data: {
    id: "",
    recordList: [],
    showAppointmentSuccess: true,
    qrCodeUrl: "",
    appointmentInfo: {
      operateTime: '',
      operateDuration: '',
      conditioningProgramSupplierName: '',
      cpSupplierDetailAddress: '',
      cpSupplierPhone: '',
      cpSupplierQrCode: '',
    },
    showAppointmentInfo: false,
  },
  onLoad(options: any) {
    if (options.id) {
      this.getVerifyRecordList(options.id);
    }
  },
  // 生成二维码
  generateQRCode(qrCodeUrl: any) {
    this.setData({
      qrCodeUrl
    });
  },
  // 获取核销记录列表
  async getVerifyRecordList(id: number) {
    try {
      const res = await Post(
        `/patientCrManage/pofflineCp/${id}`,
        {},
        {
          transform({ data }: any) {
            return data;
          },
        }
      );
      if (res && res.patientConditioningSwagItemOffline && JSON.stringify(res.patientConditioningSwagItemOffline) !== '{}') {
        this.setData({
          showAppointmentInfo: true,
        });
        this.setData({
          appointmentInfo: res.patientConditioningSwagItemOffline,
        });
        this.generateQRCode(this.data.appointmentInfo.cpSupplierQrCode);
      } else {
        this.setData({
          showAppointmentInfo: false,
        });
      }
      if (res && res.patientConditioningSwagItemOfflines && res.patientConditioningSwagItemOfflines.length > 0) {
        this.setData({
          recordList: res.patientConditioningSwagItemOfflines,
        });
      } else {
        this.setData({
          recordList: [],
        });
      }
    } catch (error) {
      console.error("核销记录列表", error);
    }
  },

});
