index.vue 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729
  1. <template>
  2. <div class="w-[100vw] bg-white page-cargo-consolidation">
  3. <div
  4. v-loading="loading"
  5. class="w-[100%] min-h-[100vh]"
  6. >
  7. <el-form
  8. style="width: 100%"
  9. inline
  10. :loading="loading"
  11. @submit.prevent="getList"
  12. >
  13. <el-form-item
  14. label="ETD Range"
  15. style="margin-bottom: 10px"
  16. >
  17. <el-date-picker
  18. size="small"
  19. v-model="dateRange"
  20. type="daterange"
  21. unlink-panels
  22. clearable
  23. start-placeholder="Start date"
  24. end-placeholder="End date"
  25. :shortcuts="dateShortcuts"
  26. />
  27. </el-form-item>
  28. <el-form-item style="margin-bottom: 10px">
  29. <el-tooltip content="时间范围最好不要选太大, 不然数据太多会卡">
  30. <el-button
  31. class="custom-button"
  32. @click="getList"
  33. >
  34. Search
  35. </el-button>
  36. </el-tooltip>
  37. <el-button
  38. @click="openTempShip"
  39. size="small"
  40. >
  41. 候选货物列表
  42. </el-button>
  43. </el-form-item>
  44. </el-form>
  45. <el-tabs v-model="currentTab">
  46. <el-tab-pane
  47. v-for="tab in finalTabs"
  48. :key="tab.value"
  49. :label="tab.label"
  50. :name="tab.value"
  51. ></el-tab-pane>
  52. </el-tabs>
  53. <el-table
  54. border
  55. :header-cell-style="{ backgroundColor: 'rgb(227, 241, 253)' }"
  56. :data="computedList"
  57. highlight-current-row
  58. style="width: 100%"
  59. max-height="330"
  60. @row-click="($e) => getSubList($e)"
  61. >
  62. <el-table-column
  63. prop="Name"
  64. label="船名&航次"
  65. min-width="500"
  66. />
  67. <el-table-column
  68. prop="Forwarder"
  69. label="货代"
  70. width="100"
  71. />
  72. <el-table-column
  73. prop="ETD"
  74. label="ETD"
  75. width="100"
  76. />
  77. <el-table-column
  78. prop="ATD"
  79. label="ATD"
  80. width="100"
  81. />
  82. <el-table-column
  83. prop="ETA"
  84. label="ETA"
  85. width="100"
  86. />
  87. <el-table-column
  88. prop="ATA"
  89. label="ATA"
  90. width="100"
  91. />
  92. <el-table-column
  93. prop="Cut_Off_Date"
  94. label="入仓时间"
  95. width="100"
  96. />
  97. <el-table-column
  98. label="截止时间"
  99. width="200"
  100. >
  101. <template #default="scope">
  102. <div>
  103. {{ formatCutOffDateTime(scope.row.Cut_Off_Date_Time) }}
  104. </div>
  105. </template>
  106. </el-table-column>
  107. <el-table-column
  108. prop="Status"
  109. label="状态"
  110. width="75"
  111. />
  112. <el-table-column
  113. prop="GRN"
  114. label="入仓单号"
  115. min-width="200"
  116. />
  117. <el-table-column
  118. prop="Booking_Number"
  119. label="订舱号"
  120. min-width="120"
  121. />
  122. <el-table-column
  123. prop="Container_Number"
  124. label="柜号"
  125. min-width="125"
  126. />
  127. <el-table-column
  128. prop="Carrier"
  129. label="船东"
  130. min-width="100"
  131. />
  132. <el-table-column label="操作">
  133. <template #default="scope">
  134. <el-button
  135. size="small"
  136. type="warning"
  137. link
  138. :disabled="!scope.row.SubscriptionId"
  139. @click="openMapDrawer(scope.row)"
  140. >
  141. 查看轨迹
  142. </el-button>
  143. </template>
  144. </el-table-column>
  145. </el-table>
  146. <div
  147. v-show="currentRow.Name?.length"
  148. class="flex justify-between mt-8"
  149. >
  150. <div class="flex">
  151. <div class="flex flex-wrap min-w-[800px] mr-2">
  152. <el-input
  153. v-if="currentTab === 'Arrangement' && superUserIDList.includes(currentUser)"
  154. :disabled="!['Arrangement', 'my_request'].includes(currentTab)"
  155. style="width: 200px; height: 24px; margin-right: 10px"
  156. size="small"
  157. v-model="bookingNumber"
  158. >
  159. <template #append>
  160. <el-button
  161. class="custom-button"
  162. size="small"
  163. style="padding-top: 0; padding-bottom: 0"
  164. @click="updateBookingNumber"
  165. >
  166. 更新订舱号
  167. </el-button>
  168. </template>
  169. </el-input>
  170. <el-input
  171. v-if="currentTab === 'Arrangement' && superUserIDList.includes(currentUser)"
  172. :disabled="!['Arrangement', 'my_request'].includes(currentTab)"
  173. style="width: 200px; height: 24px; margin-right: 10px"
  174. size="small"
  175. v-model="containerNumber"
  176. >
  177. <template #append>
  178. <el-button
  179. class="custom-button"
  180. size="small"
  181. style="padding-top: 0; padding-bottom: 0"
  182. @click="updateContainerNumber"
  183. >
  184. 更新柜号
  185. </el-button>
  186. </template>
  187. </el-input>
  188. <el-button
  189. v-if="
  190. currentTab === 'Arrangement' &&
  191. ['可用', '已截仓'].includes(currentRow.Status) &&
  192. superUserIDList.includes(currentUser)
  193. "
  194. size="small"
  195. type="danger"
  196. @click="updateStatus('已确认')"
  197. >
  198. 确认集货
  199. </el-button>
  200. <el-button
  201. v-if="
  202. currentTab === 'Arrangement' &&
  203. ['已确认'].includes(currentRow.Status) &&
  204. superUserIDList.includes(currentUser)
  205. "
  206. size="small"
  207. type="danger"
  208. @click="updateStatus('可用')"
  209. >
  210. 恢复航次
  211. </el-button>
  212. <el-button
  213. class="custom-button"
  214. v-if="
  215. ['Arrangement', 'my_request'].includes(currentTab) &&
  216. ['可用'].includes(currentRow.Status)
  217. "
  218. size="small"
  219. @click="addBulkProduct"
  220. >
  221. 提交大货集货申请
  222. </el-button>
  223. <el-button
  224. class="custom-button"
  225. v-if="
  226. ['Arrangement', 'my_request'].includes(currentTab) &&
  227. ['可用'].includes(currentRow.Status)
  228. "
  229. size="small"
  230. @click="addSample"
  231. >
  232. 提交样品集货申请
  233. </el-button>
  234. <el-button
  235. v-if="['Arrangement', 'my_request'].includes(currentTab)"
  236. :disabled="subList.length < 1"
  237. size="small"
  238. type="danger"
  239. @click="generateSubList"
  240. >
  241. 放弃下方表格改动
  242. </el-button>
  243. <el-button
  244. class="custom-button"
  245. size="small"
  246. :disabled="subList.length < 1"
  247. @click="exportSubTable(subList, currentRow.Name)"
  248. >
  249. 导出Excel文档
  250. </el-button>
  251. <el-button
  252. v-if="
  253. ['Arrangement'].includes(currentTab) ||
  254. (['可用'].includes(currentRow.Status) && ['my_request'].includes(currentTab))
  255. "
  256. :disabled="subList.length < 1"
  257. size="small"
  258. type="primary"
  259. class="custom-button small"
  260. @click="commitWithSDK"
  261. >
  262. 保存更改
  263. </el-button>
  264. </div>
  265. </div>
  266. <div>
  267. <div class="flex justify-end min-w-[380px] gap-2">
  268. <div class="flex">总重量: {{ computedWeight }}</div>
  269. <div class="flex">总体积: {{ computedCube }}</div>
  270. <div class="flex">总离岸价: {{ computedTotalFOB }}</div>
  271. </div>
  272. <div class="flex justify-end min-w-[380px] gap-2">
  273. <div class="flex">已选重量: {{ computedSelectedWeight }}</div>
  274. <div class="flex">已选体积: {{ computedSelectedCube }}</div>
  275. <div class="flex">已选离岸价: {{ computedSelectedTotalFOB }}</div>
  276. </div>
  277. </div>
  278. </div>
  279. <el-table
  280. class="mt-4"
  281. size="small"
  282. :data="subList"
  283. style="width: 100%"
  284. :row-style="calcRowStyle"
  285. :header-cell-style="{ backgroundColor: 'rgb(227, 241, 253)' }"
  286. :empty-text="
  287. currentRow.Name?.length ? '暂无数据' : '请点击voyage表格其中一行以查询相应记录'
  288. "
  289. @selection-change="handleSelectionChange"
  290. border
  291. >
  292. <el-table-column
  293. fixed
  294. type="index"
  295. width="40"
  296. ></el-table-column>
  297. <el-table-column
  298. :sortable="currentTab === 'Arrangement'"
  299. :sort-method="batchRecordSort"
  300. fixed
  301. label="CRM批次记录"
  302. width="220"
  303. >
  304. <template #default="scope">
  305. <el-select
  306. v-model="scope.row.batchRecord"
  307. size="small"
  308. :remote-method="debounce(search, 1500)"
  309. remote
  310. style="width: 100%"
  311. :loading="loading2"
  312. filterable
  313. clearable
  314. :placeholder="scope.row.Sample ? 'Sample' : ''"
  315. :disabled="scope.row.Sample || !['Arrangement', 'my_request'].includes(currentTab)"
  316. @change="($e) => onBatchRecordChange($e, scope.$index)"
  317. >
  318. <el-option
  319. v-for="option in computedOption as any[]"
  320. :disabled="!option.isSearch && scope.row.addFlag"
  321. :key="option.id"
  322. :value="option.id"
  323. :label="option.Name + (option.Reference ? ` - ${option.Reference}` : '')"
  324. ></el-option>
  325. </el-select>
  326. </template>
  327. </el-table-column>
  328. <el-table-column
  329. label="备注"
  330. width="110"
  331. fixed
  332. >
  333. <template #default="scope">
  334. <el-input
  335. :disabled="!['Arrangement', 'my_request'].includes(currentTab)"
  336. v-model="scope.row.User_Notes"
  337. size="small"
  338. :rows="2"
  339. type="textarea"
  340. @change="scope.row.editFlag = true"
  341. ></el-input>
  342. </template>
  343. </el-table-column>
  344. <el-table-column
  345. label="箱数"
  346. width="80"
  347. :sortable="currentTab === 'Arrangement'"
  348. :sort-method="customSort1"
  349. >
  350. <template #default="scope">
  351. <el-input
  352. :disabled="!['Arrangement', 'my_request'].includes(currentTab)"
  353. v-model="scope.row.Carton"
  354. size="small"
  355. @change="scope.row.editFlag = true"
  356. ></el-input>
  357. </template>
  358. </el-table-column>
  359. <el-table-column
  360. label="唛头"
  361. width="220"
  362. >
  363. <template #default="scope">
  364. <el-input
  365. :disabled="!['Arrangement', 'my_request'].includes(currentTab)"
  366. v-model="scope.row.Marks_Nos"
  367. size="small"
  368. @change="scope.row.editFlag = true"
  369. ></el-input>
  370. </template>
  371. </el-table-column>
  372. <el-table-column
  373. label="货物名称"
  374. width="180"
  375. >
  376. <template #default="scope">
  377. <el-input
  378. :disabled="!['Arrangement', 'my_request'].includes(currentTab)"
  379. v-model="scope.row.Description_of_Goods"
  380. size="small"
  381. @change="scope.row.editFlag = true"
  382. ></el-input>
  383. </template>
  384. </el-table-column>
  385. <el-table-column
  386. label="货物材质"
  387. width="220"
  388. >
  389. <template #default="scope">
  390. <el-select
  391. :disabled="!['Arrangement', 'my_request'].includes(currentTab)"
  392. v-model="scope.row.Material_of_Goods"
  393. size="small"
  394. multiple
  395. @change="scope.row.editFlag = true"
  396. >
  397. <el-option
  398. v-for="i in goodMaterialOption"
  399. :key="i"
  400. :value="i"
  401. :label="i"
  402. ></el-option>
  403. </el-select>
  404. </template>
  405. </el-table-column>
  406. <el-table-column
  407. label="数量"
  408. width="100"
  409. :sortable="currentTab === 'Arrangement'"
  410. :sort-method="customSort2"
  411. >
  412. <template #default="scope">
  413. <el-input
  414. :disabled="!['Arrangement', 'my_request'].includes(currentTab)"
  415. v-model="scope.row.Quantity"
  416. size="small"
  417. @change="changeTotal(scope.row)"
  418. ></el-input>
  419. </template>
  420. </el-table-column>
  421. <el-table-column
  422. label="单价(澳币/AUD)"
  423. :sortable="currentTab === 'Arrangement'"
  424. :sort-method="customSort3"
  425. width="145"
  426. >
  427. <template #default="scope">
  428. <el-input
  429. :disabled="!['Arrangement', 'my_request'].includes(currentTab)"
  430. v-model="scope.row.Unit_Price"
  431. size="small"
  432. @change="changeTotal(scope.row)"
  433. ></el-input>
  434. </template>
  435. </el-table-column>
  436. <el-table-column
  437. :sortable="currentTab === 'Arrangement'"
  438. :sort-method="requesterSort"
  439. label="负责人"
  440. fixed="right"
  441. width="120"
  442. >
  443. <template #default="scope">
  444. <el-input
  445. v-model="scope.row.Requester.name"
  446. size="small"
  447. disabled
  448. ></el-input>
  449. </template>
  450. </el-table-column>
  451. <el-table-column
  452. :sortable="currentTab === 'Arrangement'"
  453. :sort-method="salesPersonSort"
  454. label="申请人"
  455. fixed="right"
  456. width="120"
  457. >
  458. <template #default="scope">
  459. <el-input
  460. v-model="scope.row.Sales_Person"
  461. size="small"
  462. disabled
  463. ></el-input>
  464. </template>
  465. </el-table-column>
  466. <el-table-column
  467. v-show="superUserIDList.includes(currentUser)"
  468. fixed="right"
  469. label="操作"
  470. width="100"
  471. >
  472. <template #default="scope">
  473. <el-tooltip
  474. content="新增未commit的行会被直接移除; 已commit的行只会标记, 正式commit后才会删除"
  475. >
  476. <el-button
  477. v-if="['Arrangement', 'my_request'].includes(currentTab)"
  478. type="danger"
  479. size="small"
  480. link
  481. @click="() => onDeleteRow(scope.row, scope.$index)"
  482. >
  483. 删除
  484. </el-button>
  485. </el-tooltip>
  486. <el-button
  487. size="small"
  488. link
  489. type="primary"
  490. @click="print(scope.row)"
  491. >
  492. 打印
  493. </el-button>
  494. </template>
  495. </el-table-column>
  496. <el-table-column
  497. label="自动发送"
  498. width="75"
  499. fixed="right"
  500. >
  501. <template #default="scope">
  502. <el-tooltip
  503. content="配合'删除'操作可转移到候选货物列表中, 下次新建航次CRM会自动将其加入"
  504. >
  505. <el-checkbox
  506. :disabled="!['Arrangement'].includes(currentTab)"
  507. @change="
  508. () => {
  509. if (scope.row.Force_Send) {
  510. scope.row.editFlag = true
  511. }
  512. }
  513. "
  514. v-model="scope.row.Force_Send"
  515. ></el-checkbox>
  516. </el-tooltip>
  517. </template>
  518. </el-table-column>
  519. <el-table-column
  520. fixed="right"
  521. label="重量 (KG)"
  522. :sortable="currentTab === 'Arrangement'"
  523. :sort-method="customSort4"
  524. width="100"
  525. >
  526. <template #default="scope">
  527. <el-input
  528. :disabled="!['Arrangement', 'my_request'].includes(currentTab)"
  529. v-model="scope.row.Weight"
  530. size="small"
  531. @change="scope.row.editFlag = true"
  532. ></el-input>
  533. </template>
  534. </el-table-column>
  535. <el-table-column
  536. :sortable="currentTab === 'Arrangement'"
  537. :sort-method="customSort5"
  538. fixed="right"
  539. label="体积 m&sup3;"
  540. width="95"
  541. >
  542. <template #default="scope">
  543. <el-button
  544. @click="openCubeDialog(scope)"
  545. :disabled="!['Arrangement', 'my_request'].includes(currentTab)"
  546. type="primary"
  547. size="small"
  548. text
  549. >
  550. {{ scope.row.Cube || '点击输入' }}
  551. </el-button>
  552. </template>
  553. </el-table-column>
  554. <el-table-column
  555. :sortable="currentTab === 'Arrangement'"
  556. :sort-method="customSort6"
  557. fixed="right"
  558. label="总离岸价 (澳币/AUD)"
  559. width="165"
  560. >
  561. <template #default="scope">
  562. <el-input
  563. v-model="scope.row.Total_FOB"
  564. size="small"
  565. disabled
  566. ></el-input>
  567. </template>
  568. </el-table-column>
  569. <el-table-column
  570. :sortable="currentTab === 'Arrangement'"
  571. :sort-method="refSort"
  572. label="Reference"
  573. fixed="right"
  574. width="110"
  575. >
  576. <template #default="scope">
  577. <div class="">{{ scope.row.Reference || scope.row.PO_Number }}</div>
  578. </template>
  579. </el-table-column>
  580. <el-table-column
  581. :selectable="calcSelectAble"
  582. type="selection"
  583. width="40"
  584. fixed="right"
  585. />
  586. </el-table>
  587. <el-drawer
  588. v-model:model-value="printDrawerVisible"
  589. :size="'1050px'"
  590. :title="'打印唛 (注意先写完唛内容和宽高最后再调页数, 不然可能会很卡)'"
  591. :close-on-click-modal="false"
  592. :close-on-press-escape="false"
  593. >
  594. <comp-print
  595. v-if="printDrawerVisible"
  596. :autoOpenQRCode="false"
  597. :content="[currentPrintRow.Marks_Nos || '']"
  598. :scene="'QC'"
  599. />
  600. </el-drawer>
  601. <el-drawer
  602. v-model:model-value="mapDrawerVisible"
  603. :size="'1050px'"
  604. :close-on-click-modal="false"
  605. :close-on-press-escape="false"
  606. :destroy-on-close="true"
  607. :with-header="false"
  608. header-class="mb-1"
  609. >
  610. <div class="relative h-[20px]">
  611. <span
  612. @click="closeMapDrawer"
  613. class="absolute top-[-16px] right-0 text-gray-600 text-sm cursor-pointer"
  614. >
  615. 关闭地图窗口
  616. </span>
  617. </div>
  618. <div
  619. id="mapDrawer"
  620. class="h-[100%]"
  621. ></div>
  622. </el-drawer>
  623. </div>
  624. <el-dialog
  625. style="margin-top: 35vh"
  626. title="体积输入(直接输入体积, 或输入长宽高自动计算)"
  627. :modelValue="cubeDialogVisible >= 0"
  628. @close="closeCubeDialog"
  629. width="400px"
  630. >
  631. <el-form
  632. label-position="right"
  633. label-width="95px"
  634. >
  635. <el-form-item label="长短单位">
  636. <el-radio-group v-model="unitType">
  637. <el-radio-button :label="1">米 (m)</el-radio-button>
  638. <el-radio-button :label="2">厘米 (cm)</el-radio-button>
  639. </el-radio-group>
  640. </el-form-item>
  641. <el-form-item :label="`length (${unitType === 1 ? 'm' : 'cm'})`">
  642. <el-input v-model="cubeForm.l"></el-input>
  643. </el-form-item>
  644. <el-form-item :label="`width (${unitType === 1 ? 'm' : 'cm'})`">
  645. <el-input v-model="cubeForm.w"></el-input>
  646. </el-form-item>
  647. <el-form-item :label="`height (${unitType === 1 ? 'm' : 'cm'})`">
  648. <el-input v-model="cubeForm.h"></el-input>
  649. </el-form-item>
  650. <el-form-item label="箱数(整数)">
  651. <el-input v-model="cubeForm.Carton"></el-input>
  652. </el-form-item>
  653. <el-form-item label="cube (m³)">
  654. <el-input v-model="cubeForm2.c"></el-input>
  655. </el-form-item>
  656. <el-form-item>
  657. <div class="w-full flex justify-center">
  658. <el-button
  659. size="small"
  660. type="primary"
  661. @click="commitCube"
  662. >
  663. 确定
  664. </el-button>
  665. <el-button
  666. size="small"
  667. @click="closeCubeDialog"
  668. >
  669. 取消
  670. </el-button>
  671. </div>
  672. </el-form-item>
  673. </el-form>
  674. </el-dialog>
  675. <comp-temp-ship
  676. v-model:visible="tempShipVisible"
  677. :id="tempShipID"
  678. :current-tab="currentTab"
  679. :good-material-option="goodMaterialOption"
  680. ></comp-temp-ship>
  681. </div>
  682. </template>
  683. <script lang="ts" setup>
  684. import { defineComponent, ref, watch, computed, nextTick } from 'vue'
  685. import {
  686. ElButton,
  687. ElForm,
  688. ElFormItem,
  689. ElInput,
  690. ElTabs,
  691. ElTabPane,
  692. ElTable,
  693. ElTableColumn,
  694. ElDatePicker,
  695. ElTooltip,
  696. ElSelect,
  697. ElOption,
  698. ElMessage,
  699. ElMessageBox,
  700. ElNotification,
  701. ElDrawer,
  702. ElDialog,
  703. ElCheckbox,
  704. ElRadio,
  705. ElRadioGroup,
  706. ElRadioButton,
  707. } from 'element-plus'
  708. import cloneDeep from 'lodash.clonedeep'
  709. import dayjs from 'dayjs'
  710. import utc from 'dayjs/plugin/utc.js'
  711. import timezone from 'dayjs/plugin/timezone.js'
  712. import debounce from 'lodash.debounce'
  713. import compPrint from '@/components/print.vue'
  714. import request from '@/utils/axios'
  715. import {
  716. customSort1,
  717. customSort2,
  718. customSort3,
  719. customSort4,
  720. customSort5,
  721. customSort6,
  722. refSort,
  723. requesterSort,
  724. salesPersonSort,
  725. batchRecordSort,
  726. customMapData,
  727. calcSelectAble,
  728. calcRowStyle,
  729. exportSubTable,
  730. } from './func'
  731. import compTempShip from './compTempShip.vue'
  732. defineComponent({
  733. name: 'ComponentCargoConsolidationRequest',
  734. })
  735. const currentUser = ref('')
  736. const currentUserName = ref('')
  737. const currentUserRawData = ref({} as any)
  738. let loading = ref(false)
  739. let list = ref([] as any[])
  740. let currentTab = ref('all')
  741. let tabs = [
  742. {
  743. label: 'All',
  744. value: 'all',
  745. },
  746. {
  747. label: 'Avaliable',
  748. value: 'avaliable',
  749. },
  750. {
  751. label: 'Closed Voyage',
  752. value: 'voyage_closed',
  753. },
  754. {
  755. label: 'My Request',
  756. value: 'my_request',
  757. },
  758. ]
  759. dayjs.extend(utc)
  760. dayjs.extend(timezone)
  761. let finalTabs = ref([] as any[])
  762. finalTabs.value = cloneDeep(tabs)
  763. let computedList = computed(() => {
  764. return list.value.filter((i: any) => {
  765. let condition = true
  766. switch (currentTab.value) {
  767. case 'avaliable':
  768. condition = i.Status && i.Status === '可用'
  769. break
  770. case 'voyage_closed':
  771. condition = ['已截仓', '已确认', '已发出', '已到达'].includes(i.Status)
  772. break
  773. }
  774. return condition
  775. })
  776. })
  777. let dateRange = ref([] as any[])
  778. const generateDateRange = (days = 7) => {
  779. const today = new Date()
  780. const endDate = new Date()
  781. endDate.setDate(today.getDate() + days)
  782. return [today, endDate]
  783. }
  784. const dateShortcuts = ref([
  785. {
  786. text: 'Next 3 days',
  787. value: generateDateRange(3),
  788. },
  789. {
  790. text: 'Next week',
  791. value: generateDateRange(7),
  792. },
  793. {
  794. text: 'Next 14days',
  795. value: generateDateRange(14),
  796. },
  797. ] as any[])
  798. function getDefaultRange() {
  799. const today = dayjs()
  800. const lastMonthFirstDay = today.subtract(1, 'month').startOf('month').format('YYYY-MM-DD')
  801. const nextMonthLastDay = today.add(1, 'month').endOf('month').format('YYYY-MM-DD')
  802. return [lastMonthFirstDay, nextMonthLastDay]
  803. }
  804. dateRange.value = getDefaultRange()
  805. let formatCutOffDateTime = (str: string) =>
  806. str?.length ? dayjs.utc(str).tz('Asia/Shanghai').format('YYYY-MM-DD HH:mm:ss') : ''
  807. const clearSubList = () => {
  808. subList.value = []
  809. subListBackup = []
  810. currentRow.value = {}
  811. }
  812. let getList = () => {
  813. loading.value = true
  814. zoho.CRM.API.coql({
  815. select_query:
  816. 'select Container_Number,Name,Forwarder,ETD,ATD,ETA,ATA,Cut_Off_Date,Owner,Status,Modified_Time,SubscriptionId,Carrier,Booking_Number,GRN,Cut_Off_Date_Time from Sea_Freight_Table' +
  817. " where ETD between '" +
  818. `${dateRange.value.map((i) => dayjs(i).format('YYYY-MM-DD')).join("' and '")}` +
  819. "'",
  820. })
  821. .then((res: any) => {
  822. if (Array.isArray(res.data) && res.data.length) {
  823. list.value = res.data.sort(
  824. (a: any, b: any) =>
  825. new Date(b.Cut_Off_Date).getTime() - new Date(a.Cut_Off_Date).getTime(),
  826. )
  827. } else if (res.status === 204) {
  828. ElNotification({
  829. type: 'warning',
  830. title: 'No Data Found',
  831. message: res.statusText || `zoho api return: ${res.status}`,
  832. duration: 3000,
  833. })
  834. list.value = []
  835. }
  836. clearSubList()
  837. })
  838. .finally(() => (loading.value = false))
  839. }
  840. let currentRow = ref({} as any)
  841. let subList = ref([] as any[])
  842. // 未经过滤的crm数据
  843. let subListBackup: any[] = []
  844. watch(currentTab, (value: string) => {
  845. // 切到可用tab, 但是当前行是不是 可用 状态
  846. let notAvaliable = value === 'avaliable' && currentRow.value.Status !== '可用'
  847. // 切到关闭tab, 但当前行不是‘关闭’状态
  848. let notClose =
  849. value === 'voyage_closed' && !['已截仓', '已确认', '已发出'].includes(currentRow.value.Status)
  850. if (notAvaliable || notClose) {
  851. clearSubList()
  852. } else {
  853. generateSubList()
  854. }
  855. })
  856. const generateSubList = () => {
  857. // clonedeep 是因为数据里面有 object array, 担心浅复制到表单变量会影响到原始数据
  858. subList.value = cloneDeep(
  859. subListBackup
  860. .filter(
  861. (i: any) =>
  862. i.Parent_Id.id === currentRow.value.id &&
  863. (currentTab.value === 'my_request' ? i.Sales_Person === currentUserName.value : true),
  864. )
  865. .map((i: any) => ({
  866. ...i,
  867. Requester: i.Requester?.id
  868. ? {
  869. name: i.Requester.name || '',
  870. id: i.Requester.id,
  871. }
  872. : { name: '', id: '' },
  873. Sample: i.Sample || false,
  874. batchRecord: i.Batch_Record?.id || '',
  875. addFlag: false,
  876. editFlag: false,
  877. deleteFlag: false,
  878. })),
  879. )
  880. }
  881. const changeTotal = (row: any) => {
  882. row.editFlag = true
  883. row.Total_FOB = (Number(row.Unit_Price) * Number(row.Quantity)).toFixed(2)
  884. }
  885. /**
  886. * 用来增加新行的数据模版
  887. */
  888. const newLineTemplate = {
  889. addFlag: true,
  890. editFlag: true,
  891. deleteFlag: false,
  892. batchRecord: '',
  893. // 提交表单前删掉以上字段
  894. // id: '',
  895. Sample: false,
  896. Batch_Record: {
  897. name: '',
  898. id: '',
  899. } as any,
  900. Sales_Order: '',
  901. Purchase_Order: '',
  902. Reference: '',
  903. PO_Number: '',
  904. Parent_Id: {
  905. name: '',
  906. id: '',
  907. } as any,
  908. Carton: '',
  909. Marks_Nos: '',
  910. Description_of_Goods: '',
  911. Material_of_Goods: [],
  912. Quantity: '',
  913. Unit_Price: '',
  914. Weight: '',
  915. Cube: '',
  916. Total_FOB: '',
  917. Requester: { name: '', id: '' } as any,
  918. Sales_Person: '', // 申请人
  919. User_Notes: '',
  920. }
  921. // 用在弹窗里面给批次记录做候选项
  922. let batchListOption = computed(() =>
  923. subList.value
  924. .filter((i) => i.Batch_Record && i.Batch_Record.name && i.Batch_Record.name.length > 0)
  925. .map((i) => ({
  926. Name: i.Batch_Record.name || '',
  927. id: i.Batch_Record.id || '',
  928. isSearch: false, // 用来区分是搜索出来的还是原始数据
  929. }))
  930. // ai生成的去重逻辑.
  931. .filter(
  932. (item, index, self) =>
  933. index === self.findIndex((t) => t.Name === item.Name && t.id === item.id),
  934. ),
  935. )
  936. let computedOption = computed(() => {
  937. return qcList.value.concat(batchListOption.value)
  938. })
  939. let getSubList = (e: any = {}) => {
  940. if (e.id) currentRow.value = e
  941. loading.value = true
  942. zoho.CRM.API.searchRecord({
  943. Entity: 'Sea_Freight_Details',
  944. Type: 'criteria',
  945. Query: `(Parent_Id:equals:${currentRow.value.id})`,
  946. delay: false,
  947. })
  948. .then((res: any) => {
  949. if (Array.isArray(res.data) && res.data.length) {
  950. subListBackup = cloneDeep(res.data)
  951. } else {
  952. subListBackup = []
  953. }
  954. generateSubList()
  955. newLineTemplate.Parent_Id = { id: currentRow.value.id }
  956. newLineTemplate.Sales_Person = currentUserName.value
  957. newLineTemplate.Requester = {
  958. id: currentUser.value,
  959. name: currentUserName.value,
  960. }
  961. })
  962. .finally(() => (loading.value = false))
  963. }
  964. // 货物材质候选数据
  965. const goodMaterialOption = ref([] as any[])
  966. // 动态获取货物材质候选数据
  967. let getGoodMaterialOption = () => {
  968. request.post('/common/getWebsiteSubform', { id: '4791186000359651051' }).then((resp: any) => {
  969. const res = resp.data.result || {}
  970. if (!Array.isArray(res.data) || res.data.length < 1) return
  971. goodMaterialOption.value =
  972. res.data[0].Website_Subform.map((i: any) => i.Website_Subform_Value) || []
  973. })
  974. }
  975. getGoodMaterialOption()
  976. const addBulkProduct = () => {
  977. let temp = cloneDeep(newLineTemplate)
  978. temp.Sample = false
  979. subList.value.unshift(temp)
  980. }
  981. const addSample = () => {
  982. let temp = cloneDeep(newLineTemplate)
  983. temp.Sample = true
  984. subList.value.unshift(temp)
  985. }
  986. const onDeleteRow = (row: any, index: number = -1) => {
  987. if (row.addFlag) {
  988. subList.value.splice(index, 1)
  989. } else {
  990. row.deleteFlag = true
  991. ElNotification({
  992. type: 'warning',
  993. title: '已标记删除',
  994. duration: 3000,
  995. message: '点 提交 按钮后会正式删除. 误操作请点击 放弃改动.',
  996. })
  997. }
  998. }
  999. const onBatchRecordChange = ($e: string, line = -1) => {
  1000. const temp = computedOption.value.filter((i) => i.id === $e)
  1001. let result: any = {}
  1002. if (temp.length) {
  1003. result = cloneDeep(temp[0])
  1004. }
  1005. if (line > -1) {
  1006. // 主页面数据编辑
  1007. subList.value[line].editFlag = true
  1008. subList.value[line].Batch_Record = { id: result.id, name: result.Name }
  1009. if (result.Owner) {
  1010. subList.value[line].Requester = {
  1011. name: result.Owner.name,
  1012. id: result.Owner.id,
  1013. }
  1014. }
  1015. subList.value[line].Sales_Order = result.Sales_Order || ''
  1016. subList.value[line].Purchase_Order = result.Purchase_Order || ''
  1017. subList.value[line].Reference = result.Reference || ''
  1018. subList.value[line].PO_Number = result.PO_Number || ''
  1019. // 如果对应行的唛头为空, 则用批次记录的名称填充
  1020. if (!subList.value[line].Marks_Nos || subList.value[line].Marks_Nos.length < 1) {
  1021. subList.value[line].Marks_Nos = result.Job_Name || ''
  1022. }
  1023. if (!subList.value[line].Quantity) {
  1024. subList.value[line].Quantity = result.Quantity || ''
  1025. }
  1026. if (!subList.value[line].Unit_Price) {
  1027. subList.value[line].Unit_Price = result.List_Price || ''
  1028. }
  1029. }
  1030. }
  1031. const tempShipID = '4791186000388831863'
  1032. const commit = async () => {
  1033. let temp = cloneDeep(subList.value)
  1034. let formData = customMapData(temp.filter((i) => !i.deleteFlag))
  1035. const emptyUserNotesList: number[] = []
  1036. const emptyCartonList: number[] = [] // 箱数
  1037. const emptyMarksNosList: number[] = [] // 唛头
  1038. const emptyNameList: number[] = [] // 货物名称 Description_of_Goods
  1039. const emptyCubeList: number[] = [] // 体积
  1040. formData.forEach((i, index) => {
  1041. if (!i.User_Notes) {
  1042. emptyUserNotesList.push(index)
  1043. }
  1044. if (!i.Carton) {
  1045. emptyCartonList.push(index)
  1046. }
  1047. if (!i.Marks_Nos) {
  1048. emptyMarksNosList.push(index)
  1049. }
  1050. if (!i.Description_of_Goods) {
  1051. emptyNameList.push(index)
  1052. }
  1053. if (!i.Cube) {
  1054. emptyCubeList.push(index)
  1055. }
  1056. })
  1057. if (emptyUserNotesList.length) {
  1058. ElNotification({
  1059. title: '请检查表单, 备注是必填的',
  1060. message: `第 ${emptyUserNotesList.map((i) => i + 1).join(', ')} 行的备注数据, 不能为空`,
  1061. duration: 5000,
  1062. })
  1063. return
  1064. }
  1065. if (emptyCartonList.length) {
  1066. ElNotification({
  1067. title: '请检查表单, 箱数是必填的',
  1068. message: `第 ${emptyCartonList.map((i) => i + 1).join(', ')} 行的箱数数据, 不能为空`,
  1069. duration: 5000,
  1070. })
  1071. return
  1072. }
  1073. if (emptyMarksNosList.length) {
  1074. ElNotification({
  1075. title: '请检查表单, 唛头是必填的',
  1076. message: `第 ${emptyMarksNosList.map((i) => i + 1).join(', ')} 行的唛头数据, 不能为空`,
  1077. duration: 5000,
  1078. })
  1079. return
  1080. }
  1081. if (emptyNameList.length) {
  1082. ElNotification({
  1083. title: '请检查表单, 货物名称是必填的',
  1084. message: `第 ${emptyNameList.map((i) => i + 1).join(', ')} 行的货物名称数据, 不能为空`,
  1085. duration: 5000,
  1086. })
  1087. return
  1088. }
  1089. if (emptyCubeList.length) {
  1090. ElNotification({
  1091. title: '请检查表单, 体积是必填的',
  1092. message: `第 ${emptyCubeList.map((i) => i + 1).join(', ')} 行的体积数据, 不能为空`,
  1093. duration: 5000,
  1094. })
  1095. return
  1096. }
  1097. formData = formData.concat(
  1098. temp
  1099. .filter((i) => i.deleteFlag)
  1100. .map((i) => ({ id: i.id, _delete: null, Material_of_Goods: null })),
  1101. )
  1102. let params = {
  1103. id: currentRow.value.id,
  1104. Sea_Freight_array: formData,
  1105. Sales_Person: currentUserName.value,
  1106. Sales_Person_Obj: {
  1107. id: currentUser.value,
  1108. name: currentUserName.value,
  1109. },
  1110. }
  1111. console.log(params, '保存 无转移的数据')
  1112. let formData2 = customMapData(temp.filter((i) => i.deleteFlag && i.Force_Send)).map((i) => {
  1113. // 转移之前覆盖 Parent_Id, 否则按照customMapData的逻辑会被存成原航次的id
  1114. let t = {
  1115. ...i,
  1116. Parent_Id: { id: tempShipID },
  1117. }
  1118. try {
  1119. delete t.id // 相当于在新建记录.不删除原id的话, 不一点能转移成功(crm限制), 并且后面原航次的保存会把这个id对应的记录删除
  1120. } catch {
  1121. console.log(t, '组装转移数据时删除id出错')
  1122. }
  1123. return t
  1124. })
  1125. let params2 = {
  1126. id: tempShipID,
  1127. Sea_Freight_array: formData2,
  1128. Sales_Person: currentUserName.value,
  1129. Sales_Person_Obj: {
  1130. id: currentUser.value,
  1131. name: currentUserName.value,
  1132. },
  1133. }
  1134. console.log(params2, '保存 要转移的数据')
  1135. loading.value = true
  1136. let sendToTempShipFlag = true // (转移到临时航次) 的状态
  1137. if (formData2.length) {
  1138. let response2 = await request.post('/sea_freight/updateSeaFreightDataV2', params2)
  1139. if (response2.data.code !== 1) {
  1140. sendToTempShipFlag = false
  1141. ElMessage.error('转移到临时航次失败, 请稍后再试或者联系管理员')
  1142. loading.value = false
  1143. return
  1144. }
  1145. let result2 = response2.data.result || { data: [] }
  1146. if (
  1147. !(
  1148. Array.isArray(result2.data) &&
  1149. result2.data.length &&
  1150. result2.data.every((i: any) => i.status === 'success')
  1151. )
  1152. ) {
  1153. sendToTempShipFlag = false
  1154. ElNotification({
  1155. title: '部份内容转移失败',
  1156. message: '建议刷新再试或者联系管理员',
  1157. duration: 10000,
  1158. })
  1159. }
  1160. }
  1161. if (sendToTempShipFlag === false) {
  1162. loading.value = false
  1163. return
  1164. }
  1165. request
  1166. .post('/sea_freight/updateSeaFreightDataV2', params)
  1167. .then((res) => {
  1168. if (res.data.code !== 1) {
  1169. ElMessage.error('保存出错')
  1170. loading.value = false
  1171. return
  1172. }
  1173. let result = res.data.result || { data: [] }
  1174. if (
  1175. Array.isArray(result.data) &&
  1176. result.data.length &&
  1177. result.data.every((i: any) => i.status === 'success')
  1178. ) {
  1179. ElNotification({
  1180. title: '保存成功',
  1181. message: '正在刷新数据',
  1182. duration: 3000,
  1183. })
  1184. } else {
  1185. ElNotification({
  1186. title: '部份内容保存失败',
  1187. message: '建议刷新再试或者联系管理员',
  1188. duration: 10000,
  1189. })
  1190. }
  1191. getSubList(currentRow.value)
  1192. })
  1193. .catch((e) => {
  1194. console.log(e, 'commit error')
  1195. loading.value = false
  1196. })
  1197. }
  1198. const commitWithSDK = async () => {
  1199. let temp = cloneDeep(subList.value)
  1200. let formData = customMapData(temp.filter((i) => !i.deleteFlag))
  1201. const emptyUserNotesList: number[] = []
  1202. const emptyCartonList: number[] = [] // 箱数
  1203. const emptyMarksNosList: number[] = [] // 唛头
  1204. const emptyNameList: number[] = [] // 货物名称 Description_of_Goods
  1205. const emptyCubeList: number[] = [] // 体积
  1206. formData.forEach((i, index) => {
  1207. if (!i.User_Notes) {
  1208. emptyUserNotesList.push(index)
  1209. }
  1210. if (!i.Carton) {
  1211. emptyCartonList.push(index)
  1212. }
  1213. if (!i.Marks_Nos) {
  1214. emptyMarksNosList.push(index)
  1215. }
  1216. if (!i.Description_of_Goods) {
  1217. emptyNameList.push(index)
  1218. }
  1219. if (!i.Cube) {
  1220. emptyCubeList.push(index)
  1221. }
  1222. })
  1223. if (emptyUserNotesList.length) {
  1224. ElNotification({
  1225. title: '请检查表单, 备注是必填的',
  1226. message: `第 ${emptyUserNotesList.map((i) => i + 1).join(', ')} 行的备注数据, 不能为空`,
  1227. duration: 5000,
  1228. })
  1229. return
  1230. }
  1231. if (emptyCartonList.length) {
  1232. ElNotification({
  1233. title: '请检查表单, 箱数是必填的',
  1234. message: `第 ${emptyCartonList.map((i) => i + 1).join(', ')} 行的箱数数据, 不能为空`,
  1235. duration: 5000,
  1236. })
  1237. return
  1238. }
  1239. if (emptyMarksNosList.length) {
  1240. ElNotification({
  1241. title: '请检查表单, 唛头是必填的',
  1242. message: `第 ${emptyMarksNosList.map((i) => i + 1).join(', ')} 行的唛头数据, 不能为空`,
  1243. duration: 5000,
  1244. })
  1245. return
  1246. }
  1247. if (emptyNameList.length) {
  1248. ElNotification({
  1249. title: '请检查表单, 货物名称是必填的',
  1250. message: `第 ${emptyNameList.map((i) => i + 1).join(', ')} 行的货物名称数据, 不能为空`,
  1251. duration: 5000,
  1252. })
  1253. return
  1254. }
  1255. if (emptyCubeList.length) {
  1256. ElNotification({
  1257. title: '请检查表单, 体积是必填的',
  1258. message: `第 ${emptyCubeList.map((i) => i + 1).join(', ')} 行的体积数据, 不能为空`,
  1259. duration: 5000,
  1260. })
  1261. return
  1262. }
  1263. let params = {
  1264. APIData: {
  1265. id: currentRow.value.id,
  1266. Sea_Freight_Details: formData,
  1267. },
  1268. Entity: 'Sea_Freight_Table',
  1269. trigger: ['workflow', 'approval'],
  1270. }
  1271. console.log(params, '保存 无转移的数据')
  1272. let formData2 = customMapData(temp.filter((i) => i.deleteFlag && i.Force_Send)).map((i) => {
  1273. // 转移之前覆盖 Parent_Id, 否则按照customMapData的逻辑会被存成原航次的id
  1274. let t = {
  1275. ...i,
  1276. Parent_Id: { id: tempShipID },
  1277. }
  1278. try {
  1279. delete t.id // 相当于在新建记录.不删除原id的话, 不一点能转移成功(crm限制), 并且后面原航次的保存会把这个id对应的记录删除
  1280. delete t.parent_id
  1281. } catch {
  1282. console.log(t, '组装转移数据时删除id出错')
  1283. }
  1284. return t
  1285. })
  1286. let params2 = {
  1287. APIData: {
  1288. Temporary_Transform_Record: true,
  1289. Sea_Freight_Details: formData2,
  1290. Name: '临时调动记录(非真正航次)',
  1291. ETD: '1900-01-01',
  1292. ETA: '1900-01-01',
  1293. },
  1294. Entity: 'Sea_Freight_Table',
  1295. trigger: ['workflow', 'approval'],
  1296. }
  1297. console.log(params2, '保存 要转移的数据')
  1298. loading.value = true
  1299. let sendToTempShipFlag = true // (转移到临时航次) 的状态
  1300. if (formData2.length) {
  1301. let res2 = await zoho.CRM.API.insertRecord(params2)
  1302. if (
  1303. !(
  1304. Array.isArray(res2.data) &&
  1305. res2.data.length &&
  1306. res2.data.every((i: any) => i.status === 'success')
  1307. )
  1308. ) {
  1309. sendToTempShipFlag = false
  1310. ElNotification({
  1311. title: '部份内容转移失败',
  1312. message: '建议刷新再试或者联系管理员',
  1313. duration: 10000,
  1314. })
  1315. } else {
  1316. return
  1317. }
  1318. }
  1319. if (sendToTempShipFlag === false) {
  1320. loading.value = false
  1321. return
  1322. }
  1323. zoho.CRM.API.updateRecord(params)
  1324. .then((res: any) => {
  1325. if (
  1326. Array.isArray(res.data) &&
  1327. res.data.length &&
  1328. res.data.every((i: any) => i.status === 'success')
  1329. ) {
  1330. ElNotification({
  1331. title: '保存成功',
  1332. message: '正在刷新数据',
  1333. duration: 3000,
  1334. })
  1335. } else {
  1336. ElNotification({
  1337. title: '部份内容保存失败',
  1338. message: '建议刷新再试或者联系管理员',
  1339. duration: 10000,
  1340. })
  1341. }
  1342. getSubList(currentRow.value)
  1343. })
  1344. .catch((e: any) => {
  1345. console.log(e, 'commit error')
  1346. loading.value = false
  1347. })
  1348. }
  1349. let printDrawerVisible = ref(false)
  1350. let currentPrintRow = ref({} as any)
  1351. const print = (row: any) => {
  1352. currentPrintRow.value = row
  1353. printDrawerVisible.value = true
  1354. }
  1355. let qcList = ref([] as any[])
  1356. let loading2 = ref(false)
  1357. const search = (keyword: string) => {
  1358. if (keyword.length < 2) return
  1359. keyword = keyword.trim().toUpperCase()
  1360. loading2.value = true
  1361. zoho.CRM.API.searchRecord({
  1362. Entity: 'QC_Record',
  1363. Type: 'criteria',
  1364. Query: `(Reference:in:${keyword})or(Reference:starts_with:${keyword})or(Purchase_Order.name:in:${keyword})or(Purchase_Order.name:starts_with:${keyword})`,
  1365. delay: false,
  1366. })
  1367. .then((res: any) => {
  1368. if (Array.isArray(res.data) && res.data.length) {
  1369. qcList.value = res.data.map((i: any) => {
  1370. return {
  1371. ...i,
  1372. isSearch: true,
  1373. }
  1374. })
  1375. } else {
  1376. qcList.value = []
  1377. ElMessage.warning('No Data Found')
  1378. }
  1379. })
  1380. .finally(() => (loading2.value = false))
  1381. }
  1382. const updateStatus = (status = '已确认') => {
  1383. ElMessageBox.confirm(`确定要把该记录状态更新为"${status}"吗?`, {
  1384. confirmButtonText: '确定',
  1385. cancelButtonText: '取消',
  1386. type: 'warning',
  1387. }).then(() => {
  1388. loading.value = true
  1389. zoho.CRM.API.updateRecord({
  1390. Entity: 'Sea_Freight_Table',
  1391. Trigger: ['workflow'],
  1392. APIData: {
  1393. id: currentRow.value.id,
  1394. Status: status,
  1395. },
  1396. }).then((res: any) => {
  1397. if (Array.isArray(res.data) && res.data.length && res.data[0].code === 'SUCCESS') {
  1398. ElMessage.success('操作成功, 正在刷新数据')
  1399. loading.value = false
  1400. getList()
  1401. clearSubList()
  1402. } else {
  1403. loading.value = false
  1404. ElMessage.error('操作失败, 请稍后再试或者联系管理员')
  1405. }
  1406. })
  1407. })
  1408. }
  1409. let bookingNumber = ref('')
  1410. const updateBookingNumber = () => {
  1411. bookingNumber.value = bookingNumber.value.trim()
  1412. if (!bookingNumber.value || !currentRow.value.id) {
  1413. ElMessage.error('请填写订舱号')
  1414. return
  1415. }
  1416. ElMessageBox.confirm(`确定要把该记录的订舱号更新为"${bookingNumber.value}"吗?`, {
  1417. confirmButtonText: '确定',
  1418. cancelButtonText: '取消',
  1419. type: 'warning',
  1420. }).then(() => {
  1421. loading.value = true
  1422. zoho.CRM.API.updateRecord({
  1423. Entity: 'Sea_Freight_Table',
  1424. Trigger: ['workflow'],
  1425. APIData: {
  1426. id: currentRow.value.id,
  1427. Booking_Number: bookingNumber.value,
  1428. },
  1429. }).then((res: any) => {
  1430. if (Array.isArray(res.data) && res.data.length && res.data[0].code === 'SUCCESS') {
  1431. ElMessage.success('操作成功, 正在刷新数据')
  1432. loading.value = false
  1433. bookingNumber.value = ''
  1434. getList()
  1435. clearSubList()
  1436. } else {
  1437. loading.value = false
  1438. ElMessage.error('操作失败, 请稍后再试或者联系管理员')
  1439. }
  1440. })
  1441. })
  1442. }
  1443. let containerNumber = ref('')
  1444. const updateContainerNumber = () => {
  1445. containerNumber.value = containerNumber.value.trim()
  1446. if (!containerNumber.value || !currentRow.value.id) {
  1447. ElMessage.error('请填写柜号')
  1448. return
  1449. }
  1450. ElMessageBox.confirm(`确定要把该记录的柜号更新为"${containerNumber.value}"吗?`, {
  1451. confirmButtonText: '确定',
  1452. cancelButtonText: '取消',
  1453. type: 'warning',
  1454. }).then(() => {
  1455. loading.value = true
  1456. zoho.CRM.API.updateRecord({
  1457. Entity: 'Sea_Freight_Table',
  1458. Trigger: ['workflow'],
  1459. APIData: {
  1460. id: currentRow.value.id,
  1461. Container_Number: containerNumber.value,
  1462. },
  1463. }).then((res: any) => {
  1464. if (Array.isArray(res.data) && res.data.length && res.data[0].code === 'SUCCESS') {
  1465. ElMessage.success('操作成功, 正在刷新数据')
  1466. loading.value = false
  1467. containerNumber.value = ''
  1468. getList()
  1469. clearSubList()
  1470. } else {
  1471. loading.value = false
  1472. ElMessage.error('操作失败, 请稍后再试或者联系管理员')
  1473. }
  1474. })
  1475. })
  1476. }
  1477. // @ts-ignore
  1478. const zoho = window.ZOHO
  1479. zoho.embeddedApp.on('PageLoad', function () {
  1480. zoho.CRM.CONFIG.getCurrentUser().then(function (data: any) {
  1481. if (Array.isArray(data.users) && data.users.length) {
  1482. const user = data.users[0]
  1483. // console.log(user, 'user')
  1484. currentUser.value = user.id
  1485. currentUserName.value = user.full_name || ''
  1486. currentUserRawData.value = cloneDeep(user)
  1487. getList()
  1488. }
  1489. })
  1490. })
  1491. zoho.embeddedApp.init()
  1492. const superUserIDList = ref([
  1493. '4791186000259693001', // 小权限账号, 测试用. 目前是给jayson了.
  1494. '4791186000022965001', // kava
  1495. '4791186000052269001', // 物流部
  1496. ])
  1497. watch(currentUserRawData, () => {
  1498. if (!currentUserRawData.value.role) return false
  1499. let result =
  1500. /(CEO|Logistics)/g.test(currentUserRawData.value.role.name) ||
  1501. superUserIDList.value.includes(currentUserRawData.value.role.id)
  1502. if (result) {
  1503. finalTabs.value = cloneDeep(tabs)
  1504. finalTabs.value.push({
  1505. label: 'Arrangement',
  1506. value: 'Arrangement',
  1507. })
  1508. }
  1509. })
  1510. let computedWeight = computed(() => {
  1511. return subList.value
  1512. .reduce((t, c) => {
  1513. t = t + Number(c.Weight)
  1514. return t
  1515. }, 0)
  1516. .toFixed(2)
  1517. })
  1518. let computedCube = computed(() => {
  1519. return subList.value
  1520. .reduce((t, c) => {
  1521. t = t + Number(c.Cube)
  1522. return t
  1523. }, 0)
  1524. .toFixed(2)
  1525. })
  1526. let computedTotalFOB = computed(() => {
  1527. return subList.value
  1528. .reduce((t, c) => {
  1529. t = t + Number(c.Total_FOB)
  1530. return t
  1531. }, 0)
  1532. .toFixed(2)
  1533. })
  1534. let computedSelectedWeight = computed(() => {
  1535. return selectedRow.value
  1536. .reduce((t, c) => {
  1537. t = t + Number(c.Weight)
  1538. return t
  1539. }, 0)
  1540. .toFixed(2)
  1541. })
  1542. let computedSelectedCube = computed(() => {
  1543. return selectedRow.value
  1544. .reduce((t, c) => {
  1545. t = t + Number(c.Cube)
  1546. return t
  1547. }, 0)
  1548. .toFixed(2)
  1549. })
  1550. let computedSelectedTotalFOB = computed(() => {
  1551. return selectedRow.value
  1552. .reduce((t, c) => {
  1553. t = t + Number(c.Total_FOB)
  1554. return t
  1555. }, 0)
  1556. .toFixed(2)
  1557. })
  1558. // 订单轨迹地图插件
  1559. let mapDrawerVisible = ref(false)
  1560. const openMapDrawer = (row: any) => {
  1561. mapDrawerVisible.value = true
  1562. if ((window as any).Sgld) {
  1563. nextTick(() => {
  1564. ;(window as any).Sgld.createContainerTrack({
  1565. id: 'mapDrawer',
  1566. carrierCode: row.Carrier, // 船公司代码
  1567. billNo: row.Booking_Number, // 提单号
  1568. language: 'en', // 语言
  1569. })
  1570. })
  1571. }
  1572. }
  1573. const closeMapDrawer = () => {
  1574. mapDrawerVisible.value = false
  1575. }
  1576. let cubeDialogVisible = ref(-1)
  1577. let unitType = ref(1) // 1:m 2:cm
  1578. let cubeForm = ref({
  1579. l: '',
  1580. w: '',
  1581. h: '',
  1582. Carton: '' as string | number, // 箱数
  1583. })
  1584. let cubeForm2 = ref({
  1585. c: '' as string | number, // 体积
  1586. })
  1587. watch(unitType, () => {
  1588. cubeForm.value.l = Number(cubeForm.value.l) * (unitType.value === 1 ? 0.01 : 100) + ''
  1589. cubeForm.value.w = Number(cubeForm.value.w) * (unitType.value === 1 ? 0.01 : 100) + ''
  1590. cubeForm.value.h = Number(cubeForm.value.h) * (unitType.value === 1 ? 0.01 : 100) + ''
  1591. })
  1592. watch(
  1593. cubeForm,
  1594. () => {
  1595. cubeForm2.value.c = (
  1596. Number(cubeForm.value.l) *
  1597. Number(cubeForm.value.w) *
  1598. Number(cubeForm.value.h) *
  1599. Number(cubeForm.value.Carton) *
  1600. (unitType.value === 2 ? 0.000001 : 1)
  1601. ).toFixed(2)
  1602. },
  1603. {
  1604. immediate: true,
  1605. deep: true,
  1606. },
  1607. )
  1608. let openCubeDialog = (obj: any) => {
  1609. let index = obj.$index
  1610. if (index < 0 || index >= subList.value.length) return
  1611. const row = subList.value[index]
  1612. cubeForm.value.Carton = row.Carton || '1'
  1613. cubeDialogVisible.value = index
  1614. nextTick(() => {
  1615. cubeForm2.value.c = row.Cube || ''
  1616. })
  1617. }
  1618. let commitCube = () => {
  1619. const row = subList.value[cubeDialogVisible.value]
  1620. row.Cube = Number(cubeForm2.value.c).toFixed(2) || ''
  1621. row.Carton = Number(cubeForm.value.Carton) || '1'
  1622. row.editFlag = true
  1623. closeCubeDialog()
  1624. }
  1625. let closeCubeDialog = () => {
  1626. cubeDialogVisible.value = -1
  1627. cubeForm.value.l = ''
  1628. cubeForm.value.w = ''
  1629. cubeForm.value.h = ''
  1630. cubeForm.value.Carton = '1'
  1631. cubeForm2.value.c = ''
  1632. }
  1633. let selectedRow = ref([] as any[])
  1634. const handleSelectionChange = (val: any[]) => {
  1635. selectedRow.value = val
  1636. }
  1637. let tempShipVisible = ref(false)
  1638. const openTempShip = () => {
  1639. tempShipVisible.value = true
  1640. }
  1641. // 别说代码行数太长搞屎山, 这个页面的功能上线之后改了6个版本, 每次都往上堆功能, 能不长嘛
  1642. </script>
  1643. <style lang="scss">
  1644. .page-cargo-consolidation {
  1645. .el-table__body tr.current-row > td.el-table__cell {
  1646. background-color: rgb(56, 163, 238);
  1647. color: #fff;
  1648. }
  1649. }
  1650. </style>
  1651. <style lang="scss" scoped>
  1652. .el-button.custom-button {
  1653. height: 24px;
  1654. line-height: 24px;
  1655. background-image: linear-gradient(171deg, rgb(28, 74, 136) 49%, rgb(0, 130, 193) 100%);
  1656. background-color: rgb(97, 165, 245);
  1657. color: #fff;
  1658. font-size: 13px;
  1659. font-family: Zoho_Puvi_Bold sans-serif;
  1660. border-radius: 6px;
  1661. cursor: pointer;
  1662. &:hover,
  1663. &:active {
  1664. background-image: linear-gradient(171deg, rgb(28, 74, 136) 49%, rgb(22, 208, 239) 100%);
  1665. color: #fff;
  1666. }
  1667. &.fb {
  1668. font-weight: 900;
  1669. }
  1670. &.small {
  1671. height: 24px;
  1672. line-height: 24px;
  1673. }
  1674. }
  1675. </style>