DetailPage.vue 7.3 KB

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