index.vue 34 KB

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