"use strict";
const common_vendor = require("../../common/vendor.js");
const common_libraries_apiLoading = require("../../common/libraries/apiLoading.js");
const gen_Apis = require("../../gen/Apis.js");
const WORKORDER_poster_model = require("./model.js");
const getQrCode = (data, fun) => {
  common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.WorkOrder.HouseWorkOrders.GetWorkOrderPayQrCode, {
    id: data == null ? void 0 : data.id
  }).then((res) => {
    var _a;
    const fs = common_vendor.index.getFileSystemManager();
    let times = new Date().getTime();
    let codeimg = common_vendor.wx$1.env.USER_DATA_PATH + "/" + times + ".png";
    console.log(codeimg, "二维码路径");
    fs.writeFile({
      filePath: codeimg,
      data: (_a = res == null ? void 0 : res.data) == null ? void 0 : _a.qr_code.slice(22),
      encoding: "base64",
      success: () => {
        return fun == null ? void 0 : fun(codeimg);
      }
    });
  });
};
const method = {
  //method
  getHouseDetail(id) {
  },
  setCanvas(data) {
    console.log(data, "data");
    const context = common_vendor.index.createCanvasContext("poster_firstCanvas");
    getQrCode(data, (url) => {
      common_vendor.index.downloadFile({
        url: "https://pay-prod-1369486729.cos.ap-guangzhou.myqcloud.com/uploads/cs-test/01KFYRR5Y37PR2C1EDJYZYCDJK.png",
        success(res) {
          context.drawImage(res.tempFilePath, 0, 0, 345, 504);
          context.font = "bold 18px Arial";
          context.fillStyle = "#3D3D3D";
          context.setTextAlign("center");
          context.fillText((data == null ? void 0 : data.full_name) || "-", 345 / 2, 45);
          context.font = "bold 20px Arial";
          context.fillStyle = "#3D3D3D";
          context.fillText(`¥${(data == null ? void 0 : data.amount) || "-"}元`, 345 / 2, 85);
          context.font = "12px Arial";
          context.fillStyle = "#666";
          context.fillText("待支付", 345 / 2, 110);
          context.font = "14px Arial";
          context.fillStyle = "#00C800";
          context.fillText("请使用微信扫码支付", 345 / 2, 450);
          setTimeout(() => {
            context.drawImage(url, 72.5, 150, 200, 200);
            context.restore();
            context.draw();
          }, 500);
        }
      });
      console.log(url, "二维码路径");
    });
  },
  onDownloadPosters() {
    common_vendor.index.showLoading({
      title: "正在保存中..."
    });
    common_vendor.index.canvasToTempFilePath({
      x: 0,
      y: 0,
      width: 345,
      height: 504,
      destWidth: 345 * 4,
      destHeight: 504 * 4,
      canvasId: "poster_firstCanvas",
      success: function(res) {
        console.log(res, "res");
        common_vendor.index.saveImageToPhotosAlbum({
          filePath: res.tempFilePath,
          success: function() {
            console.log("save success");
            common_vendor.index.hideLoading();
          },
          fail() {
            common_vendor.index.hideLoading();
          }
        });
        console.log(res.tempFilePath);
      },
      fail(e) {
        console.log(e, "err");
        common_vendor.index.hideLoading();
      }
    });
  },
  initActualImages: async (id) => {
  },
  choiceImgPopControl() {
    var _a;
    this.initActualImages((_a = WORKORDER_poster_model.useModel.houseDetail.value) == null ? void 0 : _a.id);
  },
  copyLink() {
  }
};
exports.method = method;
