PilotPlan.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  1. <template>
  2. <div class="pilot-plan-container">
  3. <h2>引航计划管理</h2>
  4. <!-- 查询条件 -->
  5. <div class="search-section">
  6. <h3>查询条件</h3>
  7. <el-form :model="searchForm" class="demo-form">
  8. <!-- 第一行(默认显示,3个控件 + 按钮) -->
  9. <div class="search-row" v-if="showAllSearch || row1Visible">
  10. <el-form-item label="作业时间">
  11. <el-date-picker
  12. v-model="searchForm.planTimeRange"
  13. type="daterange"
  14. range-separator="至"
  15. start-placeholder="开始日期"
  16. end-placeholder="结束日期"
  17. style="width: 240px"
  18. ></el-date-picker>
  19. </el-form-item>
  20. <el-form-item label="港区作业类型">
  21. <el-select
  22. v-model="searchForm.portAreaOperationType"
  23. placeholder="请选择"
  24. style="width: 180px"
  25. >
  26. <el-option label="全部" value=""></el-option>
  27. <el-option label="本港计划" value="本港计划"></el-option>
  28. <el-option label="外港计划" value="外港计划"></el-option>
  29. </el-select>
  30. </el-form-item>
  31. <el-form-item label="港口">
  32. <el-select
  33. v-model="searchForm.portId"
  34. placeholder="请选择"
  35. style="width: 180px"
  36. clearable
  37. >
  38. <el-option
  39. v-for="port in portList"
  40. :key="port.portId"
  41. :label="port.portName"
  42. :value="port.portId">
  43. </el-option>
  44. </el-select>
  45. </el-form-item>
  46. <div class="search-actions">
  47. <el-button
  48. v-if="hasExtraRows"
  49. type="primary"
  50. @click="toggleSearchForm">
  51. {{ showAllSearch ? '收起' : '展开' }}
  52. </el-button>
  53. <el-button type="primary" @click="getPilotPlans" :loading="loading">查询</el-button>
  54. <el-button @click="resetSearchForm" :loading="loading">重置</el-button>
  55. </div>
  56. </div>
  57. <!-- 第二行(默认隐藏,3个控件) -->
  58. <div class="search-row" v-if="showAllSearch || row2Visible">
  59. <el-form-item label="英文船名">
  60. <el-input
  61. v-model="searchForm.englishShipName"
  62. placeholder="请输入英文船名"
  63. style="width: 180px"
  64. clearable
  65. ></el-input>
  66. </el-form-item>
  67. <el-form-item label="状态">
  68. <el-select
  69. v-model="searchForm.status"
  70. placeholder="请选择"
  71. style="width: 180px"
  72. >
  73. <el-option label="全部" value=""></el-option>
  74. <el-option label="未调度" value="未调度"></el-option>
  75. <el-option label="已调度" value="已调度"></el-option>
  76. </el-select>
  77. </el-form-item>
  78. <el-form-item label="船公司">
  79. <el-select
  80. v-model="searchForm.shipownerId"
  81. placeholder="请选择"
  82. style="width: 180px"
  83. clearable
  84. filterable
  85. remote
  86. :remote-method="searchShipCompany"
  87. :loading="shipCompanyLoading"
  88. @visible-change="handleShipCompanyVisibleChange"
  89. @scroll="handleShipCompanyScroll"
  90. >
  91. <el-option
  92. v-for="company in shipCompanyList"
  93. :key="company.companyId"
  94. :label="company.companyName"
  95. :value="company.companyId">
  96. </el-option>
  97. </el-select>
  98. </el-form-item>
  99. </div>
  100. <!-- 第三行(默认隐藏,3个控件) -->
  101. <div class="search-row" v-if="showAllSearch || row3Visible">
  102. <el-form-item label="吃水">
  103. <div class="input-group">
  104. <el-input
  105. v-model="searchForm.deepStart"
  106. placeholder="最小值"
  107. style="width: 80px"
  108. type="number"
  109. ></el-input>
  110. <span style="padding: 0 5px">-</span>
  111. <el-input
  112. v-model="searchForm.deepEnd"
  113. placeholder="最大值"
  114. style="width: 80px"
  115. type="number"
  116. ></el-input>
  117. </div>
  118. </el-form-item>
  119. <el-form-item label="交通船">
  120. <el-input
  121. v-model="searchForm.trafficboat"
  122. placeholder="请输入交通船"
  123. style="width: 180px"
  124. clearable
  125. ></el-input>
  126. </el-form-item>
  127. </div>
  128. </el-form>
  129. </div>
  130. <!-- 操作按钮 -->
  131. <div class="action-section">
  132. <el-button type="primary" @click="openImportDialog" v-permission="'010401'">导入引航计划</el-button>
  133. <el-button type="success" @click="exportPilotPlans" v-permission="'010403'">导出Excel</el-button>
  134. </div>
  135. <!-- 列表展示 -->
  136. <div class="list-section">
  137. <h3>引航计划列表</h3>
  138. <el-table
  139. :data="pilotPlans"
  140. style="width: calc(100vw - 330px); height: calc(100vh - 469px);"
  141. border
  142. size="default"
  143. stripe
  144. :header-cell-style="{ background: '#f5f7fa', color: '#303133', fontWeight: 'bold' }"
  145. @sort-change="handleSortChange">
  146. <el-table-column type="index" label="序号" width="50" fixed align="center"></el-table-column>
  147. <el-table-column prop="planTime" label="计划时间" width="160" fixed align="center" sortable show-overflow-tooltip>
  148. <template #default="scope">
  149. {{ formatDateTime(scope.row.planTime) }}
  150. </template>
  151. </el-table-column>
  152. <el-table-column prop="chineseShipName" label="中文船名" min-width="120" sortable show-overflow-tooltip></el-table-column>
  153. <el-table-column prop="englishShipName" label="英文船名" min-width="120" sortable show-overflow-tooltip></el-table-column>
  154. <el-table-column prop="shipCompanyName" label="船公司" min-width="150" sortable show-overflow-tooltip></el-table-column>
  155. <el-table-column prop="nation" label="国籍" width="100" sortable align="center"></el-table-column>
  156. <el-table-column prop="shipLength" label="船长" width="80" sortable align="center"></el-table-column>
  157. <el-table-column prop="deep" label="吃水" width="80" sortable align="center"></el-table-column>
  158. <el-table-column prop="pilotTypeName" label="动态" width="100" sortable align="center"></el-table-column>
  159. <el-table-column prop="fromBerthName" label="起点泊位" min-width="100" sortable show-overflow-tooltip></el-table-column>
  160. <el-table-column prop="toBerthName" label="终点泊位" min-width="100" sortable show-overflow-tooltip></el-table-column>
  161. <el-table-column prop="mainPilotName" label="主引" width="80" sortable align="center" show-overflow-tooltip></el-table-column>
  162. <el-table-column prop="trafficboat" label="交通船" width="100" sortable show-overflow-tooltip></el-table-column>
  163. <el-table-column prop="agencyName" label="代理" min-width="150" sortable show-overflow-tooltip></el-table-column>
  164. <el-table-column prop="portAreaOperationType" label="港区作业类型" width="120" sortable align="center"></el-table-column>
  165. <el-table-column prop="waterwayName" label="航道" min-width="100" sortable show-overflow-tooltip></el-table-column>
  166. <el-table-column prop="status" label="状态" width="80" sortable align="center">
  167. <template #default="scope">
  168. <el-tag :type="scope.row.status === '已调度' ? 'success' : 'info'" size="small">
  169. {{ scope.row.status }}
  170. </el-tag>
  171. </template>
  172. </el-table-column>
  173. </el-table>
  174. <!-- 分页 -->
  175. <div class="pagination">
  176. <el-pagination
  177. @size-change="handleSizeChange"
  178. @current-change="handleCurrentChange"
  179. :current-page="currentPage"
  180. :page-sizes="[10, 20, 50, 100]"
  181. :page-size="pageSize"
  182. layout="total, sizes, prev, pager, next, jumper"
  183. :total="total"></el-pagination>
  184. </div>
  185. </div>
  186. <!-- 导入弹窗 -->
  187. <el-dialog
  188. title="导入引航计划"
  189. v-model="importDialogVisible"
  190. width="800px"
  191. >
  192. <textarea
  193. v-model="importData"
  194. placeholder="请粘贴引航计划数据,每行一条记录,字段间用制表符分隔"
  195. rows="10"
  196. style="width: 100%; padding: 10px; border: 1px solid #dcdfe6; border-radius: 4px; resize: vertical; font-size: 14px; line-height: 1.5;"
  197. ></textarea>
  198. <template #footer>
  199. <span class="dialog-footer">
  200. <el-button @click="importDialogVisible = false">取消</el-button>
  201. <el-button type="primary" @click="parseImportData">解析数据</el-button>
  202. </span>
  203. </template>
  204. </el-dialog>
  205. <!-- 预览弹窗 -->
  206. <el-dialog
  207. title="预览引航计划"
  208. v-model="previewDialogVisible"
  209. width="90%"
  210. top="5vh"
  211. class="preview-dialog"
  212. >
  213. <div class="preview-header">
  214. <span class="preview-count">预览 {{ previewData.length }} 条记录</span>
  215. <el-input
  216. v-model="previewSearch"
  217. placeholder="搜索..."
  218. size="small"
  219. style="width: 200px;"
  220. clearable
  221. />
  222. </div>
  223. <el-table
  224. :data="filteredPreviewData"
  225. style="width: 100%"
  226. height="60vh"
  227. stripe
  228. border
  229. :header-cell-style="{background: '#f5f7fa', color: '#606266'}"
  230. >
  231. <el-table-column prop="serialNumber" label="序号" width="60" fixed align="center"></el-table-column>
  232. <el-table-column label="计划时间" width="154" fixed align="center" sortable show-overflow-tooltip>
  233. <template #default="scope">
  234. {{ formatDateTime(scope.row.planTime) }}
  235. </template>
  236. </el-table-column>
  237. <el-table-column prop="chineseShipName" label="中文船名" width="150" sortable show-overflow-tooltip></el-table-column>
  238. <el-table-column prop="englishShipName" label="英文船名" width="150" sortable show-overflow-tooltip></el-table-column>
  239. <el-table-column prop="nationality" label="国籍" width="90" sortable align="center"></el-table-column>
  240. <el-table-column prop="shipLength" label="船长(m)" width="90" sortable align="center"></el-table-column>
  241. <el-table-column prop="draft" label="吃水(m)" width="90" sortable align="center"></el-table-column>
  242. <el-table-column prop="dynamic" label="动态" width="90" sortable align="center"></el-table-column>
  243. <el-table-column prop="startBerth" label="起点泊位" width="130" sortable show-overflow-tooltip></el-table-column>
  244. <el-table-column prop="endBerth" label="终点泊位" width="130" sortable show-overflow-tooltip></el-table-column>
  245. <el-table-column prop="cooperationMark" label="合作标记" width="100" sortable align="center"></el-table-column>
  246. <el-table-column prop="pilotAgency" label="引航机构" width="120" sortable show-overflow-tooltip></el-table-column>
  247. <el-table-column prop="mainPilot" label="主引" width="100" sortable align="center" show-overflow-tooltip></el-table-column>
  248. <el-table-column prop="secondaryPilot" label="主引2" width="100" sortable align="center" show-overflow-tooltip></el-table-column>
  249. <el-table-column prop="deputyPilot" label="副引" width="100" sortable align="center" show-overflow-tooltip></el-table-column>
  250. <el-table-column prop="otherPilots" label="其它引水" width="100" sortable align="center" show-overflow-tooltip></el-table-column>
  251. <el-table-column prop="agent" label="代理" width="120" sortable show-overflow-tooltip></el-table-column>
  252. <el-table-column prop="agentPhone" label="代理电话" width="130" sortable show-overflow-tooltip></el-table-column>
  253. <el-table-column prop="transportVessel" label="交通船" width="100" sortable show-overflow-tooltip></el-table-column>
  254. <el-table-column prop="waterway" label="航道" width="120" sortable show-overflow-tooltip></el-table-column>
  255. <el-table-column prop="thruster" label="侧推" width="200" sortable show-overflow-tooltip></el-table-column>
  256. <el-table-column prop="remarks" label="备注" width="150" sortable show-overflow-tooltip></el-table-column>
  257. </el-table>
  258. <template #footer>
  259. <span class="dialog-footer">
  260. <el-button @click="previewDialogVisible = false">取消</el-button>
  261. <el-button type="primary" @click="confirmImport" :disabled="!previewData.length">
  262. 确认导入 ({{ previewData.length }} 条)
  263. </el-button>
  264. </span>
  265. </template>
  266. </el-dialog>
  267. </div>
  268. </template>
  269. <script>
  270. import { parsePilotPlanData } from '@/utils/pilotPlanParser'
  271. export default {
  272. name: 'PilotPlan',
  273. data() {
  274. return {
  275. importData: '',
  276. importDialogVisible: false,
  277. previewDialogVisible: false,
  278. previewData: [],
  279. previewSearch: '',
  280. showAllSearch: false,
  281. searchForm: {
  282. planTimeRange: [],
  283. portAreaOperationType: '',
  284. portId: '',
  285. englishShipName: '',
  286. status: '',
  287. shipownerId: '',
  288. deepStart: null,
  289. deepEnd: null,
  290. trafficboat: ''
  291. },
  292. pilotPlans: [],
  293. portList: [],
  294. shipCompanyList: [],
  295. shipCompanyQuery: '',
  296. shipCompanyPage: 1,
  297. shipCompanyPageSize: 10,
  298. shipCompanyLoading: false,
  299. shipCompanyHasMore: true,
  300. currentPage: 1,
  301. pageSize: 20,
  302. total: 0,
  303. tableHeight: 600,
  304. loading: false,
  305. exportLoading: false,
  306. importLoading: false,
  307. sortMap: {},
  308. sortFieldMap: {
  309. planTime: 'planTime',
  310. chineseShipName: 'chineseShipName',
  311. englishShipName: 'englishShipName',
  312. shipCompanyName: 'shipCompanyName',
  313. nation: 'nation',
  314. shipLength: 'shipLength',
  315. deep: 'deep',
  316. pilotTypeName: 'pilotTypeName',
  317. fromBerthName: 'fromBerthName',
  318. toBerthName: 'toBerthName',
  319. mainPilotName: 'mainPilotName',
  320. trafficboat: 'trafficboat',
  321. agencyName: 'agencyName',
  322. portAreaOperationType: 'portAreaOperationType',
  323. waterwayName: 'waterwayName',
  324. status: 'status'
  325. }
  326. }
  327. },
  328. computed: {
  329. row1Visible() {
  330. return true;
  331. },
  332. row2Visible() {
  333. return this.showAllSearch;
  334. },
  335. row3Visible() {
  336. return this.showAllSearch;
  337. },
  338. hasExtraRows() {
  339. return true;
  340. },
  341. filteredPreviewData() {
  342. if (!this.previewSearch) {
  343. return this.previewData;
  344. }
  345. const searchLower = this.previewSearch.toLowerCase();
  346. return this.previewData.filter(item => {
  347. return (
  348. (item.serialNumber && item.serialNumber.toString().toLowerCase().includes(searchLower)) ||
  349. (item.planTime && item.planTime.toLowerCase().includes(searchLower)) ||
  350. (item.chineseShipName && item.chineseShipName.toLowerCase().includes(searchLower)) ||
  351. (item.englishShipName && item.englishShipName.toLowerCase().includes(searchLower)) ||
  352. (item.nationality && item.nationality.toLowerCase().includes(searchLower)) ||
  353. (item.startBerth && item.startBerth.toLowerCase().includes(searchLower)) ||
  354. (item.endBerth && item.endBerth.toLowerCase().includes(searchLower)) ||
  355. (item.agent && item.agent.toLowerCase().includes(searchLower)) ||
  356. (item.remarks && item.remarks.toLowerCase().includes(searchLower))
  357. );
  358. });
  359. }
  360. },
  361. mounted() {
  362. this.getPortList();
  363. this.getShipCompanyList();
  364. this.setDefaultTimeRange();
  365. this.getPilotPlans();
  366. this.$nextTick(() => {
  367. this.calculateTableHeight();
  368. window.addEventListener('resize', this.calculateTableHeight);
  369. });
  370. },
  371. beforeUnmount() {
  372. window.removeEventListener('resize', this.calculateTableHeight);
  373. },
  374. methods: {
  375. calculateTableHeight() {
  376. const container = document.querySelector('.pilot-plan-container');
  377. const searchSection = document.querySelector('.search-section');
  378. const actionSection = document.querySelector('.action-section');
  379. const listSection = document.querySelector('.list-section');
  380. if (container && searchSection && actionSection && listSection) {
  381. const containerRect = container.getBoundingClientRect();
  382. const searchRect = searchSection.getBoundingClientRect();
  383. const actionRect = actionSection.getBoundingClientRect();
  384. const listRect = listSection.getBoundingClientRect();
  385. const remainingHeight = containerRect.height - searchRect.height - actionRect.height - listRect.height;
  386. this.tableHeight = Math.max(remainingHeight, 400);
  387. }
  388. },
  389. getPortList() {
  390. this.$axios.get('/api/port/list')
  391. .then(response => {
  392. this.portList = response.data;
  393. })
  394. .catch(error => {
  395. console.error('获取港口列表失败:', error);
  396. });
  397. },
  398. getShipCompanyList() {
  399. this.getShipCompanyListByPage('', 1);
  400. },
  401. getShipCompanyListByPage(query, page) {
  402. this.shipCompanyLoading = true;
  403. this.$axios.get('/api/ship-company/list', {
  404. params: {
  405. companyName: query,
  406. page: page,
  407. pageSize: this.shipCompanyPageSize
  408. }
  409. })
  410. .then(response => {
  411. if (page === 1) {
  412. this.shipCompanyList = response.data.content || [];
  413. } else {
  414. this.shipCompanyList = [...this.shipCompanyList, ...(response.data.content || [])];
  415. }
  416. this.shipCompanyHasMore = response.data.content && response.data.content.length >= this.shipCompanyPageSize;
  417. })
  418. .catch(error => {
  419. console.error('获取船公司列表失败:', error);
  420. this.$message.error('获取船公司列表失败,请稍后重试');
  421. })
  422. .finally(() => {
  423. this.shipCompanyLoading = false;
  424. });
  425. },
  426. searchShipCompany(query) {
  427. this.shipCompanyQuery = query || '';
  428. this.shipCompanyPage = 1;
  429. this.getShipCompanyListByPage(this.shipCompanyQuery, this.shipCompanyPage);
  430. },
  431. handleShipCompanyVisibleChange(visible) {
  432. if (visible && !this.shipCompanyQuery) {
  433. this.shipCompanyPage = 1;
  434. this.getShipCompanyListByPage('', this.shipCompanyPage);
  435. }
  436. },
  437. handleShipCompanyScroll() {
  438. if (this.shipCompanyHasMore && !this.shipCompanyLoading) {
  439. this.shipCompanyPage++;
  440. this.getShipCompanyListByPage(this.shipCompanyQuery, this.shipCompanyPage);
  441. }
  442. },
  443. getPilotPlans() {
  444. if (this.loading) return;
  445. this.loading = true;
  446. const planTimeStart = this.searchForm.planTimeRange && this.searchForm.planTimeRange.length > 0
  447. ? this.formatDate(this.searchForm.planTimeRange[0])
  448. : '';
  449. const planTimeEnd = this.searchForm.planTimeRange && this.searchForm.planTimeRange.length > 1
  450. ? this.formatDate(this.searchForm.planTimeRange[1])
  451. : '';
  452. const params = {
  453. planTimeStart: planTimeStart,
  454. planTimeEnd: planTimeEnd,
  455. portAreaOperationType: this.searchForm.portAreaOperationType,
  456. portId: this.searchForm.portId,
  457. englishShipName: this.searchForm.englishShipName,
  458. status: this.searchForm.status,
  459. shipownerId: this.searchForm.shipownerId,
  460. deepStart: this.searchForm.deepStart,
  461. deepEnd: this.searchForm.deepEnd,
  462. trafficboat: this.searchForm.trafficboat,
  463. page: this.currentPage,
  464. pageSize: this.pageSize,
  465. sortBy: this.sortMap.sortBy,
  466. sortOrder: this.sortMap.sortOrder
  467. };
  468. this.$axios.get('/api/pilot-plan/list', { params })
  469. .then(response => {
  470. this.pilotPlans = response.data.content;
  471. this.total = response.data.totalElements;
  472. })
  473. .catch(error => {
  474. console.error('获取引航计划失败:', error);
  475. this.$message.error('获取引航计划失败,请稍后重试');
  476. })
  477. .finally(() => {
  478. this.loading = false;
  479. });
  480. },
  481. handleSortChange({ prop, order }) {
  482. if (prop) {
  483. const sortBy = this.sortFieldMap[prop] || prop;
  484. this.sortMap = {
  485. sortBy: sortBy,
  486. sortOrder: order === 'ascending' ? 'ASC' : (order === 'descending' ? 'DESC' : null)
  487. };
  488. } else {
  489. this.sortMap = {};
  490. }
  491. this.getPilotPlans();
  492. },
  493. openImportDialog() {
  494. this.importData = '';
  495. this.importDialogVisible = true;
  496. },
  497. parseImportData() {
  498. if (!this.importData) {
  499. this.$message.warning('请粘贴引航计划数据');
  500. return;
  501. }
  502. try {
  503. this.previewData = parsePilotPlanData(this.importData);
  504. if (this.previewData.length === 0) {
  505. this.$message.warning('未解析到有效的引航计划数据,请检查数据格式');
  506. return;
  507. }
  508. this.importDialogVisible = false;
  509. this.previewDialogVisible = true;
  510. } catch (error) {
  511. console.error('解析引航计划失败:', error);
  512. this.$message.error('解析引航计划失败,请稍后重试');
  513. }
  514. },
  515. confirmImport() {
  516. if (this.importLoading) return;
  517. this.importLoading = true;
  518. this.$axios.post('/api/pilot-plan/import', this.previewData)
  519. .then(response => {
  520. if (response.data.success) {
  521. this.$message.success(`导入成功,共导入 ${response.data.importedCount} 条记录`);
  522. this.importData = '';
  523. this.previewData = [];
  524. this.previewDialogVisible = false;
  525. this.getPilotPlans();
  526. } else {
  527. this.$message.error(response.data.message);
  528. }
  529. })
  530. .catch(error => {
  531. console.error('导入引航计划失败:', error);
  532. this.$message.error('导入引航计划失败,请稍后重试');
  533. })
  534. .finally(() => {
  535. this.importLoading = false;
  536. });
  537. },
  538. async exportPilotPlans() {
  539. if (this.exportLoading) return;
  540. this.exportLoading = true;
  541. try {
  542. const planTimeStart = this.searchForm.planTimeRange && this.searchForm.planTimeRange.length > 0
  543. ? this.formatDate(this.searchForm.planTimeRange[0])
  544. : '';
  545. const planTimeEnd = this.searchForm.planTimeRange && this.searchForm.planTimeRange.length > 1
  546. ? this.formatDate(this.searchForm.planTimeRange[1])
  547. : '';
  548. const params = {
  549. planTimeStart: planTimeStart,
  550. planTimeEnd: planTimeEnd,
  551. portAreaOperationType: this.searchForm.portAreaOperationType,
  552. portId: this.searchForm.portId,
  553. englishShipName: this.searchForm.englishShipName,
  554. status: this.searchForm.status,
  555. shipownerId: this.searchForm.shipownerId,
  556. deepStart: this.searchForm.deepStart,
  557. deepEnd: this.searchForm.deepEnd,
  558. trafficboat: this.searchForm.trafficboat
  559. };
  560. const response = await this.$axios({
  561. method: 'get',
  562. url: '/api/pilot-plan/export',
  563. params: params,
  564. responseType: 'blob'
  565. });
  566. // 创建Blob对象
  567. const blob = new Blob([response.data], {
  568. type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8'
  569. });
  570. // 创建下载链接
  571. const downloadUrl = window.URL.createObjectURL(blob);
  572. const link = document.createElement('a');
  573. link.href = downloadUrl;
  574. // 获取文件名,从响应头中提取
  575. const contentDisposition = response.headers['content-disposition'];
  576. let filename = '引航计划数据.xlsx';
  577. if (contentDisposition) {
  578. const filenameMatch = contentDisposition.match(/filename="(.+)"/);
  579. if (filenameMatch) {
  580. filename = filenameMatch[1];
  581. }
  582. }
  583. link.download = filename;
  584. document.body.appendChild(link);
  585. link.click();
  586. document.body.removeChild(link);
  587. window.URL.revokeObjectURL(downloadUrl);
  588. this.$message.success('Excel文件导出成功');
  589. } catch (error) {
  590. console.error('导出失败:', error);
  591. this.$message.error('导出失败,请稍后重试');
  592. } finally {
  593. this.exportLoading = false;
  594. }
  595. },
  596. resetSearchForm() {
  597. this.searchForm = {
  598. planTimeRange: [],
  599. portAreaOperationType: '',
  600. portId: '',
  601. englishShipName: '',
  602. status: '',
  603. shipownerId: '',
  604. deepStart: null,
  605. deepEnd: null,
  606. trafficboat: ''
  607. };
  608. },
  609. toggleSearchForm() {
  610. this.showAllSearch = !this.showAllSearch;
  611. },
  612. handleSizeChange(val) {
  613. this.pageSize = val;
  614. this.getPilotPlans();
  615. },
  616. handleCurrentChange(val) {
  617. this.currentPage = val;
  618. this.getPilotPlans();
  619. },
  620. formatDate(date) {
  621. if (!date) return '';
  622. const year = date.getFullYear();
  623. const month = String(date.getMonth() + 1).padStart(2, '0');
  624. const day = String(date.getDate()).padStart(2, '0');
  625. return `${year}-${month}-${day}`;
  626. },
  627. setDefaultTimeRange() {
  628. const now = new Date();
  629. const firstDay = new Date(now.getFullYear(), now.getMonth(), 1);
  630. const lastDay = new Date(now.getFullYear(), now.getMonth() + 1, 0);
  631. // 设置时间为当天的开始和结束时间
  632. firstDay.setHours(0, 0, 0, 0);
  633. lastDay.setHours(23, 59, 59, 999);
  634. this.searchForm.planTimeRange = [firstDay, lastDay];
  635. },
  636. formatDateTime(date) {
  637. if (!date) return '';
  638. if (typeof date === 'string') {
  639. // 如果是字符串格式的日期,尝试解析
  640. const parsedDate = new Date(date);
  641. if (!isNaN(parsedDate.getTime())) {
  642. const year = parsedDate.getFullYear();
  643. const month = String(parsedDate.getMonth() + 1).padStart(2, '0');
  644. const day = String(parsedDate.getDate()).padStart(2, '0');
  645. const hours = String(parsedDate.getHours()).padStart(2, '0');
  646. const minutes = String(parsedDate.getMinutes()).padStart(2, '0');
  647. return `${year}-${month}-${day} ${hours}:${minutes}`;
  648. }
  649. return date;
  650. }
  651. const year = date.getFullYear();
  652. const month = String(date.getMonth() + 1).padStart(2, '0');
  653. const day = String(date.getDate()).padStart(2, '0');
  654. const hours = String(date.getHours()).padStart(2, '0');
  655. const minutes = String(date.getMinutes()).padStart(2, '0');
  656. return `${year}-${month}-${day} ${hours}:${minutes}`;
  657. }
  658. }
  659. }
  660. </script>
  661. <style scoped>
  662. .pilot-plan-container {
  663. width: 100%;
  664. min-height: calc(100vh - 64px);
  665. padding: 15px;
  666. background-color: #f5f7fa;
  667. box-sizing: border-box;
  668. }
  669. .search-section {
  670. background-color: white;
  671. padding: 15px;
  672. margin-bottom: 15px;
  673. border-radius: 4px;
  674. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  675. box-sizing: border-box;
  676. }
  677. .action-section {
  678. margin-bottom: 15px;
  679. }
  680. .list-section {
  681. background-color: white;
  682. padding: 15px;
  683. margin-bottom: 15px;
  684. border-radius: 4px;
  685. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  686. box-sizing: border-box;
  687. }
  688. .pagination {
  689. margin-top: 15px;
  690. text-align: right;
  691. }
  692. h2 {
  693. color: #303133;
  694. margin-bottom: 15px;
  695. font-size: 18px;
  696. }
  697. h3 {
  698. color: #606266;
  699. margin-bottom: 12px;
  700. font-size: 15px;
  701. }
  702. .preview-dialog {
  703. --el-dialog-margin-top: 5vh;
  704. }
  705. .preview-header {
  706. display: flex;
  707. justify-content: space-between;
  708. align-items: center;
  709. margin-bottom: 12px;
  710. }
  711. .preview-count {
  712. font-weight: bold;
  713. color: #606266;
  714. font-size: 13px;
  715. }
  716. .preview-footer {
  717. display: flex;
  718. justify-content: space-between;
  719. padding-top: 12px;
  720. border-top: 1px solid #ebeef5;
  721. margin-top: 12px;
  722. }
  723. .table-container {
  724. width: 100%;
  725. overflow-x: auto;
  726. }
  727. /* 查询条件样式 */
  728. .demo-form {
  729. display: flex;
  730. flex-direction: column;
  731. gap: 12px;
  732. }
  733. .search-row {
  734. display: flex;
  735. flex-wrap: wrap;
  736. gap: 12px;
  737. align-items: center;
  738. }
  739. .search-actions {
  740. display: flex;
  741. gap: 8px;
  742. align-items: center;
  743. }
  744. /* 表格样式优化 */
  745. :deep(.el-table) {
  746. font-size: 12px;
  747. }
  748. :deep(.el-table th.el-table__cell) {
  749. background-color: #f5f7fa;
  750. color: #303133;
  751. font-weight: 600;
  752. }
  753. :deep(.el-table .el-table__cell) {
  754. padding: 6px 0 !important;
  755. }
  756. /* 内容截断样式 */
  757. :deep(.el-table .cell) {
  758. overflow: hidden;
  759. text-overflow: ellipsis;
  760. white-space: nowrap;
  761. }
  762. /* 表头排序箭头样式 */
  763. :deep(.el-table .el-table__header th.el-table__cell > .el-table__cell.sortable) {
  764. cursor: pointer;
  765. }
  766. :deep(.el-table .el-table__header th.el-table__cell > .el-table__cell.sortable:hover) {
  767. background-color: #e6e6e6;
  768. }
  769. </style>