"use strict";
const common_vendor = require("../vendor.js");
const common_libraries_naviHelper = require("./naviHelper.js");
const common_libraries_apiLoading = require("./apiLoading.js");
const gen_Apis = require("../../gen/Apis.js");
function sendChatMessage(data) {
  if (!(data == null ? void 0 : data.page)) {
    return common_libraries_naviHelper.showToast("请设置跳转页面路径！");
  }
  common_vendor.index.showLoading({
    title: "加载中...",
    mask: true
  });
  common_vendor.index.qy.sendChatMessage({
    msgtype: (data == null ? void 0 : data.msgtype) || "miniprogram",
    //消息类型，必填
    enterChat: (data == null ? void 0 : data.enterChat) || false,
    //为true时表示发送完成之后顺便进入会话，仅移动端3.1.10及以上版本支持该字段
    miniprogram: {
      appid: "wx31500e871924b903",
      //小程序的appid
      title: (data == null ? void 0 : data.title) || "邀请你绑定房屋",
      //小程序消息的title
      imgUrl: (data == null ? void 0 : data.imgUrl) || "https://pay-prod-1369486729.cos.ap-guangzhou.myqcloud.com/uploads/cs-test/01K58GCT5DGWKBSYH0G7118XT4.jpg",
      //小程序消息的封面图
      page: data == null ? void 0 : data.page
      //小程序消息打开后的路径，注意要以.html作为后缀，否则在微信端打开会提示找不到页面
    },
    success: function() {
      common_vendor.index.hideLoading();
      common_libraries_naviHelper.showToast("发送成功！");
    },
    fail: function(err) {
      console.log("sendChatMessage fail", err);
      common_vendor.index.hideLoading();
      if ((err == null ? void 0 : err.errMsg) !== "qy__sendChatMessage:fail cancel") {
        common_libraries_naviHelper.showToast((err == null ? void 0 : err.errMsg) || "当前操作，只能在企业微信上聊天工具栏操作");
      }
    }
  });
}
function shareToExternalContact(data) {
  if (!(data == null ? void 0 : data.page)) {
    return common_libraries_naviHelper.showToast("请设置跳转页面路径！");
  }
  common_vendor.index.showLoading({
    title: "加载中...",
    mask: true
  });
  common_vendor.index.qy.shareToExternalContact({
    externalUserIds: (data == null ? void 0 : data.externalUserIds) || [],
    text: {
      content: (data == null ? void 0 : data.title) || "待缴费账单"
      // 文本内容
    },
    attachments: [
      {
        msgtype: (data == null ? void 0 : data.msgtype) || "miniprogram",
        //消息类型，必填
        miniprogram: {
          appid: "wx31500e871924b903",
          //小程序的appid
          title: (data == null ? void 0 : data.title) || "待缴费账单",
          //小程序消息的title
          imgUrl: (data == null ? void 0 : data.imgUrl) || "https://pay-prod-1369486729.cos.ap-guangzhou.myqcloud.com/uploads/cs-test/01K58GCT5DGWKBSYH0G7118XT4.jpg",
          //小程序消息的封面图
          page: data == null ? void 0 : data.page
          //小程序消息打开后的路径，注意要以.html作为后缀，否则在微信端打开会提示找不到页面
        }
      }
    ],
    success: function() {
      common_vendor.index.hideLoading();
      common_libraries_naviHelper.showToast("发送成功！");
    },
    fail: function(err) {
      console.log("sendChatMessage fail", err);
      common_vendor.index.hideLoading();
      if ((err == null ? void 0 : err.errMsg) !== "qy__sendChatMessage:fail cancel") {
        common_libraries_naviHelper.showToast((err == null ? void 0 : err.errMsg) || "当前操作，只能在企业微信上聊天工具栏操作");
      }
    }
  });
}
function navigateToMiniProgram(data) {
  common_vendor.index.showLoading({
    title: "加载中",
    mask: true
  });
  common_vendor.index.navigateToMiniProgram({
    appId: "wx31500e871924b903",
    path: (data == null ? void 0 : data.path) || "",
    extraData: (data == null ? void 0 : data.extraData) || {},
    envVersion: (data == null ? void 0 : data.envVersion) || "release",
    success() {
      common_vendor.index.hideLoading();
    },
    fail() {
      common_vendor.index.hideLoading();
    }
  });
}
function shareToExternalMoments(data, dataTasks) {
  console.log("shareToExternalMoments", data, dataTasks);
  common_vendor.wx$1.qy.shareToExternalMoments(
    {
      text: {
        content: (data == null ? void 0 : data.content) || ""
        // 文本内容
      },
      attachments: data == null ? void 0 : data.attachments,
      success(res) {
        if (res.errMsg == "qy__shareToExternalMoments:ok") {
          common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Customer.CustomerMomentTasks.Store, dataTasks).then((res2) => {
            common_libraries_naviHelper.showToast("发送成功！");
            console.log(res2);
          });
        }
        console.log("分享回调结果success", res);
      }
    },
    function(res) {
      console.log("分享回调结果", res);
      if (res.err_msg == "shareToExternalMoments:ok") {
        common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Customer.CustomerMomentTasks.Store, dataTasks).then((res2) => {
          common_libraries_naviHelper.showToast("发送成功！");
          console.log(res2);
        });
      }
    }
  );
}
function shareToExternalContactTask(data, dataTasks) {
  common_vendor.index.qy.shareToExternalContact({
    text: {
      content: (data == null ? void 0 : data.content) || ""
      // 文本内容
    },
    attachments: (data == null ? void 0 : data.attachments) || [],
    success: function(res) {
      console.log("shareToExternalContact", res);
      common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Customer.CustomerMomentTasks.Store, dataTasks).then((res2) => {
        common_libraries_naviHelper.showToast("发送成功！");
        console.log(res2);
      });
      console.log("success", res);
    },
    fail() {
      console.log("fail");
    },
    complete() {
      console.log("complete");
    }
  });
}
function shareToExternalChatTask(data, dataTasks) {
  common_vendor.index.qy.shareToExternalChat({
    text: {
      content: (data == null ? void 0 : data.content) || ""
      // 文本内容
    },
    attachments: (data == null ? void 0 : data.attachments) || [],
    success: function(res) {
      common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Customer.CustomerMomentTasks.Store, dataTasks).then((res2) => {
        common_libraries_naviHelper.showToast("发送成功！");
        console.log(res2);
      });
      console.log("success", res);
    },
    fail() {
      console.log("fail");
    },
    complete() {
      console.log("complete");
    }
  });
}
exports.navigateToMiniProgram = navigateToMiniProgram;
exports.sendChatMessage = sendChatMessage;
exports.shareToExternalChatTask = shareToExternalChatTask;
exports.shareToExternalContact = shareToExternalContact;
exports.shareToExternalContactTask = shareToExternalContactTask;
exports.shareToExternalMoments = shareToExternalMoments;
