portsList.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <template>
  2. <div class="full-container-p24">
  3. <div style="display: flex; justify-content: space-between">
  4. <div style="display: flex">
  5. <el-input
  6. placeholder="请输入港口名称"
  7. prefix-icon="el-icon-search"
  8. v-model="term"
  9. clearable
  10. style="width: 330px"
  11. ></el-input>
  12. <div class="seach-btn" @click="getPortsList">查询</div>
  13. </div>
  14. <div class="cargo-owner-add" @click="dialogFormVisible = true">
  15. 添加港口
  16. </div>
  17. <el-dialog title="添加港口" v-model="dialogFormVisible">
  18. <template v-slot:default>
  19. <el-form
  20. :model="ruleForm"
  21. :rules="rules"
  22. ref="form"
  23. label-width="110px"
  24. label-position="left"
  25. >
  26. <el-form-item prop="portName" label="港口名称">
  27. <el-input
  28. style="width: 280px"
  29. v-model="ruleForm.portName"
  30. ></el-input>
  31. </el-form-item>
  32. <el-form-item prop="longitude" label="经度">
  33. <el-input
  34. style="width: 280px"
  35. v-model="ruleForm.longitude"
  36. ></el-input>
  37. </el-form-item>
  38. <el-form-item prop="latitude" label="纬度">
  39. <el-input
  40. style="width: 280px"
  41. v-model="ruleForm.latitude"
  42. ></el-input>
  43. </el-form-item>
  44. </el-form>
  45. </template>
  46. <template v-slot:footer>
  47. <div class="dialog-footer">
  48. <el-button @click="resetForm">取 消</el-button>
  49. <el-button type="primary" @click="addPort(ruleForm)">
  50. 确 定
  51. </el-button>
  52. </div>
  53. </template>
  54. </el-dialog>
  55. </div>
  56. <div style="margin-top: 24px">
  57. <el-table :data="tableData" stripe style="width: 100%">
  58. <el-table-column
  59. type="index"
  60. label="序号"
  61. min-width="80"
  62. align="center"
  63. ></el-table-column>
  64. <el-table-column
  65. prop="portName"
  66. label="港口名称"
  67. min-width="120"
  68. align="center"
  69. ></el-table-column>
  70. <el-table-column
  71. prop="longitude"
  72. label="经纬度"
  73. min-width="120"
  74. align="center"
  75. >
  76. <template v-slot="scope">
  77. {{ scope.row.longitude }}, {{ scope.row.latitude }}
  78. </template>
  79. </el-table-column>
  80. <el-table-column
  81. prop="createTime"
  82. label="添加时间"
  83. min-width="200"
  84. align="center"
  85. >
  86. <template v-slot="scope">
  87. {{ subTimeStr(scope.row.createTime) }}
  88. </template>
  89. </el-table-column>
  90. <el-table-column label="启用/禁用" min-width="80" align="center">
  91. <template v-slot="scope">
  92. <el-switch
  93. v-model="scope.row.status"
  94. active-color="#13ce66"
  95. :active-value="0"
  96. :inactive-value="1"
  97. inactive-color="#ff4949"
  98. @change="changeSwitch($event, scope.row.id)"
  99. />
  100. </template>
  101. </el-table-column>
  102. </el-table>
  103. <div style="width: 100%; text-align: right; margin-top: 43px">
  104. <el-pagination
  105. background
  106. layout="prev, pager, next"
  107. :total="total"
  108. @current-change="pageChange"
  109. ></el-pagination>
  110. </div>
  111. </div>
  112. </div>
  113. </template>
  114. <script setup>
  115. import { ref, h, reactive, toRefs, onMounted } from "vue";
  116. import { ElNotification, ElMessageBox, ElMessage } from "element-plus";
  117. import store from "../../store";
  118. import router from "../../router";
  119. import md5 from "md5";
  120. import api from "../../apis/fetch";
  121. import { subTimeStr } from "../../utils/utils";
  122. let currentPage = ref(1);
  123. let term = ref("");
  124. let tableData = ref([]);
  125. let total = ref(0);
  126. let dialogFormVisible = ref(false);
  127. let form = ref(null);
  128. const ruleForm = ref({
  129. portName: "",
  130. longitude: "",
  131. latitude: "",
  132. });
  133. const rules = ref({
  134. portName: [{ required: true, message: "请填写港口名称", trigger: "blur" }],
  135. longitude: [{ required: true, message: "请填写港口经度", trigger: "blur" }],
  136. latitude: [{ required: true, message: "请填写港口纬度", trigger: "blur" }],
  137. });
  138. async function getPortsList() {
  139. tableData.value = [];
  140. let res = await api.getPortsList({
  141. currentPage: currentPage.value,
  142. size: 10,
  143. term: term.value,
  144. });
  145. term.value = "";
  146. if (res.data.status == 0) {
  147. tableData.value = res.data.result;
  148. total.value = res.data.total;
  149. }
  150. }
  151. function resetForm() {
  152. dialogFormVisible.value = false;
  153. form.value.resetFields();
  154. }
  155. async function addPort() {
  156. form.value.validate(async (valid) => {
  157. if (valid) {
  158. let { portName, longitude, latitude } = ruleForm.value;
  159. let res = await api.addPort({
  160. portName,
  161. longitude,
  162. latitude,
  163. });
  164. console.log(res);
  165. if (res.data.status == 0) {
  166. ElNotification.success({
  167. title: "添加成功",
  168. duration: 2000,
  169. message: `${portName}:${res.data.msg}`,
  170. type: "success",
  171. });
  172. resetForm();
  173. getPortsList();
  174. } else {
  175. ElNotification.error({
  176. title: "失败",
  177. duration: 3000,
  178. message: res.data.msg,
  179. });
  180. }
  181. } else {
  182. return false;
  183. }
  184. });
  185. }
  186. async function changeSwitch(status, portId) {
  187. let res = await api.updatePortStatus({
  188. status,
  189. portId,
  190. });
  191. if (res.data.status == 0) {
  192. ElNotification.success({
  193. title: "成功",
  194. duration: 2000,
  195. message: res.data.msg,
  196. });
  197. }
  198. }
  199. async function cargoOwnerCompanyDetail(id) {
  200. router.push({
  201. path: "/cargoOwnerManage/cargoOwnerCompanyDetail",
  202. query: {
  203. id,
  204. },
  205. });
  206. }
  207. function pageChange(e) {
  208. currentPage.value = e;
  209. getPortsList();
  210. }
  211. onMounted(() => {
  212. getPortsList();
  213. });
  214. </script>
  215. <style scoped>
  216. .seach-btn {
  217. display: inline-block;
  218. width: 60px;
  219. height: 38px;
  220. background: #0094fe;
  221. border-radius: 2px;
  222. font-size: 14px;
  223. font-family: PingFangSC-Regular, PingFang SC;
  224. font-weight: 400;
  225. color: #ffffff;
  226. text-align: center;
  227. line-height: 38px;
  228. margin-left: 15px;
  229. cursor: pointer;
  230. box-sizing: border-box;
  231. }
  232. .cargo-owner-add {
  233. width: 120px;
  234. height: 36px;
  235. border-radius: 2px;
  236. border: 1px solid #0094fe;
  237. font-size: 14px;
  238. font-family: PingFangSC-Regular, PingFang SC;
  239. font-weight: 400;
  240. color: #0094fe;
  241. line-height: 36px;
  242. text-align: center;
  243. cursor: pointer;
  244. margin-right: 20px;
  245. }
  246. :deep().el-dialog {
  247. width: 560px;
  248. padding: 20px 50px;
  249. border-radius: 6px;
  250. }
  251. :deep() .el-dialog__title {
  252. font-size: 18px;
  253. font-family: PingFangSC-Regular, PingFang SC;
  254. font-weight: 400;
  255. color: #0094fe;
  256. }
  257. </style>