bus.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. <template>
  2. <div class="content-box">
  3. <div class="left">
  4. <!-- <el-icon :size="23" class="camera"><VideoCameraFilled /></el-icon> -->
  5. <span class="cameratxt">车辆管理</span>
  6. </div>
  7. <div class="middle">
  8. <div class="filter">
  9. <div class="condition">
  10. <span>车牌 : </span>
  11. <el-input
  12. clearable
  13. v-model="searchInput.carnumber"
  14. class="w-50 m-2"
  15. placeholder="请输入车牌号"
  16. style="width: 150px"
  17. />
  18. </div>
  19. <div class="condition">
  20. <span>创建时间 : </span>
  21. <el-date-picker
  22. v-model="searchInput.createTime"
  23. type="date"
  24. format="YYYY-MM-DD"
  25. value-format="YYYY-MM-DD"
  26. :prefix-icon="Calendar"
  27. placeholder="请选择时间"
  28. />
  29. </div>
  30. <el-button
  31. style="margin-left: 20px"
  32. color="rgba(61, 81, 232, 1)"
  33. type="primary"
  34. class="search"
  35. @click="searchBtn"
  36. ><el-icon><Search /></el-icon> <span>查询</span></el-button
  37. >
  38. <el-button
  39. style="margin-left: 20px !important"
  40. color="rgba(61, 81, 232, 1)"
  41. type="primary"
  42. class="search"
  43. @click="searchRefresh"
  44. ><el-icon><Refresh /></el-icon><span>重置</span></el-button
  45. >
  46. </div>
  47. <!-- 按钮列表 -->
  48. <div class="gongneng">
  49. <el-button type="primary" color="rgba(61, 81, 232, 1)" @click="addlist"
  50. ><el-icon><CirclePlus /></el-icon><span>新增车辆</span></el-button
  51. >
  52. <el-button
  53. color="rgba(61, 81, 232, 1)"
  54. class="import"
  55. type="primary"
  56. @click="importExcel"
  57. ><img
  58. src="@/assets/import.png"
  59. style="width: 14px; height: 14px; margin-right: 4px"
  60. alt=""
  61. />
  62. <span>导出表单</span></el-button
  63. >
  64. </div>
  65. </div>
  66. <div class="footer">
  67. <el-table
  68. :row-class-name="tableRowClassName"
  69. :data="tableData.list"
  70. @selection-change="handleSelectionChange"
  71. style="width: 100%"
  72. :header-cell-style="{
  73. background: 'rgba(240, 243, 247, 1)',
  74. height: '50px',
  75. border: 0,
  76. }"
  77. >
  78. <!-- <el-table-column align="center" type="selection" width="80" /> -->
  79. <el-table-column
  80. width="150"
  81. align="center "
  82. prop="device_number"
  83. label="序列号"
  84. />
  85. <el-table-column align="center" prop="car_number" label="车牌" />
  86. <el-table-column
  87. align="center"
  88. prop="contain"
  89. label="容量"
  90. width="200"
  91. />
  92. <el-table-column align="center" prop="create_time" label="创建时间" />
  93. <el-table-column align="center" label="操作" width="220">
  94. <template #default="scope">
  95. <el-button link type="primary" @click="edit(scope.row)"
  96. ><div class="look">编辑</div></el-button
  97. >
  98. <el-button link type="primary" @click="del(scope.row)"
  99. ><div class="look">删除</div></el-button
  100. >
  101. </template>
  102. </el-table-column>
  103. </el-table>
  104. <!-- 添加车辆弹窗 -->
  105. <el-dialog
  106. class="addStaff"
  107. v-model="addDialogVisible"
  108. :close-on-click-modal="false"
  109. :close-on-press-escape="false"
  110. :title="dialongTitle"
  111. align-center
  112. width="609"
  113. :before-close="handleVideoClose"
  114. >
  115. <el-form
  116. ref="ruleFormRef"
  117. :model="ruleForm"
  118. :rules="rules"
  119. label-width="100px"
  120. class="demo-ruleForm"
  121. :size="formSize"
  122. label-position="left"
  123. status-icon
  124. >
  125. <el-form-item label="序列号 :" prop="serial">
  126. <el-input
  127. clearable
  128. v-model="ruleForm.serial"
  129. placeholder="请输入序列号"
  130. />
  131. </el-form-item>
  132. <el-form-item label="车牌 :" prop="buslicence">
  133. <el-input
  134. clearable
  135. v-model="ruleForm.buslicence"
  136. placeholder="请输入车牌"
  137. />
  138. </el-form-item>
  139. <el-form-item
  140. label="容量 :"
  141. prop="volume"
  142. style="
  143. padding-bottom: 40px;
  144. border-bottom: 1px solid rgba(230, 230, 230, 1);
  145. "
  146. >
  147. <el-input
  148. clearable
  149. v-model="ruleForm.volume"
  150. placeholder="请输入容量"
  151. />
  152. </el-form-item>
  153. <el-form-item class="options">
  154. <el-button class="congzhi" @click="cancelAdd(ruleFormRef)"
  155. >取消</el-button
  156. >
  157. <el-button
  158. color="rgba(61, 81, 232, 1)"
  159. class="queding"
  160. type="primary"
  161. @click="submitAdd(ruleFormRef)"
  162. >
  163. 确定
  164. </el-button>
  165. </el-form-item>
  166. </el-form>
  167. </el-dialog>
  168. </div>
  169. <!-- 分页组件 -->
  170. <el-pagination
  171. background
  172. :current-page="currentPage"
  173. :page-size="pageSize"
  174. layout="total, prev, pager, next, jumper, slot"
  175. :total="total"
  176. @update:current-page="handleCurrentChange"
  177. />
  178. </div>
  179. </template>
  180. <script setup>
  181. import { ref, reactive, nextTick, onBeforeMount, onUnmounted } from "vue";
  182. import { useRouter } from "vue-router";
  183. import { ElMessage, ElMessageBox } from "element-plus";
  184. import { Calendar } from "@element-plus/icons-vue";
  185. import vidiconsApi from "@/api/vidicons.js";
  186. import { dayjs } from "element-plus";
  187. import lodash from "lodash";
  188. import axios from "axios";
  189. import { useStore } from "vuex";
  190. const store = useStore();
  191. const api = ref("");
  192. const router = useRouter();
  193. // 表格数据
  194. const tableData = reactive({ list: [] });
  195. const activeIndex = ref(); // 默认跳转路由
  196. const dialongTitle = ref("新增车辆"); // 弹窗标题
  197. const searchInput = reactive({
  198. carnumber: "",
  199. createTime: "",
  200. }); // 搜索按钮数据
  201. 5;
  202. const currentPage = ref(1); // 当前页
  203. const pageSize = ref(10);
  204. const total = ref(); // 当前总数
  205. const selectData = reactive({ list: [] }); // 多选框选择的数据
  206. const addDialogVisible = ref(false); // 控制添加员工弹窗
  207. // 表单数据
  208. const formSize = ref("default");
  209. const ruleFormRef = ref();
  210. const ruleForm = reactive({
  211. serial: "",
  212. buslicence: "",
  213. volume: "",
  214. id: "",
  215. });
  216. // 表单验证
  217. const rules = reactive({
  218. // serial: [{ required: true, message: "序列号不能为空", trigger: "blur" }],
  219. buslicence: [
  220. { required: true, message: "请输入车牌号", trigger: "blur" },
  221. {
  222. pattern:
  223. /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$/,
  224. message: "请输入合法车牌号",
  225. trigger: "blur",
  226. },
  227. ],
  228. volume: [
  229. {
  230. required: true,
  231. message: "容量不能为空",
  232. trigger: "blur",
  233. },
  234. {
  235. pattern: /^(0|[1-9][0-9]*)$/,
  236. message: "请输入正确数字",
  237. trigger: "blur",
  238. },
  239. ],
  240. // desc: [{ required: true, message: "Please input activity form", trigger: "blur" }],
  241. });
  242. // 查看车辆管理列表
  243. const getList = async (flag) => {
  244. let data = new FormData();
  245. if (searchInput.createTime == null) {
  246. searchInput.createTime = "";
  247. }
  248. data.set("car_number", searchInput.carnumber);
  249. data.set("create_time", searchInput.createTime); //前面的key记得对应!
  250. data.set("page", currentPage.value);
  251. data.set("rows", pageSize.value); //前面的key记得对应!
  252. // let res = await adminApi.adminLogin(data);
  253. let res = await axios({
  254. method: "post",
  255. url: api.value + "/carBook/cinfolist.action",
  256. headers: {
  257. token: sessionStorage.getItem("token"),
  258. },
  259. data: data,
  260. });
  261. console.log(res);
  262. if (res.status == 200) {
  263. tableData.list = res.data.rows;
  264. if (flag == 1) {
  265. sessionStorage.setItem("busSelect", JSON.stringify(tableData.list));
  266. }
  267. // currentPage.value = res.data.currentPage;
  268. total.value = res.data.total;
  269. } else {
  270. tableData.list = res.data.rows;
  271. currentPage.value = 1;
  272. total.value = res.data.total;
  273. ElMessage({
  274. type: "error",
  275. showClose: true,
  276. message: res.data.message,
  277. center: true,
  278. });
  279. if (res.data.message == "token错误") {
  280. router.push({
  281. path: `/login`,
  282. });
  283. }
  284. }
  285. };
  286. // 搜索功能
  287. const searchBtn = lodash.debounce(async () => {
  288. getList("查询成功");
  289. }, 300);
  290. // 重置搜索
  291. const searchRefresh = lodash.debounce(async () => {
  292. searchInput.carnumber = "";
  293. searchInput.createTime = "";
  294. currentPage.value = 1;
  295. getList();
  296. }, 300);
  297. //新增车辆
  298. const addlist = () => {
  299. dialongTitle.value = "新增车辆";
  300. addDialogVisible.value = true;
  301. ruleForm.serial = "";
  302. ruleForm.buslicence = "";
  303. ruleForm.volume = "";
  304. };
  305. //编辑按钮
  306. const edit = (row) => {
  307. dialongTitle.value = "编辑车辆";
  308. addDialogVisible.value = true;
  309. ruleForm.serial = row.device_number;
  310. ruleForm.buslicence = row.car_number;
  311. ruleForm.volume = row.contain;
  312. ruleForm.id = row.id;
  313. };
  314. // 取消新增车辆
  315. const cancelAdd = () => {
  316. addDialogVisible.value = false;
  317. ruleFormRef.value.resetFields();
  318. };
  319. // 确认新增车辆
  320. const submitAdd = async (formEl) => {
  321. if (!formEl) return;
  322. await formEl.validate(async (valid, fields) => {
  323. if (valid) {
  324. if (dialongTitle.value == "新增车辆") {
  325. let data = {
  326. device_number: ruleForm.serial,
  327. car_number: ruleForm.buslicence,
  328. contain: ruleForm.volume,
  329. };
  330. // let res = await admin.adminAdd(data);
  331. let res = await axios({
  332. method: "post",
  333. url: api.value + "/carBook/cinfoinsert.action",
  334. headers: {
  335. "Content-Type": "application/json;charset=utf-8",
  336. token: sessionStorage.getItem("token"),
  337. },
  338. data: data,
  339. });
  340. // console.log(res, "添加账号");
  341. if (res.data.code == 200) {
  342. getList();
  343. store.dispatch("busNum");
  344. ElMessage({
  345. type: "success",
  346. showClose: true,
  347. message: res.data.message,
  348. center: true,
  349. });
  350. addDialogVisible.value = false;
  351. ruleFormRef.value.resetFields();
  352. } else {
  353. ElMessage({
  354. type: "error",
  355. showClose: true,
  356. message: res.data.message,
  357. center: true,
  358. });
  359. }
  360. } else {
  361. let data = {
  362. device_number: ruleForm.serial,
  363. car_number: ruleForm.buslicence,
  364. contain: ruleForm.volume,
  365. id: ruleForm.id,
  366. };
  367. // let res = await admin.adminAdd(data);
  368. let res = await axios({
  369. method: "post",
  370. url: api.value + "/carBook/cinfoupdate.action",
  371. headers: {
  372. "Content-Type": "application/json;charset=utf-8",
  373. token: sessionStorage.getItem("token"),
  374. },
  375. data: data,
  376. });
  377. // console.log(res, "修改账号");
  378. if (res.data.code == 200) {
  379. getList();
  380. store.dispatch("busNum");
  381. ElMessage({
  382. type: "success",
  383. showClose: true,
  384. message: res.data.message,
  385. center: true,
  386. });
  387. addDialogVisible.value = false;
  388. ruleFormRef.value.resetFields();
  389. } else {
  390. ElMessage({
  391. type: "error",
  392. showClose: true,
  393. message: res.data.message,
  394. center: true,
  395. });
  396. }
  397. }
  398. } else {
  399. console.log("error submit!", fields);
  400. }
  401. });
  402. };
  403. //删除按钮
  404. const del = (row) => {
  405. ElMessageBox.confirm(`是否删除 ${row.car_number} 车?`, "提示", {
  406. confirmButtonText: "确认",
  407. cancelButtonText: "取消",
  408. type: "warning",
  409. })
  410. .then(async () => {
  411. let data = new FormData();
  412. data.set("id", row.id);
  413. // let res = await adminApi.adminLogin(data);
  414. let res = await axios({
  415. method: "post",
  416. url: api.value + "/carBook/cinfodel.action",
  417. headers: {
  418. token: sessionStorage.getItem("token"),
  419. },
  420. data: data,
  421. });
  422. if (res.data.code == 200) {
  423. if (tableData.list.length == 1 && currentPage.value != 1) {
  424. currentPage.value = currentPage.value - 1;
  425. }
  426. getList();
  427. store.dispatch("busNum");
  428. ElMessage({
  429. type: "success",
  430. showClose: true,
  431. message: res.data.message,
  432. center: true,
  433. });
  434. } else {
  435. ElMessage({
  436. type: "error",
  437. showClose: true,
  438. message: res.data.message,
  439. center: true,
  440. });
  441. }
  442. console.log(res);
  443. })
  444. .catch(() => {
  445. ElMessage({
  446. type: "info",
  447. message: "已取消删除",
  448. });
  449. });
  450. };
  451. // 多选框功能
  452. const handleSelectionChange = (val) => {
  453. console.log(val);
  454. selectData.list = val;
  455. };
  456. //导出功能
  457. const importExcel = async () => {
  458. if (searchInput.createTime == null) {
  459. searchInput.createTime = "";
  460. }
  461. let data = new FormData();
  462. data.set("car_number", searchInput.carnumber);
  463. data.set("create_time", searchInput.createTime);
  464. let res = await axios({
  465. method: "post",
  466. url: api.value + "/carBook/cinfotoExcel.action",
  467. headers: {
  468. token: sessionStorage.getItem("token"),
  469. },
  470. data: data,
  471. });
  472. // console.log(res, "导出账号");
  473. if (res.data.code == 200) {
  474. // const elt = document.createElement("a");
  475. // elt.setAttribute(
  476. // "href",
  477. // "https://chtech.ncjti.edu.cn/carstop" + res.data.downurl
  478. // );
  479. // elt.setAttribute("download", "file.png");
  480. // elt.style.display = "none";
  481. // document.body.appendChild(elt);
  482. // elt.click();
  483. var downloadPath = "https://chtech.ncjti.edu.cn/carstop" + res.data.downurl;
  484. console.log("获得地址数据:", downloadPath);
  485. var downloadLink = document.createElement("a");
  486. downloadLink.style.display = "none"; // 使其隐藏
  487. downloadLink.href = downloadPath;
  488. downloadLink.download = "";
  489. downloadLink.click();
  490. document.body.appendChild(downloadLink);
  491. document.body.removeChild(downloadLink);
  492. ElMessage({
  493. type: "success",
  494. showClose: true,
  495. message: res.data.message,
  496. center: true,
  497. });
  498. } else {
  499. ElMessage({
  500. type: "error",
  501. showClose: true,
  502. message: res.data.message,
  503. center: true,
  504. });
  505. }
  506. };
  507. // 表格斑马纹颜色修改
  508. const tableRowClassName = ({ row, rowIndex }) => {
  509. if (rowIndex % 2 === 0) {
  510. return "even";
  511. } else if (rowIndex % 2 !== 0) {
  512. return "odd";
  513. }
  514. return "";
  515. };
  516. // 分页
  517. const handleCurrentChange = (value) => {
  518. // console.log(value);
  519. currentPage.value = value;
  520. getList();
  521. };
  522. onBeforeMount(() => {
  523. api.value = store.state.user.api;
  524. getList();
  525. });
  526. onUnmounted(() => {
  527. // document.removeEventListener("keyup", Enters);
  528. });
  529. </script>
  530. <style scoped lang="scss">
  531. .content-box {
  532. width: 97.5%;
  533. height: 89%;
  534. margin: 20px auto;
  535. background-color: #fff;
  536. color: #fff;
  537. display: flex;
  538. flex-direction: column;
  539. .left {
  540. // width: calc(100wh - 40px);
  541. display: flex;
  542. align-items: center;
  543. height: 60px;
  544. margin: 0 30px;
  545. border-bottom: 1px solid #ccc;
  546. color: #000;
  547. font-size: 18px;
  548. font-weight: 600;
  549. .camera {
  550. margin-right: 15px;
  551. color: #4392f7;
  552. }
  553. }
  554. .middle {
  555. width: 96%;
  556. margin: 0 auto;
  557. color: #000;
  558. // border-bottom: 1px solid rgb(231, 231, 231);
  559. .filter {
  560. display: flex;
  561. flex-wrap: wrap;
  562. align-items: center;
  563. margin: 10px 0 0 0;
  564. .search {
  565. margin-left: 0 !important;
  566. }
  567. .condition {
  568. display: flex;
  569. align-items: center;
  570. margin: 10px 30px 10px 0;
  571. span {
  572. margin: 0 10px 0 0;
  573. }
  574. }
  575. }
  576. .gongneng {
  577. margin: 10px 0;
  578. }
  579. :deep(.cont) {
  580. width: 60%;
  581. margin: 20px auto;
  582. }
  583. :deep(.download) {
  584. display: flex;
  585. align-items: center;
  586. margin: 10px;
  587. }
  588. :deep(.download span) {
  589. font-size: 16px;
  590. margin-left: 20px;
  591. }
  592. :deep(.cont .el-button) {
  593. margin-left: 60px;
  594. margin-bottom: 30px;
  595. }
  596. :deep(.cont .accomplish) {
  597. width: 100%;
  598. display: flex;
  599. justify-content: center;
  600. }
  601. :deep(.cont .accomplish .el-button) {
  602. width: 50%;
  603. margin: 0;
  604. }
  605. }
  606. .footer {
  607. width: 96%;
  608. height: 550px;
  609. margin: 10px auto 30px;
  610. .el-table--fit {
  611. height: 100%;
  612. :deep(.el-table__header-wrapper) {
  613. background-color: #000;
  614. }
  615. :deep(.el-table__row) {
  616. height: 50px;
  617. }
  618. :deep(.el-table__row td) {
  619. padding: 0;
  620. border: 0;
  621. }
  622. .el-button--primary {
  623. margin-left: 5px;
  624. }
  625. :deep(.el-table__body .even) {
  626. background-color: #fff;
  627. }
  628. :deep(.el-table__body .odd) {
  629. background-color: rgba(240, 243, 247, 1);
  630. }
  631. :deep(.look) {
  632. padding: 5px 10px;
  633. border-radius: 45px;
  634. border: 0.74px solid rgba(30, 125, 251, 1);
  635. }
  636. }
  637. // 添加员工弹窗样式
  638. :deep(.addStaff) {
  639. // height: 420px;
  640. border-radius: 11px;
  641. .el-dialog__header {
  642. border-radius: 11px 11px 0 0;
  643. background: rgba(237, 241, 245, 1);
  644. font-weight: 600;
  645. margin: 0;
  646. .el-dialog__headerbtn {
  647. outline: none;
  648. }
  649. }
  650. .el-dialog__body {
  651. padding: 30px 20px 10px 20px;
  652. .el-input {
  653. width: 200px;
  654. }
  655. .options {
  656. margin-left: 320px;
  657. }
  658. }
  659. }
  660. }
  661. .el-pagination {
  662. // width: 1600px;
  663. width: 96%;
  664. margin: 0 auto 18px;
  665. justify-content: flex-end;
  666. :deep(.el-pagination__total) {
  667. color: #000;
  668. }
  669. :deep(.el-pagination__goto) {
  670. color: #000;
  671. }
  672. :deep(.el-pagination__classifier) {
  673. color: #000;
  674. }
  675. :deep(.el-input__wrapper) {
  676. border: 1px solid rgba(0, 0, 0, 1);
  677. border-radius: 5px;
  678. box-shadow: none;
  679. }
  680. :deep(.el-pager li) {
  681. margin: 0 5px;
  682. border: 1px solid rgba(0, 0, 0, 1);
  683. border-radius: 5px;
  684. background-color: transparent;
  685. }
  686. :deep(.el-pager li.is-active) {
  687. background-color: rgba(30, 125, 251, 1);
  688. }
  689. :deep(.btn-prev) {
  690. margin-right: 5px;
  691. border: 1px solid rgba(0, 0, 0, 1);
  692. border-radius: 5px;
  693. background-color: transparent;
  694. }
  695. :deep(.btn-next) {
  696. margin-left: 5px;
  697. border: 1px solid rgba(0, 0, 0, 1);
  698. border-radius: 5px;
  699. background-color: transparent;
  700. }
  701. }
  702. }
  703. .el-input {
  704. width: 192px;
  705. }
  706. </style>