index.vue 34 KB

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