shipOwnerList.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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="height: 32px; width: 330px; line-height: 32px"
  11. ></el-input>
  12. <div class="seach-btn" @click="getShipOwnerList(1)">查询</div>
  13. </div>
  14. <div class="cargo-owner-add" @click="dialogFormVisible = true">
  15. 添加船东
  16. </div>
  17. <el-dialog
  18. title="添加船东"
  19. v-model="dialogFormVisible"
  20. @closed="resetForm"
  21. distory
  22. >
  23. <template v-slot:default>
  24. <el-form
  25. :model="ruleForm"
  26. :rules="rules"
  27. ref="form"
  28. label-width="110px"
  29. label-position="left"
  30. >
  31. <el-form-item prop="userPhone" label="手机号">
  32. <el-input
  33. style="width: 280px"
  34. v-model="ruleForm.userPhone"
  35. ></el-input>
  36. </el-form-item>
  37. <el-form-item prop="userName" label="船东姓名">
  38. <el-input
  39. style="width: 280px"
  40. v-model="ruleForm.userName"
  41. ></el-input>
  42. </el-form-item>
  43. <el-form-item prop="shipMmsi" label="MMSI">
  44. <el-input
  45. style="width: 280px"
  46. v-model="ruleForm.shipMmsi"
  47. :disabled="!!ruleForm.shipId"
  48. ></el-input>
  49. </el-form-item>
  50. <el-form-item prop="shipName" label="船名">
  51. <el-input
  52. style="width: 280px"
  53. v-model="ruleForm.shipName"
  54. :disabled="!!ruleForm.shipId"
  55. ></el-input>
  56. </el-form-item>
  57. </el-form>
  58. </template>
  59. <template v-slot:footer>
  60. <div class="dialog-footer">
  61. <el-button @click="resetForm">重 置</el-button>
  62. <el-button type="primary" @click="addShipOwner(ruleForm)">
  63. 确 定
  64. </el-button>
  65. </div>
  66. </template>
  67. </el-dialog>
  68. </div>
  69. <div style="margin-top: 24px">
  70. <el-table :data="tableData" stripe style="width: 100%">
  71. <el-table-column
  72. type="index"
  73. label="序号"
  74. min-width="80"
  75. align="center"
  76. ></el-table-column>
  77. <el-table-column
  78. prop="userName"
  79. label="船东名称"
  80. min-width="120"
  81. align="center"
  82. ></el-table-column>
  83. <el-table-column
  84. prop="userPhone"
  85. label="手机号"
  86. min-width="160"
  87. align="center"
  88. ></el-table-column>
  89. <el-table-column
  90. prop="shipName"
  91. label="船舶名称"
  92. min-width="160"
  93. align="center"
  94. ></el-table-column>
  95. <el-table-column
  96. prop="cargo"
  97. label="常运货种"
  98. min-width="160"
  99. align="center"
  100. ></el-table-column>
  101. <!-- <el-table-column
  102. prop="createTime"
  103. label="入驻时间"
  104. min-width="200"
  105. align="center"
  106. ></el-table-column>
  107. <el-table-column label="操作" min-width="80" align="center">
  108. <template v-slot="scope">
  109. <el-button
  110. @click="shipOwnerDetail(scope.row.userId, tableData)"
  111. type="text"
  112. size="small"
  113. >
  114. 查看详情
  115. </el-button>
  116. </template>
  117. </el-table-column> -->
  118. </el-table>
  119. <div style="width: 100%; text-align: right; margin-top: 43px">
  120. <el-pagination
  121. background
  122. layout="prev, pager, next"
  123. :total="total"
  124. @current-change="pageChange"
  125. :current-page="currentPage"
  126. ></el-pagination>
  127. </div>
  128. </div>
  129. </div>
  130. </template>
  131. <script setup>
  132. import { ref, h, reactive, toRefs, onMounted } from "vue";
  133. import { ElNotification, ElMessageBox, ElMessage } from "element-plus";
  134. import store from "../../store";
  135. import router from "../../router";
  136. import md5 from "md5";
  137. import api from "../../apis/fetch";
  138. let dialogFormVisible = ref(false);
  139. let form = ref(null);
  140. let ruleForm = ref({
  141. userName: "",
  142. userPhone: "",
  143. shipName: "",
  144. shipMmsi: "",
  145. });
  146. async function resetForm() {
  147. dialogFormVisible.value = false;
  148. form.value.resetFields();
  149. ruleForm.value = {};
  150. }
  151. const checkShipOwnerPhone = async (rule, value, callback) => {
  152. if (value.length != 11) {
  153. return callback(new Error("请正确输入手机号"));
  154. }
  155. let res = await api.checkShipOwnerPhone({
  156. userPhone: value,
  157. });
  158. if (res.data.status == 0) {
  159. callback(new Error("此手机号已绑定船东!"));
  160. } else {
  161. callback();
  162. }
  163. };
  164. const checkShipMmsi = async (rule, value, callback) => {
  165. if (value?.length != 9) {
  166. return callback(new Error("请正确输入MMSI"));
  167. }
  168. if (ruleForm.value.shipId) return;
  169. let res = await api.checkShipMmsi({
  170. shipMmsi: value,
  171. });
  172. if (res.data.status == 0) {
  173. ElMessageBox.confirm("已查询到船舶信息,是否匹配?", "提示", {
  174. confirmButtonText: "匹配",
  175. cancelButtonText: "更换mmsi",
  176. type: "info",
  177. })
  178. .then(() => {
  179. ruleForm.value = {
  180. ...ruleForm.value,
  181. ...res.data.result,
  182. };
  183. })
  184. .catch(() => {
  185. ruleForm.value.shipMmsi = "";
  186. ruleForm.value.shipId = "";
  187. ruleForm.value.shipName = "";
  188. });
  189. } else {
  190. callback();
  191. }
  192. };
  193. const rules = ref({
  194. userName: [{ required: true, message: "请填写船东名称", trigger: "blur" }],
  195. shipName: [{ required: true, message: "请填写船名", trigger: "blur" }],
  196. shipMmsi: [{ validator: checkShipMmsi, trigger: "blur" }],
  197. userPhone: [{ validator: checkShipOwnerPhone, trigger: "blur" }],
  198. });
  199. async function addShipOwner() {
  200. form.value.validate(async (valid) => {
  201. if (valid) {
  202. let { userName, shipName, shipMmsi, userPhone } = ruleForm.value;
  203. let res = await api.addShipOwner(ruleForm.value);
  204. if (res.data.status == 0) {
  205. ElNotification.success({
  206. title: "添加成功",
  207. duration: 0,
  208. message: `${userName}:${res.data.msg}`,
  209. type: "success",
  210. });
  211. resetForm();
  212. getShipOwnerList();
  213. } else {
  214. ElNotification.error({
  215. title: "失败",
  216. duration: 3000,
  217. message: res.data.msg,
  218. });
  219. }
  220. } else {
  221. return false;
  222. }
  223. });
  224. }
  225. let currentPage = ref(1);
  226. let term = ref("");
  227. let tableData = ref([]);
  228. let total = ref(0);
  229. async function getShipOwnerList(page) {
  230. currentPage.value = page || currentPage.value;
  231. let res = await api.getShipOwnerList({
  232. currentPage: currentPage.value,
  233. size: 10,
  234. term: term.value,
  235. });
  236. if (res.data.status == 0) {
  237. tableData.value = res.data.result;
  238. total.value = res.data.total;
  239. } else {
  240. tableData.value = [];
  241. total.value = 0;
  242. }
  243. }
  244. async function shipOwnerDetail(userId) {
  245. router.push({
  246. path: "/shipOwnerManage/shipOwnerDetail",
  247. query: {
  248. userId,
  249. },
  250. });
  251. }
  252. function pageChange(e) {
  253. currentPage.value = e;
  254. getShipOwnerList();
  255. }
  256. onMounted(() => {
  257. getShipOwnerList();
  258. });
  259. </script>
  260. <style scoped>
  261. .seach-btn {
  262. display: inline-block;
  263. width: 60px;
  264. height: 38px;
  265. background: #0094fe;
  266. border-radius: 2px;
  267. font-size: 14px;
  268. font-family: PingFangSC-Regular, PingFang SC;
  269. font-weight: 400;
  270. color: #ffffff;
  271. text-align: center;
  272. line-height: 38px;
  273. margin-left: 10px;
  274. cursor: pointer;
  275. }
  276. .cargo-owner-add {
  277. width: 80px;
  278. height: 32px;
  279. border-radius: 2px;
  280. border: 1px solid #0094fe;
  281. font-size: 14px;
  282. font-family: PingFangSC-Regular, PingFang SC;
  283. font-weight: 400;
  284. color: #0094fe;
  285. line-height: 32px;
  286. text-align: center;
  287. cursor: pointer;
  288. }
  289. :deep().el-dialog {
  290. width: 560px;
  291. padding: 20px 50px;
  292. border-radius: 6px;
  293. }
  294. :deep() .el-dialog__title {
  295. font-size: 18px;
  296. font-family: PingFangSC-Regular, PingFang SC;
  297. font-weight: 400;
  298. color: #0094fe;
  299. }
  300. </style>