Browse Source

refactor: cargo页面.代码格式化. 权限控制用的crmid整合声明.

peter 1 month ago
parent
commit
81b65bba1d
1 changed files with 55 additions and 144 deletions
  1. 55 144
      src/pages/cargo-consolidation-request/index.vue

+ 55 - 144
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,11 +174,7 @@
               v-if="
                 currentTab === 'Arrangement' &&
                 ['可用', '已截仓'].includes(currentRow.Status) &&
-                [
-                  '4791186000259693001',
-                  '4791186000022965001',
-                  '4791186000052269001',
-                ].includes(currentUser)
+                superUserIDList.includes(currentUser)
               "
               size="small"
               type="danger"
@@ -206,11 +186,7 @@
               v-if="
                 currentTab === 'Arrangement' &&
                 ['已确认'].includes(currentRow.Status) &&
-                [
-                  '4791186000259693001',
-                  '4791186000022965001',
-                  '4791186000052269001',
-                ].includes(currentUser)
+                superUserIDList.includes(currentUser)
               "
               size="small"
               type="danger"
@@ -260,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"
@@ -294,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
@@ -324,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
@@ -335,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>
@@ -483,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"
@@ -784,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]
 }
@@ -816,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({
@@ -844,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()
@@ -861,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,
@@ -925,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(() => {
@@ -976,17 +921,12 @@ let getSubList = (e: any = {}) => {
 const goodMaterialOption = ref([] as any[])
 // 动态获取货物材质候选数据
 let getGoodMaterialOption = () => {
-  request
-    .post('/common/getWebsiteSubform', { id: '4791186000359651051' })
-    .then((resp: any) => {
-      const res = resp.data.result || {}
-      if (Array.isArray(res.data) && res.data.length) {
-        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()
 
@@ -1037,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) {
@@ -1112,9 +1049,7 @@ const commit = () => {
   if (emptyUserNotesList.length) {
     ElNotification({
       title: '请检查表单, 备注是必填的',
-      message: `第 ${emptyUserNotesList
-        .map((i) => i + 1)
-        .join(', ')} 行的备注数据, 不能为空`,
+      message: `第 ${emptyUserNotesList.map((i) => i + 1).join(', ')} 行的备注数据, 不能为空`,
       duration: 5000,
     })
     return
@@ -1239,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[])
@@ -1289,11 +1222,7 @@ const updateStatus = (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()
@@ -1312,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',
@@ -1329,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 = ''
@@ -1354,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',
@@ -1371,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 = ''
@@ -1404,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)
@@ -1543,8 +1461,9 @@ 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 {
@@ -1558,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;
@@ -1571,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 {