|
|
@@ -2,69 +2,114 @@
|
|
|
import { postApi, getApi } from "../../apis/api";
|
|
|
Page({
|
|
|
data: {
|
|
|
- shipName: "长江之星",
|
|
|
- mmsi: "413123456",
|
|
|
- shipCerts: [
|
|
|
- {
|
|
|
- name: "船舶检验证书",
|
|
|
- photoUrl: "../../images/new-version/pic.png",
|
|
|
- expireDate: "2024-12-31",
|
|
|
- },
|
|
|
- {
|
|
|
- name: "船舶营运证",
|
|
|
- photoUrl: "../../images/new-version/pic.png",
|
|
|
- expireDate: "2024-06-30",
|
|
|
- },
|
|
|
- ],
|
|
|
- crewCerts: [
|
|
|
- {
|
|
|
- name: "张三",
|
|
|
- medicalReport: "../../images/new-version/pic.png",
|
|
|
- serviceBook: "../../images/new-version/pic.png",
|
|
|
- certificates: [
|
|
|
- {
|
|
|
- name: "船员适任证书",
|
|
|
- photoUrl: "../../images/new-version/pic.png",
|
|
|
- expireDate: "2024-12-31",
|
|
|
- },
|
|
|
- {
|
|
|
- name: "特殊培训合格证",
|
|
|
- photoUrl: "../../images/new-version/pic.png",
|
|
|
- expireDate: "2024-09-30",
|
|
|
- },
|
|
|
- ],
|
|
|
- },
|
|
|
- {
|
|
|
- name: "李四",
|
|
|
- medicalReport: "../../images/new-version/pic.png",
|
|
|
- serviceBook: "../../images/new-version/pic.png",
|
|
|
- certificates: [
|
|
|
- {
|
|
|
- name: "船员适任证书",
|
|
|
- photoUrl: "../../images/new-version/pic.png",
|
|
|
- expireDate: "2024-11-30",
|
|
|
- },
|
|
|
- ],
|
|
|
- },
|
|
|
- ],
|
|
|
+ shipName: "",
|
|
|
+ mmsi: "",
|
|
|
+ shipCerts: [],
|
|
|
+ crewCerts: [],
|
|
|
certs: [],
|
|
|
contacts: [],
|
|
|
introduce: {},
|
|
|
},
|
|
|
async getCerts() {
|
|
|
- let { data } = await postApi("/ship/cert/list", {
|
|
|
- userId: wx.getStorageSync("userId"),
|
|
|
- });
|
|
|
+ let { data } = await getApi("/ship/cert/list");
|
|
|
+ console.log(data);
|
|
|
if (data.status === 0) {
|
|
|
- data.result.forEach((cert) => {
|
|
|
- cert.endValidTime = cert.endValidTime.split(" ")[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, "")
|
|
|
+ )
|
|
|
+ : ["暂无"];
|
|
|
+
|
|
|
+ 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({
|
|
|
@@ -111,10 +156,32 @@ Page({
|
|
|
});
|
|
|
},
|
|
|
|
|
|
- preview(e) {
|
|
|
- wx.previewImage({
|
|
|
- urls: [e.currentTarget.dataset.url],
|
|
|
- });
|
|
|
+ previewImage(e) {
|
|
|
+ const url = e.currentTarget.dataset.url;
|
|
|
+ const urls = e.currentTarget.dataset.urls;
|
|
|
+
|
|
|
+ // 如果是暂无,则不预览
|
|
|
+ if (url === "暂无") {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果提供了多个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({
|
|
|
@@ -129,8 +196,8 @@ Page({
|
|
|
|
|
|
onLoad(options) {
|
|
|
this.getCerts();
|
|
|
- this.getContacts();
|
|
|
- this.getIntroduce();
|
|
|
+ // this.getContacts();
|
|
|
+ // this.getIntroduce();
|
|
|
},
|
|
|
onShow() {
|
|
|
if (typeof this.getTabBar === "function" && this.getTabBar()) {
|