CarSeries.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <div>
  3. <div class="car_series" v-if="queryTag">
  4. <div class="count">
  5. <button @click="showModal">新增车系</button>
  6. <Count :sum="sum"></Count>
  7. </div>
  8. <div class="table">
  9. <Table
  10. :tableData="tableData"
  11. @edit="edit"
  12. @delet_data="deleteData"
  13. @car_type="carType"
  14. :pageSize='sum'
  15. ></Table>
  16. </div>
  17. <div class="page">
  18. <Tablepage
  19. :totalPage="totalPage"
  20. :currentPage="currentPage"
  21. @change_page="changePage"
  22. @jump_page="jumpPage"
  23. ></Tablepage>
  24. </div>
  25. <div class="modal" v-if="modalFlag">
  26. <Modal :modalFlag="modalFlag" @hide_modal="showModal" @submit='submit'></Modal>
  27. </div>
  28. </div>
  29. <div v-else>
  30. <CarType />
  31. </div>
  32. </div>
  33. </template>
  34. <script>
  35. import Count from "../../components/Count";
  36. import Tablepage from "../../components/TablePage";
  37. import Table from "./components/CarSeriesTable";
  38. import Modal from "./components/CarSeriesModal";
  39. import CarType from "./components/CarType";
  40. export default {
  41. components: {
  42. Count,
  43. Table,
  44. Tablepage,
  45. Modal,
  46. CarType,
  47. },
  48. data() {
  49. return {
  50. sum: 140, // 一共有多少条数据
  51. pageSize: 20, // 每页展示的数据
  52. currentPage: 1,
  53. // 表格配置
  54. tableData: [{ carSeries: "雷克萨斯ES" }, { carSeries: "雷克萨斯ES2" }],
  55. getDate: [
  56. { carSeries: "雷克萨斯ES", str: "123" },
  57. { carSeries: "雷克萨斯ES", str: "124" },
  58. { carSeries: "雷克萨斯ES", str: "125" },
  59. ],
  60. functionData: [],
  61. modalFlag: false, // 控制模态框展示
  62. };
  63. },
  64. computed: {
  65. // 表格总页数
  66. totalPage() {
  67. return Math.ceil(this.sum / this.pageSize);
  68. },
  69. // 获取路由参数
  70. queryTag() {
  71. return this.$route.query && this.$route.query.tag ? 0 : 1;
  72. },
  73. },
  74. methods: {
  75. // 获取某一页面的数据,展示在表格
  76. changePage: function (page) {
  77. this.currentPage = page;
  78. console.log(page);
  79. },
  80. // 点击上一页,下一页,首页,尾页
  81. jumpPage: function (item) {
  82. switch (item) {
  83. case 1:
  84. this.currentPage = 1;
  85. break;
  86. case 2:
  87. this.currentPage = this.currentPage - 1;
  88. break;
  89. case 3:
  90. this.currentPage = this.currentPage + 1;
  91. break;
  92. case 4:
  93. this.currentPage = this.totalPage;
  94. break;
  95. }
  96. console.log(this.currentPage);
  97. },
  98. // 获取数据
  99. getData: function () {
  100. this.tableData = [];
  101. this.functionData = [];
  102. this.getDate.forEach((element) => {
  103. this.tableData.push({
  104. carSeries: element.carSeries,
  105. });
  106. this.functionData.push({
  107. str: element.str,
  108. });
  109. });
  110. },
  111. // 展示、隐藏模态框
  112. showModal: function () {
  113. this.modalFlag = !this.modalFlag;
  114. },
  115. // 模态框保存
  116. submit: function(car) {
  117. console.log('车系保存', car);
  118. this.modalFlag = false;
  119. },
  120. // 点击编辑
  121. edit(index, newName) {
  122. console.log(this.functionData[index].str, newName);
  123. },
  124. // 点击删除
  125. deleteData: function(index) {
  126. console.log("删除", this.functionData[index].str);
  127. },
  128. // 点击系列车型
  129. carType: function(index) {
  130. // 页面变化
  131. this.$router.push({ query: { tag: "vehicle_type" } });
  132. console.log("点击系列车型", this.functionData[index].str);
  133. },
  134. // 删除数据
  135. detletData: function() {
  136. console.log('删除数据');
  137. }
  138. },
  139. mounted() {
  140. this.getData();
  141. },
  142. };
  143. </script>
  144. <style scoped lang="less">
  145. .car_series {
  146. .count {
  147. height: 40px;
  148. width: 100%;
  149. display: flex;
  150. justify-content: space-between;
  151. align-items: center;
  152. button {
  153. width: 86px;
  154. height: 30px;
  155. position: relative;
  156. bottom: -5px;
  157. margin: 0;
  158. border-radius: 2px;
  159. }
  160. }
  161. }
  162. </style>