Browse Source

feat: cargo集货页面. 保存动作切换到zoho js sdk实现. 相关数据逻辑调整.

peter 2 weeks ago
parent
commit
8bdc46af11
1 changed files with 161 additions and 1 deletions
  1. 161 1
      src/pages/cargo-consolidation-request/index.vue

+ 161 - 1
src/pages/cargo-consolidation-request/index.vue

@@ -258,7 +258,7 @@
               size="small"
               type="primary"
               class="custom-button small"
-              @click="commit"
+              @click="commitWithSDK"
             >
               保存更改
             </el-button>
@@ -1228,6 +1228,166 @@ const commit = async () => {
       loading.value = false
     })
 }
+const commitWithSDK = async () => {
+  let temp = cloneDeep(subList.value)
+  let formData = customMapData(temp.filter((i) => !i.deleteFlag))
+
+  const emptyUserNotesList: number[] = []
+  const emptyCartonList: number[] = [] // 箱数
+  const emptyMarksNosList: number[] = [] // 唛头
+  const emptyNameList: number[] = [] // 货物名称 Description_of_Goods
+  const emptyCubeList: number[] = [] // 体积
+
+  formData.forEach((i, index) => {
+    if (!i.User_Notes) {
+      emptyUserNotesList.push(index)
+    }
+    if (!i.Carton) {
+      emptyCartonList.push(index)
+    }
+    if (!i.Marks_Nos) {
+      emptyMarksNosList.push(index)
+    }
+    if (!i.Description_of_Goods) {
+      emptyNameList.push(index)
+    }
+    if (!i.Cube) {
+      emptyCubeList.push(index)
+    }
+  })
+
+  if (emptyUserNotesList.length) {
+    ElNotification({
+      title: '请检查表单, 备注是必填的',
+      message: `第 ${emptyUserNotesList.map((i) => i + 1).join(', ')} 行的备注数据, 不能为空`,
+      duration: 5000,
+    })
+    return
+  }
+  if (emptyCartonList.length) {
+    ElNotification({
+      title: '请检查表单, 箱数是必填的',
+      message: `第 ${emptyCartonList.map((i) => i + 1).join(', ')} 行的箱数数据, 不能为空`,
+      duration: 5000,
+    })
+    return
+  }
+  if (emptyMarksNosList.length) {
+    ElNotification({
+      title: '请检查表单, 唛头是必填的',
+      message: `第 ${emptyMarksNosList.map((i) => i + 1).join(', ')} 行的唛头数据, 不能为空`,
+      duration: 5000,
+    })
+    return
+  }
+  if (emptyNameList.length) {
+    ElNotification({
+      title: '请检查表单, 货物名称是必填的',
+      message: `第 ${emptyNameList.map((i) => i + 1).join(', ')} 行的货物名称数据, 不能为空`,
+      duration: 5000,
+    })
+    return
+  }
+  if (emptyCubeList.length) {
+    ElNotification({
+      title: '请检查表单, 体积是必填的',
+      message: `第 ${emptyCubeList.map((i) => i + 1).join(', ')} 行的体积数据, 不能为空`,
+      duration: 5000,
+    })
+    return
+  }
+
+  let params = {
+    APIData: {
+      id: currentRow.value.id,
+      Sea_Freight_Details: formData,
+    },
+    Entity: 'Sea_Freight_Table',
+    trigger: ['workflow', 'approval'],
+  }
+
+  console.log(params, '保存 无转移的数据')
+  let formData2 = customMapData(temp.filter((i) => i.deleteFlag && i.Force_Send)).map((i) => {
+    // 转移之前覆盖 Parent_Id, 否则按照customMapData的逻辑会被存成原航次的id
+    let t = {
+      ...i,
+      Parent_Id: { id: tempShipID },
+    }
+    try {
+      delete t.id // 相当于在新建记录.不删除原id的话, 不一点能转移成功(crm限制), 并且后面原航次的保存会把这个id对应的记录删除
+      delete t.parent_id
+    } catch {
+      console.log(t, '组装转移数据时删除id出错')
+    }
+    return t
+  })
+
+  let params2 = {
+    APIData: {
+      Temporary_Transform_Record: true,
+      Sea_Freight_Details: formData2,
+      Name: '临时调动记录(非真正航次)',
+      ETD: '1900-01-01',
+      ETA: '1900-01-01',
+    },
+    Entity: 'Sea_Freight_Table',
+    trigger: ['workflow', 'approval'],
+  }
+  console.log(params2, '保存 要转移的数据')
+  loading.value = true
+  let sendToTempShipFlag = true // (转移到临时航次) 的状态
+  if (formData2.length) {
+    let res2 = await zoho.CRM.API.insertRecord(params2)
+
+    if (
+      !(
+        Array.isArray(res2.data) &&
+        res2.data.length &&
+        res2.data.every((i: any) => i.status === 'success')
+      )
+    ) {
+      sendToTempShipFlag = false
+      ElNotification({
+        title: '部份内容转移失败',
+        message: '建议刷新再试或者联系管理员',
+        duration: 10000,
+      })
+    } else {
+      return
+    }
+  }
+  if (sendToTempShipFlag === false) {
+    loading.value = false
+    return
+  }
+
+  zoho.CRM.API.updateRecord(params)
+    .then((res: any) => {
+      if (
+        Array.isArray(res.data) &&
+        res.data.length &&
+        res.data.every((i: any) => i.status === 'success')
+      ) {
+        ElNotification({
+          title: '保存成功',
+          message: '正在刷新数据',
+          duration: 3000,
+        })
+      } else {
+        ElNotification({
+          title: '部份内容保存失败',
+          message: '建议刷新再试或者联系管理员',
+          duration: 10000,
+        })
+      }
+      getSubList(currentRow.value)
+    })
+    .catch((e: any) => {
+      console.log(e, 'commit error')
+      loading.value = false
+    })
+}
+
 let printDrawerVisible = ref(false)
 let currentPrintRow = ref({} as any)
 const print = (row: any) => {