|
|
@@ -1,80 +1,213 @@
|
|
|
-// pages/cert/sharePage/sharePage.js
|
|
|
-import { postApi } from "../../../apis/api";
|
|
|
-const app = getApp();
|
|
|
+// pages/cert/cert.js
|
|
|
+import { postApi, getApi } from "../../../apis/api";
|
|
|
Page({
|
|
|
- /**
|
|
|
- * 页面的初始数据
|
|
|
- */
|
|
|
data: {
|
|
|
- sharedCertList: [], // 用于存储分享的证书列表
|
|
|
+ shipName: "",
|
|
|
+ mmsi: "",
|
|
|
+ shipCerts: [],
|
|
|
+ crewCerts: [],
|
|
|
+ certs: [],
|
|
|
+ contacts: [],
|
|
|
+ introduce: {},
|
|
|
+ accessToken: wx.getStorageSync("accessToken") || "",
|
|
|
},
|
|
|
-
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面加载
|
|
|
- */
|
|
|
- onLoad(options) {
|
|
|
- const token = options.token;
|
|
|
- if (token) {
|
|
|
- this.getSharedCertInfo(token);
|
|
|
- } else {
|
|
|
+ async getCerts(token) {
|
|
|
+ if (!token) {
|
|
|
wx.showToast({
|
|
|
title: "无效的分享链接",
|
|
|
icon: "none",
|
|
|
});
|
|
|
+ return;
|
|
|
}
|
|
|
- },
|
|
|
-
|
|
|
- async getSharedCertInfo(token) {
|
|
|
- wx.showLoading({
|
|
|
- title: "加载中...",
|
|
|
+ let { data } = await postApi("/ship/cert/share/list", {
|
|
|
+ token,
|
|
|
});
|
|
|
- let { data } = await postApi("/ship/cert/share/list", { token });
|
|
|
+ console.log(data);
|
|
|
+ if (data.status === 0) {
|
|
|
+ // 处理船舶基本信息
|
|
|
+ const shipInfo = data.result;
|
|
|
+
|
|
|
+ // 处理船舶证书信息
|
|
|
+ const formattedShipCerts = shipInfo.shipCerts.map((cert) => {
|
|
|
+ // 获取第一个有效期(如果有多个,默认使用第一个)
|
|
|
+ const expireDate =
|
|
|
+ cert.certValidities && cert.certValidities.length > 0
|
|
|
+ ? cert.certValidities[0].endValidTime
|
|
|
+ .split(" ")[0]
|
|
|
+ .replace(/\//g, "-")
|
|
|
+ : "";
|
|
|
+
|
|
|
+ // 处理所有的certFileViewUrls,确保它们都被正确格式化
|
|
|
+ const formattedViewUrls =
|
|
|
+ cert.certFileViewUrls && cert.certFileViewUrls.length > 0
|
|
|
+ ? cert.certFileViewUrls.map((url) =>
|
|
|
+ url.trim().replace(/` /g, "").replace(/ `/g, "")
|
|
|
+ )
|
|
|
+ : ["暂无"];
|
|
|
+
|
|
|
+ return {
|
|
|
+ name: cert.certTypeName,
|
|
|
+ photoUrls: formattedViewUrls,
|
|
|
+ photoUrl: formattedViewUrls[0], // 保留单张图片的兼容性
|
|
|
+ expireDate: expireDate,
|
|
|
+ };
|
|
|
+ });
|
|
|
+
|
|
|
+ // 处理船员证书信息
|
|
|
+ const formattedCrewCerts = shipInfo.shipCrewCerts.map((crew) => {
|
|
|
+ // 处理船员的证书
|
|
|
+ const crewCertificates = crew.certs.map((cert) => {
|
|
|
+ // 处理所有的viewUrls,确保它们都被正确格式化
|
|
|
+ const formattedViewUrls =
|
|
|
+ cert.viewUrls && cert.viewUrls.length > 0
|
|
|
+ ? cert.viewUrls.map((url) =>
|
|
|
+ url.trim().replace(/` /g, "").replace(/ `/g, "")
|
|
|
+ )
|
|
|
+ : ["暂无"];
|
|
|
+
|
|
|
+ return {
|
|
|
+ name: cert.docTypeName,
|
|
|
+ photoUrls: formattedViewUrls,
|
|
|
+ photoUrl: formattedViewUrls[0], // 保留单张图片的兼容性
|
|
|
+ expireDate: cert.expiryAt
|
|
|
+ ? cert.expiryAt.split(" ")[0].replace(/\//g, "-")
|
|
|
+ : "",
|
|
|
+ };
|
|
|
+ });
|
|
|
+
|
|
|
+ // 找到医疗报告和服务簿的URL
|
|
|
+ const medicalReportCert = crew.certs.find((cert) => cert.docType === 2);
|
|
|
+ const serviceBookCert = crew.certs.find((cert) => cert.docType === 3);
|
|
|
+
|
|
|
+ // 处理医疗报告的所有URL
|
|
|
+ const medicalReportUrls =
|
|
|
+ medicalReportCert &&
|
|
|
+ medicalReportCert.viewUrls &&
|
|
|
+ medicalReportCert.viewUrls.length > 0
|
|
|
+ ? medicalReportCert.viewUrls.map((url) =>
|
|
|
+ url.trim().replace(/` /g, "").replace(/ `/g, "")
|
|
|
+ )
|
|
|
+ : ["暂无"];
|
|
|
+
|
|
|
+ // 处理服务簿的所有URL
|
|
|
+ const serviceBookUrls =
|
|
|
+ serviceBookCert &&
|
|
|
+ serviceBookCert.viewUrls &&
|
|
|
+ serviceBookCert.viewUrls.length > 0
|
|
|
+ ? serviceBookCert.viewUrls.map((url) =>
|
|
|
+ url.trim().replace(/` /g, "").replace(/ `/g, "")
|
|
|
+ )
|
|
|
+ : ["暂无"];
|
|
|
|
|
|
- wx.hideLoading();
|
|
|
+ return {
|
|
|
+ name: crew.fullName,
|
|
|
+ medicalReportUrls: medicalReportUrls,
|
|
|
+ medicalReport: medicalReportUrls[0], // 保留单张图片的兼容性
|
|
|
+ serviceBookUrls: serviceBookUrls,
|
|
|
+ serviceBook: serviceBookUrls[0], // 保留单张图片的兼容性
|
|
|
+ certificates: crewCertificates,
|
|
|
+ };
|
|
|
+ });
|
|
|
+
|
|
|
+ this.setData({
|
|
|
+ shipName: shipInfo.shipName,
|
|
|
+ mmsi: shipInfo.mmsi,
|
|
|
+ shipCerts: formattedShipCerts,
|
|
|
+ crewCerts: formattedCrewCerts,
|
|
|
+ certs: data.result,
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ this.setData({
|
|
|
+ shipCerts: [],
|
|
|
+ crewCerts: [],
|
|
|
+ certs: [],
|
|
|
+ });
|
|
|
+ wx.showToast({
|
|
|
+ title: data.msg,
|
|
|
+ icon: "none",
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async getContacts() {
|
|
|
+ let { data } = await getApi("/ship/cert/operation/contacts");
|
|
|
if (data.status === 0) {
|
|
|
this.setData({
|
|
|
- sharedCertList: data.result,
|
|
|
+ contacts: data.result,
|
|
|
});
|
|
|
} else {
|
|
|
+ this.setData({
|
|
|
+ contacts: [],
|
|
|
+ });
|
|
|
wx.showToast({
|
|
|
- title: data.msg || "获取证书信息失败",
|
|
|
+ title: data.msg,
|
|
|
icon: "none",
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
+ async getIntroduce() {
|
|
|
+ let { data } = await getApi("/ship/cert/operation/introduce");
|
|
|
+ if (data.status === 0) {
|
|
|
+ this.setData({
|
|
|
+ introduce: data.result,
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ this.setData({
|
|
|
+ introduce: {},
|
|
|
+ });
|
|
|
+ wx.showToast({
|
|
|
+ title: data.msg,
|
|
|
+ icon: "none",
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ makePhoneCall(e) {
|
|
|
+ wx.makePhoneCall({
|
|
|
+ phoneNumber: e.currentTarget.dataset.phone,
|
|
|
+ });
|
|
|
+ },
|
|
|
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面初次渲染完成
|
|
|
- */
|
|
|
- onReady() {},
|
|
|
-
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面显示
|
|
|
- */
|
|
|
- onShow() {},
|
|
|
-
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面隐藏
|
|
|
- */
|
|
|
- onHide() {},
|
|
|
-
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面卸载
|
|
|
- */
|
|
|
- onUnload() {},
|
|
|
+ previewImage(e) {
|
|
|
+ const url = e.currentTarget.dataset.url;
|
|
|
+ const urls = e.currentTarget.dataset.urls;
|
|
|
|
|
|
- /**
|
|
|
- * 页面相关事件处理函数--监听用户下拉动作
|
|
|
- */
|
|
|
- onPullDownRefresh() {},
|
|
|
+ // 如果是暂无,则不预览
|
|
|
+ if (url === "暂无") {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * 页面上拉触底事件的处理函数
|
|
|
- */
|
|
|
- onReachBottom() {},
|
|
|
+ // 如果提供了多个URL,则使用它们
|
|
|
+ if (
|
|
|
+ urls &&
|
|
|
+ Array.isArray(JSON.parse(urls)) &&
|
|
|
+ JSON.parse(urls).length > 0
|
|
|
+ ) {
|
|
|
+ const urlsArray = JSON.parse(urls);
|
|
|
+ wx.previewImage({
|
|
|
+ current: url, // 当前显示的图片
|
|
|
+ urls: urlsArray,
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ // 兼容旧版本,只有单张图片
|
|
|
+ wx.previewImage({
|
|
|
+ urls: [url],
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ copy(e) {
|
|
|
+ wx.setClipboardData({
|
|
|
+ data: e.currentTarget.dataset.phone,
|
|
|
+ success(res) {
|
|
|
+ wx.showToast({
|
|
|
+ title: "复制成功",
|
|
|
+ });
|
|
|
+ },
|
|
|
+ });
|
|
|
+ },
|
|
|
|
|
|
- /**
|
|
|
- * 用户点击右上角分享
|
|
|
- */
|
|
|
- onShareAppMessage() {},
|
|
|
+ onLoad(options) {
|
|
|
+ this.getCerts(options.token);
|
|
|
+ // this.getContacts();
|
|
|
+ // this.getIntroduce();
|
|
|
+ },
|
|
|
+ onShow() {},
|
|
|
});
|