You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

235 lines
7.5 KiB

1 month ago
  1. <template>
  2. <div class="customer-css">
  3. <el-form :inline="true" label-position="top" :model="searchData">
  4. <el-form-item label="始发港">
  5. <el-input v-model="searchData.departure" clearable style="width: 150px"></el-input>
  6. </el-form-item>
  7. <el-form-item label="目的港">
  8. <el-input v-model="searchData.destination" clearable style="width: 150px"></el-input>
  9. </el-form-item>
  10. <el-form-item label=" ">
  11. <el-button type="primary" @click="searchTable()">查询</el-button>
  12. <el-button type="primary" @click="addModal()" v-if="shouldShowButton">新增</el-button>
  13. </el-form-item>
  14. </el-form>
  15. <el-table
  16. :data="dataList"
  17. :height="searchData.height"
  18. border
  19. v-loading="dataListLoading"
  20. style="width: 100%;">
  21. <el-table-column
  22. v-for="(item, index) in columnList"
  23. :key="index"
  24. :sortable="item.columnSortable"
  25. :prop="item.columnProp"
  26. :header-align="item.headerAlign"
  27. :show-overflow-tooltip="item.showOverflowTooltip"
  28. :align="item.align"
  29. :fixed="item.fixed == '' ? false : item.fixed"
  30. :min-width="item.columnWidth"
  31. :label="item.columnLabel">
  32. <template slot-scope="scope">
  33. <span v-if="!item.columnHidden">{{ scope.row[item.columnProp] }}</span>
  34. </template>
  35. </el-table-column>
  36. <el-table-column
  37. header-align="center"
  38. align="center"
  39. width="180"
  40. fixed="right"
  41. label="Actions">
  42. <template slot-scope="scope">
  43. <a type="text" size="small" @click="editModel(scope.row)">Edit |</a>
  44. <a type="text" size="small" @click="deleteData(scope.row)"> Delete</a>
  45. </template>
  46. </el-table-column>
  47. </el-table>
  48. <!-- 新增/编辑弹窗 -->
  49. <el-dialog :title="dialogTitle" :close-on-click-modal="false" v-drag :visible.sync="dialogVisible" width="600px">
  50. <div class="dialog-content">
  51. <el-form label-position="top" :model="formData" :rules="formRules" ref="formRef">
  52. <el-row :gutter="20">
  53. <el-col :span="12">
  54. <el-form-item label="始发港" prop="departure">
  55. <el-input v-model="formData.departure" placeholder="请输入始发港"></el-input>
  56. </el-form-item>
  57. </el-col>
  58. <el-col :span="12">
  59. <el-form-item label="目的港" prop="destination">
  60. <el-input v-model="formData.destination" placeholder="请输入目的港"></el-input>
  61. </el-form-item>
  62. </el-col>
  63. </el-row>
  64. <el-row :gutter="20">
  65. <el-col :span="12">
  66. <el-form-item label="停留天数" prop="transitDays">
  67. <el-input v-model="formData.transitDays" type="number" placeholder="请输入停留天数"></el-input>
  68. </el-form-item>
  69. </el-col>
  70. </el-row>
  71. </el-form>
  72. </div>
  73. <div slot="footer" class="dialog-footer" style="margin-top: 20px">
  74. <el-button type="primary" @click="submitData()">保存</el-button>
  75. <el-button @click="dialogVisible = false">取消</el-button>
  76. </div>
  77. </el-dialog>
  78. </div>
  79. </template>
  80. <script>
  81. // 请根据实际API路径调整导入
  82. import {
  83. searchTransitPage, // 分页查询运输周期列表(如果需要分页)
  84. searchTransitList, // 查询运输周期列表
  85. createTransit, // 新增运输周期
  86. updateTransit, // 更新运输周期
  87. deleteTransit // 删除运输周期
  88. } from '@/api/port/portTransit.js'
  89. export default {
  90. name: 'PortTransitList',
  91. data() {
  92. return {
  93. dataList: [],
  94. dataListLoading: false,
  95. searchData: {
  96. departure: '',
  97. destination: '',
  98. portId: '',
  99. portCode: '',
  100. height: '200',
  101. page: 1,
  102. limit: 1000
  103. },
  104. dialogVisible: false,
  105. dialogTitle: '新增港口运输周期',
  106. formData: {
  107. id: '',
  108. departure: '',
  109. destination: '',
  110. transitDays: ''
  111. },
  112. formRules: {
  113. departure: [{ required: true, message: '请输入始发港', trigger: 'blur' }],
  114. destination: [{ required: true, message: '请输入目的港', trigger: 'blur' }],
  115. transitDays: [{ required: true, message: '请输入停留天数', trigger: 'blur' }]
  116. },
  117. columnList: [
  118. { columnProp: 'departure', headerAlign: 'center', align: 'left', columnLabel: '始发港', columnWidth: 150, fixed: '', columnHidden: false, columnSortable: false },
  119. { columnProp: 'destination', headerAlign: 'center', align: 'left', columnLabel: '目的港', columnWidth: 150, fixed: '', columnHidden: false, columnSortable: false },
  120. { columnProp: 'transitDays', headerAlign: 'center', align: 'center', columnLabel: '停留天数', columnWidth: 120, fixed: '', columnHidden: false, columnSortable: true }
  121. ]
  122. }
  123. },
  124. computed: {
  125. shouldShowButton() {
  126. return true
  127. }
  128. },
  129. methods: {
  130. // 初始化方法,供父组件调用
  131. init(inData) {
  132. if (inData) {
  133. this.searchData = { ...this.searchData, ...inData }
  134. }
  135. this.searchTable()
  136. },
  137. // 查询列表
  138. searchTable() {
  139. this.dataListLoading = true
  140. searchTransitPage(this.searchData).then(({ data }) => {
  141. if (data && data.code === 0) {
  142. this.dataList = data.rows
  143. } else {
  144. this.dataList = []
  145. }
  146. this.dataListLoading = false
  147. }).catch(() => {
  148. this.dataListLoading = false
  149. })
  150. },
  151. // 新增
  152. addModal() {
  153. this.dialogTitle = '新增港口运输周期'
  154. this.formData = {
  155. id: '',
  156. portId: this.searchData.portId || '',
  157. departure: '',
  158. destination: '',
  159. transitDays: ''
  160. }
  161. this.dialogVisible = true
  162. this.$nextTick(() => {
  163. if (this.$refs.formRef) {
  164. this.$refs.formRef.clearValidate()
  165. }
  166. })
  167. },
  168. // 编辑
  169. editModel(row) {
  170. this.dialogTitle = '编辑港口运输周期'
  171. this.formData = JSON.parse(JSON.stringify(row))
  172. this.dialogVisible = true
  173. this.$nextTick(() => {
  174. if (this.$refs.formRef) {
  175. this.$refs.formRef.clearValidate()
  176. }
  177. })
  178. },
  179. // 提交保存
  180. submitData() {
  181. this.$refs.formRef.validate((valid) => {
  182. if (!valid) return
  183. const api = this.formData.id ? updateTransit : createTransit
  184. api(this.formData).then(({ data }) => {
  185. if (data && data.code === 0) {
  186. this.$message.success(data.msg || '保存成功')
  187. this.dialogVisible = false
  188. this.searchTable()
  189. } else {
  190. this.$message.warning(data.msg || '保存失败')
  191. }
  192. }).catch(() => {
  193. this.$message.error('保存失败')
  194. })
  195. })
  196. },
  197. // 删除
  198. deleteData(row) {
  199. this.$confirm('确认删除该条港口运输周期记录吗?', '提示', {
  200. confirmButtonText: '确认',
  201. cancelButtonText: '取消',
  202. type: 'warning'
  203. }).then(() => {
  204. deleteTransit(row.id).then(({ data }) => {
  205. if (data.code === 0) {
  206. this.$message.success('删除成功')
  207. this.searchTable()
  208. } else {
  209. this.$message.warning(data.msg || '删除失败')
  210. }
  211. }).catch(() => {
  212. this.$message.error('删除失败')
  213. })
  214. }).catch(() => {})
  215. }
  216. }
  217. }
  218. </script>
  219. <style scoped lang="scss">
  220. .dialog-content {
  221. width: 100%;
  222. max-height: 60vh;
  223. overflow-y: auto;
  224. padding-right: 10px;
  225. }
  226. .customer-css {
  227. padding: 10px;
  228. }
  229. </style>