index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. <template>
  2. <div class="data-query">
  3. <div class="data-query-header">
  4. <div class="manageTitle">{{ title }}</div>
  5. <el-form
  6. ref="formRef"
  7. :model="formData"
  8. class="data-query-form"
  9. :rules="rules"
  10. @submit.native.prevent
  11. >
  12. <div v-if="name === 'freight'" class="form-left">
  13. <el-form-item prop="startDate">
  14. <el-date-picker
  15. v-model="formData.startDate"
  16. format="YYYY-MM-DD"
  17. value-format="YYYY-MM-DD"
  18. size="default"
  19. type="date"
  20. placeholder="开始日期"
  21. :prefix-icon="datePreTitle('开始')"
  22. :clearable="false"
  23. class="pre-text"
  24. />
  25. </el-form-item>
  26. <el-form-item prop="endDate">
  27. <el-date-picker
  28. v-model="formData.endDate"
  29. format="YYYY-MM-DD"
  30. value-format="YYYY-MM-DD"
  31. :disabled-date="disabledEndDate"
  32. size="default"
  33. type="date"
  34. placeholder="结束日期"
  35. :prefix-icon="datePreTitle('结束')"
  36. :clearable="false"
  37. class="pre-text"
  38. />
  39. </el-form-item>
  40. </div>
  41. <div v-if="name === 'flight'" class="form-left">
  42. <el-form-item prop="flightDate" style="width: 148px">
  43. <el-date-picker
  44. v-model="formData.flightDate"
  45. format="YYYY-MM-DD"
  46. value-format="YYYY-MM-DD"
  47. size="default"
  48. type="date"
  49. placeholder="请选择航班日期"
  50. :clearable="false"
  51. />
  52. </el-form-item>
  53. <el-form-item prop="inOrOut" style="width: 108px">
  54. <el-select v-model="formData.inOrOut" size="default">
  55. <el-option value="in" label="进港航班" />
  56. <el-option value="out" label="出港航班" />
  57. </el-select>
  58. </el-form-item>
  59. <el-form-item prop="flightType" style="width: 108px">
  60. <el-select
  61. v-model="formData.flightType"
  62. size="default"
  63. placeholder="航班类型"
  64. clearable
  65. >
  66. <el-option :value="0" label="货机" />
  67. <el-option :value="1" label="客机" />
  68. <el-option :value="2" label="其他" />
  69. </el-select>
  70. </el-form-item>
  71. <el-form-item prop="sAirport" style="width: 108px">
  72. <el-select
  73. v-model="formData.sAirport"
  74. :disabled="formData.inOrOut === 'out'"
  75. size="default"
  76. placeholder="始发站"
  77. clearable
  78. >
  79. <el-option
  80. v-for="{ value, label } in airportOptions"
  81. :key="value"
  82. :value="value"
  83. :label="label"
  84. />
  85. </el-select>
  86. </el-form-item>
  87. <el-form-item prop="eAirport" style="width: 108px">
  88. <el-select
  89. v-model="formData.eAirport"
  90. :disabled="formData.inOrOut === 'in'"
  91. size="default"
  92. placeholder="目的站"
  93. clearable
  94. >
  95. <el-option
  96. v-for="{ value, label } in airportOptions"
  97. :key="value"
  98. :value="value"
  99. :label="label"
  100. />
  101. </el-select>
  102. </el-form-item>
  103. <el-form-item prop="planeType" style="width: 108px">
  104. <el-select
  105. v-model="formData.planeType"
  106. size="default"
  107. placeholder="属性"
  108. clearable
  109. >
  110. <el-option value="DOM" label="国内" />
  111. <el-option value="INT" label="国际" />
  112. </el-select>
  113. </el-form-item>
  114. <el-form-item prop="sFlightDate" style="width: 148px">
  115. <el-date-picker
  116. v-model="formData.sFlightDate"
  117. format="YYYY-MM-DD"
  118. value-format="YYYY-MM-DD"
  119. size="default"
  120. type="date"
  121. placeholder="请选择实飞时间"
  122. />
  123. </el-form-item>
  124. </div>
  125. <div class="form-right">
  126. <el-form-item
  127. v-if="name === 'flight'"
  128. prop="company"
  129. style="width: 180px"
  130. >
  131. <el-input
  132. v-model.trim="formData.company"
  133. size="default"
  134. placeholder="请输入航司进行搜索"
  135. :prefix-icon="Search"
  136. clearable
  137. @keyup.enter.prevent="dataQuery"
  138. />
  139. </el-form-item>
  140. <el-form-item
  141. prop="keyWords"
  142. :style="name === 'flight' ? { width: '190px' } : {}"
  143. >
  144. <el-input
  145. v-model.trim="formData.keyWords"
  146. size="default"
  147. :placeholder="keyWordsPlaceHolder"
  148. :prefix-icon="Search"
  149. clearable
  150. @keyup.enter.prevent="dataQuery"
  151. />
  152. </el-form-item>
  153. </div>
  154. </el-form>
  155. <el-button size="default" color="#ac014d" @click="dataQuery"
  156. >搜索</el-button
  157. >
  158. <el-button size="default" plain @click="resetForm">重置</el-button>
  159. <ColumnSet
  160. :table-columns="tableColumns"
  161. @checked-submit="columnChecked"
  162. />
  163. </div>
  164. <div
  165. v-loading="loading"
  166. element-loading-text="拼命加载中"
  167. element-loading-background="rgba(0, 0, 0, 0.8)"
  168. class="data-query-table"
  169. >
  170. <SimpleTable
  171. :header-cell-style="{ background: '#F9FAFC' }"
  172. ref="tableRef"
  173. :data="
  174. tableData.slice((currentPage - 1) * pagesize, currentPage * pagesize)
  175. "
  176. :columns="tableColumns"
  177. :cell-class-name="cellClass"
  178. :column-props="{ formatter }"
  179. height="calc(100vh - 220px)"
  180. @cell-click="cellClickHandler"
  181. />
  182. <el-pagination
  183. background
  184. v-if="tableData.length > 0"
  185. @size-change="handleSizeChange"
  186. @current-change="handleCurrentChange"
  187. layout="total, prev, pager, next, jumper"
  188. :total="tableData.length"
  189. :page-size="pagesize"
  190. style="position: absolute; right: 19px; bottom: 10px"
  191. >
  192. </el-pagination>
  193. </div>
  194. </div>
  195. </template>
  196. <script setup lang="tsx">
  197. import { Search } from "@element-plus/icons-vue";
  198. import ColumnSet from "@/components/ColumnSet/index.vue";
  199. import SimpleTable from "@/components/SimpleTable/index.vue";
  200. import { ElMessage, FormInstance } from "element-plus";
  201. import { parseTime } from "@/utils/validate";
  202. import { useTable } from "./useTable";
  203. import { useTableColumnSet } from "@/hooks/useTableColumnSet";
  204. import { CommonTableFormatter } from "~/common";
  205. import { Query } from "@/api/webApi";
  206. const props = defineProps({
  207. name: {
  208. type: String,
  209. required: true,
  210. },
  211. title: {
  212. type: String,
  213. required: true,
  214. },
  215. });
  216. const currentPage = ref<number>(1);
  217. const pagesize = ref<number>(11);
  218. const today = parseTime(new Date(), "{y}-{m}-{d}") as string;
  219. const formData = reactive({
  220. flightDate: today,
  221. inOrOut: "out",
  222. flightType: "",
  223. sAirport: "",
  224. eAirport: "",
  225. planeType: "",
  226. sFlightDate: "",
  227. company: "",
  228. startDate: today,
  229. endDate: today,
  230. keyWords: "",
  231. });
  232. watchEffect(() => {
  233. if (formData.inOrOut === "in") {
  234. formData.sAirport = "";
  235. formData.eAirport = "SZX";
  236. } else {
  237. formData.sAirport = "SZX";
  238. formData.eAirport = "";
  239. }
  240. if (!formData.startDate || !formData.endDate) {
  241. return;
  242. }
  243. const start = new Date(formData.startDate).getTime();
  244. const end = new Date(formData.endDate).getTime();
  245. if (start > end) {
  246. ElMessage.warning("开始时间不能晚于结束时间");
  247. formData.endDate = "";
  248. }
  249. if (start <= end - 2 * 24 * 60 * 60 * 1000) {
  250. ElMessage.warning("间隔不能超过2天");
  251. formData.endDate = "";
  252. }
  253. });
  254. const disabledEndDate = (endDate: Date) => {
  255. const start = new Date(formData.startDate + " 00:00:00").getTime();
  256. const end = endDate.getTime();
  257. return start > end || start <= end - 2 * 24 * 60 * 60 * 1000;
  258. };
  259. const datePreTitle = (title: string) => {
  260. return <div class="date-pre-title">{title}:</div>;
  261. };
  262. const searchTitleMap = {
  263. flight: "航班号",
  264. waybill: "运单号",
  265. freight: "货物编码",
  266. };
  267. const keyWordsPlaceHolder = computed(
  268. () => `请输入${searchTitleMap[props.name] ?? "内容"}进行搜索`
  269. );
  270. const airportOptions = ref<{ value: string; label: string }[]>([]);
  271. const getAirports = async () => {
  272. try {
  273. const {
  274. code,
  275. returnData: { listValues },
  276. message,
  277. } = await Query<{ [x: string]: string }>({
  278. id: DATACONTENT_ID.airportCode,
  279. dataContent: [],
  280. });
  281. if (Number(code) !== 0) {
  282. throw new Error(message || "失败");
  283. }
  284. airportOptions.value = listValues.map(({ code3 }) => ({
  285. value: code3,
  286. label: code3,
  287. }));
  288. } catch (error) {
  289. console.error(error);
  290. }
  291. };
  292. onMounted(() => {
  293. if (props.name === "flight") {
  294. getAirports();
  295. }
  296. });
  297. const keyWordsValidator = (rule: any, value: any, callback: any) => {
  298. const searchTitle = searchTitleMap[props.name] ?? "关键词";
  299. if (!value) {
  300. if (["flight"].includes(props.name)) {
  301. return callback();
  302. } else {
  303. return callback(new Error(`请输入${searchTitle}`));
  304. }
  305. }
  306. const regsMap: { [x: string]: RegExp[] } = {
  307. // flight: [/^[A-Za-z0-9][A-Za-z][0-9]{3,4}$/, /^[0-9]{3,4}$/],
  308. flight: [/^[0-9]{1,4}$/],
  309. waybill: [/^[0-9]{8}$/, /^[0-9]{11}$/, /^[0-9]{3}\-[0-9]{8}$/],
  310. freight: [/^[0-9]{5}$/, /^[0-9]{3}\-[0-9]{8}\-[0-9]{5}$/],
  311. };
  312. const regs = regsMap[props.name] ?? [];
  313. const notMatched = regs.length && regs.every((reg) => !reg.test(value));
  314. if (notMatched) {
  315. return callback(new Error(`请输入正确的${searchTitle}`));
  316. }
  317. return callback();
  318. };
  319. const rules = {
  320. startDate: [{ required: true, message: "请选择开始日期", trigger: "blur" }],
  321. endDate: [{ required: true, message: "请选择结束日期", trigger: "blur" }],
  322. keyWords: [{ validator: keyWordsValidator, trigger: "blur" }],
  323. flightDate: [{ required: true, message: "请选择航班日期", trigger: "blur" }],
  324. company: [
  325. {
  326. pattern: /^[A-Za-z0-9][A-Za-z]$/,
  327. message: "请输入正确的航司",
  328. trigger: "blur",
  329. },
  330. ],
  331. };
  332. const route = useRoute();
  333. const formRef = ref<FormInstance | null>();
  334. const { flightDate, stockCode } = route.query;
  335. const dataQuery = () => {
  336. formRef.value?.validate((valid) => {
  337. if (valid) {
  338. if (stockCode) {
  339. formData.keyWords = stockCode;
  340. formData.startDate = flightDate;
  341. formData.endDate = flightDate;
  342. }
  343. tableInit();
  344. getTableData();
  345. // load();
  346. }
  347. });
  348. };
  349. const resetForm = () => {
  350. formRef.value?.resetFields();
  351. };
  352. const loading = ref(false);
  353. const page = ref(1);
  354. const noMore = ref(false);
  355. const { tableColumns, tableData, getTableData } = useTable(
  356. props.name,
  357. formData,
  358. page,
  359. noMore,
  360. loading
  361. );
  362. // const load = () => {
  363. // if (loading.value || noMore.value) {
  364. // return
  365. // }
  366. // page.value++
  367. // getTableData()
  368. // }
  369. const handleSizeChange = (val) => {
  370. pagesize.value = val;
  371. };
  372. const handleCurrentChange = (val) => {
  373. currentPage.value = val;
  374. };
  375. const tableInit = () => {
  376. page.value = 0;
  377. noMore.value = false;
  378. tableData.value = [];
  379. };
  380. const { columnChecked } = useTableColumnSet(tableColumns);
  381. const flightStateMap = {
  382. CAN: "取消",
  383. DLY: "延误",
  384. };
  385. const flightTypeMap = ["货机", "客机", "其他"];
  386. const formatter: CommonTableFormatter = (row, column, cellValue, index) => {
  387. const value = String(cellValue ?? "").trim();
  388. if (column.property.includes("Time")) {
  389. return value.replace(/[T|\s]+/, "\n");
  390. }
  391. if (column.property === "DIType" && value) {
  392. return value === "DOM" ? "国内" : "国际";
  393. }
  394. if (column.property === "flightState") {
  395. return value ? flightStateMap[value] ?? "正常" : "正常";
  396. }
  397. if (column.property === "flightType") {
  398. return cellValue
  399. ? flightTypeMap[cellValue] ?? "其他"
  400. : "其他";
  401. }
  402. return value;
  403. };
  404. const cellClass = ({ row, column, rowIndex, columnIndex }) => {
  405. const classes: string[] = [];
  406. switch (props.name) {
  407. case "flight":
  408. if (["flightNO"].includes(column.property) && row[column.property]) {
  409. classes.push("cell-click");
  410. }
  411. break;
  412. case "waybill":
  413. if (["stockCode"].includes(column.property) && row[column.property]) {
  414. classes.push("cell-click");
  415. }
  416. break;
  417. case "freight":
  418. break;
  419. default:
  420. break;
  421. }
  422. return classes.join(" ");
  423. };
  424. const router = useRouter();
  425. const cellClickHandler = (row, column, cell, event) => {
  426. switch (props.name) {
  427. case "flight": {
  428. switch (column.property) {
  429. case "flightNO": {
  430. if (
  431. !row.flightAllNO ||
  432. !row.flightDate ||
  433. !["INT", "DOM"].includes(row.DIType) ||
  434. typeof row.FFID !== "string" ||
  435. !["A", "D"].includes(row.FFID.at(-1))
  436. ) {
  437. ElMessage.error("航班信息缺失!");
  438. return;
  439. }
  440. const viewName = `${row.DIType === "DOM" ? "" : "International"}${
  441. row.FFID.at(-1) === "D" ? "Departure" : "Arrival"
  442. }Flight`;
  443. router.push({
  444. path: `/dataQuery/flightQuery/${viewName}`,
  445. query: {
  446. flightNO: row.flightAllNO,
  447. flightDate: row.flightDate,
  448. },
  449. });
  450. break;
  451. }
  452. default:
  453. break;
  454. }
  455. break;
  456. }
  457. case "waybill": {
  458. switch (column.property) {
  459. case "stockCode": {
  460. if (
  461. !row.stockCode ||
  462. !row.flightDate ||
  463. !["INT", "DOM"].includes(row.DIType) ||
  464. typeof row.FFID !== "string" ||
  465. !["A", "D"].includes(row.FFID.at(-1))
  466. ) {
  467. ElMessage.error("运单信息缺失!");
  468. return;
  469. }
  470. const viewName = `${row.DIType === "DOM" ? "" : "International"}${
  471. row.FFID.at(-1) === "D" ? "Departure" : "Arrival"
  472. }Waybill`;
  473. router.push({
  474. path: `/dataQuery/waybillQuery/${viewName}`,
  475. query: {
  476. waybillNO: row.stockCode,
  477. flightDate: row.flightDate,
  478. },
  479. });
  480. break;
  481. }
  482. }
  483. break;
  484. }
  485. case "freight":
  486. break;
  487. default:
  488. break;
  489. }
  490. };
  491. </script>
  492. <style lang="scss" scoped>
  493. :deep(.el-pagination.is-background .el-pager li:not(.is-disabled).is-active) {
  494. background-color: #ac014d !important; //修改默认的背景色
  495. }
  496. .data-query {
  497. width: 100%;
  498. height: 100%;
  499. display: flex;
  500. flex-direction: column;
  501. &-header {
  502. width: 100%;
  503. height: 32px;
  504. margin: 12px 0;
  505. display: flex;
  506. }
  507. &-form :deep {
  508. margin-right: 12px;
  509. flex: 1;
  510. display: flex;
  511. justify-content: flex-end;
  512. .form-left {
  513. flex: 1;
  514. display: flex;
  515. .el-form-item {
  516. width: 168px;
  517. margin-right: 8px;
  518. .el-date-editor.pre-text {
  519. .el-input__prefix {
  520. flex-basis: 42px;
  521. padding-left: 15px;
  522. .date-pre-title {
  523. font-style: normal;
  524. font-size: 14px;
  525. font-family: Microsoft YaHei;
  526. color: #303133;
  527. }
  528. }
  529. }
  530. }
  531. }
  532. .form-right {
  533. display: flex;
  534. justify-content: flex-end;
  535. .el-form-item {
  536. width: 280px;
  537. &:not(:last-of-type) {
  538. margin-right: 10px;
  539. }
  540. .el-select,
  541. .el-date-editor {
  542. width: 100%;
  543. }
  544. }
  545. }
  546. .el-form-item {
  547. margin: 0;
  548. .el-input__inner {
  549. font-size: 14px;
  550. font-family: DIN, Microsoft YaHei;
  551. color: #303133;
  552. }
  553. }
  554. }
  555. &-table {
  556. height: 0;
  557. flex: 1;
  558. }
  559. }
  560. </style>