1
0

4 Коммитууд 634a66ae8a ... 81b65bba1d

Эзэн SHA1 Мессеж Огноо
  peter 81b65bba1d refactor: cargo页面.代码格式化. 权限控制用的crmid整合声明. 1 сар өмнө
  peter d8e58ce3a9 dev: prettier调整至column 100换行. 1 сар өмнө
  peter 2b0d5c70e7 refactor: cargo集货. 冗余代码删除.功能类方法拆分至单独文件. 1 сар өмнө
  peter 30c44f0b2b feat: cargo集货.增加恢复航次状态功能. 1 сар өмнө

+ 1 - 1
.prettierrc

@@ -1,5 +1,5 @@
 {
-  "printWidth": 80,
+  "printWidth": 100,
   "tabWidth": 2,
   "useTabs": false,
   "singleQuote": true,

+ 60 - 0
src/pages/cargo-consolidation-request/func.ts

@@ -0,0 +1,60 @@
+export const customSort1 = function(a: any, b: any) {
+  return parseFloat(a.Carton || 0) - parseFloat(b.Carton || 0)
+}
+export const customSort2 = function(a: any, b: any) {
+  return parseFloat(a.Quantity || 0) - parseFloat(b.Quantity || 0)
+}
+export const customSort3 = function(a: any, b: any) {
+  return parseFloat(a.Unit_Price || 0) - parseFloat(b.Unit_Price || 0)
+}
+export const customSort4 = function(a: any, b: any) {
+  return parseFloat(a.Weight || 0) - parseFloat(b.Weight || 0)
+}
+export const customSort5 = function(a: any, b: any) {
+  return parseFloat(a.Cube || 0) - parseFloat(b.Cube || 0)
+}
+export const customSort6 = function(a: any, b: any) {
+  return parseFloat(a.Total_FOB || 0) - parseFloat(b.Total_FOB || 0)
+}
+export const refSort = function(a: any, b: any) {
+  if (a.Reference && b.Reference) {
+    return a.Reference.localeCompare(b.Reference)
+  } else if (a.Reference) {
+    return -1
+  } else if (b.Reference) {
+    return 1
+  }
+  return 0
+}
+// 申请人/负责人 点击按 首字符A-Z排序
+export const requesterSort = function(a: any, b: any) {
+  if (a.Requester && b.Requester) {
+    return a.Requester.name.localeCompare(b.Requester.name)
+  } else if (a.Requester) {
+    return -1
+  } else if (b.Requester) {
+    return 1
+  }
+  return 0
+}
+export const salesPersonSort = function(a: any, b: any) {
+  if (a.Sales_Person && b.Sales_Person) {
+    return a.Sales_Person.localeCompare(b.Sales_Person)
+  } else if (a.Sales_Person) {
+    return -1
+  } else if (b.Sales_Person) {
+    return 1
+  }
+  return 0
+}
+// 批次记录batchRecord排序, 按 有值 无值 排序即可
+export const batchRecordSort = function(a: any, b: any) {
+  if (a.Batch_Record && b.Batch_Record) {
+    return a.Batch_Record.name.localeCompare(b.Batch_Record.name)
+  } else if (a.Batch_Record) {
+    return -1
+  } else if (b.Batch_Record) {
+    return 1
+  }
+  return 0
+}

+ 84 - 235
src/pages/cargo-consolidation-request/index.vue

@@ -134,16 +134,8 @@
       >
         <div class="flex">
           <div class="flex flex-wrap min-w-[800px] mr-2">
-            <!-- ['可用', '已截仓'].includes(currentRow.Status) && -->
             <el-input
-              v-if="
-                currentTab === 'Arrangement' &&
-                [
-                  '4791186000259693001',
-                  '4791186000022965001',
-                  '4791186000052269001',
-                ].includes(currentUser)
-              "
+              v-if="currentTab === 'Arrangement' && superUserIDList.includes(currentUser)"
               :disabled="!['Arrangement', 'my_request'].includes(currentTab)"
               style="width: 200px; height: 24px; margin-right: 10px"
               size="small"
@@ -160,16 +152,8 @@
                 </el-button>
               </template>
             </el-input>
-            <!-- ['可用', '已截仓'].includes(currentRow.Status) && -->
             <el-input
-              v-if="
-                currentTab === 'Arrangement' &&
-                [
-                  '4791186000259693001',
-                  '4791186000022965001',
-                  '4791186000052269001',
-                ].includes(currentUser)
-              "
+              v-if="currentTab === 'Arrangement' && superUserIDList.includes(currentUser)"
               :disabled="!['Arrangement', 'my_request'].includes(currentTab)"
               style="width: 200px; height: 24px; margin-right: 10px"
               size="small"
@@ -190,18 +174,26 @@
               v-if="
                 currentTab === 'Arrangement' &&
                 ['可用', '已截仓'].includes(currentRow.Status) &&
-                [
-                  '4791186000259693001',
-                  '4791186000022965001',
-                  '4791186000052269001',
-                ].includes(currentUser)
+                superUserIDList.includes(currentUser)
               "
               size="small"
               type="danger"
-              @click="ensure"
+              @click="updateStatus('已确认')"
             >
               确认集货
             </el-button>
+            <el-button
+              v-if="
+                currentTab === 'Arrangement' &&
+                ['已确认'].includes(currentRow.Status) &&
+                superUserIDList.includes(currentUser)
+              "
+              size="small"
+              type="danger"
+              @click="updateStatus('可用')"
+            >
+              恢复航次
+            </el-button>
             <el-button
               class="custom-button"
               v-if="
@@ -244,8 +236,7 @@
             <el-button
               v-if="
                 ['Arrangement'].includes(currentTab) ||
-                (['可用'].includes(currentRow.Status) &&
-                  ['my_request'].includes(currentTab))
+                (['可用'].includes(currentRow.Status) && ['my_request'].includes(currentTab))
               "
               :disabled="subList.length < 1"
               size="small"
@@ -278,9 +269,7 @@
         :row-style="calcRowStyle"
         :header-cell-style="{ backgroundColor: 'rgb(227, 241, 253)' }"
         :empty-text="
-          currentRow.Name?.length
-            ? '暂无数据'
-            : '请点击voyage表格其中一行以查询相应记录'
+          currentRow.Name?.length ? '暂无数据' : '请点击voyage表格其中一行以查询相应记录'
         "
         @selection-change="handleSelectionChange"
         border
@@ -308,10 +297,7 @@
               filterable
               clearable
               :placeholder="scope.row.Sample ? 'Sample' : ''"
-              :disabled="
-                scope.row.Sample ||
-                !['Arrangement', 'my_request'].includes(currentTab)
-              "
+              :disabled="scope.row.Sample || !['Arrangement', 'my_request'].includes(currentTab)"
               @change="($e) => onBatchRecordChange($e, scope.$index)"
             >
               <el-option
@@ -319,10 +305,7 @@
                 :disabled="!option.isSearch && scope.row.addFlag"
                 :key="option.id"
                 :value="option.id"
-                :label="
-                  option.Name +
-                  (option.Reference ? ` - ${option.Reference}` : '')
-                "
+                :label="option.Name + (option.Reference ? ` - ${option.Reference}` : '')"
               ></el-option>
             </el-select>
           </template>
@@ -467,13 +450,7 @@
         </el-table-column>
 
         <el-table-column
-          v-show="
-            [
-              '4791186000259693001',
-              '4791186000022965001',
-              '4791186000052269001',
-            ].includes(currentUser)
-          "
+          v-show="superUserIDList.includes(currentUser)"
           fixed="right"
           label="操作"
           width="100"
@@ -683,6 +660,18 @@ import * as XLSX from 'xlsx'
 import debounce from 'lodash.debounce'
 import compPrint from '@/components/print.vue'
 import request from '@/utils/axios'
+import {
+  customSort1,
+  customSort2,
+  customSort3,
+  customSort4,
+  customSort5,
+  customSort6,
+  refSort,
+  requesterSort,
+  salesPersonSort,
+  batchRecordSort,
+} from './func'
 
 defineComponent({
   name: 'ComponentCargoConsolidationRequest',
@@ -756,14 +745,8 @@ const dateShortcuts = ref([
 ] as any[])
 function getDefaultRange() {
   const today = dayjs()
-  const lastMonthFirstDay = today
-    .subtract(1, 'month')
-    .startOf('month')
-    .format('YYYY-MM-DD')
-  const nextMonthLastDay = today
-    .add(1, 'month')
-    .endOf('month')
-    .format('YYYY-MM-DD')
+  const lastMonthFirstDay = today.subtract(1, 'month').startOf('month').format('YYYY-MM-DD')
+  const nextMonthLastDay = today.add(1, 'month').endOf('month').format('YYYY-MM-DD')
 
   return [lastMonthFirstDay, nextMonthLastDay]
 }
@@ -788,8 +771,7 @@ let getList = () => {
       if (Array.isArray(res.data) && res.data.length) {
         list.value = res.data.sort(
           (a: any, b: any) =>
-            new Date(b.Cut_Off_Date).getTime() -
-            new Date(a.Cut_Off_Date).getTime(),
+            new Date(b.Cut_Off_Date).getTime() - new Date(a.Cut_Off_Date).getTime(),
         )
       } else if (res.status === 204) {
         ElNotification({
@@ -816,8 +798,7 @@ watch(currentTab, (value: string) => {
 
   // 切到关闭tab, 但当前行不是‘关闭’状态
   let notClose =
-    value === 'voyage_closed' &&
-    !['已截仓', '已确认', '已发出'].includes(currentRow.value.Status)
+    value === 'voyage_closed' && !['已截仓', '已确认', '已发出'].includes(currentRow.value.Status)
 
   if (notAvaliable || notClose) {
     clearSubList()
@@ -833,9 +814,7 @@ const generateSubList = () => {
       .filter(
         (i: any) =>
           i.Parent_Id.id === currentRow.value.id &&
-          (currentTab.value === 'my_request'
-            ? i.Sales_Person === currentUserName.value
-            : true),
+          (currentTab.value === 'my_request' ? i.Sales_Person === currentUserName.value : true),
       )
       .map((i: any) => ({
         ...i,
@@ -897,22 +876,16 @@ const newLineTemplate = {
 // 用在弹窗里面给批次记录做候选项
 let batchListOption = computed(() =>
   subList.value
-    .filter(
-      (i) =>
-        i.Batch_Record && i.Batch_Record.name && i.Batch_Record.name.length > 0,
-    )
-    .map((i) => {
-      return {
-        Name: i.Batch_Record.name || '',
-        id: i.Batch_Record.id || '',
-        isSearch: false, // 用来区分是搜索出来的还是原始数据
-      }
-    })
+    .filter((i) => i.Batch_Record && i.Batch_Record.name && i.Batch_Record.name.length > 0)
+    .map((i) => ({
+      Name: i.Batch_Record.name || '',
+      id: i.Batch_Record.id || '',
+      isSearch: false, // 用来区分是搜索出来的还是原始数据
+    }))
     // ai生成的去重逻辑.
     .filter(
       (item, index, self) =>
-        index ===
-        self.findIndex((t) => t.Name === item.Name && t.id === item.id),
+        index === self.findIndex((t) => t.Name === item.Name && t.id === item.id),
     ),
 )
 let computedOption = computed(() => {
@@ -945,37 +918,15 @@ let getSubList = (e: any = {}) => {
     .finally(() => (loading.value = false))
 }
 // 货物材质候选数据
-const goodMaterialOption = ref([
-  'Cotton 棉',
-  'Iron 铁',
-  'Neoprene 潜水料',
-  'Paper 纸质',
-  'Plastic 塑料',
-  'Polyester Fibre 聚酯纤维',
-  'PU 聚氨酯',
-  'PVC 聚氯乙烯',
-  'Velvet 天鹅绒',
-  'Zinc alloy 锌合金',
-  'Aluminum alloy 铝合金',
-  'Glass 玻璃',
-  'Rubber 橡胶',
-  'Stainless Steel 不锈钢',
-])
+const goodMaterialOption = ref([] as any[])
 // 动态获取货物材质候选数据
 let getGoodMaterialOption = () => {
-  request
-    .post('/common/getWebsiteSubform', { id: '4791186000359651051' })
-    .then((resp: any) => {
-      // console.log(resp, 'res')
-      const res = resp.data.result || {}
-      if (Array.isArray(res.data) && res.data.length) {
-        // console.log(res.data, 'res.data')
-        goodMaterialOption.value =
-          res.data[0].Website_Subform.map(
-            (i: any) => i.Website_Subform_Value,
-          ) || []
-      }
-    })
+  request.post('/common/getWebsiteSubform', { id: '4791186000359651051' }).then((resp: any) => {
+    const res = resp.data.result || {}
+    if (!Array.isArray(res.data) || res.data.length < 1) return
+    goodMaterialOption.value =
+      res.data[0].Website_Subform.map((i: any) => i.Website_Subform_Value) || []
+  })
 }
 getGoodMaterialOption()
 
@@ -1026,10 +977,7 @@ const onBatchRecordChange = ($e: string, line = -1) => {
     subList.value[line].Reference = result.Reference || ''
     subList.value[line].PO_Number = result.PO_Number || ''
     // 如果对应行的唛头为空, 则用批次记录的名称填充
-    if (
-      !subList.value[line].Marks_Nos ||
-      subList.value[line].Marks_Nos.length < 1
-    ) {
+    if (!subList.value[line].Marks_Nos || subList.value[line].Marks_Nos.length < 1) {
       subList.value[line].Marks_Nos = result.Job_Name || ''
     }
     if (!subList.value[line].Quantity) {
@@ -1091,32 +1039,17 @@ const commit = () => {
       }
     }) as any[]
 
-  // const emptyBatchRecordList: number[] = []
   const emptyUserNotesList: number[] = []
   result.forEach((i, index) => {
-    // if (!i.Sample) {
-    //   if (!i.Batch_Record) {
-    //     emptyBatchRecordList.push(index)
-    //   }
-    // }
     if (!i.User_Notes) {
       emptyUserNotesList.push(index)
     }
   })
-  // if (emptyBatchRecordList.length) {
-  //   ElNotification({
-  //     title: '请检查表单',
-  //     message: `第 ${emptyBatchRecordList.map((i) => i + 1).join(', ')} 行的Batch Record数据`,
-  //     duration: 5000,
-  //   })
-  //   return
-  // }
+
   if (emptyUserNotesList.length) {
     ElNotification({
       title: '请检查表单, 备注是必填的',
-      message: `第 ${emptyUserNotesList
-        .map((i) => i + 1)
-        .join(', ')} 行的备注数据, 不能为空`,
+      message: `第 ${emptyUserNotesList.map((i) => i + 1).join(', ')} 行的备注数据, 不能为空`,
       duration: 5000,
     })
     return
@@ -1241,10 +1174,8 @@ const exportSubTable = () => {
   ]
 
   XLSX.utils.book_append_sheet(wb, ws, 'Sheet1')
-  XLSX.writeFile(
-    wb,
-    encodeURIComponent(currentRow.value.Name || 'test') + '.xlsx',
-  )
+  const name = encodeURIComponent(currentRow.value.Name || 'test') + '.xlsx'
+  XLSX.writeFile(wb, name)
 }
 
 let qcList = ref([] as any[])
@@ -1276,8 +1207,8 @@ const search = (keyword: string) => {
     .finally(() => (loading2.value = false))
 }
 
-const ensure = () => {
-  ElMessageBox.confirm('确定要把该记录状态更新为"已确认"吗?', {
+const updateStatus = (status = '已确认') => {
+  ElMessageBox.confirm(`确定要把该记录状态更新为"${status}"吗?`, {
     confirmButtonText: '确定',
     cancelButtonText: '取消',
     type: 'warning',
@@ -1288,14 +1219,10 @@ const ensure = () => {
       Trigger: ['workflow'],
       APIData: {
         id: currentRow.value.id,
-        Status: '已确认',
+        Status: status,
       },
     }).then((res: any) => {
-      if (
-        Array.isArray(res.data) &&
-        res.data.length &&
-        res.data[0].code === 'SUCCESS'
-      ) {
+      if (Array.isArray(res.data) && res.data.length && res.data[0].code === 'SUCCESS') {
         ElMessage.success('操作成功, 正在刷新数据')
         loading.value = false
         getList()
@@ -1314,14 +1241,11 @@ const updateBookingNumber = () => {
     ElMessage.error('请填写订舱号')
     return
   }
-  ElMessageBox.confirm(
-    `确定要把该记录的订舱号更新为"${bookingNumber.value}"吗?`,
-    {
-      confirmButtonText: '确定',
-      cancelButtonText: '取消',
-      type: 'warning',
-    },
-  ).then(() => {
+  ElMessageBox.confirm(`确定要把该记录的订舱号更新为"${bookingNumber.value}"吗?`, {
+    confirmButtonText: '确定',
+    cancelButtonText: '取消',
+    type: 'warning',
+  }).then(() => {
     loading.value = true
     zoho.CRM.API.updateRecord({
       Entity: 'Sea_Freight_Table',
@@ -1331,11 +1255,7 @@ const updateBookingNumber = () => {
         Booking_Number: bookingNumber.value,
       },
     }).then((res: any) => {
-      if (
-        Array.isArray(res.data) &&
-        res.data.length &&
-        res.data[0].code === 'SUCCESS'
-      ) {
+      if (Array.isArray(res.data) && res.data.length && res.data[0].code === 'SUCCESS') {
         ElMessage.success('操作成功, 正在刷新数据')
         loading.value = false
         bookingNumber.value = ''
@@ -1356,14 +1276,11 @@ const updateContainerNumber = () => {
     ElMessage.error('请填写柜号')
     return
   }
-  ElMessageBox.confirm(
-    `确定要把该记录的柜号更新为"${containerNumber.value}"吗?`,
-    {
-      confirmButtonText: '确定',
-      cancelButtonText: '取消',
-      type: 'warning',
-    },
-  ).then(() => {
+  ElMessageBox.confirm(`确定要把该记录的柜号更新为"${containerNumber.value}"吗?`, {
+    confirmButtonText: '确定',
+    cancelButtonText: '取消',
+    type: 'warning',
+  }).then(() => {
     loading.value = true
     zoho.CRM.API.updateRecord({
       Entity: 'Sea_Freight_Table',
@@ -1373,11 +1290,7 @@ const updateContainerNumber = () => {
         Container_Number: containerNumber.value,
       },
     }).then((res: any) => {
-      if (
-        Array.isArray(res.data) &&
-        res.data.length &&
-        res.data[0].code === 'SUCCESS'
-      ) {
+      if (Array.isArray(res.data) && res.data.length && res.data[0].code === 'SUCCESS') {
         ElMessage.success('操作成功, 正在刷新数据')
         loading.value = false
         containerNumber.value = ''
@@ -1406,14 +1319,17 @@ zoho.embeddedApp.on('PageLoad', function () {
 })
 
 zoho.embeddedApp.init()
+const superUserIDList = ref([
+  '4791186000259693001', // 小权限账号, 测试用. 目前是给jayson了.
+  '4791186000022965001', // kava
+  '4791186000052269001', // 物流部
+])
 watch(currentUserRawData, () => {
   if (!currentUserRawData.value.role) return false
 
   let result =
     /(CEO|Logistics)/g.test(currentUserRawData.value.role.name) ||
-    ['4791186000022965001', '4791186000052269001'].includes(
-      currentUserRawData.value.role.id,
-    )
+    superUserIDList.value.includes(currentUserRawData.value.role.id)
 
   if (result) {
     finalTabs.value = cloneDeep(tabs)
@@ -1540,73 +1456,14 @@ let closeCubeDialog = () => {
   cubeForm.value.Carton = '1'
   cubeForm2.value.c = ''
 }
-let customSort1 = (a: any, b: any) => {
-  return parseFloat(a.Carton || 0) - parseFloat(b.Carton || 0)
-}
-let customSort2 = (a: any, b: any) => {
-  return parseFloat(a.Quantity || 0) - parseFloat(b.Quantity || 0)
-}
-let customSort3 = (a: any, b: any) => {
-  return parseFloat(a.Unit_Price || 0) - parseFloat(b.Unit_Price || 0)
-}
-let customSort4 = (a: any, b: any) => {
-  return parseFloat(a.Weight || 0) - parseFloat(b.Weight || 0)
-}
-let customSort5 = (a: any, b: any) => {
-  return parseFloat(a.Cube || 0) - parseFloat(b.Cube || 0)
-}
-let customSort6 = (a: any, b: any) => {
-  return parseFloat(a.Total_FOB || 0) - parseFloat(b.Total_FOB || 0)
-}
-let refSort = (a: any, b: any) => {
-  if (a.Reference && b.Reference) {
-    return a.Reference.localeCompare(b.Reference)
-  } else if (a.Reference) {
-    return -1
-  } else if (b.Reference) {
-    return 1
-  }
-  return 0
-}
-// 申请人/负责人 点击按 首字符A-Z排序
-let requesterSort = (a: any, b: any) => {
-  if (a.Requester && b.Requester) {
-    return a.Requester.name.localeCompare(b.Requester.name)
-  } else if (a.Requester) {
-    return -1
-  } else if (b.Requester) {
-    return 1
-  }
-  return 0
-}
-let salesPersonSort = (a: any, b: any) => {
-  if (a.Sales_Person && b.Sales_Person) {
-    return a.Sales_Person.localeCompare(b.Sales_Person)
-  } else if (a.Sales_Person) {
-    return -1
-  } else if (b.Sales_Person) {
-    return 1
-  }
-  return 0
-}
-// 批次记录batchRecord排序, 按 有值 无值 排序即可
-let batchRecordSort = (a: any, b: any) => {
-  if (a.Batch_Record && b.Batch_Record) {
-    return a.Batch_Record.name.localeCompare(b.Batch_Record.name)
-  } else if (a.Batch_Record) {
-    return -1
-  } else if (b.Batch_Record) {
-    return 1
-  }
-  return 0
-}
 
 let selectedRow = ref([] as any[])
 const handleSelectionChange = (val: any[]) => {
   selectedRow.value = val
 }
-let calcSelectAble = (row: any) =>
-  !row.addFlag && !row.deleteFlag && !row.editFlag
+let calcSelectAble = (row: any) => !row.addFlag && !row.deleteFlag && !row.editFlag
+
+// 别说代码行数太长搞屎山, 这个页面的功能上线之后改了6个版本, 每次都往上堆功能, 能不长嘛
 </script>
 <style lang="scss">
 .page-cargo-consolidation {
@@ -1620,11 +1477,7 @@ let calcSelectAble = (row: any) =>
 .el-button.custom-button {
   height: 24px;
   line-height: 24px;
-  background-image: linear-gradient(
-    171deg,
-    rgb(28, 74, 136) 49%,
-    rgb(0, 130, 193) 100%
-  );
+  background-image: linear-gradient(171deg, rgb(28, 74, 136) 49%, rgb(0, 130, 193) 100%);
   background-color: rgb(97, 165, 245);
   color: #fff;
   font-size: 13px;
@@ -1633,11 +1486,7 @@ let calcSelectAble = (row: any) =>
   cursor: pointer;
   &:hover,
   &:active {
-    background-image: linear-gradient(
-      171deg,
-      rgb(28, 74, 136) 49%,
-      rgb(22, 208, 239) 100%
-    );
+    background-image: linear-gradient(171deg, rgb(28, 74, 136) 49%, rgb(22, 208, 239) 100%);
     color: #fff;
   }
   &.fb {