routeTimeTable-list.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <template>
  2. <div>
  3. <el-dialog
  4. :visible.sync="showDialog"
  5. :title="title"
  6. :modal-append-to-body="true"
  7. style="text-align: left"
  8. width="600px"
  9. @close="closeDialog"
  10. :close-on-click-modal="false"
  11. append-to-body
  12. >
  13. <el-row class="button-group">
  14. <el-button
  15. type="primary"
  16. size="small"
  17. plain
  18. icon="el-icon-circle-plus"
  19. @click="handleAdd"
  20. >新增</el-button
  21. >
  22. <el-button
  23. type="primary"
  24. size="small"
  25. plain
  26. icon="el-icon-remove"
  27. :disabled="multipleSelection.length == 0"
  28. @click="handleBatchDelete"
  29. >删除选中项</el-button
  30. >
  31. </el-row>
  32. <el-table
  33. ref="formTable"
  34. :data="tableData"
  35. v-loading="loading"
  36. stripe
  37. :height="tableHeight"
  38. @sort-change="sortChange"
  39. @selection-change="handleSelectionChange"
  40. >
  41. <el-table-column type="selection" width="55"></el-table-column>
  42. <el-table-column
  43. prop="sort"
  44. label="序号"
  45. width="100"
  46. ></el-table-column>
  47. <el-table-column
  48. prop="startTime"
  49. label="发车时间"
  50. ></el-table-column>
  51. <el-table-column label="操作">
  52. <template slot-scope="{ row }">
  53. <el-button size="mini" type="warning" @click="handleEdit(row)"
  54. >编辑</el-button
  55. >
  56. <el-button size="mini" type="danger" @click="handleDelete(row)"
  57. >删除</el-button
  58. >
  59. </template>
  60. </el-table-column>
  61. </el-table>
  62. <el-pagination
  63. :current-page.sync="pageIndex"
  64. :total="totalElements"
  65. :page-sizes="pageSizeList"
  66. @current-change="changePage"
  67. @size-change="pageSizeChange"
  68. layout="total, sizes, prev, pager, next, jumper"
  69. ></el-pagination>
  70. <routeTimeTable-detail
  71. v-if="showModal"
  72. :businessKey="businessKey"
  73. :routeId="routeId"
  74. :title="modalTitle"
  75. @close="onDetailModalClose"
  76. ></routeTimeTable-detail>
  77. </el-dialog>
  78. </div>
  79. </template>
  80. <script>
  81. import routeTimeTableApi from "@/api/bus/routeTimeTable";
  82. import routeTimeTableDetail from "./routeTimeTable-detail";
  83. export default {
  84. props: ["routeId","title"],
  85. name: "routeTimeTableList",
  86. data(){
  87. return{
  88. queryModel:{},
  89. showDialog: true,
  90. loading: false,
  91. tableData: [],
  92. pageIndex: 1,
  93. pageSize: 10,
  94. totalPages: 0,
  95. totalElements: 0,
  96. field: "",
  97. direction: "",
  98. pageSizeList: [10, 20, 30],
  99. multipleSelection: [],
  100. tableHeight: 300,
  101. showModal: false,
  102. modalTitle: "",
  103. }
  104. },
  105. created() {
  106. this.changePage(1);
  107. },
  108. methods:{
  109. closeDialog() {
  110. this.$emit("close", false);
  111. },
  112. changePage(pageIndex) {
  113. var self = this;
  114. self.loading = true;
  115. self.pageIndex = pageIndex;
  116. var formData = new FormData();
  117. formData.append("pageIndex", self.pageIndex);
  118. formData.append("pageSize", self.pageSize);
  119. formData.append("routeId", self.routeId);
  120. routeTimeTableApi
  121. .pageList(formData)
  122. .then(function (response) {
  123. self.loading = false;
  124. var jsonData = response.data;
  125. self.tableData = jsonData.data;
  126. self.totalPages = jsonData.totalPages;
  127. self.totalElements = jsonData.recordsTotal;
  128. //45为分页栏的高度
  129. //页面高度-列表上面的高度-分页栏高度
  130. self.tableHeight =
  131. window.innerHeight - self.$refs.formTable.$el.offsetTop - 100;
  132. })
  133. .catch((error) => {
  134. self.loading = false;
  135. // self.$message.error(error + "");
  136. });
  137. },
  138. pageSizeChange(pageSize) {
  139. this.pageSize = pageSize;
  140. },
  141. sortChange(data) {
  142. this.field = data.column.field;
  143. this.direction = data.order == "ascending" ? "asc" : "desc";
  144. this.changePage(this.pageIndex);
  145. },
  146. handleSelectionChange(val) {
  147. this.multipleSelection = val;
  148. },
  149. handleReset(name) {
  150. this.$refs[name].resetFields();
  151. this.queryModel.companyId = "";
  152. },
  153. handleAdd() {
  154. this.modalTitle = "新增";
  155. this.businessKey = "";
  156. this.routeId=this.routeId;
  157. this.showModal = true;
  158. },
  159. handleEdit(record) {
  160. this.modalTitle = "编辑";
  161. this.businessKey = record.id;
  162. this.routeId = this.routeId;
  163. this.showModal = true;
  164. },
  165. handleDelete(record) {
  166. var self = this;
  167. self
  168. .$confirm("是否确认删除?", "提示", {
  169. confirmButtonText: "确定",
  170. cancelButtonText: "取消",
  171. type: "warning",
  172. })
  173. .then(() => {
  174. routeTimeTableApi.remove(record.id).then(function (response) {
  175. var jsonData = response.data;
  176. if (jsonData.result) {
  177. // var index = self.tableData.indexOf(record);
  178. // self.tableData.splice(index, 1);
  179. self.changePage(self.pageIndex);
  180. self.$message({
  181. type: "success",
  182. message: "删除成功!",
  183. });
  184. }
  185. });
  186. });
  187. },
  188. handleBatchDelete() {
  189. var self = this;
  190. var idList = this.multipleSelection.map((record) => {
  191. return record.id;
  192. });
  193. this.$confirm("是否确认删除选中项?", "提示", {
  194. confirmButtonText: "确定",
  195. cancelButtonText: "取消",
  196. type: "warning",
  197. }).then(() => {
  198. routeTimeTableApi.batchRemove(idList).then(function (response) {
  199. var jsonData = response.data;
  200. if (jsonData.result) {
  201. self.changePage(self.pageIndex);
  202. self.$message({
  203. type: "success",
  204. message: "删除成功!",
  205. });
  206. }
  207. });
  208. });
  209. },
  210. onDetailModalClose(refreshed) {
  211. //保存成功后回调
  212. this.showModal = false;
  213. if (refreshed) {
  214. this.changePage(this.pageIndex);
  215. }
  216. },
  217. },
  218. components: {
  219. "routeTimeTable-detail": routeTimeTableDetail,
  220. },
  221. }
  222. </script>
  223. <style lang="scss" scoped>
  224. .el-breadcrumb {
  225. margin: 10px;
  226. line-height: 20px;
  227. }
  228. .el-divider {
  229. margin: 5px 0;
  230. }
  231. .demo-form-inline {
  232. margin-left: 10px;
  233. text-align: left;
  234. }
  235. .button-group {
  236. margin-left: 10px;
  237. text-align: left;
  238. }
  239. </style>