| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- // pages/cert/cert.js
- import { postApi, getApi } from "../../apis/api";
- Page({
- data: {
- shipName: "",
- mmsi: "",
- shipCerts: [],
- crewCerts: [],
- certs: [],
- contacts: [],
- introduce: {},
- accessToken: wx.getStorageSync("accessToken") || "",
- },
- async getCerts() {
- let { data } = await getApi("/ship/cert/list");
- 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, "")
- )
- : ["暂无"];
- 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({
- contacts: data.result,
- });
- } else {
- this.setData({
- contacts: [],
- });
- wx.showToast({
- 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,
- });
- },
- 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({
- data: e.currentTarget.dataset.phone,
- success(res) {
- wx.showToast({
- title: "复制成功",
- });
- },
- });
- },
- onLoad(options) {
- this.getCerts();
- // this.getContacts();
- // this.getIntroduce();
- },
- onShow() {
- if (typeof this.getTabBar === "function" && this.getTabBar()) {
- this.getTabBar().setData({
- selected: 1,
- });
- }
- },
- async onShareAppMessage() {
- let { data } = await getApi("/ship/cert/share/token");
- return {
- title: this.data.shipName + " - 证书信息",
- path: `/pages/cert/sharePage/sharePage?token=${data.result.result}`,
- imageUrl: "../../images/logo541.png",
- };
- },
- });
|