PlatformModule.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. @jump_router="jumpRouter"
  14. :pageSize="pageSize"
  15. :currentPage='currentPage'
  16. ></Table>
  17. </div>
  18. <div class="page">
  19. <Tablepage
  20. :totalPage="totalPage"
  21. :currentPage="currentPage"
  22. @change_page="changePage"
  23. @jump_page="jumpPage"
  24. ></Tablepage>
  25. </div>
  26. <div class="modal" v-if="modalFlag">
  27. <Modal
  28. :modalFlag="modalFlag"
  29. @hide_modal="showModal"
  30. @submit="submit"
  31. ></Modal>
  32. </div>
  33. </div>
  34. <div v-else>
  35. <DetailPage />
  36. </div>
  37. </div>
  38. </template>
  39. <script>
  40. import Count from "../../components/Count";
  41. import Tablepage from "../../components/TablePage";
  42. import Table from "./components/PlatformModule/PlatformTable";
  43. import Modal from "./components/PlatformModule/PlatFormModal";
  44. import DetailPage from "./components/PlatformModule/DetailPage";
  45. export default {
  46. components: {
  47. Count,
  48. Table,
  49. Tablepage,
  50. Modal,
  51. DetailPage,
  52. },
  53. data() {
  54. return {
  55. sum: 0, // 一共有多少条数据
  56. pageSize: 20, // 每页展示的数据
  57. currentPage: 1,
  58. tableData: [],
  59. modalFlag: false, // 控制模态框展示
  60. };
  61. },
  62. computed: {
  63. // 表格总页数
  64. totalPage() {
  65. return Math.ceil(this.sum / this.pageSize);
  66. },
  67. // 获取路由参数
  68. queryTag() {
  69. return this.$route.query && this.$route.query.tag ? 0 : 1;
  70. },
  71. },
  72. methods: {
  73. // 获取某一页面的数据,展示在表格
  74. changePage: function (page) {
  75. this.currentPage = page;
  76. this.selectPublishPlatformPage(this.currentPage, this.pageSize);
  77. },
  78. // 点击上一页,下一页,首页,尾页
  79. jumpPage: function (item) {
  80. switch (item) {
  81. case 1:
  82. this.currentPage = 1;
  83. break;
  84. case 2:
  85. this.currentPage = this.currentPage - 1;
  86. break;
  87. case 3:
  88. this.currentPage = this.currentPage + 1;
  89. break;
  90. case 4:
  91. this.currentPage = this.totalPage;
  92. break;
  93. }
  94. this.selectPublishPlatformPage(this.currentPage, this.pageSize);
  95. },
  96. // 展示、隐藏模态框
  97. showModal: function () {
  98. this.modalFlag = !this.modalFlag;
  99. },
  100. // 模态框保存
  101. submit: function (plateName) {
  102. this.addPublishPlatformInfo(plateName).then(() => {
  103. this.selectPublishPlatformPage(this.currentPage, this.pageSize);
  104. });
  105. this.modalFlag = false;
  106. },
  107. // 点击编辑
  108. edit(index, newName) {
  109. let id = this.tableData[index]["id"];
  110. console.log(id);
  111. this.updatePublishPlatformInfo(id, newName).then(() => {
  112. this.selectPublishPlatformPage(this.currentPage, this.pageSize);
  113. });
  114. },
  115. // 点击删除
  116. deleteData: function (index) {
  117. let id = this.tableData[index]["id"];
  118. this.deletePublishPlatformInfo(id).then(() => {
  119. this.selectPublishPlatformPage(this.currentPage, this.pageSize);
  120. });
  121. },
  122. // 点击平台板块
  123. jumpRouter: function (index) {
  124. // 页面变化
  125. this.$router.push({
  126. query: { tag: "detail", id: this.tableData[index]["id"] },
  127. });
  128. },
  129. // 新增平台 接口
  130. addPublishPlatformInfo: function (platformName) {
  131. return new Promise((resolve, reject) => {
  132. this.$http({
  133. method: "post",
  134. url: "/base/publishPlatformManager/addPublishPlatformInfo",
  135. data: {
  136. platformName,
  137. },
  138. })
  139. .then((res) => {
  140. if (res.data && res.data.code === 200) {
  141. console.log(res);
  142. resolve();
  143. } else {
  144. alert("新增失败,请重试");
  145. console.log(res);
  146. }
  147. })
  148. .catch((err) => {
  149. console.log(err);
  150. reject(err);
  151. });
  152. });
  153. },
  154. // 获取列表 接口
  155. selectPublishPlatformPage: function (page, rows) {
  156. this.$http({
  157. method: "post",
  158. url: "/base/publishPlatformManager/selectPublishPlatformPage",
  159. data: {
  160. page,
  161. rows,
  162. },
  163. })
  164. .then((res) => {
  165. if (res.data && res.data.code === 200) {
  166. console.log(res);
  167. this.tableData = res.data.data;
  168. this.sum = res.data.count;
  169. } else {
  170. console.log(res);
  171. }
  172. })
  173. .catch((err) => {
  174. console.log(err);
  175. });
  176. },
  177. // 编辑平台模块,接口
  178. updatePublishPlatformInfo: function (id, platformName) {
  179. return new Promise((resolve, reject) => {
  180. this.$http({
  181. method: "post",
  182. url: "/base/publishPlatformManager/updatePublishPlatformInfo",
  183. data: {
  184. id,
  185. platformName,
  186. },
  187. })
  188. .then((res) => {
  189. console.log(res, 1111);
  190. if (res.data && res.data.code === 200) {
  191. console.log(res);
  192. resolve();
  193. } else {
  194. alert("编辑失败,请重试");
  195. console.log(res);
  196. }
  197. })
  198. .catch((err) => {
  199. alert("编辑失败,请重试");
  200. console.log(err);
  201. reject(err);
  202. });
  203. });
  204. },
  205. // 删除平台模块 接口
  206. deletePublishPlatformInfo: function (id) {
  207. return new Promise((resolve, reject) => {
  208. this.$http({
  209. method: "post",
  210. url: "/base/publishPlatformManager/deletePublishPlatformInfo",
  211. data: {
  212. id,
  213. parentId: id,
  214. },
  215. })
  216. .then((res) => {
  217. if (res.data && res.data.code === 200) {
  218. console.log(res);
  219. resolve();
  220. } else {
  221. alert("删除失败,请重试");
  222. console.log(res);
  223. }
  224. })
  225. .catch((err) => {
  226. alert("编辑失败,请重试");
  227. console.log(err);
  228. reject(err);
  229. });
  230. });
  231. },
  232. },
  233. created() {
  234. this.selectPublishPlatformPage(this.currentPage, this.pageSize);
  235. },
  236. };
  237. </script>
  238. <style scoped lang="less">
  239. .car_series {
  240. .count {
  241. height: 40px;
  242. width: 100%;
  243. display: flex;
  244. justify-content: space-between;
  245. align-items: center;
  246. button {
  247. width: 86px;
  248. height: 30px;
  249. position: relative;
  250. bottom: -5px;
  251. margin: 0;
  252. border-radius: 2px;
  253. }
  254. }
  255. }
  256. </style>