index.vue 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441
  1. <template>
  2. <div class="w-[100vw] bg-white page-cargo-consolidation">
  3. <div
  4. v-loading="loading"
  5. class="pt-2 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 label="ETD Range">
  14. <el-date-picker
  15. v-model="dateRange"
  16. type="daterange"
  17. unlink-panels
  18. clearable
  19. start-placeholder="Start date"
  20. end-placeholder="End date"
  21. :shortcuts="dateShortcuts"
  22. />
  23. </el-form-item>
  24. <el-form-item>
  25. <el-tooltip content="时间范围最好不要选太大, 不然数据太多会卡">
  26. <el-button
  27. class="custom-button"
  28. @click="getList"
  29. >
  30. Search
  31. </el-button>
  32. </el-tooltip>
  33. </el-form-item>
  34. </el-form>
  35. <el-tabs v-model="currentTab">
  36. <el-tab-pane
  37. v-for="tab in finalTabs"
  38. :key="tab.value"
  39. :label="tab.label"
  40. :name="tab.value"
  41. ></el-tab-pane>
  42. </el-tabs>
  43. <el-table
  44. border
  45. :header-cell-style="{ backgroundColor: 'rgb(227, 241, 253)' }"
  46. :data="computedList"
  47. highlight-current-row
  48. style="width: 100%"
  49. max-height="330"
  50. @row-click="($e) => getSubList($e)"
  51. >
  52. <el-table-column
  53. prop="Name"
  54. label="船名&航次"
  55. min-width="500"
  56. />
  57. <el-table-column
  58. prop="Forwarder"
  59. label="货代"
  60. width="100"
  61. />
  62. <el-table-column
  63. prop="ETD"
  64. label="ETD"
  65. width="100"
  66. />
  67. <el-table-column
  68. prop="ATD"
  69. label="ATD"
  70. width="100"
  71. />
  72. <el-table-column
  73. prop="ETA"
  74. label="ETA"
  75. width="100"
  76. />
  77. <el-table-column
  78. prop="ATA"
  79. label="ATA"
  80. width="100"
  81. />
  82. <el-table-column
  83. prop="Cut_Off_Date"
  84. label="入仓时间"
  85. width="100"
  86. />
  87. <el-table-column
  88. prop="Status"
  89. label="状态"
  90. width="75"
  91. />
  92. <!-- <el-table-column
  93. label="修改时间"
  94. min-width="190"
  95. >
  96. <template #default="scope">
  97. {{ dayjs(scope.row.Modified_Time).format('YYYY-MM-DD HH:mm:ss') }}
  98. </template>
  99. </el-table-column> -->
  100. <el-table-column
  101. prop="GRN"
  102. label="入仓单号"
  103. min-width="200"
  104. />
  105. <el-table-column
  106. prop="Booking_Number"
  107. label="订舱号"
  108. min-width="120"
  109. />
  110. <el-table-column
  111. prop="Container_Number"
  112. label="柜号"
  113. min-width="125"
  114. />
  115. <el-table-column
  116. prop="Carrier"
  117. label="船东"
  118. min-width="100"
  119. />
  120. <el-table-column label="操作">
  121. <template #default="scope">
  122. <el-button
  123. size="small"
  124. type="warning"
  125. link
  126. :disabled="!scope.row.SubscriptionId"
  127. @click="openMapDrawer(scope.row)"
  128. >
  129. 查看轨迹
  130. </el-button>
  131. </template>
  132. </el-table-column>
  133. </el-table>
  134. <div
  135. v-show="currentRow.Name?.length"
  136. class="flex justify-between mt-8"
  137. >
  138. <div class="flex">
  139. <!-- <div class="flex items-center mr-2">
  140. <span class="min-w-[150px]">选中的船名&航次:&nbsp;</span>
  141. <div class="text-red-700 font-bold">
  142. {{ currentRow.Name }}
  143. </div>
  144. </div> -->
  145. <div class="flex flex-wrap min-w-[800px] mr-2">
  146. <!-- ['可用', '已截仓'].includes(currentRow.Status) && -->
  147. <el-input
  148. v-if="
  149. currentTab === 'Arrangement' &&
  150. [
  151. '4791186000259693001',
  152. '4791186000022965001',
  153. '4791186000052269001',
  154. ].includes(currentUser)
  155. "
  156. :disabled="!['Arrangement', 'my_request'].includes(currentTab)"
  157. style="width: 200px; height: 24px; margin-right: 10px"
  158. size="small"
  159. v-model="bookingNumber"
  160. >
  161. <template #append>
  162. <el-button
  163. class="custom-button"
  164. size="small"
  165. style="padding-top: 0; padding-bottom: 0"
  166. @click="updateBookingNumber"
  167. >
  168. 更新订舱号
  169. </el-button>
  170. </template>
  171. </el-input>
  172. <!-- ['可用', '已截仓'].includes(currentRow.Status) && -->
  173. <el-input
  174. v-if="
  175. currentTab === 'Arrangement' &&
  176. [
  177. '4791186000259693001',
  178. '4791186000022965001',
  179. '4791186000052269001',
  180. ].includes(currentUser)
  181. "
  182. :disabled="!['Arrangement', 'my_request'].includes(currentTab)"
  183. style="width: 200px; height: 24px; margin-right: 10px"
  184. size="small"
  185. v-model="containerNumber"
  186. >
  187. <template #append>
  188. <el-button
  189. class="custom-button"
  190. size="small"
  191. style="padding-top: 0; padding-bottom: 0"
  192. @click="updateContainerNumber"
  193. >
  194. 更新柜号
  195. </el-button>
  196. </template>
  197. </el-input>
  198. <el-button
  199. v-if="
  200. currentTab === 'Arrangement' &&
  201. ['可用', '已截仓'].includes(currentRow.Status) &&
  202. [
  203. '4791186000259693001',
  204. '4791186000022965001',
  205. '4791186000052269001',
  206. ].includes(currentUser)
  207. "
  208. size="small"
  209. type="danger"
  210. @click="ensure"
  211. >
  212. 确认集货
  213. </el-button>
  214. <el-button
  215. class="custom-button"
  216. v-if="
  217. ['Arrangement', 'my_request'].includes(currentTab) &&
  218. ['可用'].includes(currentRow.Status)
  219. "
  220. size="small"
  221. @click="addBulkProduct"
  222. >
  223. 提交大货集货申请
  224. </el-button>
  225. <el-button
  226. class="custom-button"
  227. v-if="
  228. ['Arrangement', 'my_request'].includes(currentTab) &&
  229. ['可用'].includes(currentRow.Status)
  230. "
  231. size="small"
  232. @click="addSample"
  233. >
  234. 提交样品集货申请
  235. </el-button>
  236. <el-button
  237. v-if="['Arrangement', 'my_request'].includes(currentTab)"
  238. :disabled="subList.length < 1"
  239. size="small"
  240. type="danger"
  241. @click="generateSubList"
  242. >
  243. 放弃下方表格改动
  244. </el-button>
  245. <el-button
  246. class="custom-button"
  247. size="small"
  248. :disabled="subList.length < 1"
  249. @click="exportSubTable"
  250. >
  251. 导出Excel文档
  252. </el-button>
  253. <el-button
  254. v-if="
  255. ['Arrangement', 'my_request'].includes(currentTab) &&
  256. ['可用'].includes(currentRow.Status)
  257. "
  258. :disabled="subList.length < 1"
  259. size="small"
  260. type="primary"
  261. class="custom-button small"
  262. @click="commit"
  263. >
  264. 保存更改
  265. </el-button>
  266. </div>
  267. </div>
  268. <div class="flex justify-end min-w-[380px] gap-2">
  269. <div class="flex">总重量: {{ computedWeight }}</div>
  270. <div class="flex">总体积: {{ computedCube }}</div>
  271. <div class="flex">总离岸价: {{ computedTotalFOB }}</div>
  272. </div>
  273. </div>
  274. <el-table
  275. class="mt-4"
  276. size="small"
  277. :data="subList"
  278. style="width: 100%"
  279. :row-style="calcRowStyle"
  280. :header-cell-style="{ backgroundColor: 'rgb(227, 241, 253)' }"
  281. :empty-text="
  282. currentRow.Name?.length
  283. ? '暂无数据'
  284. : '请点击voyage表格其中一行以查询相应记录'
  285. "
  286. border
  287. >
  288. <el-table-column
  289. fixed
  290. type="index"
  291. width="50"
  292. ></el-table-column>
  293. <el-table-column
  294. fixed
  295. label="CRM批次记录"
  296. width="220"
  297. >
  298. <template #default="scope">
  299. <el-select
  300. v-model="scope.row.batchRecord"
  301. size="small"
  302. :remote-method="debounce(search, 1500)"
  303. remote
  304. style="width: 100%"
  305. :loading="loading2"
  306. filterable
  307. clearable
  308. :placeholder="scope.row.Sample ? 'Sample' : ''"
  309. :disabled="
  310. scope.row.Sample ||
  311. !['Arrangement', 'my_request'].includes(currentTab)
  312. "
  313. @change="($e) => onBatchRecordChange($e, scope.$index)"
  314. >
  315. <el-option
  316. v-for="option in computedOption as any[]"
  317. :disabled="!option.isSearch && scope.row.addFlag"
  318. :key="option.id"
  319. :value="option.id"
  320. :label="
  321. option.Name +
  322. (option.Reference ? ` - ${option.Reference}` : '')
  323. "
  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. >
  348. <template #default="scope">
  349. <el-input
  350. :disabled="!['Arrangement', 'my_request'].includes(currentTab)"
  351. v-model="scope.row.Carton"
  352. size="small"
  353. @change="scope.row.editFlag = true"
  354. ></el-input>
  355. </template>
  356. </el-table-column>
  357. <el-table-column
  358. label="唛头"
  359. width="220"
  360. >
  361. <template #default="scope">
  362. <el-input
  363. :disabled="!['Arrangement', 'my_request'].includes(currentTab)"
  364. v-model="scope.row.Marks_Nos"
  365. size="small"
  366. @change="scope.row.editFlag = true"
  367. ></el-input>
  368. </template>
  369. </el-table-column>
  370. <el-table-column
  371. label="货物名称"
  372. width="180"
  373. >
  374. <template #default="scope">
  375. <el-input
  376. :disabled="!['Arrangement', 'my_request'].includes(currentTab)"
  377. v-model="scope.row.Description_of_Goods"
  378. size="small"
  379. @change="scope.row.editFlag = true"
  380. ></el-input>
  381. </template>
  382. </el-table-column>
  383. <el-table-column
  384. label="货物材质"
  385. width="220"
  386. >
  387. <template #default="scope">
  388. <el-select
  389. :disabled="!['Arrangement', 'my_request'].includes(currentTab)"
  390. v-model="scope.row.Material_of_Goods"
  391. size="small"
  392. multiple
  393. @change="scope.row.editFlag = true"
  394. >
  395. <el-option
  396. v-for="i in goodMaterialOption"
  397. :key="i"
  398. :value="i"
  399. :label="i"
  400. ></el-option>
  401. </el-select>
  402. </template>
  403. </el-table-column>
  404. <el-table-column
  405. label="数量"
  406. width="100"
  407. >
  408. <template #default="scope">
  409. <el-input
  410. :disabled="!['Arrangement', 'my_request'].includes(currentTab)"
  411. v-model="scope.row.Quantity"
  412. size="small"
  413. @change="changeTotal(scope.row)"
  414. ></el-input>
  415. </template>
  416. </el-table-column>
  417. <el-table-column
  418. label="单价(澳币/AUD)"
  419. width="120"
  420. >
  421. <template #default="scope">
  422. <el-input
  423. :disabled="!['Arrangement', 'my_request'].includes(currentTab)"
  424. v-model="scope.row.Unit_Price"
  425. size="small"
  426. @change="changeTotal(scope.row)"
  427. ></el-input>
  428. </template>
  429. </el-table-column>
  430. <el-table-column
  431. label="负责人"
  432. fixed="right"
  433. width="120"
  434. >
  435. <template #default="scope">
  436. <el-input
  437. v-model="scope.row.Requester.name"
  438. size="small"
  439. disabled
  440. ></el-input>
  441. </template>
  442. </el-table-column>
  443. <el-table-column
  444. label="申请人"
  445. fixed="right"
  446. width="120"
  447. >
  448. <template #default="scope">
  449. <el-input
  450. v-model="scope.row.Sales_Person"
  451. size="small"
  452. disabled
  453. ></el-input>
  454. </template>
  455. </el-table-column>
  456. <!-- <el-table-column
  457. v-show="['Arrangement', 'my_request'].includes(currentTab)"
  458. fixed="right"
  459. label="更新时间"
  460. width="90"
  461. >
  462. <template #default="scope">
  463. <div v-if="scope.row.id">
  464. {{
  465. dayjs(scope.row.update_time || new Date()).format(
  466. 'YYYY-MM-DD HH:mm:ss',
  467. )
  468. }}
  469. </div>
  470. </template>
  471. </el-table-column> -->
  472. <el-table-column
  473. v-show="
  474. [
  475. '4791186000259693001',
  476. '4791186000022965001',
  477. '4791186000052269001',
  478. ].includes(currentUser)
  479. "
  480. fixed="right"
  481. label="操作"
  482. width="90"
  483. >
  484. <template #default="scope">
  485. <el-tooltip
  486. content="新增未commit的行会被直接移除; 已commit的行只会标记, 正式commit后才会删除"
  487. >
  488. <el-button
  489. v-if="['Arrangement', 'my_request'].includes(currentTab)"
  490. type="danger"
  491. size="small"
  492. link
  493. @click="() => onDeleteRow(scope.row, scope.$index)"
  494. >
  495. 删除
  496. </el-button>
  497. </el-tooltip>
  498. <el-button
  499. size="small"
  500. link
  501. type="primary"
  502. @click="print(scope.row)"
  503. >
  504. 打印
  505. </el-button>
  506. </template>
  507. </el-table-column>
  508. <el-table-column
  509. fixed="right"
  510. label="重量 (KG)"
  511. width="70"
  512. >
  513. <template #default="scope">
  514. <el-input
  515. :disabled="!['Arrangement', 'my_request'].includes(currentTab)"
  516. v-model="scope.row.Weight"
  517. size="small"
  518. @change="scope.row.editFlag = true"
  519. ></el-input>
  520. </template>
  521. </el-table-column>
  522. <el-table-column
  523. fixed="right"
  524. label="体积 m&sup3;"
  525. width="70"
  526. >
  527. <template #default="scope">
  528. <el-input
  529. :disabled="!['Arrangement', 'my_request'].includes(currentTab)"
  530. v-model="scope.row.Cube"
  531. size="small"
  532. @change="scope.row.editFlag = true"
  533. ></el-input>
  534. </template>
  535. </el-table-column>
  536. <el-table-column
  537. fixed="right"
  538. label="总离岸价 (澳币/AUD)"
  539. width="140"
  540. >
  541. <template #default="scope">
  542. <el-input
  543. v-model="scope.row.Total_FOB"
  544. size="small"
  545. disabled
  546. ></el-input>
  547. </template>
  548. </el-table-column>
  549. <el-table-column
  550. label="Reference"
  551. fixed="right"
  552. width="90"
  553. >
  554. <template #default="scope">
  555. <div class="">{{ scope.row.Reference || scope.row.PO_Number }}</div>
  556. </template>
  557. </el-table-column>
  558. </el-table>
  559. <el-drawer
  560. v-model:model-value="printDrawerVisible"
  561. :size="'1050px'"
  562. :title="'打印唛 (注意先写完唛内容和宽高最后再调页数, 不然可能会很卡)'"
  563. :close-on-click-modal="false"
  564. :close-on-press-escape="false"
  565. >
  566. <comp-print
  567. v-if="printDrawerVisible"
  568. :autoOpenQRCode="false"
  569. :content="[currentPrintRow.Marks_Nos || '']"
  570. :scene="'QC'"
  571. />
  572. </el-drawer>
  573. <el-drawer
  574. v-model:model-value="mapDrawerVisible"
  575. :size="'1050px'"
  576. :close-on-click-modal="false"
  577. :close-on-press-escape="false"
  578. :destroy-on-close="true"
  579. :with-header="false"
  580. header-class="mb-1"
  581. >
  582. <div class="relative h-[20px]">
  583. <span
  584. @click="closeMapDrawer"
  585. class="absolute top-[-16px] right-0 text-gray-600 text-sm cursor-pointer"
  586. >
  587. 关闭地图窗口
  588. </span>
  589. </div>
  590. <div
  591. id="mapDrawer"
  592. class="h-[100%]"
  593. ></div>
  594. </el-drawer>
  595. </div>
  596. </div>
  597. </template>
  598. <script lang="ts" setup>
  599. import { defineComponent, ref, watch, computed, nextTick } from 'vue'
  600. import {
  601. ElButton,
  602. ElForm,
  603. ElFormItem,
  604. ElInput,
  605. ElTabs,
  606. ElTabPane,
  607. ElTable,
  608. ElTableColumn,
  609. ElDatePicker,
  610. ElTooltip,
  611. ElSelect,
  612. ElOption,
  613. ElMessage,
  614. ElMessageBox,
  615. ElNotification,
  616. ElDrawer,
  617. } from 'element-plus'
  618. import cloneDeep from 'lodash.clonedeep'
  619. import dayjs from 'dayjs'
  620. import * as XLSX from 'xlsx'
  621. import debounce from 'lodash.debounce'
  622. import compPrint from '@/components/print.vue'
  623. import request from '@/utils/axios'
  624. defineComponent({
  625. name: 'ComponentCargoConsolidationRequest',
  626. })
  627. const currentUser = ref('')
  628. const currentUserName = ref('')
  629. const currentUserRawData = ref({} as any)
  630. let loading = ref(false)
  631. let list = ref([] as any[])
  632. let currentTab = ref('all')
  633. let tabs = [
  634. {
  635. label: 'All',
  636. value: 'all',
  637. },
  638. {
  639. label: 'Avaliable',
  640. value: 'avaliable',
  641. },
  642. {
  643. label: 'Closed Voyage',
  644. value: 'voyage_closed',
  645. },
  646. {
  647. label: 'My Request',
  648. value: 'my_request',
  649. },
  650. ]
  651. let finalTabs = ref([] as any[])
  652. finalTabs.value = cloneDeep(tabs)
  653. let computedList = computed(() => {
  654. return list.value.filter((i: any) => {
  655. let condition = true
  656. switch (currentTab.value) {
  657. case 'avaliable':
  658. condition = i.Status && i.Status === '可用'
  659. break
  660. case 'voyage_closed':
  661. condition = ['已截仓', '已确认', '已发出', '已到达'].includes(i.Status)
  662. break
  663. }
  664. return condition
  665. })
  666. })
  667. let dateRange = ref([] as any[])
  668. const generateDateRange = (days = 7) => {
  669. const today = new Date()
  670. const endDate = new Date()
  671. endDate.setDate(today.getDate() + days)
  672. return [today, endDate]
  673. }
  674. const dateShortcuts = ref([
  675. {
  676. text: 'Next 3 days',
  677. value: generateDateRange(3),
  678. },
  679. {
  680. text: 'Next week',
  681. value: generateDateRange(7),
  682. },
  683. {
  684. text: 'Next 14days',
  685. value: generateDateRange(14),
  686. },
  687. ] as any[])
  688. function getDefaultRange() {
  689. const today = dayjs()
  690. const lastMonthFirstDay = today
  691. .subtract(1, 'month')
  692. .startOf('month')
  693. .format('YYYY-MM-DD')
  694. const nextMonthLastDay = today
  695. .add(1, 'month')
  696. .endOf('month')
  697. .format('YYYY-MM-DD')
  698. return [lastMonthFirstDay, nextMonthLastDay]
  699. }
  700. dateRange.value = getDefaultRange()
  701. const clearSubList = () => {
  702. subList.value = []
  703. subListBackup = []
  704. currentRow.value = {}
  705. }
  706. let getList = () => {
  707. loading.value = true
  708. zoho.CRM.API.coql({
  709. select_query:
  710. 'select Container_Number,Name,Forwarder,ETD,ATD,ETA,ATA,Cut_Off_Date,Owner,Status,Modified_Time,SubscriptionId,Carrier,Booking_Number,GRN from Sea_Freight_Table' +
  711. " where ETD between '" +
  712. `${dateRange.value.map((i) => dayjs(i).format('YYYY-MM-DD')).join("' and '")}` +
  713. "'",
  714. })
  715. .then((res: any) => {
  716. if (Array.isArray(res.data) && res.data.length) {
  717. list.value = res.data.sort(
  718. (a: any, b: any) =>
  719. new Date(b.Cut_Off_Date).getTime() -
  720. new Date(a.Cut_Off_Date).getTime(),
  721. )
  722. } else if (res.status === 204) {
  723. ElNotification({
  724. type: 'warning',
  725. title: 'No Data Found',
  726. message: res.statusText || `zoho api return: ${res.status}`,
  727. duration: 3000,
  728. })
  729. list.value = []
  730. clearSubList()
  731. }
  732. })
  733. .finally(() => (loading.value = false))
  734. }
  735. let currentRow = ref({} as any)
  736. let subList = ref([] as any[])
  737. // 未经过滤的crm数据
  738. let subListBackup: any[] = []
  739. watch(currentTab, (value: string) => {
  740. // 切到可用tab, 但是当前行是不是 可用 状态
  741. let notAvaliable = value === 'avaliable' && currentRow.value.Status !== '可用'
  742. // 切到关闭tab, 但当前行不是‘关闭’状态
  743. let notClose =
  744. value === 'voyage_closed' &&
  745. !['已截仓', '已确认', '已发出'].includes(currentRow.value.Status)
  746. if (notAvaliable || notClose) {
  747. clearSubList()
  748. } else {
  749. generateSubList()
  750. }
  751. })
  752. const generateSubList = () => {
  753. // clonedeep 是因为数据里面有 object array, 担心浅复制到表单变量会影响到原始数据
  754. subList.value = cloneDeep(
  755. subListBackup
  756. .filter(
  757. (i: any) =>
  758. i.Parent_Id.id === currentRow.value.id &&
  759. (currentTab.value === 'my_request'
  760. ? i.Sales_Person === currentUserName.value
  761. : true),
  762. )
  763. .map((i: any) => ({
  764. ...i,
  765. Requester: i.Requester?.id
  766. ? {
  767. name: i.Requester.name || '',
  768. id: i.Requester.id,
  769. }
  770. : { name: '', id: '' },
  771. Sample: i.Sample || false,
  772. batchRecord: i.Batch_Record?.id || '',
  773. addFlag: false,
  774. editFlag: false,
  775. deleteFlag: false,
  776. })),
  777. )
  778. }
  779. const changeTotal = (row: any) => {
  780. row.editFlag = true
  781. row.Total_FOB = (Number(row.Unit_Price) * Number(row.Quantity)).toFixed(2)
  782. }
  783. /**
  784. * 用来增加新行的数据模版
  785. */
  786. const newLineTemplate = {
  787. addFlag: true,
  788. editFlag: true,
  789. deleteFlag: false,
  790. batchRecord: '',
  791. // 提交表单前删掉以上字段
  792. // id: '',
  793. Sample: false,
  794. Batch_Record: {
  795. name: '',
  796. id: '',
  797. } as any,
  798. Sales_Order: '',
  799. Purchase_Order: '',
  800. Reference: '',
  801. PO_Number: '',
  802. Parent_Id: {
  803. name: '',
  804. id: '',
  805. } as any,
  806. Carton: '',
  807. Marks_Nos: '',
  808. Description_of_Goods: '',
  809. Material_of_Goods: [],
  810. Quantity: '',
  811. Unit_Price: '',
  812. Weight: '',
  813. Cube: '',
  814. Total_FOB: '',
  815. Requester: { name: '', id: '' } as any,
  816. Sales_Person: '', // 申请人
  817. User_Notes: '',
  818. }
  819. // 用在弹窗里面给批次记录做候选项
  820. let batchListOption = computed(() =>
  821. subList.value
  822. .filter(
  823. (i) =>
  824. i.Batch_Record && i.Batch_Record.name && i.Batch_Record.name.length > 0,
  825. )
  826. .map((i) => {
  827. return {
  828. Name: i.Batch_Record.name || '',
  829. id: i.Batch_Record.id || '',
  830. isSearch: false, // 用来区分是搜索出来的还是原始数据
  831. }
  832. })
  833. // ai生成的去重逻辑.
  834. .filter(
  835. (item, index, self) =>
  836. index ===
  837. self.findIndex((t) => t.Name === item.Name && t.id === item.id),
  838. ),
  839. )
  840. let computedOption = computed(() => {
  841. return qcList.value.concat(batchListOption.value)
  842. })
  843. let getSubList = (e: any = {}) => {
  844. if (e.id) currentRow.value = e
  845. loading.value = true
  846. zoho.CRM.API.searchRecord({
  847. Entity: 'Sea_Freight_Details',
  848. Type: 'criteria',
  849. Query: `(Parent_Id:equals:${currentRow.value.id})`,
  850. delay: false,
  851. })
  852. .then((res: any) => {
  853. if (Array.isArray(res.data) && res.data.length) {
  854. subListBackup = cloneDeep(res.data)
  855. } else {
  856. subListBackup = []
  857. }
  858. generateSubList()
  859. newLineTemplate.Parent_Id = { id: currentRow.value.id }
  860. newLineTemplate.Sales_Person = currentUserName.value
  861. newLineTemplate.Requester = {
  862. id: currentUser.value,
  863. name: currentUserName.value,
  864. }
  865. })
  866. .finally(() => (loading.value = false))
  867. }
  868. // 货物材质候选数据
  869. const goodMaterialOption = ref([
  870. 'Cotton 棉',
  871. 'Iron 铁',
  872. 'Neoprene 潜水料',
  873. 'Paper 纸质',
  874. 'Plastic 塑料',
  875. 'Polyester Fibre 聚酯纤维',
  876. 'PU 聚氨酯',
  877. 'PVC 聚氯乙烯',
  878. 'Velvet 天鹅绒',
  879. 'Zinc alloy 锌合金',
  880. 'Aluminum alloy 铝合金',
  881. 'Glass 玻璃',
  882. 'Rubber 橡胶',
  883. 'Stainless Steel 不锈钢',
  884. ])
  885. // 动态获取货物材质候选数据
  886. let getGoodMaterialOption = () => {
  887. request
  888. .post('/common/getWebsiteSubform', { id: '4791186000359651051' })
  889. .then((resp: any) => {
  890. // console.log(resp, 'res')
  891. const res = resp.data.result || {}
  892. if (Array.isArray(res.data) && res.data.length) {
  893. // console.log(res.data, 'res.data')
  894. goodMaterialOption.value =
  895. res.data[0].Website_Subform.map(
  896. (i: any) => i.Website_Subform_Value,
  897. ) || []
  898. }
  899. })
  900. }
  901. getGoodMaterialOption()
  902. const addBulkProduct = () => {
  903. let temp = cloneDeep(newLineTemplate)
  904. temp.Sample = false
  905. subList.value.unshift(temp)
  906. }
  907. const addSample = () => {
  908. let temp = cloneDeep(newLineTemplate)
  909. temp.Sample = true
  910. subList.value.unshift(temp)
  911. }
  912. const onDeleteRow = (row: any, index: number = -1) => {
  913. if (row.addFlag) {
  914. subList.value.splice(index, 1)
  915. } else {
  916. row.deleteFlag = true
  917. ElNotification({
  918. type: 'warning',
  919. title: '已标记删除',
  920. duration: 3000,
  921. message: '点 提交 按钮后会正式删除. 误操作请点击 放弃改动.',
  922. })
  923. }
  924. }
  925. const onBatchRecordChange = ($e: string, line = -1) => {
  926. const temp = computedOption.value.filter((i) => i.id === $e)
  927. let result: any = {}
  928. if (temp.length) {
  929. result = cloneDeep(temp[0])
  930. }
  931. if (line > -1) {
  932. // 主页面数据编辑
  933. subList.value[line].editFlag = true
  934. subList.value[line].Batch_Record = { id: result.id, name: result.Name }
  935. if (result.Owner) {
  936. subList.value[line].Requester = {
  937. name: result.Owner.name,
  938. id: result.Owner.id,
  939. }
  940. }
  941. subList.value[line].Sales_Order = result.Sales_Order || ''
  942. subList.value[line].Purchase_Order = result.Purchase_Order || ''
  943. subList.value[line].Reference = result.Reference || ''
  944. subList.value[line].PO_Number = result.PO_Number || ''
  945. }
  946. }
  947. // 给子表格加红绿背景. 颜色用的tailwind的 red green
  948. const calcRowStyle = ($e: any) => {
  949. const result = {} as any
  950. if ($e.row.addFlag) result['background-color'] = 'rgb(187, 247, 208)'
  951. if ($e.row.editFlag) result['background-color'] = 'rgb(187, 247, 208)'
  952. if ($e.row.deleteFlag) result['background-color'] = 'rgb(254, 202, 202)'
  953. return result
  954. }
  955. const commit = () => {
  956. let temp = cloneDeep(subList.value)
  957. let result = temp
  958. .filter((i) => !i.deleteFlag)
  959. .map((i) => {
  960. return {
  961. id: i.id,
  962. Sample: i.Sample || false,
  963. Batch_Record: i.batchRecord
  964. ? {
  965. name: i.Batch_Record.name,
  966. id: i.Batch_Record.id,
  967. }
  968. : '',
  969. Parent_Id: {
  970. name: i.Parent_Id.name,
  971. id: i.Parent_Id.id || '',
  972. },
  973. Material_of_Goods: i.Material_of_Goods,
  974. Requester: i.Requester.name
  975. ? {
  976. name: i.Requester.name,
  977. id: i.Requester.id || '',
  978. }
  979. : '',
  980. Sales_Person: i.Sales_Person || '',
  981. Carton: i.Carton || '',
  982. Marks_Nos: i.Marks_Nos || '',
  983. Description_of_Goods: i.Description_of_Goods || '',
  984. Quantity: i.Quantity || '',
  985. Unit_Price: i.Unit_Price || '',
  986. Weight: i.Weight || '',
  987. Cube: i.Cube || '',
  988. Total_FOB: i.Total_FOB || '',
  989. User_Notes: i.User_Notes || '',
  990. Sales_Order: i.Sales_Order || '',
  991. Purchase_Order: i.Purchase_Order || '',
  992. Reference: i.Reference || '',
  993. PO_Number: i.PO_Number || '',
  994. }
  995. }) as any[]
  996. result = result.concat(
  997. temp
  998. .filter((i) => i.deleteFlag)
  999. .map((i) => ({ id: i.id, _delete: null, Material_of_Goods: null })),
  1000. )
  1001. // const emptyBatchRecordList: number[] = []
  1002. const emptyUserNotesList: number[] = []
  1003. result.forEach((i, index) => {
  1004. // if (!i.Sample) {
  1005. // if (!i.Batch_Record) {
  1006. // emptyBatchRecordList.push(index)
  1007. // }
  1008. // }
  1009. if (!i.User_Notes) {
  1010. emptyUserNotesList.push(index)
  1011. }
  1012. })
  1013. // if (emptyBatchRecordList.length) {
  1014. // ElNotification({
  1015. // title: '请检查表单',
  1016. // message: `第 ${emptyBatchRecordList.map((i) => i + 1).join(', ')} 行的Batch Record数据`,
  1017. // duration: 5000,
  1018. // })
  1019. // return
  1020. // }
  1021. if (emptyUserNotesList.length) {
  1022. ElNotification({
  1023. title: '请检查表单, 备注是必填的',
  1024. message: `第 ${emptyUserNotesList
  1025. .map((i) => i + 1)
  1026. .join(', ')} 行的备注数据, 不能为空`,
  1027. duration: 5000,
  1028. })
  1029. return
  1030. }
  1031. console.log(result, 'submit result')
  1032. loading.value = true
  1033. request
  1034. .post('/sea_freight/updateSeaFreightDataV2', {
  1035. id: newLineTemplate.Parent_Id.id,
  1036. Sea_Freight_array: result,
  1037. Sales_Person: currentUserName.value,
  1038. Sales_Person_Obj: {
  1039. id: currentUser.value,
  1040. name: currentUserName.value,
  1041. },
  1042. })
  1043. .then((res) => {
  1044. if (res.data.code === 1) {
  1045. let result = res.data.result || { data: [] }
  1046. if (
  1047. Array.isArray(result.data) &&
  1048. result.data.length &&
  1049. result.data.every((i: any) => i.status === 'success')
  1050. ) {
  1051. ElNotification({
  1052. title: '保存成功',
  1053. message: '正在刷新数据',
  1054. duration: 3000,
  1055. })
  1056. } else {
  1057. ElNotification({
  1058. title: '部份内容保存失败',
  1059. message: '建议刷新再试或者联系管理员',
  1060. duration: 10000,
  1061. })
  1062. }
  1063. getSubList(currentRow.value)
  1064. } else {
  1065. ElMessage.error('保存出错')
  1066. loading.value = false
  1067. }
  1068. })
  1069. .catch((e) => {
  1070. console.log(e, 'commit error')
  1071. loading.value = false
  1072. })
  1073. }
  1074. let printDrawerVisible = ref(false)
  1075. let currentPrintRow = ref({} as any)
  1076. const print = (row: any) => {
  1077. currentPrintRow.value = row
  1078. printDrawerVisible.value = true
  1079. }
  1080. const exportSubTable = () => {
  1081. const headers = [
  1082. '箱数 Carton',
  1083. '唛头 Marks & Nos',
  1084. '货物名称 Description of Goods',
  1085. '货物材质 Material goods',
  1086. '数量 QTY',
  1087. '单价 澳币/AUD Unit Price',
  1088. '重量KG Weight',
  1089. '体积m³ Cube',
  1090. '总离岸价 澳币/AUD Total FOB',
  1091. '负责人 Owner',
  1092. 'Reference',
  1093. ]
  1094. const data: any[] = subList.value.map((i) => {
  1095. return {
  1096. '箱数 Carton': i.Carton || '',
  1097. '唛头 Marks & Nos': i.Marks_Nos || '',
  1098. '货物名称 Description of Goods': i.Description_of_Goods || '',
  1099. '货物材质 Material goods': i.Material_of_Goods,
  1100. '数量 QTY': i.Quantity || '',
  1101. '单价 澳币/AUD Unit Price': i.Unit_Price || '',
  1102. '重量KG Weight': i.Weight || '',
  1103. '体积m³ Cube': i.Cube || '',
  1104. '总离岸价 澳币/AUD Total FOB': i.Total_FOB || '',
  1105. '负责人 Owner': i.Requester.name || '',
  1106. Reference: i.Reference || i.PO_Number || '',
  1107. }
  1108. })
  1109. if (data.length === 0) {
  1110. throw new Error('Invalid data: Data array is empty.')
  1111. }
  1112. const worksheetData = []
  1113. worksheetData.push(['发票/装箱单/INVOICE/PACKING LIST'])
  1114. if (headers && headers.length > 0) {
  1115. worksheetData.push(headers)
  1116. } else {
  1117. worksheetData.push(Object.keys(data[0]))
  1118. }
  1119. data.forEach((row) => {
  1120. worksheetData.push(Object.values(row))
  1121. })
  1122. const wb = XLSX.utils.book_new()
  1123. let ws = XLSX.utils.aoa_to_sheet(worksheetData)
  1124. ws['!merges'] = [
  1125. { s: { r: 0, c: 0 }, e: { r: 0, c: 9 } }, // 合并列作为标题
  1126. ]
  1127. ws['!cols'] = [
  1128. { wpx: 80 },
  1129. { wpx: 200 },
  1130. { wpx: 180 },
  1131. { wpx: 120 },
  1132. { wpx: 90 },
  1133. { wpx: 120 },
  1134. { wpx: 100 },
  1135. { wpx: 100 },
  1136. { wpx: 120 },
  1137. { wpx: 120 },
  1138. { wpx: 100 },
  1139. ]
  1140. XLSX.utils.book_append_sheet(wb, ws, 'Sheet1')
  1141. XLSX.writeFile(
  1142. wb,
  1143. encodeURIComponent(currentRow.value.Name || 'test') + '.xlsx',
  1144. )
  1145. }
  1146. let qcList = ref([] as any[])
  1147. let loading2 = ref(false)
  1148. const search = (keyword: string) => {
  1149. if (keyword.length < 2) return
  1150. loading2.value = true
  1151. zoho.CRM.API.searchRecord({
  1152. Entity: 'QC_Record',
  1153. Type: 'criteria',
  1154. Query: `(Reference:in:${keyword})or(Reference:starts_with:${keyword})or(Purchase_Order.name:in:${keyword})or(Purchase_Order.name:starts_with:${keyword})`,
  1155. delay: false,
  1156. })
  1157. .then((res: any) => {
  1158. if (Array.isArray(res.data) && res.data.length) {
  1159. qcList.value = res.data.map((i: any) => {
  1160. return {
  1161. ...i,
  1162. isSearch: true,
  1163. }
  1164. })
  1165. } else {
  1166. qcList.value = []
  1167. ElMessage.warning('No Data Found')
  1168. }
  1169. })
  1170. .finally(() => (loading2.value = false))
  1171. }
  1172. const ensure = () => {
  1173. ElMessageBox.confirm('确定要把该记录状态更新为"已确认"吗?', {
  1174. confirmButtonText: '确定',
  1175. cancelButtonText: '取消',
  1176. type: 'warning',
  1177. }).then(() => {
  1178. loading.value = true
  1179. zoho.CRM.API.updateRecord({
  1180. Entity: 'Sea_Freight_Table',
  1181. Trigger: ['workflow'],
  1182. APIData: {
  1183. id: currentRow.value.id,
  1184. Status: '已确认',
  1185. },
  1186. }).then((res: any) => {
  1187. if (
  1188. Array.isArray(res.data) &&
  1189. res.data.length &&
  1190. res.data[0].code === 'SUCCESS'
  1191. ) {
  1192. ElMessage.success('操作成功, 正在刷新数据')
  1193. loading.value = false
  1194. getList()
  1195. clearSubList()
  1196. } else {
  1197. loading.value = false
  1198. ElMessage.error('操作失败, 请稍后再试或者联系管理员')
  1199. }
  1200. })
  1201. })
  1202. }
  1203. let bookingNumber = ref('')
  1204. const updateBookingNumber = () => {
  1205. bookingNumber.value = bookingNumber.value.trim()
  1206. if (!bookingNumber.value || !currentRow.value.id) {
  1207. ElMessage.error('请填写订舱号')
  1208. return
  1209. }
  1210. ElMessageBox.confirm(
  1211. `确定要把该记录的订舱号更新为"${bookingNumber.value}"吗?`,
  1212. {
  1213. confirmButtonText: '确定',
  1214. cancelButtonText: '取消',
  1215. type: 'warning',
  1216. },
  1217. ).then(() => {
  1218. loading.value = true
  1219. zoho.CRM.API.updateRecord({
  1220. Entity: 'Sea_Freight_Table',
  1221. Trigger: ['workflow'],
  1222. APIData: {
  1223. id: currentRow.value.id,
  1224. Booking_Number: bookingNumber.value,
  1225. },
  1226. }).then((res: any) => {
  1227. if (
  1228. Array.isArray(res.data) &&
  1229. res.data.length &&
  1230. res.data[0].code === 'SUCCESS'
  1231. ) {
  1232. ElMessage.success('操作成功, 正在刷新数据')
  1233. loading.value = false
  1234. bookingNumber.value = ''
  1235. getList()
  1236. clearSubList()
  1237. } else {
  1238. loading.value = false
  1239. ElMessage.error('操作失败, 请稍后再试或者联系管理员')
  1240. }
  1241. })
  1242. })
  1243. }
  1244. let containerNumber = ref('')
  1245. const updateContainerNumber = () => {
  1246. containerNumber.value = containerNumber.value.trim()
  1247. if (!containerNumber.value || !currentRow.value.id) {
  1248. ElMessage.error('请填写柜号')
  1249. return
  1250. }
  1251. ElMessageBox.confirm(
  1252. `确定要把该记录的柜号更新为"${containerNumber.value}"吗?`,
  1253. {
  1254. confirmButtonText: '确定',
  1255. cancelButtonText: '取消',
  1256. type: 'warning',
  1257. },
  1258. ).then(() => {
  1259. loading.value = true
  1260. zoho.CRM.API.updateRecord({
  1261. Entity: 'Sea_Freight_Table',
  1262. Trigger: ['workflow'],
  1263. APIData: {
  1264. id: currentRow.value.id,
  1265. Container_Number: containerNumber.value,
  1266. },
  1267. }).then((res: any) => {
  1268. if (
  1269. Array.isArray(res.data) &&
  1270. res.data.length &&
  1271. res.data[0].code === 'SUCCESS'
  1272. ) {
  1273. ElMessage.success('操作成功, 正在刷新数据')
  1274. loading.value = false
  1275. containerNumber.value = ''
  1276. getList()
  1277. clearSubList()
  1278. } else {
  1279. loading.value = false
  1280. ElMessage.error('操作失败, 请稍后再试或者联系管理员')
  1281. }
  1282. })
  1283. })
  1284. }
  1285. // @ts-ignore
  1286. const zoho = window.ZOHO
  1287. zoho.embeddedApp.on('PageLoad', function () {
  1288. zoho.CRM.CONFIG.getCurrentUser().then(function (data: any) {
  1289. if (Array.isArray(data.users) && data.users.length) {
  1290. const user = data.users[0]
  1291. // console.log(user, 'user')
  1292. currentUser.value = user.id
  1293. currentUserName.value = user.full_name || ''
  1294. currentUserRawData.value = cloneDeep(user)
  1295. getList()
  1296. }
  1297. })
  1298. })
  1299. zoho.embeddedApp.init()
  1300. watch(currentUserRawData, () => {
  1301. if (!currentUserRawData.value.role) return false
  1302. let result =
  1303. /(CEO|Logistics)/g.test(currentUserRawData.value.role.name) ||
  1304. ['4791186000022965001', '4791186000052269001'].includes(
  1305. currentUserRawData.value.role.id,
  1306. )
  1307. if (result) {
  1308. finalTabs.value = cloneDeep(tabs)
  1309. finalTabs.value.push({
  1310. label: 'Arrangement',
  1311. value: 'Arrangement',
  1312. })
  1313. }
  1314. })
  1315. let computedWeight = computed(() => {
  1316. return subList.value
  1317. .reduce((t, c) => {
  1318. t = t + Number(c.Weight)
  1319. return t
  1320. }, 0)
  1321. .toFixed(2)
  1322. })
  1323. let computedCube = computed(() => {
  1324. return subList.value
  1325. .reduce((t, c) => {
  1326. t = t + Number(c.Cube)
  1327. return t
  1328. }, 0)
  1329. .toFixed(2)
  1330. })
  1331. let computedTotalFOB = computed(() => {
  1332. return subList.value
  1333. .reduce((t, c) => {
  1334. t = t + Number(c.Total_FOB)
  1335. return t
  1336. }, 0)
  1337. .toFixed(2)
  1338. })
  1339. // 订单轨迹地图插件
  1340. let mapDrawerVisible = ref(false)
  1341. const openMapDrawer = (row: any) => {
  1342. mapDrawerVisible.value = true
  1343. // console.log(row.Carrier, 'row.value.Carrier')
  1344. // console.log(row.Booking_Number, 'row.value.Booking_Number')
  1345. if ((window as any).Sgld) {
  1346. nextTick(() => {
  1347. ;(window as any).Sgld.createContainerTrack({
  1348. id: 'mapDrawer',
  1349. carrierCode: row.Carrier, // 船公司代码
  1350. billNo: row.Booking_Number, // 提单号
  1351. })
  1352. })
  1353. }
  1354. }
  1355. const closeMapDrawer = () => {
  1356. mapDrawerVisible.value = false
  1357. }
  1358. </script>
  1359. <style lang="scss">
  1360. .page-cargo-consolidation {
  1361. .el-table__body tr.current-row > td.el-table__cell {
  1362. background-color: rgb(56, 163, 238);
  1363. color: #fff;
  1364. }
  1365. }
  1366. </style>
  1367. <style lang="scss" scoped>
  1368. .el-button.custom-button {
  1369. height: 24px;
  1370. line-height: 24px;
  1371. background-image: linear-gradient(
  1372. 171deg,
  1373. rgb(28, 74, 136) 49%,
  1374. rgb(0, 130, 193) 100%
  1375. );
  1376. background-color: rgb(97, 165, 245);
  1377. color: #fff;
  1378. font-size: 13px;
  1379. font-family: Zoho_Puvi_Bold sans-serif;
  1380. border-radius: 6px;
  1381. cursor: pointer;
  1382. &:hover,
  1383. &:active {
  1384. background-image: linear-gradient(
  1385. 171deg,
  1386. rgb(28, 74, 136) 49%,
  1387. rgb(22, 208, 239) 100%
  1388. );
  1389. color: #fff;
  1390. }
  1391. &.fb {
  1392. font-weight: 900;
  1393. }
  1394. &.small {
  1395. height: 24px;
  1396. line-height: 24px;
  1397. }
  1398. }
  1399. </style>