shipyardManage.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. <template>
  2. <div class="full-container-p24">
  3. <div class="mb30 df aic jcsb">
  4. <div class="df aic">
  5. <el-input
  6. v-model="searchKey"
  7. placeholder="请输入船厂名称"
  8. class="w300"
  9. @keyup.enter="handleSearch"
  10. clearable
  11. @clear="handleSearch"
  12. />
  13. <el-button class="ml10" type="primary" @click="handleSearch">
  14. 搜索
  15. </el-button>
  16. </div>
  17. <el-button class="ml10" type="primary" @click="handleAdd">
  18. 新增船厂
  19. </el-button>
  20. </div>
  21. <el-table border :data="tableData" stripe>
  22. <el-table-column type="index" label="序号" width="80" align="center" />
  23. <el-table-column
  24. prop="shipyardName"
  25. label="船厂名称"
  26. min-width="150"
  27. align="center"
  28. />
  29. <el-table-column
  30. prop="shipyardAddress"
  31. label="地址"
  32. min-width="200"
  33. align="center"
  34. />
  35. <el-table-column
  36. prop="contactName"
  37. label="联系人"
  38. min-width="120"
  39. align="center"
  40. />
  41. <el-table-column
  42. prop="contactPhone"
  43. label="联系电话"
  44. min-width="150"
  45. align="center"
  46. />
  47. <el-table-column
  48. prop="shipyardIntroduce"
  49. label="船厂介绍"
  50. min-width="150"
  51. align="center"
  52. :show-overflow-tooltip="true"
  53. />
  54. <el-table-column
  55. prop="shipyardDockNum"
  56. label="船坞数量"
  57. min-width="100"
  58. align="center"
  59. />
  60. <el-table-column
  61. prop="shipyardAnnualProdCapacity"
  62. label="年产能(艘)"
  63. min-width="100"
  64. align="center"
  65. />
  66. <el-table-column label="操作" width="180" align="center">
  67. <template #default="scope">
  68. <el-button type="primary" text @click="handleEdit(scope.row)">
  69. 修改
  70. </el-button>
  71. <el-button type="danger" text @click="deleteShipyard(scope.row)">
  72. 删除
  73. </el-button>
  74. </template>
  75. </el-table-column>
  76. </el-table>
  77. <div class="df aic jcfe mt40 mr20">
  78. <el-pagination
  79. background
  80. layout="prev, pager, next"
  81. :current-page="currentPage"
  82. :total="total"
  83. @current-change="pageChange"
  84. />
  85. </div>
  86. <el-dialog v-model="dialogVisible" :title="dialogTitle" width="700">
  87. <el-form
  88. ref="formRef"
  89. :model="formData"
  90. :rules="rules"
  91. label-width="120px"
  92. >
  93. <el-form-item label="船厂名称" prop="shipyardName">
  94. <el-input v-model="formData.shipyardName" class="w400" />
  95. </el-form-item>
  96. <el-form-item label="船厂图片" prop="shipyardImgFileKey">
  97. <Uploader
  98. :limit="1"
  99. :file-list="shipyardImgList"
  100. action-url="/api/file/upload"
  101. @on-upload-file-list="handleUploadImg"
  102. @on-remove-file-list="handleRemoveImg"
  103. />
  104. </el-form-item>
  105. <el-form-item label="地址" prop="shipyardAddress">
  106. <el-input v-model="formData.shipyardAddress" class="w400" />
  107. </el-form-item>
  108. <el-form-item label="联系人" prop="contactName">
  109. <el-input v-model="formData.contactName" class="w400" />
  110. </el-form-item>
  111. <el-form-item label="联系电话" prop="contactPhone">
  112. <el-input v-model="formData.contactPhone" class="w400" />
  113. </el-form-item>
  114. <el-form-item label="船坞数量" prop="shipyardDockNum">
  115. <el-input-number
  116. v-model="formData.shipyardDockNum"
  117. :min="0"
  118. class="w400"
  119. />
  120. </el-form-item>
  121. <el-form-item label="年产能(艘)" prop="shipyardAnnualProdCapacity">
  122. <el-input-number
  123. v-model="formData.shipyardAnnualProdCapacity"
  124. :min="0"
  125. class="w400"
  126. />
  127. </el-form-item>
  128. <el-form-item label="船厂介绍" prop="shipyardIntroduce">
  129. <el-input
  130. v-model="formData.shipyardIntroduce"
  131. type="textarea"
  132. :rows="4"
  133. class="w400"
  134. />
  135. </el-form-item>
  136. </el-form>
  137. <template #footer>
  138. <el-button @click="dialogVisible = false">取消</el-button>
  139. <el-button type="primary" @click="submitForm">确定</el-button>
  140. </template>
  141. </el-dialog>
  142. </div>
  143. </template>
  144. <script setup>
  145. import { ref, reactive } from "vue";
  146. import { ElMessage, ElMessageBox } from "element-plus";
  147. import api from "../../apis/fetch";
  148. import Uploader from "../../components/Uploader.vue";
  149. import { useStore } from "vuex";
  150. const store = useStore();
  151. const loginAccountId = store.state.loginAccountId;
  152. const searchKey = ref("");
  153. const currentPage = ref(1);
  154. const total = ref(0);
  155. const tableData = ref([]);
  156. const dialogVisible = ref(false);
  157. const dialogTitle = ref("新增船厂");
  158. const formRef = ref(null);
  159. const shipyardImgList = ref([]);
  160. const formData = reactive({
  161. loginAccountId: loginAccountId,
  162. shipyardId: 0,
  163. shipyardName: "",
  164. shipyardImgFileKey: "",
  165. shipyardAddress: "",
  166. contactName: "",
  167. contactPhone: "",
  168. shipyardIntroduce: "",
  169. shipyardDockNum: 0,
  170. shipyardAnnualProdCapacity: 0,
  171. });
  172. const rules = reactive({
  173. shipyardName: [
  174. { required: true, message: "请输入船厂名称", trigger: "blur" },
  175. ],
  176. shipyardAddress: [{ required: true, message: "请输入地址", trigger: "blur" }],
  177. contactName: [{ required: true, message: "请输入联系人", trigger: "blur" }],
  178. contactPhone: [
  179. { required: true, message: "请输入联系电话", trigger: "blur" },
  180. ],
  181. shipyardDockNum: [
  182. { required: true, message: "请输入船坞数量", trigger: "blur" },
  183. ],
  184. shipyardAnnualProdCapacity: [
  185. { required: true, message: "请输入年产能", trigger: "blur" },
  186. ],
  187. });
  188. // 获取船厂列表
  189. async function getShipyardList() {
  190. try {
  191. const { data } = await api.getShipyardList({
  192. loginAccountId: loginAccountId,
  193. term: searchKey.value,
  194. currentPage: currentPage.value,
  195. size: 10,
  196. });
  197. if (data.status === 0) {
  198. tableData.value = data.result;
  199. total.value = data.total;
  200. } else {
  201. tableData.value = [];
  202. total.value = 0;
  203. ElMessage.error(data.msg || "获取数据失败");
  204. }
  205. } catch (error) {
  206. ElMessage.error("获取数据失败");
  207. }
  208. }
  209. // 处理图片上传
  210. const handleUploadImg = ({ response: data }) => {
  211. if (data.status === 0) {
  212. formData.shipyardImgFileKey = data.result.key;
  213. shipyardImgList.value = [
  214. { viewUrl: data.result.viewUrl, fileKey: data.result.key },
  215. ];
  216. ElMessage.success("上传成功");
  217. } else {
  218. ElMessage.error(data.msg || "上传失败");
  219. }
  220. };
  221. // 处理图片删除
  222. const handleRemoveImg = () => {
  223. formData.shipyardImgFileKey = "";
  224. shipyardImgList.value = [];
  225. };
  226. // 分页切换
  227. function pageChange(page) {
  228. currentPage.value = page;
  229. getShipyardList();
  230. }
  231. // 搜索
  232. function handleSearch() {
  233. currentPage.value = 1;
  234. getShipyardList();
  235. }
  236. // 新增
  237. function handleAdd() {
  238. dialogTitle.value = "新增船厂";
  239. Object.keys(formData).forEach((key) => {
  240. if (key !== "shipyardId" && key !== "loginAccountId") {
  241. if (key === "shipyardDockNum" || key === "shipyardAnnualProdCapacity") {
  242. formData[key] = 0;
  243. } else {
  244. formData[key] = "";
  245. }
  246. }
  247. });
  248. formData.shipyardId = 0;
  249. shipyardImgList.value = [];
  250. dialogVisible.value = true;
  251. }
  252. // 编辑
  253. function handleEdit(row) {
  254. dialogTitle.value = "修改船厂";
  255. formData.shipyardId = row.shipyardId;
  256. formData.shipyardName = row.shipyardName;
  257. formData.shipyardAddress = row.shipyardAddress;
  258. formData.contactName = row.contactName;
  259. formData.contactPhone = row.contactPhone;
  260. formData.shipyardIntroduce = row.shipyardIntroduce;
  261. formData.shipyardDockNum = row.shipyardDockNum || 0;
  262. formData.shipyardAnnualProdCapacity = row.shipyardAnnualProdCapacity || 0;
  263. formData.shipyardImgFileKey = row.shipyardImgFileKey || "";
  264. // 设置图片
  265. shipyardImgList.value = [];
  266. if (row.shipyardImgFileKey) {
  267. shipyardImgList.value = [
  268. {
  269. fileKey: row.shipyardImgFileKey,
  270. viewUrl: `/api/file/view?fileKey=${row.shipyardImgFileKey}`,
  271. },
  272. ];
  273. }
  274. dialogVisible.value = true;
  275. }
  276. // 提交表单
  277. async function submitForm() {
  278. try {
  279. await formRef.value.validate();
  280. const apiMethod =
  281. formData.shipyardId === 0 ? api.addShipyard : api.updateShipyard;
  282. const { data } = await apiMethod(formData);
  283. if (data.status === 0) {
  284. ElMessage.success("操作成功");
  285. dialogVisible.value = false;
  286. getShipyardList();
  287. } else {
  288. ElMessage.error(data.message || "操作失败");
  289. }
  290. } catch (error) {
  291. console.error(error);
  292. ElMessage.error("操作失败");
  293. }
  294. }
  295. // 删除
  296. function deleteShipyard(row) {
  297. ElMessageBox.confirm("确认删除该船厂信息?", "警告", {
  298. confirmButtonText: "确认",
  299. cancelButtonText: "取消",
  300. type: "warning",
  301. }).then(async () => {
  302. try {
  303. const { data } = await api.deleteShipyard({
  304. loginAccountId: loginAccountId,
  305. shipyardId: row.shipyardId,
  306. });
  307. if (data.status === 0) {
  308. ElMessage.success("删除成功");
  309. getShipyardList();
  310. } else {
  311. ElMessage.error(data.message || "删除失败");
  312. }
  313. } catch (error) {
  314. ElMessage.error("删除失败");
  315. }
  316. });
  317. }
  318. // 初始化获取数据
  319. getShipyardList();
  320. </script>
  321. <style scoped>
  322. .w300 {
  323. width: 300px;
  324. }
  325. .w400 {
  326. width: 400px;
  327. }
  328. .ml10 {
  329. margin-left: 10px;
  330. }
  331. </style>