import { getInspectOrderGet } from "@/api/inspection";
import { getRepairDetail } from "@/api/repair";

/**
 * 根据不同类型的消息跳转目标页面
 * @param data
 */
export const messageNavigate = async data => {
  console.log("data :>> ", data);
  if (!data.userId) {
    data.userId = "";
  }
  if (data.type === "generateInspect") {
    // 巡检工单填写页面
    const detail = (await getInspectOrderGet({ id: data.id })).data;
    if (detail.status === "finished") {
      uni.navigateTo({
        url: `/pages/inspection/detail?id=${data.id}&reloginUserId=${data.userId}`,
      });
    } else {
      uni.navigateTo({
        url: `/pages/inspection/edit?id=${data.id}&reloginUserId=${data.userId}`,
      });
    }
  } else if (data.type === "failureReport") {
    // 故障上报审批页面
    uni.navigateTo({
      url: `/pages/message/detail/index?processInstanceId=${data.id}&reloginUserId=${data.userId}`,
    });
  } else if (data.type === "generateMaintain") {
    // 维修工单填写页面
    const detail = (await getRepairDetail({ id: data.id })).data;
    if (detail.status !== "tx") {
      uni.navigateTo({
        url: `/pages/repair/detail?id=${data.id}&reloginUserId=${data.userId}`,
      });
    } else {
      uni.navigateTo({
        url: `/pages/repair/edit?id=${data.id}&reloginUserId=${data.userId}`,
      });
    }
  } else if (data.type === "maintainOut") {
    // 维修工单委外流程审批页面
    uni.navigateTo({
      url: `/pages/message/detail/index?processInstanceId=${data.id}&reloginUserId=${data.userId}`,
    });
  } else if (data.type === "generateMaintenance") {
    // 保养工单填写页面
    uni.navigateTo({
      url: `/pages/maintenance/edit?id=${data.id}&reloginUserId=${data.userId}`,
    });
  } else if (data.type === "generateOperation") {
    // 运行记录填写页面
    const json = JSON.stringify({
      deptId: data.deptId,
      userId: data.userId,
      createTime: data.createTime,
      orderId: data.id,
      orderStatus: data.orderStatus,
      orderName: data.orderName,
      userName: data.userName,
    });
    // {0: '待填写', 1: '已完成', 2: '填写中', 3: '忽略'}
    uni.navigateTo({
      url: `/pages/recordFilling/detail?view=${data.orderStatus % 2 == 0 ? 1 : 0}&param=${json}&reloginUserId=${
        data.userId
      }`,
    });
  } else if (data.type === "rdDailyReport") {
    uni.navigateTo({
      url: `/pages/ruiDu/edit?id=${data.businessId}&istime=${false}`,
    });
  } else if (data.type === "rdReportApproval") {
    uni.navigateTo({
      url: `/pages/ruiDu/approval?id=${data.businessId}`,
    });
  } else if (data.type === "rdReportDetail") {
    uni.navigateTo({
      url: `/pages/ruiDu/detail?id=${data.businessId}`,
    });
  } else if (data.type === "rhDailyReport") {
    uni.navigateTo({
      url: `/pages/ruihen/edit?id=${data.businessId}`,
    });
  } else if (data.type === "rhReportApproval") {
    uni.navigateTo({
      url: `/pages/ruihen/approval?id=${data.businessId}`,
    });
  } else if (data.type === "ryDailyReport") {
    uni.navigateTo({
      url: `/pages/ruiying/edit?id=${data.businessId}`,
    });
  } else if (data.type === "ryReportApproval") {
    uni.navigateTo({
      url: `/pages/ruiying/approval?id=${data.businessId}`,
    });
  } else if (data.type === "ryXjDailyReport") {
    uni.navigateTo({
      url: `/pages/ruiyingx/edit?id=${data.businessId}`,
    });
  } else if (data.type === "ryXjReportApproval") {
    uni.navigateTo({
      url: `/pages/ruiyingx/approval?id=${data.businessId}`,
    });
  }
};
