Просмотр исходного кода

feat(shipOwnerManage): 增加船员信息匹配功能

- 新增 searchShipOwner 接口用于匹配船员信息
- 实现船员信息匹配逻辑,包括手机号验证和详情获取
- 添加保存已匹配船员信息的功能
- 优化船员详情页面,增加船舶详情按钮
- 修复船舶列表中船籍字段的显示问题
wzg 8 месяцев назад
Родитель
Сommit
2f58c3001a

+ 4 - 0
src/apis/fetch.js

@@ -71,6 +71,10 @@ export default {
   searchShip(data) {
   searchShip(data) {
     return $http("/ship/search", data);
     return $http("/ship/search", data);
   },
   },
+  // 匹配船员
+  searchShipOwner(data) {
+    return $http("/shipOwner/search", data);
+  },
 
 
   // 更新船舶基础信息
   // 更新船舶基础信息
   updateShip(data) {
   updateShip(data) {

+ 1 - 1
src/views/shipManage/shipDetail.vue

@@ -59,7 +59,7 @@
   </div>
   </div>
   <div class="container-title">船舶图片</div>
   <div class="container-title">船舶图片</div>
   <div class="line-container-p24">
   <div class="line-container-p24">
-    <div v-if="!medias.length" class="medias-content df ffw">
+    <div v-if="medias.length" class="medias-content df ffw">
       <div class="pic-container">
       <div class="pic-container">
         <div v-for="(item, index) in medias" :key="item" class="pic-main">
         <div v-for="(item, index) in medias" :key="item" class="pic-main">
           <div :class="['box', index % 2 == 0 ? '' : 'bottom-box']">
           <div :class="['box', index % 2 == 0 ? '' : 'bottom-box']">

+ 1 - 1
src/views/shipManage/shipList.vue

@@ -35,7 +35,7 @@
         ></el-table-column>
         ></el-table-column>
         <el-table-column
         <el-table-column
           align="center"
           align="center"
-          prop="shipRegistryProvince"
+          prop="registryProvince"
           label="船籍"
           label="船籍"
           min-width="80"
           min-width="80"
         />
         />

+ 58 - 9
src/views/shipOwnerManage/shipOwnerDetail.vue

@@ -475,6 +475,14 @@
           />
           />
         </div>
         </div>
       </div>
       </div>
+      <div class="df aic jcfe pr20" v-if="shipOwnerForm?.shipInfo?.code">
+        <el-button
+          type="primary"
+          @click="shipDetail(shipOwnerForm?.shipInfo?.code)"
+        >
+          船舶详情
+        </el-button>
+      </div>
       <div
       <div
         class="df aic jcfe pr20"
         class="df aic jcfe pr20"
         v-if="!shipOwnerForm.shipInfo.id && isBindShipVisible"
         v-if="!shipOwnerForm.shipInfo.id && isBindShipVisible"
@@ -715,9 +723,9 @@ const serviceFileList = computed(() => {
   );
   );
 });
 });
 
 
-async function getShipOwnerDetail() {
+async function getShipOwnerDetail(shipOwnerId) {
   let { data } = await api.getShipOwnerDetail({
   let { data } = await api.getShipOwnerDetail({
-    shipOwnerId: route.query.shipOwnerId,
+    shipOwnerId,
   });
   });
 
 
   if (data.status === 0 && data.result) {
   if (data.status === 0 && data.result) {
@@ -756,13 +764,30 @@ async function getShipOwnerDetail() {
     ElMessage.error(data.msg || "获取船员详情失败");
     ElMessage.error(data.msg || "获取船员详情失败");
   }
   }
 }
 }
+function isPhoneNumber(str) {
+  const phoneNumberRegex = /^1[3-9]\d{9}$/;
+  return phoneNumberRegex.test(str);
+}
 
 
+const isBlurPhone = ref(false);
 // 手机号失去焦点时检查是否已存在船员信息
 // 手机号失去焦点时检查是否已存在船员信息
-const handlePhoneBlur = () => {
+const handlePhoneBlur = async () => {
   if (!shipOwnerForm.value.userPhone) return;
   if (!shipOwnerForm.value.userPhone) return;
+  if (!isPhoneNumber(shipOwnerForm.value.userPhone)) {
+    ElMessage.error("请输入正确的手机号格式");
+    return;
+  }
+  let { data } = await api.searchShipOwner({
+    userPhone: shipOwnerForm.value.userPhone,
+  });
+
+  if (data.status === 0) {
+    getShipOwnerDetail(data.result.id);
+    isBlurPhone.value = true;
+  }
 
 
   // 如果已经有shipOwnerId,说明已经匹配到了船员,不需要再查询
   // 如果已经有shipOwnerId,说明已经匹配到了船员,不需要再查询
-  if (shipOwnerForm.value.shipOwnerId) return;
+  // if (shipOwnerForm.value.shipOwnerId) return;
 };
 };
 
 
 // 身份证人像面删除处理
 // 身份证人像面删除处理
@@ -996,7 +1021,7 @@ const saveBasicInfo = () => {
             JSON.stringify(shipOwnerForm.value)
             JSON.stringify(shipOwnerForm.value)
           );
           );
           // 刷新数据
           // 刷新数据
-          getShipOwnerDetail();
+          getShipOwnerDetail(shipOwnerForm.value.shipOwnerId);
         } else {
         } else {
           ElMessage.error(res.data.msg || "保存失败");
           ElMessage.error(res.data.msg || "保存失败");
         }
         }
@@ -1061,7 +1086,7 @@ const updateShipOwnerCert = () => {
             JSON.stringify(shipOwnerForm.value.certificate)
             JSON.stringify(shipOwnerForm.value.certificate)
           );
           );
           // 刷新数据
           // 刷新数据
-          getShipOwnerDetail();
+          getShipOwnerDetail(shipOwnerForm.value.shipOwnerId);
         } else {
         } else {
           ElMessage.error(res.data.msg || "保存失败");
           ElMessage.error(res.data.msg || "保存失败");
         }
         }
@@ -1077,8 +1102,22 @@ const updateShipOwnerCert = () => {
 };
 };
 
 
 // 保存船员信息
 // 保存船员信息
-const saveShipOwner = () => {
+const saveShipOwner = async () => {
   // 使用Element Plus表单验证
   // 使用Element Plus表单验证
+  if (isBlurPhone.value && shipOwnerForm.value.shipOwnerId) {
+    if (!(await confirm("确定保存已匹配船员信息吗?"))) return;
+    let { data } = await api.addShipOwner({
+      shipOwnerId: shipOwnerForm.value.shipOwnerId,
+    });
+    if (data.status === 0) {
+      ElMessage.success("保存成功");
+      router.replace({ path: "/shipOwnerManage/shipOwnerList" });
+    } else {
+      ElMessage.error(data.msg || "保存失败");
+    }
+    console.log(data);
+    return;
+  }
   shipOwnerFormRef.value.validate((valid1) => {
   shipOwnerFormRef.value.validate((valid1) => {
     if (!valid1) return;
     if (!valid1) return;
 
 
@@ -1245,7 +1284,7 @@ async function addShip() {
         type: "success",
         type: "success",
         message: "绑定成功",
         message: "绑定成功",
       });
       });
-      getShipOwnerDetail();
+      getShipOwnerDetail(route.query.shipOwnerId);
     } else {
     } else {
       ElMessage({
       ElMessage({
         type: "error",
         type: "error",
@@ -1282,12 +1321,22 @@ async function confirm(
   });
   });
 }
 }
 
 
+async function shipDetail(shipCode) {
+  store.commit("addAlive", "shipList");
+  router.push({
+    path: "/shipManage/shipDetail",
+    query: {
+      shipCode,
+    },
+  });
+}
+
 // 初始化数据
 // 初始化数据
 onMounted(() => {
 onMounted(() => {
   // 如果有ID参数,获取船员详情
   // 如果有ID参数,获取船员详情
   if (route.query.shipOwnerId) {
   if (route.query.shipOwnerId) {
     shipOwnerForm.value.shipOwnerId = Number(route.query.shipOwnerId);
     shipOwnerForm.value.shipOwnerId = Number(route.query.shipOwnerId);
-    getShipOwnerDetail();
+    getShipOwnerDetail(route.query.shipOwnerId);
   }
   }
 });
 });
 </script>
 </script>