| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- <template>
- <div class="full-container-p24">
- <div style="display: flex; justify-content: space-between">
- <div style="display: flex">
- <el-input
- placeholder="请输入港口名称"
- prefix-icon="el-icon-search"
- v-model="term"
- clearable
- style="width: 330px"
- ></el-input>
- <div class="seach-btn" @click="getPortsList">查询</div>
- </div>
- <div class="cargo-owner-add" @click="dialogFormVisible = true">
- 添加港口
- </div>
- <el-dialog title="添加港口" v-model="dialogFormVisible">
- <template v-slot:default>
- <el-form
- :model="ruleForm"
- :rules="rules"
- ref="form"
- label-width="110px"
- label-position="left"
- >
- <el-form-item prop="portName" label="港口名称">
- <el-input
- style="width: 280px"
- v-model="ruleForm.portName"
- ></el-input>
- </el-form-item>
- <el-form-item prop="longitude" label="经度">
- <el-input
- style="width: 280px"
- v-model="ruleForm.longitude"
- ></el-input>
- </el-form-item>
- <el-form-item prop="latitude" label="纬度">
- <el-input
- style="width: 280px"
- v-model="ruleForm.latitude"
- ></el-input>
- </el-form-item>
- </el-form>
- </template>
- <template v-slot:footer>
- <div class="dialog-footer">
- <el-button @click="resetForm">取 消</el-button>
- <el-button type="primary" @click="addPort(ruleForm)">
- 确 定
- </el-button>
- </div>
- </template>
- </el-dialog>
- </div>
- <div style="margin-top: 24px">
- <el-table :data="tableData" stripe style="width: 100%">
- <el-table-column
- type="index"
- label="序号"
- min-width="80"
- align="center"
- ></el-table-column>
- <el-table-column
- prop="portName"
- label="港口名称"
- min-width="120"
- align="center"
- ></el-table-column>
- <el-table-column
- prop="longitude"
- label="经纬度"
- min-width="120"
- align="center"
- >
- <template v-slot="scope">
- {{ scope.row.longitude }}, {{ scope.row.latitude }}
- </template>
- </el-table-column>
- <el-table-column
- prop="createTime"
- label="添加时间"
- min-width="200"
- align="center"
- >
- <template v-slot="scope">
- {{ subTimeStr(scope.row.createTime) }}
- </template>
- </el-table-column>
- <el-table-column label="启用/禁用" min-width="80" align="center">
- <template v-slot="scope">
- <el-switch
- v-model="scope.row.status"
- active-color="#13ce66"
- :active-value="0"
- :inactive-value="1"
- inactive-color="#ff4949"
- @change="changeSwitch($event, scope.row.id)"
- />
- </template>
- </el-table-column>
- </el-table>
- <div style="width: 100%; text-align: right; margin-top: 43px">
- <el-pagination
- background
- layout="prev, pager, next"
- :total="total"
- @current-change="pageChange"
- ></el-pagination>
- </div>
- </div>
- </div>
- </template>
- <script setup>
- import { ref, h, reactive, toRefs, onMounted } from "vue";
- import { ElNotification, ElMessageBox, ElMessage } from "element-plus";
- import store from "../../store";
- import router from "../../router";
- import md5 from "md5";
- import api from "../../apis/fetch";
- import { subTimeStr } from "../../utils/utils";
- let currentPage = ref(1);
- let term = ref("");
- let tableData = ref([]);
- let total = ref(0);
- let dialogFormVisible = ref(false);
- let form = ref(null);
- const ruleForm = ref({
- portName: "",
- longitude: "",
- latitude: "",
- });
- const rules = ref({
- portName: [{ required: true, message: "请填写港口名称", trigger: "blur" }],
- longitude: [{ required: true, message: "请填写港口经度", trigger: "blur" }],
- latitude: [{ required: true, message: "请填写港口纬度", trigger: "blur" }],
- });
- async function getPortsList() {
- tableData.value = [];
- let res = await api.getPortsList({
- currentPage: currentPage.value,
- size: 10,
- term: term.value,
- });
- term.value = "";
- if (res.data.status == 0) {
- tableData.value = res.data.result;
- total.value = res.data.total;
- }
- }
- function resetForm() {
- dialogFormVisible.value = false;
- form.value.resetFields();
- }
- async function addPort() {
- form.value.validate(async (valid) => {
- if (valid) {
- let { portName, longitude, latitude } = ruleForm.value;
- let res = await api.addPort({
- portName,
- longitude,
- latitude,
- });
- console.log(res);
- if (res.data.status == 0) {
- ElNotification.success({
- title: "添加成功",
- duration: 2000,
- message: `${portName}:${res.data.msg}`,
- type: "success",
- });
- resetForm();
- getPortsList();
- } else {
- ElNotification.error({
- title: "失败",
- duration: 3000,
- message: res.data.msg,
- });
- }
- } else {
- return false;
- }
- });
- }
- async function changeSwitch(status, portId) {
- let res = await api.updatePortStatus({
- status,
- portId,
- });
- if (res.data.status == 0) {
- ElNotification.success({
- title: "成功",
- duration: 2000,
- message: res.data.msg,
- });
- }
- }
- async function cargoOwnerCompanyDetail(id) {
- router.push({
- path: "/cargoOwnerManage/cargoOwnerCompanyDetail",
- query: {
- id,
- },
- });
- }
- function pageChange(e) {
- currentPage.value = e;
- getPortsList();
- }
- onMounted(() => {
- getPortsList();
- });
- </script>
- <style scoped>
- .seach-btn {
- display: inline-block;
- width: 60px;
- height: 38px;
- background: #0094fe;
- border-radius: 2px;
- font-size: 14px;
- font-family: PingFangSC-Regular, PingFang SC;
- font-weight: 400;
- color: #ffffff;
- text-align: center;
- line-height: 38px;
- margin-left: 15px;
- cursor: pointer;
- box-sizing: border-box;
- }
- .cargo-owner-add {
- width: 120px;
- height: 36px;
- border-radius: 2px;
- border: 1px solid #0094fe;
- font-size: 14px;
- font-family: PingFangSC-Regular, PingFang SC;
- font-weight: 400;
- color: #0094fe;
- line-height: 36px;
- text-align: center;
- cursor: pointer;
- margin-right: 20px;
- }
- :deep().el-dialog {
- width: 560px;
- padding: 20px 50px;
- border-radius: 6px;
- }
- :deep() .el-dialog__title {
- font-size: 18px;
- font-family: PingFangSC-Regular, PingFang SC;
- font-weight: 400;
- color: #0094fe;
- }
- </style>
|